This is a new idea this time. Say I have an Array of sounds, where each sound represents a note on the piano. With an Accelerometer attached to my finger, If I move my hand upwards, it should run through the Array in an upward direction (so each sound becomes a higher pitch). If i move my hand down, the sound gets lower. I am trying to get it to sound how a kaossilator does. So whats the best approach to do this.
Example:
Say the middle point of the accelerometer is 500. 500 > is it moving upwards. 500 < is it moving downwards. To make it sensitive, I get it to play a new sound at each interval of 10 e.g. 500 > plays middle C < 510 510> plays middle D <520 etc. I would imagine this would be very memory intensive if at each interval (which will be a lot once the hand is moving around a lot), a new method has to be called to initialise and play a new sound. What would be the best way to handle possibly a large multiple of sounds which would be called within miliseconds of eachother?
My code example so far to show why it would currently be to intensive
if(Accelorometer.getValue() >500 && Accelorometer.getValue()<510)
{
playSound("Middle C");
}
if (Accelorometer.getValue() > 511 && Accelorometer.getValue() <520)
{
playSound("Middle D");
}
........
public static void playSound(String fileName) {
File soundFile = new File(fileName);
try {
AudioInputStream soundIn = AudioSystem.getAudioInputStream(soundFile);
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 16, 2, 4, AudioSystem.NOT_SPECIFIED, true);
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip)AudioSystem.getLine(info);
clip.open(soundIn);
clip.start();
}
catch (Exception ex) {}
}
So really, I will end up with 100 if statements all doing the same as above, which when set off within miliseconds of each other, would be far to much to handle. Sorry for dragging on, just want to give an idea of what I am doing. So what would be the best way to handle somthing like this?
cheers