Skip to content

Sound programming notes

arturoc edited this page Oct 3, 2012 · 57 revisions

Subclassing

subclassing ofBaseSoundStream

  • ofSoundStream's isSetup() calls getNumInputChannels() and getNumOutputChannels() to determine if the streaming system is setup or not. Make sure your subclass returns 0 for these immediately after construction.

subclassing ofBaseSoundOutput/ implementing audioOut

  • Wait for the call to buffersChanged() before setting up your internal buffers. Ensure you can cleanly tear down and setup again if buffersChanged() is called twice with different settings.
  • Until we have an internal FIFO on the ofSoundStream, audioOut is called on the sound card's timer thread, not the main thread. Make sure your audioOut is threadsafe but try not to do things that might block for a long time, like file I/O. If you need to do a lot of work, do it in a different thread that writes to a lock-free FIFO and read from this FIFO in audioOut. See Ross Bencina's guide for tips.
  • audioOut()'s float* output comes pre-cleared: audioOut does not need to set to 0 if it doesn't render anything

Todo

Testing

damian is developing on OSX

  • test iOS
  • test Linux
  • test Windows
  • test Android

ofSoundMixer

  • damian move ofMixer instance out of ofBasicSoundPlayer, make singleton

  • damian deal with singleton/root ofSoundStream instance: need some way of selecting the output at startup

    -(arturo) i would try to avoid singletons they give lots of headaches, instead every ofSoundStream should create it's own mixer then you can chain other mixers if needed. that way you can add more than one out to a soundstream transparently and it'll add them to it's internal mixer

ofBaseSoundStream, ofBaseSoundOutput subclasses

  • damian wip implement buffersChanged() method (called when buffer sizes changed, before audioOut is called: subclasses should overload this if they have an internal buffer that needs to be allocated to match the buffer size in audioOut())
  • migrate all subclasses to use audioOut( ofSoundBuffer& buffer ) instead of audioOut( float*, int, int )
  • change all testApp (examples, templates, ...) to use audioOut( ofSoundBuffer& buffer )
  • damian wip refactor bufferSize->numFrames, nChannels->nChannelsPerFrame

ofSoundStream

  • implement FIFO in ofSoundStream, default to calling audioOut on the main thread (increasing latency but making audio more robust and avoiding thread-safety issues)
  • allow users to switch audioOut calls from main thread to their own thread (for low-latency applications)
  • allow separate input and output device IDs

ofSoundBuffer

  • refactor bufferSize->numFrames
  • inspection methods? ofSoundBuffer::drawSpectrum()?
  • FFT methods

ofSoundFile

  • test libaudiodecoder streaming on iOS/OSX
  • build libaudiodecoder on Windows, test

ofVideoPlayer

  • optionally route audio from ofVideoPlayer through the system ofMixer

Clone this wiki locally