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 mOldPlaybackVolume
 
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 std::map< int, std::vector< long > > mCachedPlaybackRates
 
static std::map< int, std::vector< long > > mCachedCaptureRates
 
static std::map< std::pair< int, int >, std::vector< long > > mCachedSampleRates
 
static int mCurrentPlaybackIndex { -1 }
 
static int mCurrentCaptureIndex { -1 }
 
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)
 Get a list of sample rates the output (playback) device supports. More...
 
static long GetClosestSupportedPlaybackRate (int devIndex, long rate)
 Find the closest supported sample rate for given playback device. More...
 
static std::vector< long > GetSupportedCaptureRates (int devIndex=-1)
 Get a list of sample rates the input (recording) device supports. More...
 
static long GetClosestSupportedCaptureRate (int devIndex, long rate)
 Find the closest supported sample rate for given recording device. More...
 
static std::vector< long > GetSupportedSampleRates (int playDevice=-1, int recDevice=-1)
 Get a list of sample rates the current input/output device combination supports. More...
 
static long GetClosestSupportedSampleRate (int playDevice, int recDevice, long rate)
 Find the closest supported sample rate for given playback and recording devices. More...
 
static int GetOptimalSupportedSampleRate ()
 Get a supported sample rate which can be used a an optimal default. More...
 
static bool IsPlaybackRateSupported (int devIndex, long rate)
 Check if the specified playback rate is supported by a device. More...
 
static bool IsCaptureRateSupported (int devIndex, long rate)
 Check if the specified sample rate is supported by a device. 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 111 of file AudioIO.h.

Member Typedef Documentation

◆ RingBuffers

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

Definition at line 257 of file AudioIO.h.

Constructor & Destructor Documentation

◆ AudioIoCallback()

AudioIoCallback::AudioIoCallback ( )

Definition at line 3107 of file AudioIO.cpp.

3108{
3109 auto &factories = AudioIOExt::GetFactories();
3110 for (auto &factory: factories)
3111 if (auto pExt = factory(mPlaybackSchedule))
3112 mAudioIOExt.push_back( move(pExt) );
3113}
static RegisteredToolbarFactory factory
static Factories & GetFactories()
Definition: AudioIOExt.cpp:15
PlaybackSchedule mPlaybackSchedule
Definition: AudioIO.h:396
std::vector< std::unique_ptr< AudioIOExtBase > > mAudioIOExt
Definition: AudioIOBase.h:381

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

Here is the call graph for this function:

◆ ~AudioIoCallback()

AudioIoCallback::~AudioIoCallback ( )

Definition at line 3116 of file AudioIO.cpp.

3117{
3118}

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 3121 of file AudioIO.cpp.

3126{
3127 // Poll sequences for change of state.
3128 // (User might click mute and solo buttons.)
3130 mCallbackReturn = paContinue;
3131
3132 if (IsPaused()
3133 // PRL: Why was this added? Was it only because of the mysterious
3134 // initial leading zeroes, now solved by setting mStreamToken early?
3135 // JKC: I think it's used for the MIDI time cursor. See comments
3136 // at head of file about AudioTime().
3137 || mStreamToken <= 0
3138 )
3139 mNumPauseFrames += framesPerBuffer;
3140
3141 for( auto &ext : Extensions() ) {
3142 ext.ComputeOtherTimings(mRate, IsPaused(),
3143 timeInfo,
3144 framesPerBuffer);
3145 ext.FillOtherBuffers(
3147 }
3148
3149 // ------ MEMORY ALLOCATIONS -----------------------------------------------
3150 // tempFloats will be a reusable scratch pad for (possibly format converted)
3151 // audio data. One temporary use is for the InputMeter data.
3152 const auto numPlaybackChannels = mNumPlaybackChannels;
3153 const auto numCaptureChannels = mNumCaptureChannels;
3154 const auto tempFloats = stackAllocate(float,
3155 framesPerBuffer * std::max(numCaptureChannels, numPlaybackChannels));
3156
3157 bool bVolEmulationActive =
3158 (outputBuffer && GetMixerOutputVol() != 1.0);
3159 // outputMeterFloats is the scratch pad for the output meter.
3160 // we can often reuse the existing outputBuffer and save on allocating
3161 // something new.
3162 const auto outputMeterFloats = bVolEmulationActive
3163 ? stackAllocate(float, framesPerBuffer * numPlaybackChannels)
3164 : outputBuffer;
3165 // ----- END of MEMORY ALLOCATIONS ------------------------------------------
3166
3167 if (inputBuffer && numCaptureChannels) {
3168 float *inputSamples;
3169
3170 if (mCaptureFormat == floatSample) {
3171 inputSamples = (float *) inputBuffer;
3172 }
3173 else {
3174 SamplesToFloats(reinterpret_cast<constSamplePtr>(inputBuffer),
3175 mCaptureFormat, tempFloats, framesPerBuffer * numCaptureChannels);
3176 inputSamples = tempFloats;
3177 }
3178
3180 inputSamples,
3181 framesPerBuffer);
3182
3183 // This function may queue up a pause or resume.
3184 // TODO this is a bit dodgy as it toggles the Pause, and
3185 // relies on an idle event to have handled that, so could
3186 // queue up multiple toggle requests and so do nothing.
3187 // Eventually it will sort itself out by random luck, but
3188 // the net effect is a delay in starting/stopping sound activated
3189 // recording.
3191 inputSamples,
3192 framesPerBuffer);
3193 }
3194
3195 // Even when paused, we do playthrough.
3196 // Initialise output buffer to zero or to playthrough data.
3197 // Initialise output meter values.
3199 inputBuffer,
3200 outputBuffer,
3201 framesPerBuffer,
3202 outputMeterFloats);
3203
3204 // Test for no sequence audio to play (because we are paused and have faded
3205 // out)
3206 if( IsPaused() && (( !mbMicroFades ) || mOldPlaybackVolume == 0.0f ))
3207 return mCallbackReturn;
3208
3209 // To add sequence output to output (to play sound on speaker)
3210 // possible exit, if we were seeking.
3212 outputBuffer,
3213 framesPerBuffer,
3214 outputMeterFloats))
3215 return mCallbackReturn;
3216
3217 // To move the cursor onwards. (uses mMaxFramesOutput)
3218 UpdateTimePosition(framesPerBuffer);
3219
3220 // To capture input into sequence (sound from microphone)
3222 inputBuffer,
3223 framesPerBuffer,
3224 statusFlags,
3225 tempFloats);
3226
3227 SendVuOutputMeterData( outputMeterFloats, framesPerBuffer);
3228
3229 return mCallbackReturn;
3230}
#define stackAllocate(T, count)
Definition: AudioIO.cpp:1956
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:314
int mStreamToken
Definition: AudioIOBase.h:310
bool IsPaused() const
Find out if playback / recording is currently paused.
unsigned CountSoloingSequences()
Definition: AudioIO.cpp:3076
size_t mNumPlaybackChannels
Definition: AudioIO.h:306
bool mbMicroFades
Definition: AudioIO.h:283
AudioIOExtRange Extensions()
Definition: AudioIO.h:163
float GetMixerOutputVol()
Definition: AudioIO.h:340
void CheckSoundActivatedRecordingLevel(float *inputSamples, unsigned long framesPerBuffer)
Definition: AudioIO.cpp:2636
void UpdateTimePosition(unsigned long framesPerBuffer)
Definition: AudioIO.cpp:2823
int mbHasSoloSequences
Definition: AudioIO.h:182
int mCallbackReturn
Definition: AudioIO.h:183
long mNumPauseFrames
How many frames of zeros were output due to pauses?
Definition: AudioIO.h:233
void DrainInputBuffers(constSamplePtr inputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackFlags statusFlags, float *tempFloats)
Definition: AudioIO.cpp:2838
void SendVuInputMeterData(const float *inputSamples, unsigned long framesPerBuffer)
Definition: AudioIO.cpp:3032
void SendVuOutputMeterData(const float *outputMeterFloats, unsigned long framesPerBuffer)
Definition: AudioIO.cpp:3048
void DoPlaythrough(constSamplePtr inputBuffer, float *outputBuffer, unsigned long framesPerBuffer, float *outputMeterFloats)
Definition: AudioIO.cpp:2996
float mOldPlaybackVolume
Definition: AudioIO.h:271
size_t mNumCaptureChannels
Definition: AudioIO.h:304
bool FillOutputBuffers(float *outputFloats, unsigned long framesPerBuffer, float *outputMeterFloats)
Definition: AudioIO.cpp:2674
sampleFormat mCaptureFormat
Definition: AudioIO.h:307

References CheckSoundActivatedRecordingLevel(), CountSoloingSequences(), DoPlaythrough(), DrainInputBuffers(), Extensions(), FillOutputBuffers(), floatSample, GetMixerOutputVol(), AudioIOBase::IsPaused(), mbHasSoloSequences, mbMicroFades, mCallbackReturn, mCaptureFormat, mNumCaptureChannels, mNumPauseFrames, mNumPlaybackChannels, mOldPlaybackVolume, 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 3292 of file AudioIO.cpp.

3294{
3295 if (IsPaused())
3296 return;
3297
3298 bool done =
3300 if (!done)
3301 return;
3302
3303 for( auto &ext : Extensions() )
3304 ext.SignalOtherCompletion();
3305 callbackReturn = paComplete;
3306}
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 3232 of file AudioIO.cpp.

3233{
3234 const int token = mStreamToken;
3235 wxMutexLocker locker(mSuspendAudioThread);
3236 if (token != mStreamToken)
3237 // This stream got destroyed while we waited for it
3238 return paAbort;
3239
3240 // Pause audio thread and wait for it to finish
3241 //
3242 // [PM] the following 8 lines of code could be probably replaced by
3243 // a single call to StopAudioThreadAndWait()
3244 //
3245 // CAUTION: when trying the above, you must also replace the setting of the
3246 // atomic before the return, with a call to StartAudioThread()
3247 //
3248 // If that works, then we can remove mAudioThreadSequenceBufferExchangeLoopActive,
3249 // as it will become unused; consequently, the AudioThread loop would get simpler too.
3250 //
3252 .store(false, std::memory_order_relaxed);
3253
3255 .load(std::memory_order_relaxed ) )
3256 {
3257 using namespace std::chrono;
3258 std::this_thread::sleep_for(50ms);
3259 }
3260
3261 // Calculate the NEW time position, in the PortAudio callback
3262 const auto time =
3264
3266 mSeek = 0.0;
3267
3268
3269 // Reset mixer positions and flush buffers for all sequences
3270 for (auto &mixer : mPlaybackMixers)
3271 mixer->Reposition( time, true );
3272 for (auto &buffer : mPlaybackBuffers) {
3273 const auto toDiscard = buffer->AvailForGet();
3274 const auto discarded = buffer->Discard( toDiscard );
3275 // wxASSERT( discarded == toDiscard );
3276 // but we can't assert in this thread
3277 wxUnusedVar(discarded);
3278 }
3279
3281
3282 // Reload the ring buffers
3284
3285 // Reenable the audio thread
3287 .store(true, std::memory_order_relaxed);
3288
3289 return paContinue;
3290}
std::atomic< bool > mAudioThreadSequenceBufferExchangeLoopRunning
Definition: AudioIO.h:311
double mSeek
Definition: AudioIO.h:285
wxMutex mSuspendAudioThread
Definition: AudioIO.h:360
std::vector< std::unique_ptr< Mixer > > mPlaybackMixers
Definition: AudioIO.h:276
std::atomic< bool > mAudioThreadSequenceBufferExchangeLoopActive
Definition: AudioIO.h:312
RingBuffers mPlaybackBuffers
Definition: AudioIO.h:267
void ProcessOnceAndWait(std::chrono::milliseconds sleepTime=std::chrono::milliseconds(50))
Definition: AudioIO.cpp:3346
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 2636 of file AudioIO.cpp.

2640{
2641 // Quick returns if next to nothing to do.
2642 if( !mPauseRec )
2643 return;
2644
2645 float maxPeak = 0.;
2646 for( unsigned long i = 0, cnt = framesPerBuffer * mNumCaptureChannels; i < cnt; ++i ) {
2647 float sample = fabs(*(inputSamples++));
2648 if (sample > maxPeak) {
2649 maxPeak = sample;
2650 }
2651 }
2652
2653 bool bShouldBePaused = maxPeak < mSilenceLevel;
2654 if( bShouldBePaused != IsPaused() )
2655 {
2656 auto pListener = GetListener();
2657 if ( pListener )
2658 pListener->OnSoundActivationThreshold();
2659 }
2660}
std::shared_ptr< AudioIOListener > GetListener() const
Definition: AudioIO.h:171
float mSilenceLevel
Definition: AudioIO.h:302
bool mPauseRec
True if Sound Activated Recording is enabled.
Definition: AudioIO.h:301

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 375 of file AudioIO.h.

376 { if (mRecordingException) wxAtomicDec( mRecordingException ); }
wxAtomicInt mRecordingException
Definition: AudioIO.h:372

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

Here is the caller graph for this function:

◆ CountSoloingSequences()

unsigned AudioIoCallback::CountSoloingSequences ( )

Definition at line 3076 of file AudioIO.cpp.

3076 {
3077 const auto numPlaybackSequences = mPlaybackSequences.size();
3078
3079 // MOVE_TO: CountSoloingSequences() function
3080 unsigned numSolo = 0;
3081 for (unsigned t = 0; t < numPlaybackSequences; t++ )
3082 if (mPlaybackSequences[t]->GetSolo())
3083 numSolo++;
3084 auto range = Extensions();
3085 numSolo += std::accumulate(range.begin(), range.end(), 0,
3086 [](unsigned sum, auto &ext){
3087 return sum + ext.CountOtherSolo(); });
3088 return numSolo;
3089}
ConstPlayableSequences mPlaybackSequences
Definition: AudioIO.h:268

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 2996 of file AudioIO.cpp.

3002{
3003 const auto numCaptureChannels = mNumCaptureChannels;
3004 const auto numPlaybackChannels = mNumPlaybackChannels;
3005
3006 // Quick returns if next to nothing to do.
3007 if( !outputBuffer )
3008 return;
3009 if( numPlaybackChannels <= 0 )
3010 return;
3011
3012 float *outputFloats = outputBuffer;
3013 for(unsigned i = 0; i < framesPerBuffer*numPlaybackChannels; i++)
3014 outputFloats[i] = 0.0;
3015
3016 if (inputBuffer && mSoftwarePlaythrough) {
3018 numCaptureChannels,
3019 outputBuffer, framesPerBuffer);
3020 }
3021
3022 // Copy the results to outputMeterFloats if necessary
3023 if (outputMeterFloats != outputFloats) {
3024 for (unsigned i = 0; i < framesPerBuffer*numPlaybackChannels; ++i) {
3025 outputMeterFloats[i] = outputFloats[i];
3026 }
3027 }
3028}
static void DoSoftwarePlaythrough(constSamplePtr inputBuffer, sampleFormat inputFormat, unsigned inputChannels, float *outputBuffer, unsigned long len)
Definition: AudioIO.cpp:2598
bool mSoftwarePlaythrough
Definition: AudioIO.h:298

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 2838 of file AudioIO.cpp.

2844{
2845 const auto numPlaybackChannels = mNumPlaybackChannels;
2846 const auto numCaptureChannels = mNumCaptureChannels;
2847
2848 // Quick returns if next to nothing to do.
2849 if (mStreamToken <= 0)
2850 return;
2851 if( !inputBuffer )
2852 return;
2853 if( numCaptureChannels <= 0 )
2854 return;
2855
2856 // If there are no playback sequences, and we are recording, then the
2857 // earlier checks for being past the end won't happen, so do it here.
2859 mCallbackReturn = paComplete;
2860 }
2861
2862 // The error likely from a too-busy CPU falling behind real-time data
2863 // is paInputOverflow
2864 bool inputError =
2865 (statusFlags & (paInputOverflow))
2866 && !(statusFlags & paPrimingOutput);
2867
2868 // But it seems it's easy to get false positives, at least on Mac
2869 // So we have not decided to enable this extra detection yet in
2870 // production
2871
2872 size_t len = framesPerBuffer;
2873 for(unsigned t = 0; t < numCaptureChannels; t++)
2874 len = std::min( len, mCaptureBuffers[t]->AvailForPut() );
2875
2876 if (mSimulateRecordingErrors && 100LL * rand() < RAND_MAX)
2877 // Make spurious errors for purposes of testing the error
2878 // reporting
2879 len = 0;
2880
2881 // A different symptom is that len < framesPerBuffer because
2882 // the other thread, executing SequenceBufferExchange, isn't consuming fast
2883 // enough from mCaptureBuffers; maybe it's CPU-bound, or maybe the
2884 // storage device it writes is too slow
2885 if (mDetectDropouts &&
2886 ((mDetectUpstreamDropouts.load(std::memory_order_relaxed)
2887 && inputError) ||
2888 len < framesPerBuffer) ) {
2889 // Assume that any good partial buffer should be written leftmost
2890 // and zeroes will be padded after; label the zeroes.
2891 auto start = mPlaybackSchedule.GetSequenceTime() +
2893 auto duration = (framesPerBuffer - len) / mRate;
2894 auto pLast = mLostCaptureIntervals.empty()
2895 ? nullptr : &mLostCaptureIntervals.back();
2896 if (pLast &&
2897 fabs(pLast->first + pLast->second - start) < 0.5/mRate)
2898 // Make one bigger interval, not two butting intervals
2899 pLast->second = start + duration - pLast->first;
2900 else
2901 mLostCaptureIntervals.emplace_back( start, duration );
2902 }
2903
2904 if (len < framesPerBuffer)
2905 {
2906 mLostSamples += (framesPerBuffer - len);
2907 wxPrintf(wxT("lost %d samples\n"), (int)(framesPerBuffer - len));
2908 }
2909
2910 if (len <= 0)
2911 return;
2912
2913 // We have an ASSERT in the AudioIO constructor to alert us to
2914 // possible issues with the (short*) cast. We'd have a problem if
2915 // sizeof(short) > sizeof(float) since our buffers are sized for floats.
2916 for(unsigned t = 0; t < numCaptureChannels; t++) {
2917
2918 // dmazzoni:
2919 // Un-interleave. Ugly special-case code required because the
2920 // capture channels could be in three different sample formats;
2921 // it'd be nice to be able to call CopySamples, but it can't
2922 // handle multiplying by the gain and then clipping. Bummer.
2923
2924 switch(mCaptureFormat) {
2925 case floatSample: {
2926 auto inputFloats = (const float *)inputBuffer;
2927 for(unsigned i = 0; i < len; i++)
2928 tempFloats[i] =
2929 inputFloats[numCaptureChannels*i+t];
2930 } break;
2931 case int24Sample:
2932 // We should never get here. Audacity's int24Sample format
2933 // is different from PortAudio's sample format and so we
2934 // make PortAudio return float samples when recording in
2935 // 24-bit samples.
2936 wxASSERT(false);
2937 break;
2938 case int16Sample: {
2939 auto inputShorts = (const short *)inputBuffer;
2940 short *tempShorts = (short *)tempFloats;
2941 for( unsigned i = 0; i < len; i++) {
2942 float tmp = inputShorts[numCaptureChannels*i+t];
2943 tmp = std::clamp(tmp, -32768.0f, 32767.0f);
2944 tempShorts[i] = (short)(tmp);
2945 }
2946 } break;
2947 } // switch
2948
2949 // JKC: mCaptureFormat must be for samples with sizeof(float) or
2950 // fewer bytes (because tempFloats is sized for floats). All
2951 // formats are 2 or 4 bytes, so we are OK.
2952 const auto put =
2953 mCaptureBuffers[t]->Put(
2954 (samplePtr)tempFloats, mCaptureFormat, len);
2955 // wxASSERT(put == len);
2956 // but we can't assert in this thread
2957 wxUnusedVar(put);
2958 mCaptureBuffers[t]->Flush();
2959 }
2960}
wxT("CloseDown"))
int min(int a, int b)
char * samplePtr
Definition: SampleFormat.h:57
RecordingSchedule mRecordingSchedule
Definition: AudioIO.h:395
RingBuffers mCaptureBuffers
Definition: AudioIO.h:258
bool mDetectDropouts
Definition: AudioIO.h:380
bool mSimulateRecordingErrors
Definition: AudioIO.h:388
std::atomic< bool > mDetectUpstreamDropouts
Definition: AudioIO.h:392
std::vector< std::pair< double, double > > mLostCaptureIntervals
Definition: AudioIO.h:378
unsigned long long mLostSamples
Definition: AudioIO.h:309
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 163 of file AudioIO.h.

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

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 2674 of file AudioIO.cpp.

2679{
2680 const auto numPlaybackSequences = mPlaybackSequences.size();
2681 const auto numPlaybackChannels = mNumPlaybackChannels;
2682
2683 mMaxFramesOutput = 0;
2684
2685 // Quick returns if next to nothing to do.
2686 if (mStreamToken <= 0 ||
2687 !outputFloats ||
2688 numPlaybackChannels <= 0) {
2689 // So that UpdateTimePosition() will be correct, in case of MIDI play with
2690 // no audio output channels
2691 mMaxFramesOutput = framesPerBuffer;
2692 return false;
2693 }
2694
2696 mSeek = 0.0;
2697
2698 if (mSeek){
2700 return true;
2701 }
2702
2703 // Choose a common size to take from all ring buffers
2704 const auto toGet =
2705 std::min<size_t>(framesPerBuffer, GetCommonlyReadyPlayback());
2706
2707 // Poke: If there are no playback sequences, then check playback
2708 // completion condition and do early return
2709 // PRL: Also consume frbom the single playback ring buffer
2710 if (numPlaybackSequences == 0) {
2711 mMaxFramesOutput = mPlaybackBuffers[0]->Discard(toGet);
2713 mLastPlaybackTimeMillis = ::wxGetUTCTimeMillis();
2714 return false;
2715 }
2716
2717 // JKC: The original code attempted to be faster by doing nothing on silenced audio.
2718 // This, IMHO, is 'premature optimisation'. Instead clearer and cleaner code would
2719 // simply use a volume of 0.0 for silent audio and go on through to the stage of
2720 // applying that 0.0 volume to the data mixed into the buffer.
2721 // Then (and only then) we would have if needed fast paths for:
2722 // - Applying a uniform volume of 0.0.
2723 // - Applying a uniform volume of 1.0.
2724 // - Applying some other uniform volume.
2725 // - Applying a linearly interpolated volume.
2726 // I would expect us not to need the fast paths, since linearly interpolated volume
2727 // is very cheap to process.
2728
2729 // ------ MEMORY ALLOCATION ----------------------
2730 // These are small structures.
2731 const auto tempBufs = stackAllocate(float *, numPlaybackChannels);
2732
2733 // And these are larger structures....
2734 for (unsigned int c = 0; c < numPlaybackChannels; c++)
2735 tempBufs[c] = stackAllocate(float, framesPerBuffer);
2736 // ------ End of MEMORY ALLOCATION ---------------
2737
2738 auto playbackVolume = ExpGain(GetMixerOutputVol());
2739 if (mForceFadeOut.load(std::memory_order_relaxed) || IsPaused())
2740 playbackVolume = 0.0;
2741
2742 for(unsigned n = 0; n < numPlaybackChannels; ++n)
2743 {
2744 decltype(framesPerBuffer) len = mPlaybackBuffers[n]->Get(
2745 reinterpret_cast<samplePtr>(tempBufs[n]),
2747 toGet
2748 );
2749 if(len < framesPerBuffer)
2750 {
2751 // This used to happen normally at the end of non-looping
2752 // plays, but it can also be an anomalous case where the
2753 // supply from SequenceBufferExchange fails to keep up with the
2754 // real-time demand in this thread (see bug 1932). We
2755 // must supply something to the sound card, so pad it with
2756 // zeroes and not random garbage.
2757 memset((void*)&tempBufs[n][len], 0,
2758 (framesPerBuffer - len) * sizeof(float));
2759 }
2760
2761 // PRL: More recent rewrites of SequenceBufferExchange should guarantee a
2762 // padding out of the ring buffers so that equal lengths are
2763 // available, so maxLen ought to increase from 0 only once
2764 mMaxFramesOutput = std::max(mMaxFramesOutput, len);
2765
2766 len = mMaxFramesOutput;
2767
2768 // Realtime effect transformation of the sound used to happen here
2769 // but it is now done already on the producer side of the RingBuffer
2770
2771 // Mix the results with the existing output (software playthrough) and
2772 // apply panning. If post panning effects are desired, the panning would
2773 // need to be be split out from the mixing and applied in a separate step.
2774
2775 // Our channels aren't silent. We need to pass their data on.
2776 //
2777 // Each channel in the sequences can output to more than one channel on
2778 // the device. For example mono channels output to both left and right
2779 // output channels.
2780 if (len > 0)
2781 {
2782 // Output volume emulation: possibly copy meter samples, then
2783 // apply volume, then copy to the output buffer
2784 if(outputMeterFloats != outputFloats)
2785 {
2786 for ( unsigned i = 0; i < len; ++i)
2787 outputMeterFloats[numPlaybackChannels*i+n] +=
2788 playbackVolume*tempBufs[n][i];
2789 }
2790
2791 auto oldVolume = mOldPlaybackVolume;
2792 // if no microfades, jump in volume.
2793 if (!mbMicroFades)
2794 oldVolume = playbackVolume;
2795
2796 // Linear interpolate.
2797 // PRL todo: choose denominator differently, so it doesn't depend on
2798 // framesPerBuffer, which is influenced by the portAudio implementation in
2799 // opaque ways
2800 const float deltaVolume = (playbackVolume - oldVolume) / len;
2801 for (unsigned i = 0; i < len; i++)
2802 {
2803 outputFloats[numPlaybackChannels * i + n] +=
2804 (oldVolume + deltaVolume * i) * tempBufs[n][i];
2805 }
2806 }
2808 }
2809
2810 mOldPlaybackVolume = playbackVolume;
2811
2812 // wxASSERT( maxLen == toGet );
2813
2814 mLastPlaybackTimeMillis = ::wxGetUTCTimeMillis();
2815
2816 ClampBuffer( outputFloats, framesPerBuffer*numPlaybackChannels );
2817 if (outputMeterFloats != outputFloats)
2818 ClampBuffer( outputMeterFloats, framesPerBuffer*numPlaybackChannels );
2819
2820 return false;
2821}
void ClampBuffer(float *pBuffer, unsigned long len)
Definition: AudioIO.cpp:2663
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:3292
std::atomic< bool > mForceFadeOut
Definition: AudioIO.h:328
wxLongLong mLastPlaybackTimeMillis
Definition: AudioIO.h:330
int CallbackDoSeek()
Definition: AudioIO.cpp:3232
unsigned long mMaxFramesOutput
Definition: AudioIO.h:281
size_t GetCommonlyReadyPlayback()
Get the number of audio samples ready in all of the playback buffers.
Definition: AudioIO.cpp:1854
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, mOldPlaybackVolume, 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 1854 of file AudioIO.cpp.

1855{
1857}
static size_t MinValue(const RingBuffers &buffers, size_t(RingBuffer::*pmf)() const)
Definition: AudioIO.cpp:1837
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 1859 of file AudioIO.cpp.

1860{
1862}
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 171 of file AudioIO.h.

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

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 340 of file AudioIO.h.

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

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

Here is the caller graph for this function:

◆ HasRecordingException()

bool AudioIoCallback::HasRecordingException ( ) const
inline

Definition at line 366 of file AudioIO.h.

367 { 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 384 of file AudioIO.h.

385 { return mLostCaptureIntervals; }

◆ MinValue()

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

Definition at line 1837 of file AudioIO.cpp.

1839{
1840 return std::accumulate(buffers.begin(), buffers.end(),
1841 std::numeric_limits<size_t>::max(),
1842 [pmf](auto value, auto &pBuffer){
1843 return std::min(value, (pBuffer.get()->*pmf)()); });
1844}

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 3346 of file AudioIO.cpp.

3347{
3349 .store(true, std::memory_order_release);
3350
3352 .load(std::memory_order_acquire))
3353 {
3354 using namespace std::chrono;
3355 std::this_thread::sleep_for(sleepTime);
3356 }
3357}
std::atomic< bool > mAudioThreadShouldCallSequenceBufferExchangeOnce
Definition: AudioIO.h:310

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 3032 of file AudioIO.cpp.

3036{
3037 const auto numCaptureChannels = mNumCaptureChannels;
3038 auto pInputMeter = mInputMeter.lock();
3039 if ( !pInputMeter )
3040 return;
3041 if( pInputMeter->IsMeterDisabled())
3042 return;
3043 pInputMeter->UpdateDisplay(
3044 numCaptureChannels, framesPerBuffer, inputSamples);
3045}
std::weak_ptr< Meter > mInputMeter
Definition: AudioIOBase.h:318

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 3048 of file AudioIO.cpp.

3051{
3052 const auto numPlaybackChannels = mNumPlaybackChannels;
3053
3054 auto pOutputMeter = mOutputMeter.lock();
3055 if (!pOutputMeter)
3056 return;
3057 if( pOutputMeter->IsMeterDisabled() )
3058 return;
3059 if( !outputMeterFloats)
3060 return;
3061 pOutputMeter->UpdateDisplay(
3062 numPlaybackChannels, framesPerBuffer, outputMeterFloats);
3063
3064 //v Vaughan, 2011-02-25: Moved this update back to TrackPanel::OnTimer()
3065 // as it helps with playback issues reported by Bill and noted on Bug 258.
3066 // The problem there occurs if Software Playthrough is on.
3067 // Could conditionally do the update here if Software Playthrough is off,
3068 // and in TrackPanel::OnTimer() if Software Playthrough is on, but not now.
3069 // PRL 12 Jul 2015: and what was in TrackPanel::OnTimer is now handled by means of track panel timer events
3070 //MixerBoard* pMixerBoard = mOwningProject->GetMixerBoard();
3071 //if (pMixerBoard)
3072 // pMixerBoard->UpdateMeters(GetStreamTime(),
3073 // (pProj->GetControlToolBar()->GetLastPlayMode() == loopedPlay));
3074}
std::weak_ptr< Meter > mOutputMeter
Definition: AudioIOBase.h:319

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 3097 of file AudioIO.cpp.

3098{
3099 return !ps.GetSolo() && (
3100 // Cut if somebody else is soloing
3102 // Cut if we're muted (and not soloing)
3103 ps.GetMute()
3104 );
3105}
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 2419 of file AudioIO.cpp.

2421{
2422 if (IsBusy())
2423 return;
2424
2425 mListener = listener;
2426}
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 342 of file AudioIO.h.

342 {
343 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 373 of file AudioIO.h.

374 { wxAtomicInc( mRecordingException ); }

Referenced by AudioIO::DrainRecordBuffers().

Here is the caller graph for this function:

◆ StartAudioThread()

void AudioIoCallback::StartAudioThread ( )

Definition at line 3316 of file AudioIO.cpp.

3317{
3318 mAudioThreadSequenceBufferExchangeLoopRunning.store(true, std::memory_order_release);
3319}

References mAudioThreadSequenceBufferExchangeLoopRunning.

Referenced by AudioIO::StartStream().

Here is the caller graph for this function:

◆ StopAudioThread()

void AudioIoCallback::StopAudioThread ( )

Definition at line 3331 of file AudioIO.cpp.

3332{
3333 mAudioThreadSequenceBufferExchangeLoopRunning.store(false, std::memory_order_release);
3334}

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 2823 of file AudioIO.cpp.

2824{
2825 // Quick returns if next to nothing to do.
2826 if (mStreamToken <= 0)
2827 return;
2828
2829 // Update the position seen by drawing code
2832}
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 3321 of file AudioIO.cpp.

3322{
3323 while (mAudioThreadAcknowledge.load(std::memory_order_acquire) != Acknowledge::eStart)
3324 {
3325 using namespace std::chrono;
3326 std::this_thread::sleep_for(50ms);
3327 }
3328 mAudioThreadAcknowledge.store(Acknowledge::eNone, std::memory_order_release);
3329}
std::atomic< Acknowledge > mAudioThreadAcknowledge
Definition: AudioIO.h:314

References eNone, eStart, and mAudioThreadAcknowledge.

Referenced by AudioIO::StartStream().

Here is the caller graph for this function:

◆ WaitForAudioThreadStopped()

void AudioIoCallback::WaitForAudioThreadStopped ( )

Definition at line 3336 of file AudioIO.cpp.

3337{
3338 while (mAudioThreadAcknowledge.load(std::memory_order_acquire) != Acknowledge::eStop)
3339 {
3340 using namespace std::chrono;
3341 std::this_thread::sleep_for(50ms);
3342 }
3343 mAudioThreadAcknowledge.store(Acknowledge::eNone, std::memory_order_release);
3344}

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 381 of file AudioIOBase.h.

Referenced by AudioIoCallback().

◆ mAudioThread

std::thread AudioIoCallback::mAudioThread

Definition at line 252 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 312 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 182 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 283 of file AudioIO.h.

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

◆ mCachedBestRateCapturing

bool AudioIoCallback::mCachedBestRateCapturing
staticprotected

Definition at line 356 of file AudioIO.h.

Referenced by AudioIO::GetBestRate().

◆ mCachedBestRateOut

double AudioIoCallback::mCachedBestRateOut
staticprotected

Definition at line 354 of file AudioIO.h.

Referenced by AudioIO::GetBestRate().

◆ mCachedBestRatePlaying

bool AudioIoCallback::mCachedBestRatePlaying
staticprotected

Definition at line 355 of file AudioIO.h.

Referenced by AudioIO::GetBestRate().

◆ mCallbackReturn

int AudioIoCallback::mCallbackReturn

Definition at line 183 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 287 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 380 of file AudioIO.h.

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

◆ mDetectUpstreamDropouts

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

◆ mFactor

double AudioIoCallback::mFactor

Definition at line 280 of file AudioIO.h.

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

◆ mFinishAudioThread

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

Definition at line 253 of file AudioIO.h.

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

◆ mForceFadeOut

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

Definition at line 328 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 292 of file AudioIO.h.

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

◆ mLastPaError

PaError AudioIoCallback::mLastPaError

◆ mLastPlaybackTimeMillis

wxLongLong AudioIoCallback::mLastPlaybackTimeMillis

Definition at line 330 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 333 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 348 of file AudioIO.h.

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

◆ mLostCaptureIntervals

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

Definition at line 378 of file AudioIO.h.

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

◆ mLostSamples

unsigned long long AudioIoCallback::mLostSamples { 0 }

Definition at line 309 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 265 of file AudioIO.h.

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

◆ mMaxFramesOutput

unsigned long AudioIoCallback::mMaxFramesOutput

Definition at line 281 of file AudioIO.h.

Referenced by FillOutputBuffers(), and UpdateTimePosition().

◆ mMinCaptureSecsToCopy

double AudioIoCallback::mMinCaptureSecsToCopy

Definition at line 296 of file AudioIO.h.

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

◆ mMixerOutputVol

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

Definition at line 278 of file AudioIO.h.

◆ mNextStreamToken

int AudioIoCallback::mNextStreamToken = 0
static

Definition at line 279 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 233 of file AudioIO.h.

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

◆ mNumPlaybackChannels

size_t AudioIoCallback::mNumPlaybackChannels

◆ mOldPlaybackVolume

float AudioIoCallback::mOldPlaybackVolume

Definition at line 271 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 301 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 294 of file AudioIO.h.

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

◆ mPlaybackRingBufferSecs

PlaybackPolicy::Duration AudioIoCallback::mPlaybackRingBufferSecs

Definition at line 286 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers().

◆ mPlaybackSamplesToCopy

size_t AudioIoCallback::mPlaybackSamplesToCopy

Preferred batch size for replenishing the playback RingBuffer.

Definition at line 290 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 262 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 400 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 372 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 285 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 298 of file AudioIO.h.

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

◆ mSuspendAudioThread

wxMutex AudioIoCallback::mSuspendAudioThread
protected

Definition at line 360 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 351 of file AudioIO.h.

Referenced by AudioIO::StartPortAudioStream().


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