Vuo  2.0.0
Classes | Macros | Typedefs | Functions | Variables
VuoAudio.cc File Reference

Description

VuoAudio implementation.

Definition in file VuoAudio.cc.

Go to the source code of this file.

Classes

struct  _VuoAudio_internal
 Private data for a VuoAudio instance. More...
 

Macros

#define setRealizedDevice(newDevice)
 Helper for VuoAudioInputDevice_realize. More...
 

Typedefs

typedef std::map< void *, std::queue< VuoList_VuoAudioSamples > > pendingOutputType
 For each unique audio source (identified by void *), a queue of buffers to output. More...
 
typedef std::map< void *, std::map< VuoInteger, VuoReal > > lastOutputSampleType
 For each unique audio source (identified by void *), the last sample value that was output on each channel. More...
 
typedef struct _VuoAudio_internalVuoAudio_internal
 Private data for a VuoAudio instance. More...
 

Functions

static void __attribute__ ((constructor)) VuoAudio_init()
 Ensure we're listening for the system's device notifications. More...
 
VuoList_VuoAudioInputDevice VuoAudio_getInputDevices (void)
 Returns a list of the available audio input devices. More...
 
VuoList_VuoAudioOutputDevice VuoAudio_getOutputDevices (void)
 Returns a list of the available audio output devices. More...
 
static OSStatus VuoAudio_reconfigurationCallback (AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses, void *inClientData)
 Invoked by Core Audio. More...
 
void VuoAudio_use (void)
 Indicates that the caller needs to get notifications about audio devices. More...
 
void VuoAudio_disuse (void)
 Indicates that the caller no longer needs notifications about audio devices. More...
 
void VuoAudio_addDevicesChangedTriggers (VuoOutputTrigger(inputDevices, VuoList_VuoAudioInputDevice), VuoOutputTrigger(outputDevices, VuoList_VuoAudioOutputDevice))
 Adds a trigger callback, to be invoked whenever the list of known audio devices changes. More...
 
void VuoAudio_removeDevicesChangedTriggers (VuoOutputTrigger(inputDevices, VuoList_VuoAudioInputDevice), VuoOutputTrigger(outputDevices, VuoList_VuoAudioOutputDevice))
 Removes a trigger callback previously added by VuoAudio_addDevicesChangedTriggers. More...
 
int VuoAudio_receivedEvent (void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData)
 RtAudio calls this function when a new sample buffer is ready or needed. More...
 
VuoAudioIn VuoAudioIn_getShared (VuoAudioInputDevice aid)
 Returns the reference-counted object for the specified audio input device. More...
 
VuoAudioOut VuoAudioOut_getShared (VuoAudioOutputDevice aod)
 Returns the reference-counted object for the specified audio output device. More...
 
void VuoAudioIn_addTrigger (VuoAudioIn ai, VuoOutputTrigger(receivedChannels, VuoList_VuoAudioSamples))
 Sets up the audio input device to call the trigger functions when it receives an event. More...
 
void VuoAudioOut_addTrigger (VuoAudioOut ao, VuoOutputTrigger(requestedChannels, VuoReal))
 Sets up the audio output device to call the trigger functions when it receives an event. More...
 
void VuoAudioIn_removeTrigger (VuoAudioIn ai, VuoOutputTrigger(receivedChannels, VuoList_VuoAudioSamples))
 Stops the audio input device from calling trigger functions when it receives an event. More...
 
void VuoAudioOut_removeTrigger (VuoAudioOut ao, VuoOutputTrigger(requestedChannels, VuoReal))
 Stops the audio output device from calling trigger functions when it receives an event. More...
 
void VuoAudioOut_sendChannels (VuoAudioOut ao, VuoList_VuoAudioSamples channels, void *id)
 Enqueues channels for eventual playback. More...
 
bool VuoAudioInputDevice_realize (VuoAudioInputDevice device, VuoAudioInputDevice *realizedDevice)
 If device's channel count is unknown (zero): More...
 
