svapp  1.9
AudioCallbackPlaySource Class Reference

AudioCallbackPlaySource manages audio data supply to callback-based audio APIs such as JACK or CoreAudio. More...

#include <AudioCallbackPlaySource.h>

Collaboration diagram for AudioCallbackPlaySource:

List of all members.

Classes

class  FillThread
class  RingBufferVector

Public Slots

void audioProcessingOverload ()

Signals

void modelReplaced ()
void playStatusChanged (bool isPlaying)
void sampleRateMismatch (int requested, int available, bool willResample)
void audioOverloadPluginDisabled ()
void audioTimeStretchMultiChannelDisabled ()
void activity (QString)

Public Member Functions

 AudioCallbackPlaySource (ViewManagerBase *, QString clientName)
virtual ~AudioCallbackPlaySource ()
virtual void addModel (Model *model)
 Add a data model to be played from.
virtual void removeModel (Model *model)
 Remove a model.
virtual void clearModels ()
 Remove all models.
virtual void play (int startFrame)
 Start making data available in the ring buffers for playback, from the given frame.
virtual void stop ()
 Stop playback and ensure that no more data is returned.
virtual bool isPlaying () const
 Return whether playback is currently supposed to be happening.
virtual int getCurrentPlayingFrame ()
 Return the frame number that is currently expected to be coming out of the speakers.
virtual int getCurrentBufferedFrame ()
 Return the last frame that would come out of the speakers if we stopped playback right now.
virtual int getPlayEndFrame ()
 Return the frame at which playback is expected to end (if not looping).
void setTarget (AudioCallbackPlayTarget *, int blockSize)
 Set the target and the block size of the target audio device.
int getTargetBlockSize () const
 Get the block size of the target audio device.
void setTargetPlayLatency (int)
 Set the playback latency of the target audio device, in frames at the target sample rate.
int getTargetPlayLatency () const
 Get the playback latency of the target audio device.
