Audacity 3.2.0
Classes | Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
AudioIoCallback Class Reference

AudioIoCallback is a class that implements the callback required by PortAudio. The callback needs to be responsive, has no GUI, and copies data into and out of the sound card buffers. It also sends data to the meters. More...

#include <AudioIO.h>

Inheritance diagram for AudioIoCallback:
[legend]
Collaboration diagram for AudioIoCallback:
[legend]

Classes

class  AudioIOExtIterator
 
struct  AudioIOExtRange
 
struct  TransportState
 

Public Types

using RingBuffers = std::vector< std::unique_ptr< RingBuffer > >
 

Public Member Functions

 AudioIoCallback ()
 
 ~AudioIoCallback ()
 
int AudioCallback (constSamplePtr inputBuffer, float *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, const PaStreamCallbackFlags statusFlags, void *userData)
 
std::shared_ptr< AudioIOListenerGetListener () const
 
void SetListener (const std::shared_ptr< AudioIOListener > &listener)
 
int CallbackDoSeek ()
 
void CallbackCheckCompletion (int &callbackReturn, unsigned long len)
 
unsigned CountSoloingSequences ()
 
bool SequenceShouldBeSilent (const PlayableSequence &ps)
 
void CheckSoundActivatedRecordingLevel (float *inputSamples, unsigned long framesPerBuffer)
 
bool FillOutputBuffers (float *outputFloats, unsigned long framesPerBuffer, float *outputMeterFloats)
 
void DrainInputBuffers (constSamplePtr inputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackFlags statusFlags, float *tempFloats)
 
void UpdateTimePosition (unsigned long framesPerBuffer)
 
void DoPlaythrough (constSamplePtr inputBuffer, float *outputBuffer, unsigned long framesPerBuffer, float *outputMeterFloats)
 
void SendVuInputMeterData (const float *inputSamples, unsigned long framesPerBuffer)
 
void SendVuOutputMeterData (const float *outputMeterFloats, unsigned long framesPerBuffer)
 
size_t GetCommonlyReadyPlayback ()
 Get the number of audio samples ready in all of the playback buffers. More...
 
size_t GetCommonlyWrittenForPlayback ()
 
void StartAudioThread ()
 
void WaitForAudioThreadStarted ()
 
void StopAudioThread ()
 
void WaitForAudioThreadStopped ()
 
void ProcessOnceAndWait (std::chrono::milliseconds sleepTime=std::chrono::milliseconds(50))
 
bool HasRecordingException () const
 
const std::vector< std::pair< double, double > > & LostCaptureIntervals ()
 
iteration over extensions, supporting range-for syntax
AudioIOExtRange Extensions ()
 
- Public Member Functions inherited from AudioIOBase
 AudioIOBase ()
 
virtual ~AudioIOBase ()
 
 AudioIOBase (const AudioIOBase &)=delete
 
AudioIOBaseoperator= (const AudioIOBase &)=delete
 
void SetCaptureMeter (const std::shared_ptr< AudacityProject > &project, const std::weak_ptr< Meter > &meter)
 
void SetPlaybackMeter (const std::shared_ptr< AudacityProject > &project, const std::weak_ptr< Meter > &meter)
 
void HandleDeviceChange ()
 update state after changing what audio devices are selected More...
 
wxString GetDeviceInfo () const
 Get diagnostic information on all the available audio I/O devices. More...
 
std::vector< AudioIODiagnosticsGetAllDeviceInfo ()
 Get diagnostic information for audio devices and also for extensions. More...
 
bool IsPaused () const
 Find out if playback / recording is currently paused. More...
 
virtual void StopStream ()=0
 
bool IsBusy () const
 Returns true if audio i/o is busy starting, stopping, playing, or recording. More...
 
bool IsStreamActive () const
 Returns true if the audio i/o is running at all, but not during cleanup. More...
 
bool IsStreamActive (int token) const
 
bool IsAudioTokenActive (int token) const
 Returns true if the stream is active, or even if audio I/O is busy cleaning up its data or writing to disk. More...
 
bool IsMonitoring () const
 Returns true if we're monitoring input (but not recording or playing actual audio) More...
 
void SetMixer (int inputSource)
 

Public Attributes

int mbHasSoloSequences
 
int mCallbackReturn
 
long mNumPauseFrames
 How many frames of zeros were output due to pauses? More...
 
std::thread mAudioThread
 
std::atomic< bool > mFinishAudioThread { false }
 
std::vector< std::unique_ptr< Resample > > mResample
 
RingBuffers mCaptureBuffers
 
RecordableSequences mCaptureSequences
 
std::vector< std::vector< float > > mProcessingBuffers
 
std::vector< std::vector< float > > mMasterBuffers
 
RingBuffers mPlaybackBuffers
 
ConstPlayableSequences mPlaybackSequences
 
float mOldPlaybackGain
 
std::vector< SampleBuffermScratchBuffers
 
std::vector< float * > mScratchPointers
 pointing into mScratchBuffers More...
 
std::vector< std::unique_ptr< Mixer > > mPlaybackMixers
 
std::atomic< float > mMixerOutputVol { 1.0 }
 
double mFactor
 
unsigned long mMaxFramesOutput
 
bool mbMicroFades
 
double mSeek
 
PlaybackPolicy::Duration mPlaybackRingBufferSecs
 
double mCaptureRingBufferSecs
 
size_t mPlaybackSamplesToCopy
 Preferred batch size for replenishing the playback RingBuffer. More...
 
size_t mHardwarePlaybackLatencyFrames {}
 Hardware output latency in frames. More...
 
size_t mPlaybackQueueMinimum
 Occupancy of the queue we try to maintain, with bigger batches if needed. More...
 
double mMinCaptureSecsToCopy
 
bool mSoftwarePlaythrough
 
bool mPauseRec
 True if Sound Activated Recording is enabled. More...
 
float mSilenceLevel
 
size_t mNumCaptureChannels
 
size_t mNumPlaybackChannels
 
sampleFormat mCaptureFormat
 
double mCaptureRate {}
 
unsigned long long mLostSamples { 0 }
 
std::atomic< bool > mAudioThreadShouldCallSequenceBufferExchangeOnce
 
std::atomic< bool > mAudioThreadSequenceBufferExchangeLoopRunning
 
std::atomic< bool > mAudioThreadSequenceBufferExchangeLoopActive
 
std::atomic< AcknowledgemAudioThreadAcknowledge
 
std::atomic< bool > mForceFadeOut { false }
 
wxLongLong mLastPlaybackTimeMillis
 
double mLastRecordingOffset
 Not (yet) used; should perhaps be atomic when it is. More...
 
PaError mLastPaError
 
bool mSimulateRecordingErrors { false }
 
std::atomic< bool > mDetectUpstreamDropouts { true }
 

Static Public Attributes

static int mNextStreamToken = 0
 
- Static Public Attributes inherited from AudioIOBase
static const int StandardRates []
 Array of common audio sample rates. More...
 
static const int NumStandardRates = WXSIZEOF(AudioIOBase::StandardRates)
 How many standard sample rates there are. More...
 

Protected Member Functions

float GetMixerOutputVol ()
 
void SetMixerOutputVol (float value)
 
void SetRecordingException ()
 
void ClearRecordingException ()
 

Static Protected Member Functions

static size_t MinValue (const RingBuffers &buffers, size_t(RingBuffer::*pmf)() const)
 
- Static Protected Member Functions inherited from AudioIOBase
static wxString DeviceName (const PaDeviceInfo *info)
 
static wxString HostName (const PaDeviceInfo *info)
 
static int getRecordDevIndex (const wxString &devName={})
 get the index of the supplied (named) recording device, or the device selected in the preferences if none given. More...
 
static int getPlayDevIndex (const wxString &devName={})
 get the index of the device selected in the preferences. More...
 

Protected Attributes

std::weak_ptr< AudioIOListenermListener
 
bool mUsingAlsa { false }
 
bool mUsingJack { false }
 
wxMutex mSuspendAudioThread
 
wxAtomicInt mRecordingException {}
 
std::vector< std::pair< double, double > > mLostCaptureIntervals
 
bool mDetectDropouts { true }
 
RecordingSchedule mRecordingSchedule {}
 
PlaybackSchedule mPlaybackSchedule
 
std::unique_ptr< TransportStatempTransportState
 Holds some state for duration of playback or recording. More...
 
- Protected Attributes inherited from AudioIOBase
std::weak_ptr< AudacityProjectmOwningProject
 
std::atomic< bool > mPaused { false }
 True if audio playback is paused. More...
 
int mStreamToken { 0 }
 
double mRate
 Audio playback rate in samples per second. More...
 
PaStreammPortStreamV19
 
std::weak_ptr< MetermInputMeter {}
 
std::weak_ptr< MetermOutputMeter {}
 
bool mInputMixerWorks
 Can we control the hardware input level? More...
 
std::vector< std::unique_ptr< AudioIOExtBase > > mAudioIOExt
 

Static Protected Attributes

static double mCachedBestRateOut
 
static bool mCachedBestRatePlaying
 
static bool mCachedBestRateCapturing
 
- Static Protected Attributes inherited from AudioIOBase
static std::unique_ptr< AudioIOBaseugAudioIO
 
static int mCachedPlaybackIndex = -1
 
static std::vector< long > mCachedPlaybackRates
 
static int mCachedCaptureIndex = -1
 
static std::vector< long > mCachedCaptureRates
 
static std::vector< long > mCachedSampleRates
 
static double mCachedBestRateIn = 0.0
 
static const int RatesToTry []
 Array of audio sample rates to try to use. More...
 
static const int NumRatesToTry = WXSIZEOF(AudioIOBase::RatesToTry)
 How many sample rates to try. More...
 

Private Attributes

std::vector< std::unique_ptr< AudioIOExtBase > > mAudioIOExt
 

Additional Inherited Members

- Static Public Member Functions inherited from AudioIOBase
static AudioIOBaseGet ()
 
static std::vector< long > GetSupportedPlaybackRates (int DevIndex=-1, double rate=0.0)
 Get a list of sample rates the output (playback) device supports. More...
 
static std::vector< long > GetSupportedCaptureRates (int devIndex=-1, double rate=0.0)
 Get a list of sample rates the input (recording) device supports. More...
 
static std::vector< long > GetSupportedSampleRates (int playDevice=-1, int recDevice=-1, double rate=0.0)
 Get a list of sample rates the current input/output device combination supports. More...
 
static int GetOptimalSupportedSampleRate ()
 Get a supported sample rate which can be used a an optimal default. More...
 

Detailed Description

AudioIoCallback is a class that implements the callback required by PortAudio. The callback needs to be responsive, has no GUI, and copies data into and out of the sound card buffers. It also sends data to the meters.

Definition at line 110 of file AudioIO.h.

Member Typedef Documentation

◆ RingBuffers

using AudioIoCallback::RingBuffers = std::vector<std::unique_ptr<RingBuffer> >

Definition at line 256 of file AudioIO.h.

Constructor & Destructor Documentation

◆ AudioIoCallback()

AudioIoCallback::AudioIoCallback ( )

Definition at line 3145 of file AudioIO.cpp.

3146{
3147 auto &factories = AudioIOExt::GetFactories();
3148 for (auto &factory: factories)
3149 if (auto pExt = factory(mPlaybackSchedule))
3150 mAudioIOExt.push_back( move(pExt) );
3151}
static RegisteredToolbarFactory factory
static Factories & GetFactories()
Definition: AudioIOExt.cpp:15
PlaybackSchedule mPlaybackSchedule
Definition: AudioIO.h:395
std::vector< std::unique_ptr< AudioIOExtBase > > mAudioIOExt
Definition: AudioIOBase.h:322

References factory, AudioIOExt::GetFactories(), mAudioIOExt, and mPlaybackSchedule.

Here is the call graph for this function:

◆ ~AudioIoCallback()

AudioIoCallback::~AudioIoCallback ( )

Definition at line 3154 of file AudioIO.cpp.

3155{
3156}

Member Function Documentation

◆ AudioCallback()

int AudioIoCallback::AudioCallback ( constSamplePtr  inputBuffer,
float *  outputBuffer,
unsigned long  framesPerBuffer,
const PaStreamCallbackTimeInfo *  timeInfo,
const PaStreamCallbackFlags  statusFlags,
void *  userData 
)

Definition at line 3159 of file AudioIO.cpp.

3164{
3165 // Poll sequences for change of state.
3166 // (User might click mute and solo buttons.)
3168 mCallbackReturn = paContinue;
3169
3170 if (IsPaused()
3171 // PRL: Why was this added? Was it only because of the mysterious
3172 // initial leading zeroes, now solved by setting mStreamToken early?
3173 // JKC: I think it's used for the MIDI time cursor. See comments
3174 // at head of file about AudioTime().
3175 || mStreamToken <= 0
3176 )
3177 mNumPauseFrames += framesPerBuffer;
3178
3179 for( auto &ext : Extensions() ) {
3180 ext.ComputeOtherTimings(mRate, IsPaused(),
3181 timeInfo,
3182 framesPerBuffer);
3183 ext.FillOtherBuffers(
3185 }
3186
3187 // ------ MEMORY ALLOCATIONS -----------------------------------------------
3188 // tempFloats will be a reusable scratch pad for (possibly format converted)
3189 // audio data. One temporary use is for the InputMeter data.
3190 const auto numPlaybackChannels = mNumPlaybackChannels;
3191 const auto numCaptureChannels = mNumCaptureChannels;
3192 const auto tempFloats = stackAllocate(float,
3193 framesPerBuffer * std::max(numCaptureChannels, numPlaybackChannels));
3194
3195 bool bVolEmulationActive =
3196 (outputBuffer && GetMixerOutputVol() != 1.0);
3197 // outputMeterFloats is the scratch pad for the output meter.
3198 // we can often reuse the existing outputBuffer and save on allocating
3199 // something new.
3200 const auto outputMeterFloats = bVolEmulationActive
3201 ? stackAllocate(float, framesPerBuffer * numPlaybackChannels)
3202 : outputBuffer;
3203 // ----- END of MEMORY ALLOCATIONS ------------------------------------------
3204
3205 if (inputBuffer && numCaptureChannels) {
3206 float *inputSamples;
3207
3208 if (mCaptureFormat == floatSample) {
3209 inputSamples = (float *) inputBuffer;
3210 }
3211 else {
3212 SamplesToFloats(reinterpret_cast<constSamplePtr>(inputBuffer),
3213 mCaptureFormat, tempFloats, framesPerBuffer * numCaptureChannels);
3214 inputSamples = tempFloats;
3215 }
3216
3218 inputSamples,
3219 framesPerBuffer);
3220
3221 // This function may queue up a pause or resume.
3222 // TODO this is a bit dodgy as it toggles the Pause, and
3223 // relies on an idle event to have handled that, so could
3224 // queue up multiple toggle requests and so do nothing.
3225 // Eventually it will sort itself out by random luck, but
3226 // the net effect is a delay in starting/stopping sound activated
3227 // recording.
3229 inputSamples,
3230 framesPerBuffer);
3231 }
3232
3233 // Even when paused, we do playthrough.
3234 // Initialise output buffer to zero or to playthrough data.
3235 // Initialise output meter values.
3237 inputBuffer,
3238 outputBuffer,
3239 framesPerBuffer,
3240 outputMeterFloats);
3241
3242 // Test for no sequence audio to play (because we are paused and have faded
3243 // out)
3244 if( IsPaused() && (( !mbMicroFades ) || mOldPlaybackGain == 0.0f ))
3245 return mCallbackReturn;
3246
3247 // To add sequence output to output (to play sound on speaker)
3248 // possible exit, if we were seeking.
3250 outputBuffer,
3251 framesPerBuffer,
3252 outputMeterFloats))
3253 return mCallbackReturn;
3254
3255 // To move the cursor onwards. (uses mMaxFramesOutput)
3256 UpdateTimePosition(framesPerBuffer);
3257
3258 // To capture input into sequence (sound from microphone)
3260 inputBuffer,
3261 framesPerBuffer,
3262 statusFlags,
3263 tempFloats);
3264
3265 SendVuOutputMeterData( outputMeterFloats, framesPerBuffer);
3266
3267 return mCallbackReturn;
3268}
#define stackAllocate(T, count)
Definition: AudioIO.cpp:1990
void SamplesToFloats(constSamplePtr src, sampleFormat srcFormat, float *dst, size_t len, size_t srcStride, size_t dstStride)
Copy samples from any format into the widest format, which is 32 bit float, with no dithering.
const char * constSamplePtr
Definition: SampleFormat.h:58
double mRate
Audio playback rate in samples per second.
Definition: AudioIOBase.h:255
int mStreamToken
Definition: AudioIOBase.h:251
bool IsPaused() const
Find out if playback / recording is currently paused.
unsigned CountSoloingSequences()
Definition: AudioIO.cpp:3114
size_t mNumPlaybackChannels
Definition: AudioIO.h:305
bool mbMicroFades
Definition: AudioIO.h:282
AudioIOExtRange Extensions()
Definition: AudioIO.h:162
float GetMixerOutputVol()
Definition: AudioIO.h:339
void CheckSoundActivatedRecordingLevel(float *inputSamples, unsigned long framesPerBuffer)
Definition: AudioIO.cpp:2673
void UpdateTimePosition(unsigned long framesPerBuffer)
Definition: AudioIO.cpp:2861
int mbHasSoloSequences
Definition: AudioIO.h:181
int mCallbackReturn
Definition: AudioIO.h:182
long mNumPauseFrames
How many frames of zeros were output due to pauses?
Definition: AudioIO.h:232
void DrainInputBuffers(constSamplePtr inputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackFlags statusFlags, float *tempFloats)
Definition: AudioIO.cpp:2876
void SendVuInputMeterData(const float *inputSamples, unsigned long framesPerBuffer)
Definition: AudioIO.cpp:3070
void SendVuOutputMeterData(const float *outputMeterFloats, unsigned long framesPerBuffer)
Definition: AudioIO.cpp:3086
void DoPlaythrough(constSamplePtr inputBuffer, float *outputBuffer, unsigned long framesPerBuffer, float *outputMeterFloats)
Definition: AudioIO.cpp:3034
float mOldPlaybackGain
Definition: AudioIO.h:270
size_t mNumCaptureChannels
Definition: AudioIO.h:303
bool FillOutputBuffers(float *outputFloats, unsigned long framesPerBuffer, float *outputMeterFloats)
Definition: AudioIO.cpp:2711
sampleFormat mCaptureFormat
Definition: AudioIO.h:306

References CheckSoundActivatedRecordingLevel(), CountSoloingSequences(), DoPlaythrough(), DrainInputBuffers(), Extensions(), FillOutputBuffers(), floatSample, GetMixerOutputVol(), AudioIOBase::IsPaused(), mbHasSoloSequences, mbMicroFades, mCallbackReturn, mCaptureFormat, mNumCaptureChannels, mNumPauseFrames, mNumPlaybackChannels, mOldPlaybackGain, AudioIOBase::mRate, AudioIOBase::mStreamToken, SamplesToFloats(), SendVuInputMeterData(), SendVuOutputMeterData(), stackAllocate, and UpdateTimePosition().

Here is the call graph for this function:

◆ CallbackCheckCompletion()

void AudioIoCallback::CallbackCheckCompletion ( int &  callbackReturn,
unsigned long  len 
)

Definition at line 3330 of file AudioIO.cpp.

3332{
3333 if (IsPaused())
3334 return;
3335
3336 bool done =
3338 if (!done)
3339 return;
3340
3341 for( auto &ext : Extensions() )
3342 ext.SignalOtherCompletion();
3343 callbackReturn = paComplete;
3344}
virtual bool Done(PlaybackSchedule &schedule, unsigned long outputFrames)
Returns true if schedule.GetSequenceTime() has reached the end of playback.
PlaybackPolicy & GetPolicy()

References PlaybackPolicy::Done(), Extensions(), PlaybackSchedule::GetPolicy(), AudioIOBase::IsPaused(), and mPlaybackSchedule.

Referenced by FillOutputBuffers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CallbackDoSeek()

int AudioIoCallback::CallbackDoSeek ( )

Definition at line 3270 of file AudioIO.cpp.

3271{
3272 const int token = mStreamToken;
3273 wxMutexLocker locker(mSuspendAudioThread);
3274 if (token != mStreamToken)
3275 // This stream got destroyed while we waited for it
3276 return paAbort;
3277
3278 // Pause audio thread and wait for it to finish
3279 //
3280 // [PM] the following 8 lines of code could be probably replaced by
3281 // a single call to StopAudioThreadAndWait()
3282 //
3283 // CAUTION: when trying the above, you must also replace the setting of the
3284 // atomic before the return, with a call to StartAudioThread()
3285 //
3286 // If that works, then we can remove mAudioThreadSequenceBufferExchangeLoopActive,
3287 // as it will become unused; consequently, the AudioThread loop would get simpler too.
3288 //
3290 .store(false, std::memory_order_relaxed);
3291
3293 .load(std::memory_order_relaxed ) )
3294 {
3295 using namespace std::chrono;
3296 std::this_thread::sleep_for(50ms);
3297 }
3298
3299 // Calculate the NEW time position, in the PortAudio callback
3300 const auto time =
3302
3304 mSeek = 0.0;
3305
3306
3307 // Reset mixer positions and flush buffers for all sequences
3308 for (auto &mixer : mPlaybackMixers)
3309 mixer->Reposition( time, true );
3310 for (auto &buffer : mPlaybackBuffers) {
3311 const auto toDiscard = buffer->AvailForGet();
3312 const auto discarded = buffer->Discard( toDiscard );
3313 // wxASSERT( discarded == toDiscard );
3314 // but we can't assert in this thread
3315 wxUnusedVar(discarded);
3316 }
3317
3319
3320 // Reload the ring buffers
3322
3323 // Reenable the audio thread
3325 .store(true, std::memory_order_relaxed);
3326
3327 return paContinue;
3328}
std::atomic< bool > mAudioThreadSequenceBufferExchangeLoopRunning
Definition: AudioIO.h:310
double mSeek
Definition: AudioIO.h:284
wxMutex mSuspendAudioThread
Definition: AudioIO.h:359
std::vector< std::unique_ptr< Mixer > > mPlaybackMixers
Definition: AudioIO.h:275
std::atomic< bool > mAudioThreadSequenceBufferExchangeLoopActive
Definition: AudioIO.h:311
RingBuffers mPlaybackBuffers
Definition: AudioIO.h:266
void ProcessOnceAndWait(std::chrono::milliseconds sleepTime=std::chrono::milliseconds(50))
Definition: AudioIO.cpp:3384
virtual double OffsetSequenceTime(PlaybackSchedule &schedule, double offset)
Called when the play head needs to jump a certain distance.
void Prime(double time)
Empty the queue and reassign the last produced time.
void SetSequenceTime(double time)
Set current track time value, unadjusted.
class AUDIO_IO_API PlaybackSchedule::TimeQueue mTimeQueue

References PlaybackSchedule::GetPolicy(), mAudioThreadSequenceBufferExchangeLoopActive, mAudioThreadSequenceBufferExchangeLoopRunning, mPlaybackBuffers, mPlaybackMixers, mPlaybackSchedule, mSeek, AudioIOBase::mStreamToken, mSuspendAudioThread, PlaybackSchedule::mTimeQueue, PlaybackPolicy::OffsetSequenceTime(), PlaybackSchedule::TimeQueue::Prime(), ProcessOnceAndWait(), and PlaybackSchedule::SetSequenceTime().

Referenced by FillOutputBuffers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckSoundActivatedRecordingLevel()

void AudioIoCallback::CheckSoundActivatedRecordingLevel ( float *  inputSamples,
unsigned long  framesPerBuffer 
)

Definition at line 2673 of file AudioIO.cpp.

2677{
2678 // Quick returns if next to nothing to do.
2679 if( !mPauseRec )
2680 return;
2681
2682 float maxPeak = 0.;
2683 for( unsigned long i = 0, cnt = framesPerBuffer * mNumCaptureChannels; i < cnt; ++i ) {
2684 float sample = fabs(*(inputSamples++));
2685 if (sample > maxPeak) {
2686 maxPeak = sample;
2687 }
2688 }
2689
2690 bool bShouldBePaused = maxPeak < mSilenceLevel;
2691 if( bShouldBePaused != IsPaused() )
2692 {
2693 auto pListener = GetListener();
2694 if ( pListener )
2695 pListener->OnSoundActivationThreshold();
2696 }
2697}
std::shared_ptr< AudioIOListener > GetListener() const
Definition: AudioIO.h:170
float mSilenceLevel
Definition: AudioIO.h:301
bool mPauseRec
True if Sound Activated Recording is enabled.
Definition: AudioIO.h:300

References GetListener(), AudioIOBase::IsPaused(), mNumCaptureChannels, mPauseRec, and mSilenceLevel.

Referenced by AudioCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearRecordingException()

void AudioIoCallback::ClearRecordingException ( )
inlineprotected

Definition at line 374 of file AudioIO.h.

375 { if (mRecordingException) wxAtomicDec( mRecordingException ); }
wxAtomicInt mRecordingException
Definition: AudioIO.h:371

Referenced by AudioIO::StartStream(), and AudioIO::StopStream().

Here is the caller graph for this function:

◆ CountSoloingSequences()

unsigned AudioIoCallback::CountSoloingSequences ( )

Definition at line 3114 of file AudioIO.cpp.

3114 {
3115 const auto numPlaybackSequences = mPlaybackSequences.size();
3116
3117 // MOVE_TO: CountSoloingSequences() function
3118 unsigned numSolo = 0;
3119 for (unsigned t = 0; t < numPlaybackSequences; t++ )
3120 if (mPlaybackSequences[t]->GetSolo())
3121 numSolo++;
3122 auto range = Extensions();
3123 numSolo += std::accumulate(range.begin(), range.end(), 0,
3124 [](unsigned sum, auto &ext){
3125 return sum + ext.CountOtherSolo(); });
3126 return numSolo;
3127}
ConstPlayableSequences mPlaybackSequences
Definition: AudioIO.h:267

References Extensions(), and mPlaybackSequences.

Referenced by AudioCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoPlaythrough()

void AudioIoCallback::DoPlaythrough ( constSamplePtr  inputBuffer,
float *  outputBuffer,
unsigned long  framesPerBuffer,
float *  outputMeterFloats 
)

Definition at line 3034 of file AudioIO.cpp.

3040{
3041 const auto numCaptureChannels = mNumCaptureChannels;
3042 const auto numPlaybackChannels = mNumPlaybackChannels;
3043
3044 // Quick returns if next to nothing to do.
3045 if( !outputBuffer )
3046 return;
3047 if( numPlaybackChannels <= 0 )
3048 return;
3049
3050 float *outputFloats = outputBuffer;
3051 for(unsigned i = 0; i < framesPerBuffer*numPlaybackChannels; i++)
3052 outputFloats[i] = 0.0;
3053
3054 if (inputBuffer && mSoftwarePlaythrough) {
3056 numCaptureChannels,
3057 outputBuffer, framesPerBuffer);
3058 }
3059
3060 // Copy the results to outputMeterFloats if necessary
3061 if (outputMeterFloats != outputFloats) {
3062 for (unsigned i = 0; i < framesPerBuffer*numPlaybackChannels; ++i) {
3063 outputMeterFloats[i] = outputFloats[i];
3064 }
3065 }
3066}
static void DoSoftwarePlaythrough(constSamplePtr inputBuffer, sampleFormat inputFormat, unsigned inputChannels, float *outputBuffer, unsigned long len)
Definition: AudioIO.cpp:2635
bool mSoftwarePlaythrough
Definition: AudioIO.h:297

References DoSoftwarePlaythrough(), mCaptureFormat, mNumCaptureChannels, mNumPlaybackChannels, and mSoftwarePlaythrough.

Referenced by AudioCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrainInputBuffers()

void AudioIoCallback::DrainInputBuffers ( constSamplePtr  inputBuffer,
unsigned long  framesPerBuffer,
const PaStreamCallbackFlags  statusFlags,
float *  tempFloats 
)

Definition at line 2876 of file AudioIO.cpp.

2882{
2883 const auto numPlaybackChannels = mNumPlaybackChannels;
2884 const auto numCaptureChannels = mNumCaptureChannels;
2885
2886 // Quick returns if next to nothing to do.
2887 if (mStreamToken <= 0)
2888 return;
2889 if( !inputBuffer )
2890 return;
2891 if( numCaptureChannels <= 0 )
2892 return;
2893
2894 // If there are no playback sequences, and we are recording, then the
2895 // earlier checks for being past the end won't happen, so do it here.
2897 mCallbackReturn = paComplete;
2898 }
2899
2900 // The error likely from a too-busy CPU falling behind real-time data
2901 // is paInputOverflow
2902 bool inputError =
2903 (statusFlags & (paInputOverflow))
2904 && !(statusFlags & paPrimingOutput);
2905
2906 // But it seems it's easy to get false positives, at least on Mac
2907 // So we have not decided to enable this extra detection yet in
2908 // production
2909
2910 size_t len = framesPerBuffer;
2911 for(unsigned t = 0; t < numCaptureChannels; t++)
2912 len = std::min( len, mCaptureBuffers[t]->AvailForPut() );
2913
2914 if (mSimulateRecordingErrors && 100LL * rand() < RAND_MAX)
2915 // Make spurious errors for purposes of testing the error
2916 // reporting
2917 len = 0;
2918
2919 // A different symptom is that len < framesPerBuffer because
2920 // the other thread, executing SequenceBufferExchange, isn't consuming fast
2921 // enough from mCaptureBuffers; maybe it's CPU-bound, or maybe the
2922 // storage device it writes is too slow
2923 if (mDetectDropouts &&
2924 ((mDetectUpstreamDropouts.load(std::memory_order_relaxed)
2925 && inputError) ||
2926 len < framesPerBuffer) ) {
2927 // Assume that any good partial buffer should be written leftmost
2928 // and zeroes will be padded after; label the zeroes.
2929 auto start = mPlaybackSchedule.GetSequenceTime() +
2931 auto duration = (framesPerBuffer - len) / mRate;
2932 auto pLast = mLostCaptureIntervals.empty()
2933 ? nullptr : &mLostCaptureIntervals.back();
2934 if (pLast &&
2935 fabs(pLast->first + pLast->second - start) < 0.5/mRate)
2936 // Make one bigger interval, not two butting intervals
2937 pLast->second = start + duration - pLast->first;
2938 else
2939 mLostCaptureIntervals.emplace_back( start, duration );
2940 }
2941
2942 if (len < framesPerBuffer)
2943 {
2944 mLostSamples += (framesPerBuffer - len);
2945 wxPrintf(wxT("lost %d samples\n"), (int)(framesPerBuffer - len));
2946 }
2947
2948 if (len <= 0)
2949 return;
2950
2951 // We have an ASSERT in the AudioIO constructor to alert us to
2952 // possible issues with the (short*) cast. We'd have a problem if
2953 // sizeof(short) > sizeof(float) since our buffers are sized for floats.
2954 for(unsigned t = 0; t < numCaptureChannels; t++) {
2955
2956 // dmazzoni:
2957 // Un-interleave. Ugly special-case code required because the
2958 // capture channels could be in three different sample formats;
2959 // it'd be nice to be able to call CopySamples, but it can't
2960 // handle multiplying by the gain and then clipping. Bummer.
2961
2962 switch(mCaptureFormat) {
2963 case floatSample: {
2964 auto inputFloats = (const float *)inputBuffer;
2965 for(unsigned i = 0; i < len; i++)
2966 tempFloats[i] =
2967 inputFloats[numCaptureChannels*i+t];
2968 } break;
2969 case int24Sample:
2970 // We should never get here. Audacity's int24Sample format
2971 // is different from PortAudio's sample format and so we
2972 // make PortAudio return float samples when recording in
2973 // 24-bit samples.
2974 wxASSERT(false);
2975 break;
2976 case int16Sample: {
2977 auto inputShorts = (const short *)inputBuffer;
2978 short *tempShorts = (short *)tempFloats;
2979 for( unsigned i = 0; i < len; i++) {
2980 float tmp = inputShorts[numCaptureChannels*i+t];
2981 tmp = std::clamp(tmp, -32768.0f, 32767.0f);
2982 tempShorts[i] = (short)(tmp);
2983 }
2984 } break;
2985 } // switch
2986
2987 // JKC: mCaptureFormat must be for samples with sizeof(float) or
2988 // fewer bytes (because tempFloats is sized for floats). All
2989 // formats are 2 or 4 bytes, so we are OK.
2990 const auto put =
2991 mCaptureBuffers[t]->Put(
2992 (samplePtr)tempFloats, mCaptureFormat, len);
2993 // wxASSERT(put == len);
2994 // but we can't assert in this thread
2995 wxUnusedVar(put);
2996 mCaptureBuffers[t]->Flush();
2997 }
2998}
wxT("CloseDown"))
int min(int a, int b)
char * samplePtr
Definition: SampleFormat.h:57
RecordingSchedule mRecordingSchedule
Definition: AudioIO.h:394
RingBuffers mCaptureBuffers
Definition: AudioIO.h:257
bool mDetectDropouts
Definition: AudioIO.h:379
bool mSimulateRecordingErrors
Definition: AudioIO.h:387
std::atomic< bool > mDetectUpstreamDropouts
Definition: AudioIO.h:391
std::vector< std::pair< double, double > > mLostCaptureIntervals
Definition: AudioIO.h:377
unsigned long long mLostSamples
Definition: AudioIO.h:308
double GetSequenceTime() const
Get current track time value, unadjusted.

