We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › keep hasmap of buffered audiosamples
Page Index Toggle Pages: 1
keep hasmap of buffered audiosamples? (Read 499 times)
keep hasmap of buffered audiosamples?
Feb 21st, 2009, 9:25am
 
hey minim wizards.

i want to load a bunch of audiosamples, keep them in a hashmap (or other data structure, but a map would be convenient if possible), then retrieve a specific object from the map using an ID key and trigger it.

the code i have gives me a null pointer exception on the last line [a.trigger()]. though the audiosample object exists and can be successfully triggered before i put it in the hashmap (i tried it), all i get in the hashmap are null objects.

any suggestions, hints or thoughts would be greatly appreciated :)

---
import ddf.minim.*;

Map sounds = new HashMap();
int numFidID = 14;
String[] audioTitles = new String[numFidID];
Minim minim;

void setup(){
 minim = new Minim(this);
 String fileName = "titles_small.txt";
 readTitlesFromFile(fileName);
 loadSounds();
 playSound(0);
}

void readTitlesFromFile(String fileName){
 audioTitles = loadStrings(fileName);
 }
}

void loadSounds() {
 for(int fidID = 0; fidID < numFidID; fidID++){
    AudioSample sample = minim.loadSample(audioTitles[fidID], 2048);
    sounds.put(Integer.toString(fidID), sample);
 }
}

void playSound(int fidID){
 AudioSample a = (AudioSample)sounds.get(fidID);
 a.trigger();
}
---
Re: keep hasmap of buffered audiosamples?
Reply #1 - Feb 21st, 2009, 12:51pm
 
have you tried printing out the value of sample during loadSounds() and of a in playSound()? are they sensible?

the only other thing i notice is that you're putting with Integer.toString(fidID) but getting with just (int)fidID. i think the autoboxing should handle this but...
Re: keep hasmap of buffered audiosamples?
Reply #2 - Feb 21st, 2009, 8:09pm
 
oh, it was the getting part i was doing wrong, it totally works now Smiley thank you so much, i've been going crazy over this!
Page Index Toggle Pages: 1