-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support and documentation for AudioSample/SoundFile multi-playback modes #91
Comments
Hello, you already found a solution with #92 but just to clarify:
Indeed there is no (decoding or memory) penalty whatsoever for creating new SoundFiles when one has been created from the same file/URL before: unless explicitly removed from cache, a reference to any decoded audio is kept as long as the sketch is running, new SoundFiles of the same audio files get their own playback/volume parameters but share the same audio data underneath. The internal cloning constructor mentioned above (which still only clones the playback settings, not the actual audio data) should probably be made public so that it's easier to create 'copies' of a SoundFile with all of its relevant parameters that might have been changed.. |
Hi,
I am trying to avoid clipping when playing multiple times the single SoundFile sample. I am using version 2.4.0-preview (in version 2.3.1 it behaves the same). However, I can NOT control volume of multiple playbacks of soundFile instance. If you repeatedly call .play() you will get multiple laybacks of the sample over each other - however I can only control volume of the first one even if I save the instance to variable. Simple example:
Instance inside ArrayList of Class example:
When loading new sample file each time it works but that's not good for performance? Currently we can trigger multiple sounds referencing single file but we can only control the volume of the first instance (this is probably true for other variables such as rate? I did not test that thought)
I would like to see a getter to all instances of the sample being played - like sample.getPlaybacks() - returning array of instances on which I can call amp() pan() rate() stop() play() loop(). Normal behavior of these functions can stay as they are. Alternatively we can have an overloaded function amp(float volume, int instance index) and such - so it can be called without the index in which case the first instance is assumed or with index in which case we try to issue the command to particular instance?
I have also found this function:
[removeFromCache()](https://processing.org/reference/libraries/sound/SoundFile_removeFromCache_.html)
So I might use that to dispose of the soundFile when not needed. I also tried performance test - loading hundreds of files (but the same one file on the disk - just hundreds call to new SoundFile() ) but either my PC is too powerful or there is no penalty for this? What is going on behind the scenes when creating a new SounFile() from file? Does it check if it is already in RAM? In that case I can simply load as many as I like....not sure about this.
I just might need clarification on how to think about this. Thanks a lot.
Relevant source code:
https://github.com/processing/processing-sound/blob/main/src/processing/sound/SoundFile.java
https://github.com/processing/processing-sound/blob/main/src/processing/sound/AudioSample.java
line 308 in AudioSample.java
Will return new copy of AudioSample(this) - but that is not visible from sampleFile I guess?
And line 461
So I think we want that reference here?
The text was updated successfully, but these errors were encountered: