Skip to content

Sound programming notes

damiannz edited this page Oct 3, 2012 · 57 revisions

Subclassing

subclassing ofBaseSoundStream

  • ofSoundStream's isSetup() calls getNumInputChannels() and getNumOutputChannels() to determine if the 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 ofBaseSoundOutput::audioConnect() before setting up your internal buffers. Ensure you can cleanly tear down and setup again if audioConnect() 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 DON'T do this by using standard mutexes etc. Don't block! Don't do 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

ofSoundMixer

✓ move ofMixer instance out of ofBasicSoundPlayer, make singleton damian wip

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

ofSoundStream

  • implement FIFO in ofSoundStream so that audioOut can run on the main thread

ofSoundFile

  • test streaming on iOS/OSX

Clone this wiki locally