bool VuoAudioOutputDevice_realize (VuoAudioOutputDevice device, VuoAudioOutputDevice *realizedDevice)
 If device's channel count is unknown (zero): More...
 
 VUOKEYEDPOOL (unsigned int, VuoAudio_internal)
 
static void VuoAudio_destroy (VuoAudio_internal ai)
 
VuoAudio_internal VuoAudio_make (unsigned int deviceId)
 
 VUOKEYEDPOOL_DEFINE (unsigned int, VuoAudio_internal, VuoAudio_make)
 

Variables

const VuoInteger VuoAudio_queueSize = 8
 The number of buffers that must be enqueued before starting playback. More...
 
static VuoTriggerSet< VuoList_VuoAudioInputDeviceVuoAudio_inputDeviceCallbacks
 Trigger functions to call when the list of audio input devices changes. More...
 
static VuoTriggerSet< VuoList_VuoAudioOutputDeviceVuoAudio_outputDeviceCallbacks
 Trigger functions to call when the list of audio output devices changes. More...
 
unsigned int VuoAudio_useCount = 0
 Process-wide count of callers (typically node instances) interested in notifications about audio devices. More...
 

Class Documentation

◆ _VuoAudio_internal

struct _VuoAudio_internal
Class Members
VuoAudioInputDevice inputDevice The device's id must be nonnegative, and channelCount must be set.
VuoTriggerSet< VuoList_VuoAudioSamples > inputTriggers Trigger methods to call when an audio buffer is received.
lastOutputSampleType lastOutputSample The last sample value sent on each channel (to smoothly move back to 0 DC when there's a dropout). Not present means no buffer was sent to the channel during the last frame.
VuoAudioOutputDevice outputDevice The device's id must be nonnegative, and channelCount must be set.
VuoTriggerSet< VuoReal > outputTriggers Trigger methods to call when an audio buffer is needed.
pendingOutputType pendingOutput Sample buffers waiting to be output.
dispatch_queue_t pendingOutputQueue Serializes access to the following set of buffers.
VuoReal priorStreamTime The time at which the prior VuoAudio_receivedEvent() happened, to track stream overflows.
RtAudio * rta RtAudio's device pointer.

Macro Definition Documentation

◆ setRealizedDevice

#define setRealizedDevice (   newDevice)
Value:
realizedDevice->id = newDevice.id; \
realizedDevice->modelUid = VuoText_make(newDevice.modelUid); \
realizedDevice->name = VuoText_make(newDevice.name); \
realizedDevice->channelCount = newDevice.channelCount;

Helper for VuoAudioInputDevice_realize.

Definition at line 608 of file VuoAudio.cc.

Typedef Documentation

◆ lastOutputSampleType

typedef std::map<void *, std::map<VuoInteger, VuoReal> > lastOutputSampleType

For each unique audio source (identified by void *), the last sample value that was output on each channel.

Definition at line 205 of file VuoAudio.cc.

◆ pendingOutputType

typedef std::map<void *, std::queue<VuoList_VuoAudioSamples> > pendingOutputType

For each unique audio source (identified by void *), a queue of buffers to output.

Definition at line 200 of file VuoAudio.cc.

◆ VuoAudio_internal

Private data for a VuoAudio instance.

Function Documentation

◆ __attribute__()

static void __attribute__ ( (constructor)  )
static

Ensure we're listening for the system's device notifications.

https://b33p.net/kosada/node/12551 http://lists.apple.com/archives/Coreaudio-api/2010/Aug//msg00304.html

Definition at line 59 of file VuoAudio.cc.

◆ VuoAudio_addDevicesChangedTriggers()

void VuoAudio_addDevicesChangedTriggers ( VuoOutputTrigger(inputDevices, VuoList_VuoAudioInputDevice ,
VuoOutputTrigger(outputDevices, VuoList_VuoAudioOutputDevice  
)

Adds a trigger callback, to be invoked whenever the list of known audio devices changes.

Call VuoAudio_use() before calling this.

This function may be called from any thread.

Changed in Vuo 2.0.0:
New.

Definition at line 177 of file VuoAudio.cc.

◆ VuoAudio_destroy()

static void VuoAudio_destroy ( VuoAudio_internal  ai)
static

Definition at line 445 of file VuoAudio.cc.

◆ VuoAudio_disuse()

void VuoAudio_disuse ( void  )

Indicates that the caller no longer needs notifications about audio devices.

This function may be called from any thread.

Changed in Vuo 2.0.0:
New.

Definition at line 145 of file VuoAudio.cc.

◆ VuoAudio_getInputDevices()

VuoList_VuoAudioInputDevice VuoAudio_getInputDevices ( void  )

Returns a list of the available audio input devices.

Definition at line 74 of file VuoAudio.cc.

◆ VuoAudio_getOutputDevices()

VuoList_VuoAudioOutputDevice VuoAudio_getOutputDevices ( void  )

Returns a list of the available audio output devices.

Definition at line 91 of file VuoAudio.cc.

◆ VuoAudio_make()

VuoAudio_internal VuoAudio_make ( unsigned int  deviceId)

Definition at line 363 of file VuoAudio.cc.

◆ VuoAudio_receivedEvent()

int VuoAudio_receivedEvent ( void *  outputBuffer,
void *  inputBuffer,
unsigned int  nBufferFrames,
double  streamTime,
RtAudioStreamStatus  status,
void *  userData 
)

RtAudio calls this function when a new sample buffer is ready or needed.

Definition at line 230 of file VuoAudio.cc.

◆ VuoAudio_reconfigurationCallback()

static OSStatus VuoAudio_reconfigurationCallback ( AudioObjectID  inObjectID,
UInt32  inNumberAddresses,
const AudioObjectPropertyAddress *  inAddresses,
void *  inClientData 
)
static

Invoked by Core Audio.

Definition at line 108 of file VuoAudio.cc.

◆ VuoAudio_removeDevicesChangedTriggers()

void VuoAudio_removeDevicesChangedTriggers ( VuoOutputTrigger(inputDevices, VuoList_VuoAudioInputDevice ,
VuoOutputTrigger(outputDevices, VuoList_VuoAudioOutputDevice  
)

Removes a trigger callback previously added by VuoAudio_addDevicesChangedTriggers.

This function may be called from any thread.

Changed in Vuo 2.0.0:
New.

Definition at line 191 of file VuoAudio.cc.

◆ VuoAudio_use()

void VuoAudio_use ( void  )

Indicates that the caller needs to get notifications about audio devices.

This function may be called from any thread.

Changed in Vuo 2.0.0:
New.

Definition at line 121 of file VuoAudio.cc.

◆ VuoAudioIn_addTrigger()

void VuoAudioIn_addTrigger ( VuoAudioIn  ai,
VuoOutputTrigger(receivedChannels, VuoList_VuoAudioSamples  
)

Sets up the audio input device to call the trigger functions when it receives an event.

This function may be called from any thread.

Definition at line 519 of file VuoAudio.cc.

◆ VuoAudioIn_getShared()

VuoAudioIn VuoAudioIn_getShared ( VuoAudioInputDevice  aid)

Returns the reference-counted object for the specified audio input device.

Definition at line 484 of file VuoAudio.cc.

◆ VuoAudioIn_removeTrigger()

void VuoAudioIn_removeTrigger ( VuoAudioIn  ai,
VuoOutputTrigger(receivedChannels, VuoList_VuoAudioSamples  
)

Stops the audio input device from calling trigger functions when it receives an event.

This function may be called from any thread.

Definition at line 555 of file VuoAudio.cc.

◆ VuoAudioInputDevice_realize()

bool VuoAudioInputDevice_realize ( VuoAudioInputDevice  device,
VuoAudioInputDevice realizedDevice 
)

If device's channel count is unknown (zero):

  • If a matching device is present, sets realizedDevice to that device, and returns true.
  • If no matching device is present, returns false, leaving realizedDevice unset.

If device's channel count is already known (presumably from the List Audio Devices node), sets realizedDevice to a copy of device, and returns true. (Doesn't bother checking whether the device is currently present.)

This function may be called from any thread.

Definition at line 626 of file VuoAudio.cc.

◆ VuoAudioOut_addTrigger()

void VuoAudioOut_addTrigger ( VuoAudioOut  ao,
VuoOutputTrigger(requestedChannels, VuoReal  
)

Sets up the audio output device to call the trigger functions when it receives an event.

This function may be called from any thread.

Definition at line 537 of file VuoAudio.cc.

◆ VuoAudioOut_getShared()

VuoAudioOut VuoAudioOut_getShared ( VuoAudioOutputDevice  aod)

Returns the reference-counted object for the specified audio output device.

Definition at line 500 of file VuoAudio.cc.

◆ VuoAudioOut_removeTrigger()

void VuoAudioOut_removeTrigger ( VuoAudioOut  ao,
VuoOutputTrigger(requestedChannels, VuoReal  
)

Stops the audio output device from calling trigger functions when it receives an event.

This function may be called from any thread.

Definition at line 573 of file VuoAudio.cc.

◆ VuoAudioOut_sendChannels()

void VuoAudioOut_sendChannels ( VuoAudioOut  ao,
VuoList_VuoAudioSamples  channels,
void *  id 
)

Enqueues channels for eventual playback.

id should be a unique identifier for the audio stream (e.g., a pointer to the node's instance data).

When multiple sources are simultaneously sending to the same audio device, each is buffered independently — each unique id gets its own queue, and at output time a single buffer from each source's queue is mixed to form the final output stream.

Definition at line 595 of file VuoAudio.cc.

◆ VuoAudioOutputDevice_realize()

bool VuoAudioOutputDevice_realize ( VuoAudioOutputDevice  device,
VuoAudioOutputDevice realizedDevice 
)

If device's channel count is unknown (zero):

  • If a matching device is present, sets realizedDevice to that device, and returns true.
  • If no matching device is present, returns false, leaving realizedDevice unset.

If device's channel count is already known (presumably from the List Audio Devices node), sets realizedDevice to a copy of device, and returns true. (Doesn't bother checking whether the device is currently present.)

This function may be called from any thread.

Definition at line 735 of file VuoAudio.cc.

◆ VUOKEYEDPOOL()

VUOKEYEDPOOL ( unsigned int  ,
VuoAudio_internal   
)

◆ VUOKEYEDPOOL_DEFINE()

VUOKEYEDPOOL_DEFINE ( unsigned int  ,
VuoAudio_internal  ,
VuoAudio_make   
)

Variable Documentation

◆ VuoAudio_inputDeviceCallbacks

VuoTriggerSet<VuoList_VuoAudioInputDevice> VuoAudio_inputDeviceCallbacks
static

Trigger functions to call when the list of audio input devices changes.

Definition at line 50 of file VuoAudio.cc.

◆ VuoAudio_outputDeviceCallbacks

VuoTriggerSet<VuoList_VuoAudioOutputDevice> VuoAudio_outputDeviceCallbacks
static

Trigger functions to call when the list of audio output devices changes.

Definition at line 51 of file VuoAudio.cc.

◆ VuoAudio_queueSize

const VuoInteger VuoAudio_queueSize = 8

The number of buffers that must be enqueued before starting playback.

Definition at line 48 of file VuoAudio.cc.

◆ VuoAudio_useCount

unsigned int VuoAudio_useCount = 0

Process-wide count of callers (typically node instances) interested in notifications about audio devices.

Definition at line 52 of file VuoAudio.cc.