References PlaybackPolicy::Done(), floatSample, PlaybackSchedule::GetPolicy(), PlaybackSchedule::GetSequenceTime(), int16Sample, int24Sample, mCallbackReturn, mCaptureBuffers, mCaptureFormat, mDetectDropouts, mDetectUpstreamDropouts, min(), RecordingSchedule::mLatencyCorrection, mLostCaptureIntervals, mLostSamples, mNumCaptureChannels, mNumPlaybackChannels, mPlaybackSchedule, AudioIOBase::mRate, mRecordingSchedule, mSimulateRecordingErrors, AudioIOBase::mStreamToken, and wxT().

Referenced by AudioCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extensions()

AudioIOExtRange AudioIoCallback::Extensions ( )
inline

Definition at line 162 of file AudioIO.h.

162 {
163 return {
164 AudioIOExtIterator{ *this, false },
165 AudioIOExtIterator{ *this, true }
166 };
167 }

Referenced by AudioCallback(), CallbackCheckCompletion(), CountSoloingSequences(), AudioIO::StartStream(), and AudioIO::StopStream().

Here is the caller graph for this function:

◆ FillOutputBuffers()

bool AudioIoCallback::FillOutputBuffers ( float *  outputFloats,
unsigned long  framesPerBuffer,
float *  outputMeterFloats 
)

Definition at line 2711 of file AudioIO.cpp.

2716{
2717 const auto numPlaybackSequences = mPlaybackSequences.size();
2718 const auto numPlaybackChannels = mNumPlaybackChannels;
2719
2720 mMaxFramesOutput = 0;
2721
2722 // Quick returns if next to nothing to do.
2723 if (mStreamToken <= 0 ||
2724 !outputFloats ||
2725 numPlaybackChannels <= 0) {
2726 // So that UpdateTimePosition() will be correct, in case of MIDI play with
2727 // no audio output channels
2728 mMaxFramesOutput = framesPerBuffer;
2729 return false;
2730 }
2731
2733 mSeek = 0.0;
2734
2735 if (mSeek){
2737 return true;
2738 }
2739
2740 // Choose a common size to take from all ring buffers
2741 const auto toGet =
2742 std::min<size_t>(framesPerBuffer, GetCommonlyReadyPlayback());
2743
2744 // Poke: If there are no playback sequences, then check playback
2745 // completion condition and do early return
2746 // PRL: Also consume frbom the single playback ring buffer
2747 if (numPlaybackSequences == 0) {
2748 mMaxFramesOutput = mPlaybackBuffers[0]->Discard(toGet);
2750 mLastPlaybackTimeMillis = ::wxGetUTCTimeMillis();
2751 return false;
2752 }
2753
2754 // JKC: The original code attempted to be faster by doing nothing on silenced audio.
2755 // This, IMHO, is 'premature optimisation'. Instead clearer and cleaner code would
2756 // simply use a gain of 0.0 for silent audio and go on through to the stage of
2757 // applying that 0.0 gain to the data mixed into the buffer.
2758 // Then (and only then) we would have if needed fast paths for:
2759 // - Applying a uniform gain of 0.0.
2760 // - Applying a uniform gain of 1.0.
2761 // - Applying some other uniform gain.
2762 // - Applying a linearly interpolated gain.
2763 // I would expect us not to need the fast paths, since linearly interpolated gain
2764 // is very cheap to process.
2765
2766 // ------ MEMORY ALLOCATION ----------------------
2767 // These are small structures.
2768 const auto tempBufs = stackAllocate(float *, numPlaybackChannels);
2769
2770 // And these are larger structures....
2771 for (unsigned int c = 0; c < numPlaybackChannels; c++)
2772 tempBufs[c] = stackAllocate(float, framesPerBuffer);
2773 // ------ End of MEMORY ALLOCATION ---------------
2774
2775 auto gain = ExpGain(GetMixerOutputVol());
2776 if (mForceFadeOut.load(std::memory_order_relaxed) || IsPaused())
2777 gain = 0.0;
2778
2779 for(unsigned n = 0; n < numPlaybackChannels; ++n)
2780 {
2781 decltype(framesPerBuffer) len = mPlaybackBuffers[n]->Get(
2782 reinterpret_cast<samplePtr>(tempBufs[n]),
2784 toGet
2785 );
2786 if(len < framesPerBuffer)
2787 {
2788 // This used to happen normally at the end of non-looping
2789 // plays, but it can also be an anomalous case where the
2790 // supply from SequenceBufferExchange fails to keep up with the
2791 // real-time demand in this thread (see bug 1932). We
2792 // must supply something to the sound card, so pad it with
2793 // zeroes and not random garbage.
2794 memset((void*)&tempBufs[n][len], 0,
2795 (framesPerBuffer - len) * sizeof(float));
2796 }
2797
2798 // PRL: More recent rewrites of SequenceBufferExchange should guarantee a
2799 // padding out of the ring buffers so that equal lengths are
2800 // available, so maxLen ought to increase from 0 only once
2801 mMaxFramesOutput = std::max(mMaxFramesOutput, len);
2802
2803 len = mMaxFramesOutput;
2804
2805 // Realtime effect transformation of the sound used to happen here
2806 // but it is now done already on the producer side of the RingBuffer
2807
2808 // Mix the results with the existing output (software playthrough) and
2809 // apply panning. If post panning effects are desired, the panning would
2810 // need to be be split out from the mixing and applied in a separate step.
2811
2812 // Our channels aren't silent. We need to pass their data on.
2813 //
2814 // Each channel in the sequences can output to more than one channel on
2815 // the device. For example mono channels output to both left and right
2816 // output channels.
2817 if (len > 0)
2818 {
2819 // Output volume emulation: possibly copy meter samples, then
2820 // apply volume, then copy to the output buffer
2821 if(outputMeterFloats != outputFloats)
2822 {
2823 for ( unsigned i = 0; i < len; ++i)
2824 outputMeterFloats[numPlaybackChannels*i+n] +=
2825 gain*tempBufs[n][i];
2826 }
2827
2828 auto oldGain = mOldPlaybackGain;
2829 // if no microfades, jump in volume.
2830 if (!mbMicroFades)
2831 oldGain = gain;
2832
2833 // Linear interpolate.
2834 // PRL todo: choose denominator differently, so it doesn't depend on
2835 // framesPerBuffer, which is influenced by the portAudio implementation in
2836 // opaque ways
2837 const float deltaGain = (gain - oldGain) / len;
2838 for (unsigned i = 0; i < len; i++)
2839 {
2840 outputFloats[numPlaybackChannels * i + n] +=
2841 (oldGain + deltaGain * i) * tempBufs[n][i];
2842 }
2843
2845 }
2846 }
2847
2848 mOldPlaybackGain = gain;
2849
2850 // wxASSERT( maxLen == toGet );
2851
2852 mLastPlaybackTimeMillis = ::wxGetUTCTimeMillis();
2853
2854 ClampBuffer( outputFloats, framesPerBuffer*numPlaybackChannels );
2855 if (outputMeterFloats != outputFloats)
2856 ClampBuffer( outputMeterFloats, framesPerBuffer*numPlaybackChannels );
2857
2858 return false;
2859}
void ClampBuffer(float *pBuffer, unsigned long len)
Definition: AudioIO.cpp:2700
Type ExpGain(Type gain) noexcept
Definition: Gain.h:19
static AudioIOBase * Get()
Definition: AudioIOBase.cpp:94
void CallbackCheckCompletion(int &callbackReturn, unsigned long len)
Definition: AudioIO.cpp:3330
std::atomic< bool > mForceFadeOut
Definition: AudioIO.h:327
wxLongLong mLastPlaybackTimeMillis
Definition: AudioIO.h:329
int CallbackDoSeek()
Definition: AudioIO.cpp:3270
unsigned long mMaxFramesOutput
Definition: AudioIO.h:280
size_t GetCommonlyReadyPlayback()
Get the number of audio samples ready in all of the playback buffers.
Definition: AudioIO.cpp:1888
virtual bool AllowSeek(PlaybackSchedule &schedule)
Whether repositioning commands are allowed during playback.

References PlaybackPolicy::AllowSeek(), CallbackCheckCompletion(), CallbackDoSeek(), ClampBuffer(), ExpGain(), floatSample, AudioIOBase::Get(), GetCommonlyReadyPlayback(), GetMixerOutputVol(), PlaybackSchedule::GetPolicy(), AudioIOBase::IsPaused(), mbMicroFades, mCallbackReturn, mForceFadeOut, mLastPlaybackTimeMillis, mMaxFramesOutput, mNumPlaybackChannels, mOldPlaybackGain, mPlaybackBuffers, mPlaybackSchedule, mPlaybackSequences, mSeek, AudioIOBase::mStreamToken, and stackAllocate.

Referenced by AudioCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCommonlyReadyPlayback()

size_t AudioIoCallback::GetCommonlyReadyPlayback ( )

Get the number of audio samples ready in all of the playback buffers.

Returns the smallest of the buffer ready space values in the event that they are different.

Definition at line 1888 of file AudioIO.cpp.

1889{
1891}
static size_t MinValue(const RingBuffers &buffers, size_t(RingBuffer::*pmf)() const)
Definition: AudioIO.cpp:1871
size_t AvailForGet() const
Definition: RingBuffer.cpp:226

References RingBuffer::AvailForGet(), MinValue(), and mPlaybackBuffers.

Referenced by FillOutputBuffers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCommonlyWrittenForPlayback()

size_t AudioIoCallback::GetCommonlyWrittenForPlayback ( )

Definition at line 1893 of file AudioIO.cpp.

1894{
1896}
size_t WrittenForGet() const
Reader may concurrently cause a decrease of what this returns.
Definition: RingBuffer.cpp:73

References MinValue(), mPlaybackBuffers, and RingBuffer::WrittenForGet().

Referenced by AudioIO::FillPlayBuffers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetListener()

std::shared_ptr< AudioIOListener > AudioIoCallback::GetListener ( ) const
inline

Definition at line 170 of file AudioIO.h.

171 { return mListener.lock(); }
std::weak_ptr< AudioIOListener > mListener
Definition: AudioIO.h:347

Referenced by CheckSoundActivatedRecordingLevel(), AudioIO::DrainRecordBuffers(), AudioIO::StartMonitoring(), AudioIO::StartStream(), and AudioIO::StopStream().

Here is the caller graph for this function:

◆ GetMixerOutputVol()

float AudioIoCallback::GetMixerOutputVol ( )
inlineprotected

Definition at line 339 of file AudioIO.h.

339 {
340 return mMixerOutputVol.load(std::memory_order_relaxed); }
std::atomic< float > mMixerOutputVol
Definition: AudioIO.h:277

Referenced by AudioCallback(), FillOutputBuffers(), and AudioIO::GetMixer().

Here is the caller graph for this function:

◆ HasRecordingException()

bool AudioIoCallback::HasRecordingException ( ) const
inline

Definition at line 365 of file AudioIO.h.

366 { return mRecordingException; }

Referenced by ProjectAudioManager::OnAudioIOStopRecording().

Here is the caller graph for this function:

◆ LostCaptureIntervals()

const std::vector< std::pair< double, double > > & AudioIoCallback::LostCaptureIntervals ( )
inline

Definition at line 383 of file AudioIO.h.

384 { return mLostCaptureIntervals; }

◆ MinValue()

size_t AudioIoCallback::MinValue ( const RingBuffers buffers,
size_t(RingBuffer::*)() const  pmf 
)
staticprotected

Definition at line 1871 of file AudioIO.cpp.

1873{
1874 return std::accumulate(buffers.begin(), buffers.end(),
1875 std::numeric_limits<size_t>::max(),
1876 [pmf](auto value, auto &pBuffer){
1877 return std::min(value, (pBuffer.get()->*pmf)()); });
1878}

Referenced by AudioIO::GetCommonlyAvailCapture(), AudioIO::GetCommonlyFreePlayback(), GetCommonlyReadyPlayback(), and GetCommonlyWrittenForPlayback().

Here is the caller graph for this function:

◆ ProcessOnceAndWait()

void AudioIoCallback::ProcessOnceAndWait ( std::chrono::milliseconds  sleepTime = std::chrono::milliseconds(50))

Definition at line 3384 of file AudioIO.cpp.

3385{
3387 .store(true, std::memory_order_release);
3388
3390 .load(std::memory_order_acquire))
3391 {
3392 using namespace std::chrono;
3393 std::this_thread::sleep_for(sleepTime);
3394 }
3395}
std::atomic< bool > mAudioThreadShouldCallSequenceBufferExchangeOnce
Definition: AudioIO.h:309

References mAudioThreadShouldCallSequenceBufferExchangeOnce.

Referenced by CallbackDoSeek(), and AudioIO::StopStream().

Here is the caller graph for this function:

◆ SendVuInputMeterData()

void AudioIoCallback::SendVuInputMeterData ( const float *  inputSamples,
unsigned long  framesPerBuffer 
)

Definition at line 3070 of file AudioIO.cpp.

3074{
3075 const auto numCaptureChannels = mNumCaptureChannels;
3076 auto pInputMeter = mInputMeter.lock();
3077 if ( !pInputMeter )
3078 return;
3079 if( pInputMeter->IsMeterDisabled())
3080 return;
3081 pInputMeter->UpdateDisplay(
3082 numCaptureChannels, framesPerBuffer, inputSamples);
3083}
std::weak_ptr< Meter > mInputMeter
Definition: AudioIOBase.h:259

References AudioIOBase::mInputMeter, and mNumCaptureChannels.

Referenced by AudioCallback().

Here is the caller graph for this function:

◆ SendVuOutputMeterData()

void AudioIoCallback::SendVuOutputMeterData ( const float *  outputMeterFloats,
unsigned long  framesPerBuffer 
)

Definition at line 3086 of file AudioIO.cpp.

3089{
3090 const auto numPlaybackChannels = mNumPlaybackChannels;
3091
3092 auto pOutputMeter = mOutputMeter.lock();
3093 if (!pOutputMeter)
3094 return;
3095 if( pOutputMeter->IsMeterDisabled() )
3096 return;
3097 if( !outputMeterFloats)
3098 return;
3099 pOutputMeter->UpdateDisplay(
3100 numPlaybackChannels, framesPerBuffer, outputMeterFloats);
3101
3102 //v Vaughan, 2011-02-25: Moved this update back to TrackPanel::OnTimer()
3103 // as it helps with playback issues reported by Bill and noted on Bug 258.
3104 // The problem there occurs if Software Playthrough is on.
3105 // Could conditionally do the update here if Software Playthrough is off,
3106 // and in TrackPanel::OnTimer() if Software Playthrough is on, but not now.
3107 // PRL 12 Jul 2015: and what was in TrackPanel::OnTimer is now handled by means of track panel timer events
3108 //MixerBoard* pMixerBoard = mOwningProject->GetMixerBoard();
3109 //if (pMixerBoard)
3110 // pMixerBoard->UpdateMeters(GetStreamTime(),
3111 // (pProj->GetControlToolBar()->GetLastPlayMode() == loopedPlay));
3112}
std::weak_ptr< Meter > mOutputMeter
Definition: AudioIOBase.h:260

References mNumPlaybackChannels, and AudioIOBase::mOutputMeter.

Referenced by AudioCallback().

Here is the caller graph for this function:

◆ SequenceShouldBeSilent()

bool AudioIoCallback::SequenceShouldBeSilent ( const PlayableSequence ps)

Definition at line 3135 of file AudioIO.cpp.

3136{
3137 return !ps.GetSolo() && (
3138 // Cut if somebody else is soloing
3140 // Cut if we're muted (and not soloing)
3141 ps.GetMute()
3142 );
3143}
virtual bool GetSolo() const =0
May vary asynchronously.
virtual bool GetMute() const =0
May vary asynchronously.

References PlayableSequence::GetMute(), PlayableSequence::GetSolo(), and mbHasSoloSequences.

Referenced by AudioIO::ProcessPlaybackSlices().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetListener()

void AudioIoCallback::SetListener ( const std::shared_ptr< AudioIOListener > &  listener)

Definition at line 2456 of file AudioIO.cpp.

2458{
2459 if (IsBusy())
2460 return;
2461
2462 mListener = listener;
2463}
bool IsBusy() const
Returns true if audio i/o is busy starting, stopping, playing, or recording.

References AudioIOBase::IsBusy(), and mListener.

Here is the call graph for this function:

◆ SetMixerOutputVol()

void AudioIoCallback::SetMixerOutputVol ( float  value)
inlineprotected

Definition at line 341 of file AudioIO.h.

341 {
342 mMixerOutputVol.store(value, std::memory_order_relaxed); }

Referenced by AudioIO::AudioIO(), and AudioIO::SetMixer().

Here is the caller graph for this function:

◆ SetRecordingException()

void AudioIoCallback::SetRecordingException ( )
inlineprotected

Definition at line 372 of file AudioIO.h.

373 { wxAtomicInc( mRecordingException ); }

Referenced by AudioIO::DrainRecordBuffers().

Here is the caller graph for this function:

◆ StartAudioThread()

void AudioIoCallback::StartAudioThread ( )

Definition at line 3354 of file AudioIO.cpp.

3355{
3356 mAudioThreadSequenceBufferExchangeLoopRunning.store(true, std::memory_order_release);
3357}

References mAudioThreadSequenceBufferExchangeLoopRunning.

Referenced by AudioIO::StartStream().

Here is the caller graph for this function:

◆ StopAudioThread()

void AudioIoCallback::StopAudioThread ( )

Definition at line 3369 of file AudioIO.cpp.

3370{
3371 mAudioThreadSequenceBufferExchangeLoopRunning.store(false, std::memory_order_release);
3372}

References mAudioThreadSequenceBufferExchangeLoopRunning.

Referenced by AudioIO::StartStream(), and AudioIO::StopStream().

Here is the caller graph for this function:

◆ UpdateTimePosition()

void AudioIoCallback::UpdateTimePosition ( unsigned long  framesPerBuffer)

Definition at line 2861 of file AudioIO.cpp.

2862{
2863 // Quick returns if next to nothing to do.
2864 if (mStreamToken <= 0)
2865 return;
2866
2867 // Update the position seen by drawing code
2870}
double Consumer(size_t nSamples, double rate)
Find the track time value nSamples after the last consumed sample.

References PlaybackSchedule::TimeQueue::Consumer(), mMaxFramesOutput, mPlaybackSchedule, AudioIOBase::mRate, AudioIOBase::mStreamToken, PlaybackSchedule::mTimeQueue, and PlaybackSchedule::SetSequenceTime().

Referenced by AudioCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WaitForAudioThreadStarted()

void AudioIoCallback::WaitForAudioThreadStarted ( )

Definition at line 3359 of file AudioIO.cpp.

3360{
3361 while (mAudioThreadAcknowledge.load(std::memory_order_acquire) != Acknowledge::eStart)
3362 {
3363 using namespace std::chrono;
3364 std::this_thread::sleep_for(50ms);
3365 }
3366 mAudioThreadAcknowledge.store(Acknowledge::eNone, std::memory_order_release);
3367}
std::atomic< Acknowledge > mAudioThreadAcknowledge
Definition: AudioIO.h:313

References eNone, eStart, and mAudioThreadAcknowledge.

Referenced by AudioIO::StartStream().

Here is the caller graph for this function:

◆ WaitForAudioThreadStopped()

void AudioIoCallback::WaitForAudioThreadStopped ( )

Definition at line 3374 of file AudioIO.cpp.

3375{
3376 while (mAudioThreadAcknowledge.load(std::memory_order_acquire) != Acknowledge::eStop)
3377 {
3378 using namespace std::chrono;
3379 std::this_thread::sleep_for(50ms);
3380 }
3381 mAudioThreadAcknowledge.store(Acknowledge::eNone, std::memory_order_release);
3382}

References eNone, eStop, and mAudioThreadAcknowledge.

Referenced by AudioIO::StopStream().

Here is the caller graph for this function:

Member Data Documentation

◆ mAudioIOExt

std::vector<std::unique_ptr<AudioIOExtBase> > AudioIOBase::mAudioIOExt
private

Privatize the inherited array but give access by Extensions(). This class guarantees that this array is populated only with non-null pointers to the subtype AudioIOExt

Definition at line 322 of file AudioIOBase.h.

Referenced by AudioIoCallback().

◆ mAudioThread

std::thread AudioIoCallback::mAudioThread

Definition at line 251 of file AudioIO.h.

Referenced by AudioIO::StartThread(), and AudioIO::~AudioIO().

◆ mAudioThreadAcknowledge

std::atomic<Acknowledge> AudioIoCallback::mAudioThreadAcknowledge

◆ mAudioThreadSequenceBufferExchangeLoopActive

std::atomic<bool> AudioIoCallback::mAudioThreadSequenceBufferExchangeLoopActive

Definition at line 311 of file AudioIO.h.

Referenced by AudioIO::AudioIO(), AudioIO::AudioThread(), and CallbackDoSeek().

◆ mAudioThreadSequenceBufferExchangeLoopRunning

std::atomic<bool> AudioIoCallback::mAudioThreadSequenceBufferExchangeLoopRunning

◆ mAudioThreadShouldCallSequenceBufferExchangeOnce

std::atomic<bool> AudioIoCallback::mAudioThreadShouldCallSequenceBufferExchangeOnce

◆ mbHasSoloSequences

int AudioIoCallback::mbHasSoloSequences

Definition at line 181 of file AudioIO.h.

Referenced by AudioCallback(), and SequenceShouldBeSilent().

◆ mbMicroFades

bool AudioIoCallback::mbMicroFades

Read by a worker thread but unchanging during playback

Definition at line 282 of file AudioIO.h.

Referenced by AudioCallback(), FillOutputBuffers(), AudioIO::StartStream(), and AudioIO::StopStream().

◆ mCachedBestRateCapturing

bool AudioIoCallback::mCachedBestRateCapturing
staticprotected

Definition at line 355 of file AudioIO.h.

Referenced by AudioIO::GetBestRate().

◆ mCachedBestRateOut

double AudioIoCallback::mCachedBestRateOut
staticprotected

Definition at line 353 of file AudioIO.h.

Referenced by AudioIO::GetBestRate().

◆ mCachedBestRatePlaying

bool AudioIoCallback::mCachedBestRatePlaying
staticprotected

Definition at line 354 of file AudioIO.h.

Referenced by AudioIO::GetBestRate().

◆ mCallbackReturn

int AudioIoCallback::mCallbackReturn

Definition at line 182 of file AudioIO.h.

Referenced by AudioCallback(), DrainInputBuffers(), and FillOutputBuffers().

◆ mCaptureBuffers

RingBuffers AudioIoCallback::mCaptureBuffers

◆ mCaptureFormat

sampleFormat AudioIoCallback::mCaptureFormat

◆ mCaptureRate

double AudioIoCallback::mCaptureRate {}

◆ mCaptureRingBufferSecs

double AudioIoCallback::mCaptureRingBufferSecs

Definition at line 286 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers().

◆ mCaptureSequences

RecordableSequences AudioIoCallback::mCaptureSequences

◆ mDetectDropouts

bool AudioIoCallback::mDetectDropouts { true }
protected

Read by a worker thread but unchanging during playback

Definition at line 379 of file AudioIO.h.

Referenced by DrainInputBuffers(), and AudioIO::StartStream().

◆ mDetectUpstreamDropouts

std::atomic<bool> AudioIoCallback::mDetectUpstreamDropouts { true }

◆ mFactor

double AudioIoCallback::mFactor

Definition at line 279 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers(), and AudioIO::DrainRecordBuffers().

◆ mFinishAudioThread

std::atomic<bool> AudioIoCallback::mFinishAudioThread { false }

Definition at line 252 of file AudioIO.h.

Referenced by AudioIO::StartThread(), and AudioIO::~AudioIO().

◆ mForceFadeOut

std::atomic<bool> AudioIoCallback::mForceFadeOut { false }

Definition at line 327 of file AudioIO.h.

Referenced by FillOutputBuffers(), AudioIO::StartStream(), and AudioIO::StopStream().

◆ mHardwarePlaybackLatencyFrames

size_t AudioIoCallback::mHardwarePlaybackLatencyFrames {}

Hardware output latency in frames.

Definition at line 291 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers(), and AudioIO::StartPortAudioStream().

◆ mLastPaError

PaError AudioIoCallback::mLastPaError

◆ mLastPlaybackTimeMillis

wxLongLong AudioIoCallback::mLastPlaybackTimeMillis

Definition at line 329 of file AudioIO.h.

Referenced by AudioIO::AudioIO(), and FillOutputBuffers().

◆ mLastRecordingOffset

double AudioIoCallback::mLastRecordingOffset

Not (yet) used; should perhaps be atomic when it is.

Definition at line 332 of file AudioIO.h.

Referenced by AudioIO::AudioIO(), and AudioIO::StartStream().

◆ mListener

std::weak_ptr< AudioIOListener > AudioIoCallback::mListener
protected

Pointer is read by a worker thread but unchanging during playback. (Whether its overriding methods are race-free is not for AudioIO to ensure.)

Definition at line 347 of file AudioIO.h.

Referenced by SetListener(), and AudioIO::StartStream().

◆ mLostCaptureIntervals

std::vector< std::pair<double, double> > AudioIoCallback::mLostCaptureIntervals
protected

Definition at line 377 of file AudioIO.h.

Referenced by DrainInputBuffers(), AudioIO::StartStream(), and AudioIO::StopStream().

◆ mLostSamples

unsigned long long AudioIoCallback::mLostSamples { 0 }

Definition at line 308 of file AudioIO.h.

Referenced by DrainInputBuffers(), and AudioIO::StartStream().

◆ mMasterBuffers

std::vector<std::vector<float> > AudioIoCallback::mMasterBuffers

These buffers are used to mix and process the result of processed source channels. Number of buffers equals to number of output channels.

Definition at line 264 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers(), and AudioIO::ProcessPlaybackSlices().

◆ mMaxFramesOutput

unsigned long AudioIoCallback::mMaxFramesOutput

Definition at line 280 of file AudioIO.h.

Referenced by FillOutputBuffers(), and UpdateTimePosition().

◆ mMinCaptureSecsToCopy

double AudioIoCallback::mMinCaptureSecsToCopy

Definition at line 295 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers(), and AudioIO::DrainRecordBuffers().

◆ mMixerOutputVol

std::atomic<float> AudioIoCallback::mMixerOutputVol { 1.0 }

Definition at line 277 of file AudioIO.h.

◆ mNextStreamToken

int AudioIoCallback::mNextStreamToken = 0
static

Definition at line 278 of file AudioIO.h.

Referenced by AudioIO::StartStream().

◆ mNumCaptureChannels

size_t AudioIoCallback::mNumCaptureChannels

◆ mNumPauseFrames

long AudioIoCallback::mNumPauseFrames

How many frames of zeros were output due to pauses?

Definition at line 232 of file AudioIO.h.

Referenced by AudioCallback(), AudioIO::AudioIO(), and AudioIO::StartPortAudioStream().

◆ mNumPlaybackChannels

size_t AudioIoCallback::mNumPlaybackChannels

◆ mOldPlaybackGain

float AudioIoCallback::mOldPlaybackGain

Definition at line 270 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers(), AudioCallback(), and FillOutputBuffers().

◆ mPauseRec

bool AudioIoCallback::mPauseRec

True if Sound Activated Recording is enabled.

Read by a worker thread but unchanging during playback

Definition at line 300 of file AudioIO.h.

Referenced by CheckSoundActivatedRecordingLevel(), and AudioIO::StartStream().

◆ mPlaybackBuffers

RingBuffers AudioIoCallback::mPlaybackBuffers

◆ mPlaybackMixers

std::vector<std::unique_ptr<Mixer> > AudioIoCallback::mPlaybackMixers

◆ mPlaybackQueueMinimum

size_t AudioIoCallback::mPlaybackQueueMinimum

Occupancy of the queue we try to maintain, with bigger batches if needed.

Definition at line 293 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers(), and AudioIO::FillPlayBuffers().

◆ mPlaybackRingBufferSecs

PlaybackPolicy::Duration AudioIoCallback::mPlaybackRingBufferSecs

Definition at line 285 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers().

◆ mPlaybackSamplesToCopy

size_t AudioIoCallback::mPlaybackSamplesToCopy

Preferred batch size for replenishing the playback RingBuffer.

Definition at line 289 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers(), and AudioIO::FillPlayBuffers().

◆ mPlaybackSchedule

PlaybackSchedule AudioIoCallback::mPlaybackSchedule
protected

◆ mPlaybackSequences

ConstPlayableSequences AudioIoCallback::mPlaybackSequences

◆ mProcessingBuffers

std::vector<std::vector<float> > AudioIoCallback::mProcessingBuffers

Buffers that hold outcome of transformations applied to each individual sample source. Number of buffers equals to the sum of number all source channels.

Definition at line 261 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers(), and AudioIO::ProcessPlaybackSlices().

◆ mpTransportState

std::unique_ptr<TransportState> AudioIoCallback::mpTransportState
protected

Holds some state for duration of playback or recording.

Definition at line 399 of file AudioIO.h.

Referenced by AudioIO::AddState(), AudioIO::FillPlayBuffers(), AudioIO::RemoveState(), AudioIO::ReplaceState(), AudioIO::StartStream(), AudioIO::StartStreamCleanup(), and AudioIO::StopStream().

◆ mRecordingException

wxAtomicInt AudioIoCallback::mRecordingException {}
protected

Definition at line 371 of file AudioIO.h.

Referenced by AudioIO::DrainRecordBuffers().

◆ mRecordingSchedule

RecordingSchedule AudioIoCallback::mRecordingSchedule {}
protected

◆ mResample

std::vector<std::unique_ptr<Resample> > AudioIoCallback::mResample

◆ mScratchBuffers

std::vector<SampleBuffer> AudioIoCallback::mScratchBuffers

◆ mScratchPointers

std::vector<float *> AudioIoCallback::mScratchPointers

◆ mSeek

double AudioIoCallback::mSeek

Definition at line 284 of file AudioIO.h.

Referenced by CallbackDoSeek(), FillOutputBuffers(), and AudioIO::StartStream().

◆ mSilenceLevel

float AudioIoCallback::mSilenceLevel

◆ mSimulateRecordingErrors

bool AudioIoCallback::mSimulateRecordingErrors { false }

◆ mSoftwarePlaythrough

bool AudioIoCallback::mSoftwarePlaythrough

Read by a worker thread but unchanging during playback

Definition at line 297 of file AudioIO.h.

Referenced by DoPlaythrough(), AudioIO::StartMonitoring(), AudioIO::StartPortAudioStream(), and AudioIO::StartStream().

◆ mSuspendAudioThread

wxMutex AudioIoCallback::mSuspendAudioThread
protected

Definition at line 359 of file AudioIO.h.

Referenced by CallbackDoSeek(), and AudioIO::StopStream().

◆ mUsingAlsa

bool AudioIoCallback::mUsingAlsa { false }
protected

◆ mUsingJack

bool AudioIoCallback::mUsingJack { false }
protected

Definition at line 350 of file AudioIO.h.

Referenced by AudioIO::StartPortAudioStream().


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