void setTargetSampleRate (int)
 Specify that the target audio device has a fixed sample rate (i.e.
virtual int getTargetSampleRate () const
 Return the sample rate set by the target audio device (or the source sample rate if the target hasn't set one).
void setOutputLevels (float left, float right)
 Set the current output levels for metering (for call from the target)
virtual bool getOutputLevels (float &left, float &right)
 Return the current (or thereabouts) output levels in the range 0.0 -> 1.0, for metering purposes.
int getSourceChannelCount () const
 Get the number of channels of audio that in the source models.
int getTargetChannelCount () const
 Get the number of channels of audio that will be provided to the play target.
virtual int getSourceSampleRate () const
 Get the actual sample rate of the source material.
int getSourceSamples (int count, float **buffer)
 Get "count" samples (at the target sample rate) of the mixed audio data, in all channels.
void setTimeStretch (float factor)
 Set the time stretcher factor (i.e.
void setResampleQuality (int q)
 Set the resampler quality, 0 - 2 where 0 is fastest and 2 is highest quality.
void setAuditioningEffect (Auditionable *plugin)
 Set a single real-time plugin as a processing effect for auditioning during playback.
void setSoloModelSet (std::set< Model * >s)
 Specify that only the given set of models should be played.
void clearSoloModelSet ()
 Specify that all models should be played as normal (if not muted).
QString getClientName () const

Protected Slots

void selectionChanged ()
void playLoopModeChanged ()
void playSelectionModeChanged ()
void playParametersChanged (PlayParameters *)
void preferenceChanged (PropertyContainer::PropertyName)
void modelChangedWithin (int startFrame, int endFrame)

Protected Member Functions

RingBuffer< float > * getWriteRingBuffer (int c)
RingBuffer< float > * getReadRingBuffer (int c)
void clearRingBuffers (bool haveLock=false, int count=0)
void unifyRingBuffers ()
bool fillBuffers ()
int mixModels (int &frame, int count, float **buffers)
void applyAuditioningEffect (int count, float **buffers)
void rebuildRangeLists ()
int getCurrentFrame (RealTime outputLatency)
void initialiseConverter ()

Protected Attributes

ViewManagerBase * m_viewManager
AudioGeneratorm_audioGenerator
QString m_clientName
std::set< Model * > m_models
RingBufferVectorm_readBuffers
RingBufferVectorm_writeBuffers
int m_readBufferFill
int m_writeBufferFill
Scavenger< RingBufferVectorm_bufferScavenger
int m_sourceChannelCount
int m_blockSize
int m_sourceSampleRate
int m_targetSampleRate
int m_playLatency
AudioCallbackPlayTargetm_target
double m_lastRetrievalTimestamp
int m_lastRetrievedBlockSize
bool m_trustworthyTimestamps
int m_lastCurrentFrame
bool m_playing
bool m_exiting
int m_lastModelEndFrame
int m_ringBufferSize
float m_outputLeft
float m_outputRight
RealTimePluginInstance * m_auditioningPlugin
bool m_auditioningPluginBypassed
Scavenger< RealTimePluginInstance > m_pluginScavenger
int m_playStartFrame
bool m_playStartFramePassed
RealTime m_playStartedAt
RubberBand::RubberBandStretcher * m_timeStretcher
RubberBand::RubberBandStretcher * m_monoStretcher
float m_stretchRatio
bool m_stretchMono
int m_stretcherInputCount
float ** m_stretcherInputs
int * m_stretcherInputSizes
std::vector< RealTime > m_rangeStarts
std::vector< RealTime > m_rangeDurations
QMutex m_mutex
QWaitCondition m_condition
FillThreadm_fillThread
SRC_STATE * m_converter
SRC_STATE * m_crapConverter
int m_resampleQuality

Detailed Description

AudioCallbackPlaySource manages audio data supply to callback-based audio APIs such as JACK or CoreAudio.

It maintains one ring buffer per channel, filled during playback by a non-realtime thread, and provides a method for a realtime thread to pick up the latest available sample data from these buffers.

Definition at line 54 of file AudioCallbackPlaySource.h.


Constructor & Destructor Documentation


Member Function Documentation

void AudioCallbackPlaySource::addModel ( Model *  model) [virtual]

Add a data model to be played from.

The source can mix playback from a number of sources including dense and sparse models. The models must match in sample rate, but they don't have to have identical numbers of channels.

Definition at line 148 of file AudioCallbackPlaySource.cpp.

References AudioGenerator::addModel(), clearRingBuffers(), getTargetChannelCount(), m_audioGenerator, m_condition, m_converter, m_crapConverter, m_fillThread, m_lastModelEndFrame, m_models, m_mutex, m_sourceChannelCount, m_sourceSampleRate, m_writeBuffers, modelChangedWithin(), modelReplaced(), rebuildRangeLists(), sampleRateMismatch(), and AudioGenerator::setTargetChannelCount().

Referenced by MainWindowBase::layerInAView(), and MainWindowBase::modelAdded().

void AudioCallbackPlaySource::stop ( ) [virtual]

Stop playback and ensure that no more data is returned.

Definition at line 489 of file AudioCallbackPlaySource.cpp.

References activity(), m_condition, m_lastCurrentFrame, m_lastRetrievalTimestamp, m_playing, m_sourceSampleRate, and playStatusChanged().

Referenced by getCurrentFrame(), and MainWindowBase::stop().

Return the frame number that is currently expected to be coming out of the speakers.

(i.e. compensating for playback latency.)

Definition at line 612 of file AudioCallbackPlaySource.cpp.

References getCurrentFrame(), getTargetSampleRate(), and m_playLatency.

Referenced by clearRingBuffers(), and MainWindowBase::getFrame().

Return the last frame that would come out of the speakers if we stopped playback right now.

Definition at line 629 of file AudioCallbackPlaySource.cpp.

References getCurrentFrame().

Referenced by clearRingBuffers(), and MainWindowBase::currentPaneChanged().

virtual int AudioCallbackPlaySource::getPlayEndFrame ( ) [inline, virtual]

Return the frame at which playback is expected to end (if not looping).

Definition at line 113 of file AudioCallbackPlaySource.h.

References m_lastModelEndFrame.

Referenced by MainWindowBase::playbackFrameChanged(), and MainWindowBase::zoomToFit().

void AudioCallbackPlaySource::setTarget ( AudioCallbackPlayTarget target,
int  blockSize 
)

Set the target and the block size of the target audio device.

This should be called by the target class.

Definition at line 573 of file AudioCallbackPlaySource.cpp.

References clearRingBuffers(), m_blockSize, m_ringBufferSize, m_target, and m_writeBuffers.

Referenced by AudioJACKTarget::sourceModelReplaced(), and AudioJACKTarget::~AudioJACKTarget().

Get the block size of the target audio device.

This may be an estimate or upper bound, if the target has a variable block size; the source should behave itself even if this value turns out to be inaccurate.

Definition at line 593 of file AudioCallbackPlaySource.cpp.

References m_blockSize.

Referenced by getCurrentFrame().

Set the playback latency of the target audio device, in frames at the target sample rate.

This is the difference between the frame currently "leaving the speakers" and the last frame (or highest last frame across all channels) requested via getSamples(). The default is zero.

Definition at line 600 of file AudioCallbackPlaySource.cpp.

References m_playLatency.

Referenced by AudioJACKTarget::sourceModelReplaced().

Get the playback latency of the target audio device.

Definition at line 606 of file AudioCallbackPlaySource.cpp.

References m_playLatency.

Specify that the target audio device has a fixed sample rate (i.e.

cannot accommodate arbitrary sample rates based on the source). If the target sets this to something other than the source sample rate, this class will resample automatically to fit.

Definition at line 919 of file AudioCallbackPlaySource.cpp.

References initialiseConverter(), m_stretchRatio, m_targetSampleRate, and setTimeStretch().

Referenced by AudioJACKTarget::sourceModelReplaced().

Return the sample rate set by the target audio device (or the source sample rate if the target hasn't set one).

Definition at line 1037 of file AudioCallbackPlaySource.cpp.

References getSourceSampleRate(), and m_targetSampleRate.

Referenced by fillBuffers(), getCurrentFrame(), getCurrentPlayingFrame(), initialiseConverter(), and setTimeStretch().

void AudioCallbackPlaySource::setOutputLevels ( float  left,
float  right 
)

Set the current output levels for metering (for call from the target)

Definition at line 904 of file AudioCallbackPlaySource.cpp.

References m_outputLeft, and m_outputRight.

Referenced by AudioJACKTarget::process().

bool AudioCallbackPlaySource::getOutputLevels ( float &  left,
float &  right 
) [virtual]

Return the current (or thereabouts) output levels in the range 0.0 -> 1.0, for metering purposes.

Definition at line 911 of file AudioCallbackPlaySource.cpp.

References m_outputLeft, and m_outputRight.

Get the number of channels of audio that in the source models.

This may safely be called from a realtime thread. Returns 0 if there is no source yet available.

Definition at line 1044 of file AudioCallbackPlaySource.cpp.

References m_sourceChannelCount.

Referenced by AudioJACKTarget::sourceModelReplaced().

Get the number of channels of audio that will be provided to the play target.

This may be more than the source channel count: for example, a mono source will provide 2 channels after pan. This may safely be called from a realtime thread. Returns 0 if there is no source yet available.

Definition at line 1050 of file AudioCallbackPlaySource.cpp.

References m_sourceChannelCount.

Referenced by addModel(), applyAuditioningEffect(), fillBuffers(), getCurrentFrame(), getSourceSamples(), initialiseConverter(), mixModels(), play(), AudioCallbackPlaySource::FillThread::run(), setTimeStretch(), and unifyRingBuffers().

Get the actual sample rate of the source material.

This may safely be called from a realtime thread. Returns 0 if there is no source yet available.

Definition at line 1057 of file AudioCallbackPlaySource.cpp.

References m_sourceSampleRate.

Referenced by fillBuffers(), getCurrentFrame(), getTargetSampleRate(), initialiseConverter(), MainWindowBase::openAudio(), MainWindowBase::openLayersFromRDF(), rebuildRangeLists(), and AudioCallbackPlaySource::FillThread::run().

int AudioCallbackPlaySource::getSourceSamples ( int  count,
float **  buffer 
)

Set the resampler quality, 0 - 2 where 0 is fastest and 2 is highest quality.

Definition at line 995 of file AudioCallbackPlaySource.cpp.

References initialiseConverter(), and m_resampleQuality.

Referenced by preferenceChanged().

void AudioCallbackPlaySource::setAuditioningEffect ( Auditionable *  plugin)

Set a single real-time plugin as a processing effect for auditioning during playback.

The plugin must have been initialised with getTargetChannelCount() channels and a getTargetBlockSize() sample frame processing block size.

This playback source takes ownership of the plugin, which will be deleted at some point after the following call to setAuditioningEffect (depending on real-time constraints).

Pass a null pointer to remove the current auditioning plugin, if any.

Definition at line 1009 of file AudioCallbackPlaySource.cpp.

References m_auditioningPlugin, m_auditioningPluginBypassed, and m_mutex.

void AudioCallbackPlaySource::setSoloModelSet ( std::set< Model * >  s)

Specify that only the given set of models should be played.

Definition at line 1023 of file AudioCallbackPlaySource.cpp.

References clearRingBuffers(), m_audioGenerator, and AudioGenerator::setSoloModelSet().

Referenced by MainWindowBase::currentPaneChanged().

Specify that all models should be played as normal (if not muted).

Definition at line 1030 of file AudioCallbackPlaySource.cpp.

References clearRingBuffers(), AudioGenerator::clearSoloModelSet(), and m_audioGenerator.

Referenced by MainWindowBase::playSoloToggled().

QString AudioCallbackPlaySource::getClientName ( ) const [inline]

Definition at line 240 of file AudioCallbackPlaySource.h.

References m_clientName.

Referenced by AudioJACKTarget::AudioJACKTarget().

Referenced by addModel().

void AudioCallbackPlaySource::playStatusChanged ( bool  isPlaying) [signal]

Referenced by AudioCallbackPlaySource(), play(), and stop().

void AudioCallbackPlaySource::sampleRateMismatch ( int  requested,
int  available,
bool  willResample 
) [signal]

Referenced by addModel(), and initialiseConverter().

void AudioCallbackPlaySource::activity ( QString  ) [signal]

Referenced by play(), setTimeStretch(), and stop().

void AudioCallbackPlaySource::selectionChanged ( ) [protected, slot]

Definition at line 513 of file AudioCallbackPlaySource.cpp.

References clearRingBuffers(), and m_viewManager.

Referenced by AudioCallbackPlaySource().

Definition at line 521 of file AudioCallbackPlaySource.cpp.

References clearRingBuffers().

Referenced by AudioCallbackPlaySource().

Definition at line 527 of file AudioCallbackPlaySource.cpp.

References clearRingBuffers(), and m_viewManager.

Referenced by AudioCallbackPlaySource().

void AudioCallbackPlaySource::playParametersChanged ( PlayParameters *  ) [protected, slot]

Definition at line 535 of file AudioCallbackPlaySource.cpp.

References clearRingBuffers().

Referenced by AudioCallbackPlaySource().

void AudioCallbackPlaySource::preferenceChanged ( PropertyContainer::PropertyName  n) [protected, slot]

Definition at line 541 of file AudioCallbackPlaySource.cpp.

References setResampleQuality().

Referenced by AudioCallbackPlaySource().

void AudioCallbackPlaySource::modelChangedWithin ( int  startFrame,
int  endFrame 
) [protected, slot]

Definition at line 270 of file AudioCallbackPlaySource.cpp.

References m_lastModelEndFrame, and rebuildRangeLists().

Referenced by addModel(), and removeModel().

RingBuffer<float>* AudioCallbackPlaySource::getWriteRingBuffer ( int  c) [inline, protected]

Definition at line 309 of file AudioCallbackPlaySource.h.

References m_writeBuffers.

Referenced by fillBuffers(), and unifyRingBuffers().

RingBuffer<float>* AudioCallbackPlaySource::getReadRingBuffer ( int  c) [inline, protected]

!! Then what?

!! how do we know when ended? need to mark up a fully-buffered flag and check this if we find the buffers empty in getSourceSamples

Definition at line 1357 of file AudioCallbackPlaySource.cpp.

References AudioGenerator::getBlockSize(), getSourceSampleRate(), getTargetChannelCount(), getTargetSampleRate(), getWriteRingBuffer(), m_audioGenerator, m_converter, m_crapConverter, m_readBufferFill, m_readBuffers, m_timeStretcher, m_writeBufferFill, m_writeBuffers, and mixModels().

Referenced by AudioCallbackPlaySource::FillThread::run().

int AudioCallbackPlaySource::mixModels ( int &  frame,
int  count,
float **  buffers 
) [protected]
void AudioCallbackPlaySource::applyAuditioningEffect ( int  count,
float **  buffers 
) [protected]

Member Data Documentation

Definition at line 268 of file AudioCallbackPlaySource.h.

Referenced by getClientName().

std::set<Model *> AudioCallbackPlaySource::m_models [protected]

Definition at line 280 of file AudioCallbackPlaySource.h.

Referenced by addModel(), clearModels(), mixModels(), and removeModel().

Definition at line 294 of file AudioCallbackPlaySource.h.

Referenced by getCurrentFrame().

Definition at line 295 of file AudioCallbackPlaySource.h.

Referenced by getCurrentFrame(), play(), and stop().

Definition at line 300 of file AudioCallbackPlaySource.h.

Referenced by getOutputLevels(), and setOutputLevels().

Definition at line 301 of file AudioCallbackPlaySource.h.

Referenced by getOutputLevels(), and setOutputLevels().

Scavenger<RealTimePluginInstance> AudioCallbackPlaySource::m_pluginScavenger [protected]

Definition at line 305 of file AudioCallbackPlaySource.h.

Referenced by getCurrentFrame(), and play().

Definition at line 306 of file AudioCallbackPlaySource.h.

Referenced by getCurrentFrame(), and play().

Definition at line 307 of file AudioCallbackPlaySource.h.

Referenced by getCurrentFrame(), and play().

std::vector<RealTime> AudioCallbackPlaySource::m_rangeStarts [protected]

Definition at line 352 of file AudioCallbackPlaySource.h.

Referenced by getCurrentFrame(), and rebuildRangeLists().

std::vector<RealTime> AudioCallbackPlaySource::m_rangeDurations [protected]

Definition at line 353 of file AudioCallbackPlaySource.h.

Referenced by getCurrentFrame(), and rebuildRangeLists().


The documentation for this class was generated from the following files: