We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to play a sound file controlled by a number. I have written this simplified code:-
import ddf.minim.*;
Minim minim;
AudioPlayer [] player= new AudioPlayer[5];
void setup()
{
size(512, 200);
minim = new Minim(this);
player[0] = minim.loadFile("1.wav");
player[1] = minim.loadFile("1.wav");
player[2] = minim.loadFile("1.wav");
player[3] = minim.loadFile("1.wav");
player[4] = minim.loadFile("1.wav");
}
void draw()
{ }
So I am loading in the same file five times. Four times it works fine but the fifth gives an error message:- ==== JavaSound Minim Error ==== ==== Unable to return a SourceDataLine: unsupported format - PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian
=== Minim Error ===
=== Couldn't load the file 1.wav
It is the same file so how can the format be wrong? I am using a Raspberry Pi, and four files ( different ones ) will play fine but when I extend it to 5 or above it fails. Is their another way to do what I want?
Thanks
Answers
Tagging @jeremydouglass as there is a better alternative to this approach.
Kf
@Grumpy_Mike --
This may be a basic limitation of memory (depending on the size of your audio files and the memory available on your Raspberry Pi. However -- one alternate approach with minim is to use Sampler, optionally with multiple voices. This is optimized for playing short audio clips that overlap and repeat.
For an example of using minim Sampler with bouncing ball noises, see:
https://forum.processing.org/two/discussion/comment/90737/#Comment_90737
Thanks for that. I had seen that link and couldn't see how that would give me say 12 different sounds, not the same ones.
My samples are short, no more that 130K each. I tried increasing the memory to 512M but it was still the same problem. I have also tried FilePlayer in place of AudioPlayer as suggested at the end of https://forum.processing.org/one/topic/minim-and-real-memory-memory.html but that gave me array out of bounds errors whenever I tried the .play() method.
Thanks for the hint. I have now got the sampler method to work. Just to round things off for anyone finding this here is my demo code that uses keys 0 to 8 to play samples 0.wav to 9.wav stored in the data folder.
Thanks guys.
@Grumpy_Mike -- glad it helped -- thanks for sharing your solution!