We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I've try to load 2nd source file into minim sample. Because I need to change the sound effect in my program at runtime. With first loading source file into sample, every is OK. But with loading 2nd one, it's failed and there is no sound. So the question is: What I missed?
Example code:
import ddf.minim.*;
Minim minim;
AudioSample sample;
void setup()
{
size(512, 200, P3D);
minim = new Minim(this);
sample = minim.loadSample( "BD.mp3", 512);
sample = minim.loadSample( "SD.wav", 512); //this doesn't work
}
void draw()
{
}
void keyPressed()
{
if ( key == 's' )
{
sample.trigger();
}
}
Error message:
==== JavaSound Minim Error ==== ==== Couldn't open the line: line with format PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
==== JavaSound Minim Error ==== ==== Unable to return a SourceDataLine: unsupported format - PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian
Answers
Apparently, Minim doesn't like the file format of the second file. You can try and convert it to another format.
Dunno what the problem is, but reassigning a newly initialized variable w/ another object got no much logic!
Yeah, this too, but this is "Example code", made to avoid showing a full project, which is a good thing. Perhaps it was simplified a bit too much... :-)
The problem is, that I have a triggered "play" function somewhere in project and I need change source file to play at runtime. Both of these audio files presented here are from minim example "TriggerASample", so these files are OK for loading and playing. If PhiLho want see project, go here: https://github.com/laabicz/HomeLESS/tree/master/HomeLESS_Hit_Analyzer, but "Example code" is OK for this problem.
GoToLoop: There is no logic, this is just example :).
@Laabicz, you can always keep them all in some data structure, an array for example, and then assign 1 of them to sample when it's time to change! O:-)
Hi, I tried your advice. But there is the same problem... :( There must be something else at this library... :-?
Uh? You don't need two instances of Minim, but you need two instances of sample.
I just tested the above code (replacing (without saving!) the code in the TriggerASample sketch), and it works fine on my Windows 7 computer, with Processing 2.2.1.
1 Minim instance is all we need! And variables can only hold 1 single value at a time.
We need an object to hold more than 1 value at a time. Simplest 1 is a regular array[].
W/ an array[], the only extra value we need is the index we wanna access. Let's call it idx.
I've adapted the code above to have a samples[] array rather than 2 separate AudioSample variables:
P.S.: Oops! Didn't see @PhiLho's answer! :-\"