I have a project where I am trying to play a sound every time an enemy shoots at you, The only problem is that when too many sounds are played they all get super distorted and never actually stop playing, I will try to include the code but the whole game is several thousand lines so I have added a video showing it instead of the code because even when I shortened it as much as possible I was still almost 10,000 characters over the limit
here is the video link, the problem starts at about 1:07 if you want I can share some of the code
1 Like
Create a version of your code that deletes everything except the audio clip and the call to the sound, like this:
// import libraries
// global audio variables
void setup(){
frameRate(4);
// set up your audio object(s)
}
void draw(){
myObject.playSound(); // just play your sound
}
This will start playing the sound file four times per second. It will help explore your problem and also show us what spefically.
Share that. Are you using a minim Sampler object? This is what they are for.
http://code.compartmental.net/minim/sampler_class_sampler.html
here I just put the whole project on github
1 Like
It looks like you aren’t using a minim Sampler object. I would recommend using a minim Sampler object. Multiple overlapping “voices” is what they are for.
1 Like
I couldn’t find the documentation for that, could you link it?
I already included the link in my last post.
http://code.compartmental.net/minim/sampler_class_sampler.html
Sampler is the UGen version of AudioSample and is the preferred method of triggering short audio files. You will also find Sampler much more flexible, since it provides ways to trigger only part of a sample, and to trigger a sample at different playback rates. Also, unlike AudioSample, a Sampler lets you specify how many voices (i.e. simultaneous playbacks of the sample) should have.
You could also use the older minim class AudioSample.
http://code.compartmental.net/minim/audiosample_class_audiosample.html
An AudioSample
keeps the entire file in an internal buffer and all you can do is trigger()
the sound. However, you can trigger the sound even if it is still playing back. It is not advised that you use this class for long sounds (like entire songs, for example) because the entire file is kept in memory.
There is a demo sketch in the minim examples, PDE > File > Examples > Contributed > Minim > Basics > TriggerAsSample
1 Like
oh, sorry, Im in school and my brain is scattered right now
1 Like
ok, Ive done all that and now the sounds play without issue so thank you, but I now can’t figure out how to change the amplitude on the sound files with a variable that can be changed and stored as a volume setting, with different volumes for certain types of sounds eg, music, enemies, etc.
It is in the documentation. If you are using a Sampler, then just use the sampler amplitude field.
http://code.compartmental.net/minim/sampler_field_amplitude.html
The amplitude of this Sampler. This acts as an overall volume control. So changing the amplitude will effect all currently active voices.
You can see all the available fields and methods of the Sampler on the left of its documentation page.