Thanks! That totally put me on the right track…and thanks for reminding my about WolframAlpha - I’d totally forgotten about the handy graphing function.
A couple of things I found were:
* ln isn’t defined on my PC…it seems log on Win is log[sub]e[/sub] ?
* I used log10 in the end as this seems closer to what I could find as a ‘natural’ dB damping curve and makes all the maths a little nicer looking…I think the way audio programs work is by changing the log/exp base in order to vary the ‘steepness’ of the attack/dropoff - would be nice to implement this but didn’t have time to figure out how to get the log of any base
* I struggled to figure out how to invert this (ie., do an exponential fade in-out) and ended up having to resort to a magic number:
this is exactly what I was looking for. However, I have just started with oF. Could you give an example of how you use it to fade out a sound file?
I am re-programming an app I once built for school children in Max/MSP. It is basically a very simple sampler. The kids see a computer keyboard on the screen, can drag and drop samples onto the keys and then, when pressing those keys on the real computer keyboard, can play back the according samples. The samples play as long, as the keys are pressed down. When the key is released the according sample stops.Now, I want to call your fader when a key is released and only afterwards stop the sample. I am not sure how to call the Fader and also am not sure how to stop the playback only after the time of the fading has passed…
I would appreciate a simple example of how you used it…
I’ve cleaned up the Fader.h class a little bit and made two examples.
The first draws the fades and shows a simple sound fade; the second pretty much does what you want (I think) - I tried to come up with something that demonstrated the idea without actually doing the key/play sound idea, but in the end it was easiest to just try it out…
Because of the nature of threads and copy constructors I’ve had to make the Fader class work only as a pointer. I’m not sure how far down the c++ track you’ve come with pointers and references, but it does make using this class a little unwieldy…I’m sure there’s a nicer/simpler way, particularly if all you need is fade up and down of a sound file (ie., you could modify the guts of the Fader.h class so that everything that gets called in the threadedFunction() actually happens in an update method)…but I wanted to use it for several things (fades to black, etc) so made this class instead.
Thank you so much. I am looking into it right now…I really appreciate it and actually I am glad you programmed it so flexible and powerful, it already inspired me to use it for visual feedback as well. Perfect. Thanks again!
IOhanna
it is really great and helpful, thanks again!
After playing with it for a while I found out how to crash it by triggering a sample very quickly again and again (pressing the a or b button as fast as I can a few times in a row). I get the same **Mutex_POSIX.h cannot unlock mutex **error message as described on the forum earlier in here (http://forum.openframeworks.cc/t/mutex-posix.h-cannot-unlock-mutex/7073/0)
I’m not super good with mutex and threaded functions
I think maybe it’s because the way I’ve coded it the mutex’s are actually separate instances, rather than a single static mutex shared between all the threaded instances of the Faders…
This is very useful.
I used this code to create a multitrack player with a single ofThread.
Tracks that have to loop start again some time before finishing to create a continuous loop without any interruption. This code has been used to play continuous ambient sounds. The exponential fade is the most natural one for my ears.
It shouldn’t be used with tracks that have a perfect loop and don’t need to crossfade with themselves.
Also the file duration in ms should be greater than the fade duration (now it is 2 seconds).
Supported files: wav, aif, mp3, with sample rate 44100 and bit depth 16bit. Mp3s should be encoded with constant bitrate (this infos are needed to calculate the duration of the audio files since ofSoundPlayer has no method for that).
Works best with wav or aif files, sometimes mp3s don’t start, maybe caused by strange encodings.
It can be improved adding some mutex locking so that tracks can be added on the fly.
For now it is advised to add new tracks before any loading/playing.
Tested with OF 0.9.8 on Ubuntu 16.10 and Mac OS X 10.9.5.
Thank you gameover for your code!
Suggestions or improvements are welcome testAudioThread.zip (1.7 MB)