Audacity  3.0.3
Classes | Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | Friends | 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
 

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 CountSoloingTracks ()
 
bool TrackShouldBeSilent (const WaveTrack &wt)
 
bool TrackHasBeenFadedOut (const WaveTrack &wt)
 
bool AllTracksAlreadySilent ()
 
void CheckSoundActivatedRecordingLevel (float *inputSamples, unsigned long framesPerBuffer)
 
void AddToOutputChannel (unsigned int chan, float *outputMeterFloats, float *outputFloats, const float *tempBuf, bool drop, unsigned long len, WaveTrack *vt)
 
bool FillOutputBuffers (float *outputBuffer, 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...
 
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 mbHasSoloTracks
 
int mCallbackReturn
 
long mNumPauseFrames
 How many frames of zeros were output due to pauses? More...
 
std::unique_ptr< AudioThreadmThread
 
ArrayOf< std::unique_ptr< Resample > > mResample
 
ArrayOf< std::unique_ptr< RingBuffer > > mCaptureBuffers
 
WaveTrackArray mCaptureTracks
 
ArrayOf< std::unique_ptr< RingBuffer > > mPlaybackBuffers
 
WaveTrackArray mPlaybackTracks
 
std::vector< std::unique_ptr< Mixer > > mPlaybackMixers
 
float mMixerOutputVol { 1.0 }
 
double mFactor
 
unsigned long mMaxFramesOutput
 
bool mbMicroFades
 
double mSeek
 
double mPlaybackRingBufferSecs
 
double mCaptureRingBufferSecs
 
size_t mPlaybackSamplesToCopy
 Preferred batch size for replenishing the playback RingBuffer. 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
 
unsigned int mNumCaptureChannels
 
unsigned int mNumPlaybackChannels
 
sampleFormat mCaptureFormat
 
unsigned long long mLostSamples { 0 }
 
volatile bool mAudioThreadShouldCallTrackBufferExchangeOnce
 
volatile bool mAudioThreadTrackBufferExchangeLoopRunning
 
volatile bool mAudioThreadTrackBufferExchangeLoopActive
 
std::atomic< bool > mForceFadeOut { false }
 
wxLongLong mLastPlaybackTimeMillis
 
volatile double mLastRecordingOffset
 
PaError mLastPaError
 
bool mSimulateRecordingErrors { false }
 
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

void SetRecordingException ()
 
void ClearRecordingException ()
 

Protected Attributes

bool mUpdateMeters
 
volatile bool mUpdatingMeters
 
std::weak_ptr< AudioIOListenermListener
 
bool mUsingAlsa { false }
 
wxMutex mSuspendAudioThread
 
wxAtomicInt mRecordingException {}
 
std::vector< std::pair< double, double > > mLostCaptureIntervals
 
bool mDetectDropouts { true }
 
RecordingSchedule mRecordingSchedule {}
 
PlaybackSchedule mPlaybackSchedule
 
- Protected Attributes inherited from AudioIOBase
std::weak_ptr< AudacityProjectmOwningProject
 
bool mPaused
 True if audio playback is paused. More...
 
volatile int mStreamToken
 
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
 

Friends

class AudioThread
 

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...
 
- 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...
 

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

Constructor & Destructor Documentation

◆ AudioIoCallback()

AudioIoCallback::AudioIoCallback ( )

Definition at line 2916 of file AudioIO.cpp.

2917 {
2918  auto &factories = AudioIOExt::GetFactories();
2919  for (auto &factory: factories)
2920  if (auto pExt = factory(mPlaybackSchedule))
2921  mAudioIOExt.push_back( move(pExt) );
2922 }

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

Here is the call graph for this function:

◆ ~AudioIoCallback()

AudioIoCallback::~AudioIoCallback ( )

Definition at line 2925 of file AudioIO.cpp.

2926 {
2927 }

Member Function Documentation

◆ AddToOutputChannel()

void AudioIoCallback::AddToOutputChannel ( unsigned int  chan,
float *  outputMeterFloats,
float *  outputFloats,
const float *  tempBuf,
bool  drop,
unsigned long  len,
WaveTrack vt 
)

Definition at line 2324 of file AudioIO.cpp.

2332 {
2333  const auto numPlaybackChannels = mNumPlaybackChannels;
2334 
2335  float gain = vt->GetChannelGain(chan);
2336  if (drop || mForceFadeOut.load(std::memory_order_relaxed) || mPaused)
2337  gain = 0.0;
2338 
2339  // Output volume emulation: possibly copy meter samples, then
2340  // apply volume, then copy to the output buffer
2341  if (outputMeterFloats != outputFloats)
2342  for ( unsigned i = 0; i < len; ++i)
2343  outputMeterFloats[numPlaybackChannels*i+chan] +=
2344  gain*tempBuf[i];
2345 
2346  // DV: We use gain to emulate panning.
2347  // Let's keep the old behavior for panning.
2348  gain *= ExpGain(mMixerOutputVol);
2349 
2350  float oldGain = vt->GetOldChannelGain(chan);
2351  if( gain != oldGain )
2352  vt->SetOldChannelGain(chan, gain);
2353  // if no microfades, jump in volume.
2354  if( !mbMicroFades )
2355  oldGain =gain;
2356  wxASSERT(len > 0);
2357 
2358  // Linear interpolate.
2359  float deltaGain = (gain - oldGain) / len;
2360  for (unsigned i = 0; i < len; i++)
2361  outputFloats[numPlaybackChannels*i+chan] += (oldGain + deltaGain * i) *tempBuf[i];
2362 };

References ExpGain(), WaveTrack::GetChannelGain(), WaveTrack::GetOldChannelGain(), mbMicroFades, mForceFadeOut, mMixerOutputVol, mNumPlaybackChannels, AudioIOBase::mPaused, and WaveTrack::SetOldChannelGain().

Referenced by FillOutputBuffers().

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

◆ AllTracksAlreadySilent()

bool AudioIoCallback::AllTracksAlreadySilent ( )

Definition at line 2904 of file AudioIO.cpp.

2905 {
2906  const bool dropAllQuickly = std::all_of(
2907  mPlaybackTracks.begin(), mPlaybackTracks.end(),
2908  [&]( const std::shared_ptr< WaveTrack > &vt )
2909  { return
2910  TrackShouldBeSilent( *vt ) &&
2911  TrackHasBeenFadedOut( *vt ); }
2912  );
2913  return dropAllQuickly;
2914 }

References mPlaybackTracks.

Referenced by AudioCallback().

Here is the caller graph for this function:

◆ AudioCallback()

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

Definition at line 2930 of file AudioIO.cpp.

2935 {
2936  // Poll tracks for change of state. User might click mute and solo buttons.
2938  mCallbackReturn = paContinue;
2939 
2940  if (IsPaused()
2941  // PRL: Why was this added? Was it only because of the mysterious
2942  // initial leading zeroes, now solved by setting mStreamToken early?
2943  // JKC: I think it's used for the MIDI time cursor. See comments
2944  // at head of file about AudioTime().
2945  || mStreamToken <= 0
2946  )
2947  mNumPauseFrames += framesPerBuffer;
2948 
2949  for( auto &ext : Extensions() ) {
2950  ext.ComputeOtherTimings(mRate,
2951  timeInfo,
2952  framesPerBuffer);
2953  ext.FillOtherBuffers(
2955  }
2956 
2957  // ------ MEMORY ALLOCATIONS -----------------------------------------------
2958  // tempFloats will be a reusable scratch pad for (possibly format converted)
2959  // audio data. One temporary use is for the InputMeter data.
2960  const auto numPlaybackChannels = mNumPlaybackChannels;
2961  const auto numCaptureChannels = mNumCaptureChannels;
2962  float *tempFloats = (float *)alloca(framesPerBuffer*sizeof(float)*
2963  MAX(numCaptureChannels,numPlaybackChannels));
2964 
2965  bool bVolEmulationActive =
2966  (outputBuffer && mMixerOutputVol != 1.0);
2967  // outputMeterFloats is the scratch pad for the output meter.
2968  // we can often reuse the existing outputBuffer and save on allocating
2969  // something new.
2970  float *outputMeterFloats = bVolEmulationActive ?
2971  (float *)alloca(framesPerBuffer*numPlaybackChannels * sizeof(float)) :
2972  outputBuffer;
2973  // ----- END of MEMORY ALLOCATIONS ------------------------------------------
2974 
2975  if (inputBuffer && numCaptureChannels) {
2976  float *inputSamples;
2977 
2978  if (mCaptureFormat == floatSample) {
2979  inputSamples = (float *) inputBuffer;
2980  }
2981  else {
2982  SamplesToFloats(reinterpret_cast<constSamplePtr>(inputBuffer),
2983  mCaptureFormat, tempFloats, framesPerBuffer * numCaptureChannels);
2984  inputSamples = tempFloats;
2985  }
2986 
2988  inputSamples,
2989  framesPerBuffer);
2990 
2991  // This function may queue up a pause or resume.
2992  // TODO this is a bit dodgy as it toggles the Pause, and
2993  // relies on an idle event to have handled that, so could
2994  // queue up multiple toggle requests and so do nothing.
2995  // Eventually it will sort itself out by random luck, but
2996  // the net effect is a delay in starting/stopping sound activated
2997  // recording.
2999  inputSamples,
3000  framesPerBuffer);
3001  }
3002 
3003  // Even when paused, we do playthrough.
3004  // Initialise output buffer to zero or to playthrough data.
3005  // Initialise output meter values.
3006  DoPlaythrough(
3007  inputBuffer,
3008  outputBuffer,
3009  framesPerBuffer,
3010  outputMeterFloats);
3011 
3012  // Test for no track audio to play (because we are paused and have faded out)
3013  if( mPaused && (( !mbMicroFades ) || AllTracksAlreadySilent() ))
3014  return mCallbackReturn;
3015 
3016  // To add track output to output (to play sound on speaker)
3017  // possible exit, if we were seeking.
3018  if( FillOutputBuffers(
3019  outputBuffer,
3020  framesPerBuffer,
3021  outputMeterFloats))
3022  return mCallbackReturn;
3023 
3024  // To move the cursor onwards. (uses mMaxFramesOutput)
3025  UpdateTimePosition(framesPerBuffer);
3026 
3027  // To capture input into track (sound from microphone)
3029  inputBuffer,
3030  framesPerBuffer,
3031  statusFlags,
3032  tempFloats);
3033 
3034  SendVuOutputMeterData( outputMeterFloats, framesPerBuffer);
3035 
3036  return mCallbackReturn;
3037 }

References AllTracksAlreadySilent(), CheckSoundActivatedRecordingLevel(), CountSoloingTracks(), DoPlaythrough(), DrainInputBuffers(), Extensions(), FillOutputBuffers(), floatSample, AudioIOBase::IsPaused(), MAX, mbHasSoloTracks, mbMicroFades, mCallbackReturn, mCaptureFormat, mMixerOutputVol, mNumCaptureChannels, mNumPauseFrames, mNumPlaybackChannels, AudioIOBase::mPaused, AudioIOBase::mRate, AudioIOBase::mStreamToken, SamplesToFloats(), SendVuInputMeterData(), SendVuOutputMeterData(), and UpdateTimePosition().

Here is the call graph for this function:

◆ CallbackCheckCompletion()

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

Definition at line 3093 of file AudioIO.cpp.

3095 {
3096  if (mPaused)
3097  return;
3098 
3099  bool done =
3101  if (!done)
3102  return;
3103 
3104  for( auto &ext : Extensions() )
3105  ext.SignalOtherCompletion();
3106  callbackReturn = paComplete;
3107 }

References PlaybackPolicy::Done(), Extensions(), PlaybackSchedule::GetPolicy(), AudioIOBase::mPaused, 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 3039 of file AudioIO.cpp.

3040 {
3041  const int token = mStreamToken;
3042  wxMutexLocker locker(mSuspendAudioThread);
3043  if (token != mStreamToken)
3044  // This stream got destroyed while we waited for it
3045  return paAbort;
3046 
3047  const auto numPlaybackTracks = mPlaybackTracks.size();
3048 
3049  // Pause audio thread and wait for it to finish
3052  {
3053  wxMilliSleep( 50 );
3054  }
3055 
3056  // Calculate the NEW time position, in the PortAudio callback
3057  const auto time =
3059 
3061  mSeek = 0.0;
3062 
3063 
3064  // Reset mixer positions and flush buffers for all tracks
3065  for (size_t i = 0; i < numPlaybackTracks; i++)
3066  {
3067  const bool skipping = true;
3068  mPlaybackMixers[i]->Reposition( time, skipping );
3069  const auto toDiscard =
3070  mPlaybackBuffers[i]->AvailForGet();
3071  const auto discarded =
3072  mPlaybackBuffers[i]->Discard( toDiscard );
3073  // wxASSERT( discarded == toDiscard );
3074  // but we can't assert in this thread
3075  wxUnusedVar(discarded);
3076  }
3077 
3079 
3080  // Reload the ring buffers
3083  {
3084  wxMilliSleep( 50 );
3085  }
3086 
3087  // Reenable the audio thread
3089 
3090  return paContinue;
3091 }

References PlaybackSchedule::GetPolicy(), mAudioThreadShouldCallTrackBufferExchangeOnce, mAudioThreadTrackBufferExchangeLoopActive, mAudioThreadTrackBufferExchangeLoopRunning, mPlaybackBuffers, mPlaybackMixers, mPlaybackSchedule, mPlaybackTracks, mSeek, AudioIOBase::mStreamToken, mSuspendAudioThread, PlaybackSchedule::mTimeQueue, PlaybackPolicy::OffsetTrackTime(), PlaybackSchedule::TimeQueue::Prime(), and PlaybackSchedule::SetTrackTime().

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

2300 {
2301  // Quick returns if next to nothing to do.
2302  if( !mPauseRec )
2303  return;
2304 
2305  float maxPeak = 0.;
2306  for( unsigned long i = 0, cnt = framesPerBuffer * mNumCaptureChannels; i < cnt; ++i ) {
2307  float sample = fabs(*(inputSamples++));
2308  if (sample > maxPeak) {
2309  maxPeak = sample;
2310  }
2311  }
2312 
2313  bool bShouldBePaused = maxPeak < mSilenceLevel;
2314  if( bShouldBePaused != IsPaused() )
2315  {
2316  auto pListener = GetListener();
2317  if ( pListener )
2318  pListener->OnSoundActivationThreshold();
2319  }
2320 }

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

322  { if (mRecordingException) wxAtomicDec( mRecordingException ); }

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

Here is the caller graph for this function:

◆ CountSoloingTracks()

unsigned AudioIoCallback::CountSoloingTracks ( )

Definition at line 2860 of file AudioIO.cpp.

2860  {
2861  const auto numPlaybackTracks = mPlaybackTracks.size();
2862 
2863  // MOVE_TO: CountSoloedTracks() function
2864  unsigned numSolo = 0;
2865  for(unsigned t = 0; t < numPlaybackTracks; t++ )
2866  if( mPlaybackTracks[t]->GetSolo() )
2867  numSolo++;
2868  auto range = Extensions();
2869  numSolo += std::accumulate(range.begin(), range.end(), 0,
2870  [](unsigned sum, auto &ext){
2871  return sum + ext.CountOtherSoloTracks(); });
2872  return numSolo;
2873 }

References Extensions(), and mPlaybackTracks.

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

2751 {
2752  const auto numCaptureChannels = mNumCaptureChannels;
2753  const auto numPlaybackChannels = mNumPlaybackChannels;
2754 
2755  // Quick returns if next to nothing to do.
2756  if( !outputBuffer )
2757  return;
2758  if( numPlaybackChannels <= 0 )
2759  return;
2760 
2761  float *outputFloats = outputBuffer;
2762  for(unsigned i = 0; i < framesPerBuffer*numPlaybackChannels; i++)
2763  outputFloats[i] = 0.0;
2764 
2765  if (inputBuffer && mSoftwarePlaythrough) {
2767  numCaptureChannels,
2768  outputBuffer, framesPerBuffer);
2769  }
2770 
2771  // Copy the results to outputMeterFloats if necessary
2772  if (outputMeterFloats != outputFloats) {
2773  for (unsigned i = 0; i < framesPerBuffer*numPlaybackChannels; ++i) {
2774  outputMeterFloats[i] = outputFloats[i];
2775  }
2776  }
2777 }

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

2594 {
2595  const auto numPlaybackTracks = mPlaybackTracks.size();
2596  const auto numPlaybackChannels = mNumPlaybackChannels;
2597  const auto numCaptureChannels = mNumCaptureChannels;
2598 
2599  // Quick returns if next to nothing to do.
2600  if (mStreamToken <= 0)
2601  return;
2602  if( !inputBuffer )
2603  return;
2604  if( numCaptureChannels <= 0 )
2605  return;
2606 
2607  // If there are no playback tracks, and we are recording, then the
2608  // earlier checks for being past the end won't happen, so do it here.
2610  mCallbackReturn = paComplete;
2611  }
2612 
2613  // The error likely from a too-busy CPU falling behind real-time data
2614  // is paInputOverflow
2615  bool inputError =
2616  (statusFlags & (paInputOverflow))
2617  && !(statusFlags & paPrimingOutput);
2618 
2619  // But it seems it's easy to get false positives, at least on Mac
2620  // So we have not decided to enable this extra detection yet in
2621  // production
2622 
2623  size_t len = framesPerBuffer;
2624  for(unsigned t = 0; t < numCaptureChannels; t++)
2625  len = std::min( len, mCaptureBuffers[t]->AvailForPut() );
2626 
2627  if (mSimulateRecordingErrors && 100LL * rand() < RAND_MAX)
2628  // Make spurious errors for purposes of testing the error
2629  // reporting
2630  len = 0;
2631 
2632  // A different symptom is that len < framesPerBuffer because
2633  // the other thread, executing TrackBufferExchange, isn't consuming fast
2634  // enough from mCaptureBuffers; maybe it's CPU-bound, or maybe the
2635  // storage device it writes is too slow
2636  if (mDetectDropouts &&
2637  ((mDetectUpstreamDropouts && inputError) ||
2638  len < framesPerBuffer) ) {
2639  // Assume that any good partial buffer should be written leftmost
2640  // and zeroes will be padded after; label the zeroes.
2641  auto start = mPlaybackSchedule.GetTrackTime() +
2643  auto duration = (framesPerBuffer - len) / mRate;
2644  auto pLast = mLostCaptureIntervals.empty()
2645  ? nullptr : &mLostCaptureIntervals.back();
2646  if (pLast &&
2647  fabs(pLast->first + pLast->second - start) < 0.5/mRate)
2648  // Make one bigger interval, not two butting intervals
2649  pLast->second = start + duration - pLast->first;
2650  else
2651  mLostCaptureIntervals.emplace_back( start, duration );
2652  }
2653 
2654  if (len < framesPerBuffer)
2655  {
2656  mLostSamples += (framesPerBuffer - len);
2657  wxPrintf(wxT("lost %d samples\n"), (int)(framesPerBuffer - len));
2658  }
2659 
2660  if (len <= 0)
2661  return;
2662 
2663  // We have an ASSERT in the AudioIO constructor to alert us to
2664  // possible issues with the (short*) cast. We'd have a problem if
2665  // sizeof(short) > sizeof(float) since our buffers are sized for floats.
2666  for(unsigned t = 0; t < numCaptureChannels; t++) {
2667 
2668  // dmazzoni:
2669  // Un-interleave. Ugly special-case code required because the
2670  // capture channels could be in three different sample formats;
2671  // it'd be nice to be able to call CopySamples, but it can't
2672  // handle multiplying by the gain and then clipping. Bummer.
2673 
2674  switch(mCaptureFormat) {
2675  case floatSample: {
2676  auto inputFloats = (const float *)inputBuffer;
2677  for(unsigned i = 0; i < len; i++)
2678  tempFloats[i] =
2679  inputFloats[numCaptureChannels*i+t];
2680  } break;
2681  case int24Sample:
2682  // We should never get here. Audacity's int24Sample format
2683  // is different from PortAudio's sample format and so we
2684  // make PortAudio return float samples when recording in
2685  // 24-bit samples.
2686  wxASSERT(false);
2687  break;
2688  case int16Sample: {
2689  auto inputShorts = (const short *)inputBuffer;
2690  short *tempShorts = (short *)tempFloats;
2691  for( unsigned i = 0; i < len; i++) {
2692  float tmp = inputShorts[numCaptureChannels*i+t];
2693  tmp = wxClip( -32768, tmp, 32767 );
2694  tempShorts[i] = (short)(tmp);
2695  }
2696  } break;
2697  } // switch
2698 
2699  // JKC: mCaptureFormat must be for samples with sizeof(float) or
2700  // fewer bytes (because tempFloats is sized for floats). All
2701  // formats are 2 or 4 bytes, so we are OK.
2702  const auto put =
2703  mCaptureBuffers[t]->Put(
2704  (samplePtr)tempFloats, mCaptureFormat, len);
2705  // wxASSERT(put == len);
2706  // but we can't assert in this thread
2707  wxUnusedVar(put);
2708  }
2709 }

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

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

155  {
156  return {
157  AudioIOExtIterator{ *this, false },
158  AudioIOExtIterator{ *this, true }
159  };
160  }

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

Here is the caller graph for this function:

◆ FillOutputBuffers()

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

Definition at line 2376 of file AudioIO.cpp.

2381 {
2382  const auto numPlaybackTracks = mPlaybackTracks.size();
2383  const auto numPlaybackChannels = mNumPlaybackChannels;
2384  const auto numCaptureChannels = mNumCaptureChannels;
2385 
2386  mMaxFramesOutput = 0;
2387 
2388  // Quick returns if next to nothing to do.
2389  if (mStreamToken <= 0 ||
2390  !outputBuffer ||
2391  numPlaybackChannels <= 0) {
2392  // So that UpdateTimePosition() will be correct, in case of MIDI play with
2393  // no audio output channels
2394  mMaxFramesOutput = framesPerBuffer;
2395  return false;
2396  }
2397 
2398  float *outputFloats = outputBuffer;
2399 
2401  mSeek = 0.0;
2402 
2403  if (mSeek){
2405  return true;
2406  }
2407 
2408  // ------ MEMORY ALLOCATION ----------------------
2409  // These are small structures.
2410  WaveTrack **chans = (WaveTrack **) alloca(numPlaybackChannels * sizeof(WaveTrack *));
2411  float **tempBufs = (float **) alloca(numPlaybackChannels * sizeof(float *));
2412 
2413  // And these are larger structures....
2414  for (unsigned int c = 0; c < numPlaybackChannels; c++)
2415  tempBufs[c] = (float *) alloca(framesPerBuffer * sizeof(float));
2416  // ------ End of MEMORY ALLOCATION ---------------
2417 
2418  auto & em = RealtimeEffectManager::Get();
2419  em.RealtimeProcessStart();
2420 
2421  bool selected = false;
2422  int group = 0;
2423  int chanCnt = 0;
2424 
2425  // Choose a common size to take from all ring buffers
2426  const auto toGet =
2427  std::min<size_t>(framesPerBuffer, GetCommonlyReadyPlayback());
2428 
2429  // The drop and dropQuickly booleans are so named for historical reasons.
2430  // JKC: The original code attempted to be faster by doing nothing on silenced audio.
2431  // This, IMHO, is 'premature optimisation'. Instead clearer and cleaner code would
2432  // simply use a gain of 0.0 for silent audio and go on through to the stage of
2433  // applying that 0.0 gain to the data mixed into the buffer.
2434  // Then (and only then) we would have if needed fast paths for:
2435  // - Applying a uniform gain of 0.0.
2436  // - Applying a uniform gain of 1.0.
2437  // - Applying some other uniform gain.
2438  // - Applying a linearly interpolated gain.
2439  // I would expect us not to need the fast paths, since linearly interpolated gain
2440  // is very cheap to process.
2441 
2442  bool drop = false; // Track should become silent.
2443  bool dropQuickly = false; // Track has already been faded to silence.
2444  for (unsigned t = 0; t < numPlaybackTracks; t++)
2445  {
2446  WaveTrack *vt = mPlaybackTracks[t].get();
2447  chans[chanCnt] = vt;
2448 
2449  // TODO: more-than-two-channels
2450  auto nextTrack =
2451  t + 1 < numPlaybackTracks
2452  ? mPlaybackTracks[t + 1].get()
2453  : nullptr;
2454 
2455  // First and last channel in this group (for example left and right
2456  // channels of stereo).
2457  bool firstChannel = vt->IsLeader();
2458  bool lastChannel = !nextTrack || nextTrack->IsLeader();
2459 
2460  if ( firstChannel )
2461  {
2462  selected = vt->GetSelected();
2463  // IF mono THEN clear 'the other' channel.
2464  if ( lastChannel && (numPlaybackChannels>1)) {
2465  // TODO: more-than-two-channels
2466  memset(tempBufs[1], 0, framesPerBuffer * sizeof(float));
2467  }
2468  drop = TrackShouldBeSilent( *vt );
2469  dropQuickly = drop;
2470  }
2471 
2472  if( mbMicroFades )
2473  dropQuickly = dropQuickly && TrackHasBeenFadedOut( *vt );
2474 
2475  decltype(framesPerBuffer) len = 0;
2476 
2477  if (dropQuickly)
2478  {
2479  len = mPlaybackBuffers[t]->Discard(toGet);
2480  // keep going here.
2481  // we may still need to issue a paComplete.
2482  }
2483  else
2484  {
2485  len = mPlaybackBuffers[t]->Get((samplePtr)tempBufs[chanCnt],
2486  floatSample,
2487  toGet);
2488  // wxASSERT( len == toGet );
2489  if (len < framesPerBuffer)
2490  // This used to happen normally at the end of non-looping
2491  // plays, but it can also be an anomalous case where the
2492  // supply from TrackBufferExchange fails to keep up with the
2493  // real-time demand in this thread (see bug 1932). We
2494  // must supply something to the sound card, so pad it with
2495  // zeroes and not random garbage.
2496  memset((void*)&tempBufs[chanCnt][len], 0,
2497  (framesPerBuffer - len) * sizeof(float));
2498  chanCnt++;
2499  }
2500 
2501  // PRL: Bug1104:
2502  // There can be a difference of len in different loop passes if one channel
2503  // of a stereo track ends before the other! Take a max!
2504 
2505  // PRL: More recent rewrites of TrackBufferExchange should guarantee a
2506  // padding out of the ring buffers so that equal lengths are
2507  // available, so maxLen ought to increase from 0 only once
2508  mMaxFramesOutput = std::max(mMaxFramesOutput, len);
2509 
2510  if ( !lastChannel )
2511  continue;
2512 
2513  // Last channel of a track seen now
2514  len = mMaxFramesOutput;
2515 
2516  if( !dropQuickly && selected )
2517  len = em.RealtimeProcess(group, chanCnt, tempBufs, len);
2518  group++;
2519 
2521  if (dropQuickly) // no samples to process, they've been discarded
2522  continue;
2523 
2524  // Our channels aren't silent. We need to pass their data on.
2525  //
2526  // Note that there are two kinds of channel count.
2527  // c and chanCnt are counting channels in the Tracks.
2528  // chan (and numPlayBackChannels) is counting output channels on the device.
2529  // chan = 0 is left channel
2530  // chan = 1 is right channel.
2531  //
2532  // Each channel in the tracks can output to more than one channel on the device.
2533  // For example mono channels output to both left and right output channels.
2534  if (len > 0) for (int c = 0; c < chanCnt; c++)
2535  {
2536  vt = chans[c];
2537 
2540  AddToOutputChannel( 0, outputMeterFloats, outputFloats,
2541  tempBufs[c], drop, len, vt);
2542 
2545  AddToOutputChannel( 1, outputMeterFloats, outputFloats,
2546  tempBufs[c], drop, len, vt);
2547  }
2548 
2549  chanCnt = 0;
2550  }
2551 
2552  // Poke: If there are no playback tracks, then the earlier check
2553  // about the time indicator being past the end won't happen;
2554  // do it here instead (but not if looping or scrubbing)
2555  // PRL: Also consume from the single playback ring buffer
2556  if (numPlaybackTracks == 0) {
2557  mMaxFramesOutput = mPlaybackBuffers[0]->Discard(toGet);
2559  }
2560 
2561  // wxASSERT( maxLen == toGet );
2562 
2563  em.RealtimeProcessEnd();
2564  mLastPlaybackTimeMillis = ::wxGetUTCTimeMillis();
2565 
2566  ClampBuffer( outputFloats, framesPerBuffer*numPlaybackChannels );
2567  if (outputMeterFloats != outputFloats)
2568  ClampBuffer( outputMeterFloats, framesPerBuffer*numPlaybackChannels );
2569 
2570  return false;
2571 }

References AddToOutputChannel(), PlaybackPolicy::AllowSeek(), CallbackCheckCompletion(), CallbackDoSeek(), ClampBuffer(), floatSample, RealtimeEffectManager::Get(), WaveTrack::GetChannelIgnoringPan(), GetCommonlyReadyPlayback(), PlaybackSchedule::GetPolicy(), Track::GetSelected(), Track::IsLeader(), Track::LeftChannel, mbMicroFades, mCallbackReturn, mLastPlaybackTimeMillis, mMaxFramesOutput, mNumCaptureChannels, mNumPlaybackChannels, Track::MonoChannel, mPlaybackBuffers, mPlaybackSchedule, mPlaybackTracks, mSeek, AudioIOBase::mStreamToken, Track::RightChannel, TrackHasBeenFadedOut(), and TrackShouldBeSilent().

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

1760 {
1761  auto commonlyAvail = mPlaybackBuffers[0]->AvailForGet();
1762  for (unsigned i = 1; i < mPlaybackTracks.size(); ++i)
1763  commonlyAvail = std::min(commonlyAvail,
1764  mPlaybackBuffers[i]->AvailForGet());
1765  return commonlyAvail;
1766 }

References min(), mPlaybackBuffers, and mPlaybackTracks.

Referenced by FillOutputBuffers(), and 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 163 of file AudioIO.h.

164  { return mListener.lock(); }

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

Here is the caller graph for this function:

◆ LostCaptureIntervals()

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

Definition at line 329 of file AudioIO.h.

330  { return mLostCaptureIntervals; }

◆ SendVuInputMeterData()

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

Definition at line 2781 of file AudioIO.cpp.

2785 {
2786  const auto numCaptureChannels = mNumCaptureChannels;
2787 
2788  auto pInputMeter = mInputMeter.lock();
2789  if ( !pInputMeter )
2790  return;
2791  if( pInputMeter->IsMeterDisabled())
2792  return;
2793 
2794  // get here if meters are actually live , and being updated
2795  /* It's critical that we don't update the meters while StopStream is
2796  * trying to stop PortAudio, otherwise it can lead to a freeze. We use
2797  * two variables to synchronize:
2798  * mUpdatingMeters tells StopStream when the callback is about to enter
2799  * the code where it might update the meters, and
2800  * mUpdateMeters is how the rest of the code tells the callback when it
2801  * is allowed to actually do the updating.
2802  * Note that mUpdatingMeters must be set first to avoid a race condition.
2803  */
2804  //TODO use atomics instead.
2805  mUpdatingMeters = true;
2806  if (mUpdateMeters) {
2807  pInputMeter->UpdateDisplay(numCaptureChannels,
2808  framesPerBuffer,
2809  inputSamples);
2810  }
2811  mUpdatingMeters = false;
2812 }

References AudioIOBase::mInputMeter, mNumCaptureChannels, mUpdateMeters, and mUpdatingMeters.

Referenced by AudioCallback().

Here is the caller graph for this function:

◆ SendVuOutputMeterData()

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

Definition at line 2815 of file AudioIO.cpp.

2818 {
2819  const auto numPlaybackChannels = mNumPlaybackChannels;
2820 
2821  auto pOutputMeter = mOutputMeter.lock();
2822  if (!pOutputMeter)
2823  return;
2824  if( pOutputMeter->IsMeterDisabled() )
2825  return;
2826  if( !outputMeterFloats)
2827  return;
2828 
2829  // Get here if playback meter is live
2830  /* It's critical that we don't update the meters while StopStream is
2831  * trying to stop PortAudio, otherwise it can lead to a freeze. We use
2832  * two variables to synchronize:
2833  * mUpdatingMeters tells StopStream when the callback is about to enter
2834  * the code where it might update the meters, and
2835  * mUpdateMeters is how the rest of the code tells the callback when it
2836  * is allowed to actually do the updating.
2837  * Note that mUpdatingMeters must be set first to avoid a race condition.
2838  */
2839  mUpdatingMeters = true;
2840  if (mUpdateMeters) {
2841  pOutputMeter->UpdateDisplay(numPlaybackChannels,
2842  framesPerBuffer,
2843  outputMeterFloats);
2844 
2845  //v Vaughan, 2011-02-25: Moved this update back to TrackPanel::OnTimer()
2846  // as it helps with playback issues reported by Bill and noted on Bug 258.
2847  // The problem there occurs if Software Playthrough is on.
2848  // Could conditionally do the update here if Software Playthrough is off,
2849  // and in TrackPanel::OnTimer() if Software Playthrough is on, but not now.
2850  // PRL 12 Jul 2015: and what was in TrackPanel::OnTimer is now handled by means of event
2851  // type EVT_TRACK_PANEL_TIMER
2852  //MixerBoard* pMixerBoard = mOwningProject->GetMixerBoard();
2853  //if (pMixerBoard)
2854  // pMixerBoard->UpdateMeters(GetStreamTime(),
2855  // (pProj->GetControlToolBar()->GetLastPlayMode() == loopedPlay));
2856  }
2857  mUpdatingMeters = false;
2858 }

References mNumPlaybackChannels, AudioIOBase::mOutputMeter, mUpdateMeters, and mUpdatingMeters.

Referenced by AudioCallback().

Here is the caller graph for this function:

◆ SetListener()

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

Definition at line 2077 of file AudioIO.cpp.

2079 {
2080  if (IsBusy())
2081  return;
2082 
2083  mListener = listener;
2084 }

References AudioIOBase::IsBusy(), and mListener.

Here is the call graph for this function:

◆ SetRecordingException()

void AudioIoCallback::SetRecordingException ( )
inlineprotected

Definition at line 319 of file AudioIO.h.

320  { wxAtomicInc( mRecordingException ); }

Referenced by AudioIO::DrainRecordBuffers().

Here is the caller graph for this function:

◆ TrackHasBeenFadedOut()

bool AudioIoCallback::TrackHasBeenFadedOut ( const WaveTrack wt)

Definition at line 2892 of file AudioIO.cpp.

2893 {
2894  const auto channel = wt.GetChannelIgnoringPan();
2895  if ((channel == Track::LeftChannel || channel == Track::MonoChannel) &&
2896  wt.GetOldChannelGain(0) != 0.0)
2897  return false;
2898  if ((channel == Track::RightChannel || channel == Track::MonoChannel) &&
2899  wt.GetOldChannelGain(1) != 0.0)
2900  return false;
2901  return true;
2902 }

References WaveTrack::GetChannelIgnoringPan(), WaveTrack::GetOldChannelGain(), Track::LeftChannel, Track::MonoChannel, and Track::RightChannel.

Referenced by FillOutputBuffers().

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

◆ TrackShouldBeSilent()

bool AudioIoCallback::TrackShouldBeSilent ( const WaveTrack wt)

Definition at line 2881 of file AudioIO.cpp.

2882 {
2883  return mPaused || (!wt.GetSolo() && (
2884  // Cut if somebody else is soloing
2885  mbHasSoloTracks ||
2886  // Cut if we're muted (and not soloing)
2887  wt.GetMute()
2888  ));
2889 }

References PlayableTrack::GetMute(), PlayableTrack::GetSolo(), mbHasSoloTracks, and AudioIOBase::mPaused.

Referenced by FillOutputBuffers().

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

◆ UpdateTimePosition()

void AudioIoCallback::UpdateTimePosition ( unsigned long  framesPerBuffer)

Definition at line 2573 of file AudioIO.cpp.

2574 {
2575  // Quick returns if next to nothing to do.
2576  if (mStreamToken <= 0)
2577  return;
2578 
2579  // Update the position seen by drawing code
2582 }

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

Referenced by AudioCallback().

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

Friends And Related Function Documentation

◆ AudioThread

friend class AudioThread
friend

Definition at line 302 of file AudioIO.h.

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

Referenced by AudioIoCallback(), and AudioIoCallback::AudioIOExtIterator::AudioIOExtIterator().

◆ mAudioThreadShouldCallTrackBufferExchangeOnce

volatile bool AudioIoCallback::mAudioThreadShouldCallTrackBufferExchangeOnce

◆ mAudioThreadTrackBufferExchangeLoopActive

volatile bool AudioIoCallback::mAudioThreadTrackBufferExchangeLoopActive

Definition at line 286 of file AudioIO.h.

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

◆ mAudioThreadTrackBufferExchangeLoopRunning

volatile bool AudioIoCallback::mAudioThreadTrackBufferExchangeLoopRunning

◆ mbHasSoloTracks

int AudioIoCallback::mbHasSoloTracks

Definition at line 174 of file AudioIO.h.

Referenced by AudioCallback(), and TrackShouldBeSilent().

◆ mbMicroFades

bool AudioIoCallback::mbMicroFades

◆ mCachedBestRateCapturing

bool AudioIoCallback::mCachedBestRateCapturing
staticprotected

Definition at line 309 of file AudioIO.h.

Referenced by AudioIO::GetBestRate().

◆ mCachedBestRateOut

double AudioIoCallback::mCachedBestRateOut
staticprotected

Definition at line 307 of file AudioIO.h.

Referenced by AudioIO::GetBestRate().

◆ mCachedBestRatePlaying

bool AudioIoCallback::mCachedBestRatePlaying
staticprotected

Definition at line 308 of file AudioIO.h.

Referenced by AudioIO::GetBestRate().

◆ mCallbackReturn

int AudioIoCallback::mCallbackReturn

Definition at line 175 of file AudioIO.h.

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

◆ mCaptureBuffers

ArrayOf<std::unique_ptr<RingBuffer> > AudioIoCallback::mCaptureBuffers

◆ mCaptureFormat

sampleFormat AudioIoCallback::mCaptureFormat

◆ mCaptureRingBufferSecs

double AudioIoCallback::mCaptureRingBufferSecs

Definition at line 268 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers().

◆ mCaptureTracks

WaveTrackArray AudioIoCallback::mCaptureTracks

◆ mDetectDropouts

bool AudioIoCallback::mDetectDropouts { true }
protected

Definition at line 325 of file AudioIO.h.

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

◆ mDetectUpstreamDropouts

bool AudioIoCallback::mDetectUpstreamDropouts { true }

◆ mFactor

double AudioIoCallback::mFactor

Definition at line 262 of file AudioIO.h.

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

◆ mForceFadeOut

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

Definition at line 288 of file AudioIO.h.

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

◆ mLastPaError

PaError AudioIoCallback::mLastPaError

◆ mLastPlaybackTimeMillis

wxLongLong AudioIoCallback::mLastPlaybackTimeMillis

Definition at line 290 of file AudioIO.h.

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

◆ mLastRecordingOffset

volatile double AudioIoCallback::mLastRecordingOffset

Definition at line 292 of file AudioIO.h.

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

◆ mListener

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

Definition at line 300 of file AudioIO.h.

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

◆ mLostCaptureIntervals

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

Definition at line 324 of file AudioIO.h.

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

◆ mLostSamples

unsigned long long AudioIoCallback::mLostSamples { 0 }

Definition at line 283 of file AudioIO.h.

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

◆ mMaxFramesOutput

unsigned long AudioIoCallback::mMaxFramesOutput

Definition at line 263 of file AudioIO.h.

Referenced by FillOutputBuffers(), and UpdateTimePosition().

◆ mMinCaptureSecsToCopy

double AudioIoCallback::mMinCaptureSecsToCopy

Definition at line 275 of file AudioIO.h.

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

◆ mMixerOutputVol

float AudioIoCallback::mMixerOutputVol { 1.0 }

◆ mNextStreamToken

int AudioIoCallback::mNextStreamToken = 0
static

Definition at line 261 of file AudioIO.h.

Referenced by AudioIO::StartStream().

◆ mNumCaptureChannels

unsigned int AudioIoCallback::mNumCaptureChannels

◆ mNumPauseFrames

long AudioIoCallback::mNumPauseFrames

How many frames of zeros were output due to pauses?

Definition at line 231 of file AudioIO.h.

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

◆ mNumPlaybackChannels

unsigned int AudioIoCallback::mNumPlaybackChannels

◆ mPauseRec

bool AudioIoCallback::mPauseRec

True if Sound Activated Recording is enabled.

Definition at line 278 of file AudioIO.h.

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

◆ mPlaybackBuffers

ArrayOf<std::unique_ptr<RingBuffer> > 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 273 of file AudioIO.h.

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

◆ mPlaybackRingBufferSecs

double AudioIoCallback::mPlaybackRingBufferSecs

Definition at line 267 of file AudioIO.h.

Referenced by AudioIO::AllocateBuffers().

◆ mPlaybackSamplesToCopy

size_t AudioIoCallback::mPlaybackSamplesToCopy

Preferred batch size for replenishing the playback RingBuffer.

Definition at line 271 of file AudioIO.h.

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

◆ mPlaybackSchedule

PlaybackSchedule AudioIoCallback::mPlaybackSchedule
protected

◆ mPlaybackTracks

WaveTrackArray AudioIoCallback::mPlaybackTracks

◆ mRecordingException

wxAtomicInt AudioIoCallback::mRecordingException {}
protected

Definition at line 318 of file AudioIO.h.

Referenced by AudioIO::DrainRecordBuffers().

◆ mRecordingSchedule

RecordingSchedule AudioIoCallback::mRecordingSchedule {}
protected

◆ mResample

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

◆ mSeek

double AudioIoCallback::mSeek

Definition at line 266 of file AudioIO.h.

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

◆ mSilenceLevel

float AudioIoCallback::mSilenceLevel

◆ mSimulateRecordingErrors

bool AudioIoCallback::mSimulateRecordingErrors { false }

◆ mSoftwarePlaythrough

bool AudioIoCallback::mSoftwarePlaythrough

◆ mSuspendAudioThread

wxMutex AudioIoCallback::mSuspendAudioThread
protected

Definition at line 313 of file AudioIO.h.

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

◆ mThread

std::unique_ptr<AudioThread> AudioIoCallback::mThread

Definition at line 250 of file AudioIO.h.

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

◆ mUpdateMeters

bool AudioIoCallback::mUpdateMeters
protected

◆ mUpdatingMeters

volatile bool AudioIoCallback::mUpdatingMeters
protected

◆ mUsingAlsa

bool AudioIoCallback::mUsingAlsa { false }
protected

Definition at line 304 of file AudioIO.h.

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


The documentation for this class was generated from the following files:
WaveTrack::SetOldChannelGain
void SetOldChannelGain(int channel, float gain)
Definition: WaveTrack.cpp:526
AudioIoCallback::mCaptureFormat
sampleFormat mCaptureFormat
Definition: AudioIO.h:282
RecordingSchedule::mLatencyCorrection
double mLatencyCorrection
Definition: PlaybackSchedule.h:133
AudioIoCallback::mPlaybackTracks
WaveTrackArray mPlaybackTracks
Definition: AudioIO.h:256
AudioIoCallback::mbMicroFades
bool mbMicroFades
Definition: AudioIO.h:264
ExpGain
Type ExpGain(Type gain) noexcept
Definition: Gain.h:19
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
AudioIoCallback::DrainInputBuffers
void DrainInputBuffers(constSamplePtr inputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackFlags statusFlags, float *tempFloats)
Definition: AudioIO.cpp:2588
AudioIoCallback::CheckSoundActivatedRecordingLevel
void CheckSoundActivatedRecordingLevel(float *inputSamples, unsigned long framesPerBuffer)
Definition: AudioIO.cpp:2296
AudioIoCallback::mForceFadeOut
std::atomic< bool > mForceFadeOut
Definition: AudioIO.h:288
PlayableTrack::GetSolo
bool GetSolo() const
Definition: Track.h:861
PlaybackSchedule::SetTrackTime
void SetTrackTime(double time)
Set current track time value, unadjusted.
Definition: PlaybackSchedule.h:416
PlayableTrack::GetMute
bool GetMute() const
Definition: Track.h:860
PlaybackSchedule::GetPolicy
PlaybackPolicy & GetPolicy()
Definition: PlaybackSchedule.cpp:136
AudioIOExt::GetFactories
static Factories & GetFactories()
Definition: AudioIOExt.cpp:15
AudioIoCallback::mNumPlaybackChannels
unsigned int mNumPlaybackChannels
Definition: AudioIO.h:281
AudioIoCallback::mPlaybackMixers
std::vector< std::unique_ptr< Mixer > > mPlaybackMixers
Definition: AudioIO.h:258
AudioIoCallback::mNumCaptureChannels
unsigned int mNumCaptureChannels
Definition: AudioIO.h:280
AudioIoCallback::mMixerOutputVol
float mMixerOutputVol
Definition: AudioIO.h:260
PlaybackSchedule::TimeQueue::Prime
void Prime(double time)
Empty the queue and reassign the last produced time.
Definition: PlaybackSchedule.cpp:473
AudioIoCallback::mUpdatingMeters
volatile bool mUpdatingMeters
Definition: AudioIO.h:298
AudioIoCallback::mMaxFramesOutput
unsigned long mMaxFramesOutput
Definition: AudioIO.h:263
PlaybackPolicy::Done
virtual bool Done(PlaybackSchedule &schedule, unsigned long outputFrames)
Returns true if schedule.GetTrackTime() has reached the end of playback.
Definition: PlaybackSchedule.cpp:43
int24Sample
@ int24Sample
Definition: SampleFormat.h:33
SamplesToFloats
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.
Definition: SampleFormat.cpp:102
AudioIoCallback::mPlaybackBuffers
ArrayOf< std::unique_ptr< RingBuffer > > mPlaybackBuffers
Definition: AudioIO.h:255
AudioIoCallback::mUpdateMeters
bool mUpdateMeters
Definition: AudioIO.h:297
AudioIoCallback::mSimulateRecordingErrors
bool mSimulateRecordingErrors
Definition: AudioIO.h:333
AudioIoCallback::mDetectDropouts
bool mDetectDropouts
Definition: AudioIO.h:325
AudioIoCallback::mRecordingException
wxAtomicInt mRecordingException
Definition: AudioIO.h:318
ClampBuffer
void ClampBuffer(float *pBuffer, unsigned long len)
Definition: AudioIO.cpp:2365
AudioIOBase::IsPaused
bool IsPaused() const
Find out if playback / recording is currently paused.
Definition: AudioIOBase.cpp:327
MAX
#define MAX(a, b)
Definition: AudioIO.cpp:2256
AudioIOBase::IsBusy
bool IsBusy() const
Returns true if audio i/o is busy starting, stopping, playing, or recording.
Definition: AudioIOBase.cpp:332
PlaybackSchedule::mTimeQueue
class PlaybackSchedule::TimeQueue mTimeQueue
AudioIoCallback::mAudioThreadShouldCallTrackBufferExchangeOnce
volatile bool mAudioThreadShouldCallTrackBufferExchangeOnce
Definition: AudioIO.h:284
PlaybackPolicy::AllowSeek
virtual bool AllowSeek(PlaybackSchedule &schedule)
Whether repositioning commands are allowed during playback.
Definition: PlaybackSchedule.cpp:38
floatSample
@ floatSample
Definition: SampleFormat.h:34
AudioIoCallback::Extensions
AudioIOExtRange Extensions()
Definition: AudioIO.h:155
AudioIoCallback::mDetectUpstreamDropouts
bool mDetectUpstreamDropouts
Definition: AudioIO.h:337
AudioIoCallback::mSoftwarePlaythrough
bool mSoftwarePlaythrough
Definition: AudioIO.h:276
AudioIOBase::mPaused
bool mPaused
True if audio playback is paused.
Definition: AudioIOBase.h:246
AudioIoCallback::CallbackDoSeek
int CallbackDoSeek()
Definition: AudioIO.cpp:3039
factory
static RegisteredToolbarFactory factory
Definition: ControlToolBar.cpp:817
AudioIoCallback::mPauseRec
bool mPauseRec
True if Sound Activated Recording is enabled.
Definition: AudioIO.h:278
PlaybackPolicy::OffsetTrackTime
virtual double OffsetTrackTime(PlaybackSchedule &schedule, double offset)
Called when the play head needs to jump a certain distance.
Definition: PlaybackSchedule.cpp:54
AudioIoCallback::mCaptureBuffers
ArrayOf< std::unique_ptr< RingBuffer > > mCaptureBuffers
Definition: AudioIO.h:253
AudioIoCallback::mAudioThreadTrackBufferExchangeLoopRunning
volatile bool mAudioThreadTrackBufferExchangeLoopRunning
Definition: AudioIO.h:285
int16Sample
@ int16Sample
Definition: SampleFormat.h:32
AudioIoCallback::mLastPlaybackTimeMillis
wxLongLong mLastPlaybackTimeMillis
Definition: AudioIO.h:290
AudioIOBase::mInputMeter
std::weak_ptr< Meter > mInputMeter
Definition: AudioIOBase.h:255
constSamplePtr
const char * constSamplePtr
Definition: SampleFormat.h:50
AudioIoCallback::mRecordingSchedule
RecordingSchedule mRecordingSchedule
Definition: AudioIO.h:340
AudioIoCallback::UpdateTimePosition
void UpdateTimePosition(unsigned long framesPerBuffer)
Definition: AudioIO.cpp:2573
AudioIoCallback::mCallbackReturn
int mCallbackReturn
Definition: AudioIO.h:175
AudioIoCallback::mAudioIOExt
std::vector< std::unique_ptr< AudioIOExtBase > > mAudioIOExt
Definition: AudioIOBase.h:318
Track::RightChannel
@ RightChannel
Definition: Track.h:277
AudioIoCallback::mLostSamples
unsigned long long mLostSamples
Definition: AudioIO.h:283
AudioIOBase::mRate
double mRate
Audio playback rate in samples per second.
Definition: AudioIOBase.h:251
AudioIoCallback::mSuspendAudioThread
wxMutex mSuspendAudioThread
Definition: AudioIO.h:313
RealtimeEffectManager::Get
static RealtimeEffectManager & Get()
Definition: RealtimeEffectManager.cpp:43
AudioIoCallback::DoPlaythrough
void DoPlaythrough(constSamplePtr inputBuffer, float *outputBuffer, unsigned long framesPerBuffer, float *outputMeterFloats)
Definition: AudioIO.cpp:2745
AudioIoCallback::FillOutputBuffers
bool FillOutputBuffers(float *outputBuffer, unsigned long framesPerBuffer, float *outputMeterFloats)
Definition: AudioIO.cpp:2376
Track::GetSelected
bool GetSelected() const
Definition: Track.h:431
AudioIoCallback::SendVuOutputMeterData
void SendVuOutputMeterData(const float *outputMeterFloats, unsigned long framesPerBuffer)
Definition: AudioIO.cpp:2815
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
WaveTrack::GetChannelIgnoringPan
virtual ChannelType GetChannelIgnoringPan() const
Definition: WaveTrack.cpp:254
WaveTrack::GetOldChannelGain
float GetOldChannelGain(int channel) const
Definition: WaveTrack.cpp:521
AudioIoCallback::GetCommonlyReadyPlayback
size_t GetCommonlyReadyPlayback()
Get the number of audio samples ready in all of the playback buffers.
Definition: AudioIO.cpp:1759
AudioIoCallback::mbHasSoloTracks
int mbHasSoloTracks
Definition: AudioIO.h:174
Track::IsLeader
bool IsLeader() const
Definition: Track.cpp:379
AudioIoCallback::CallbackCheckCompletion
void CallbackCheckCompletion(int &callbackReturn, unsigned long len)
Definition: AudioIO.cpp:3093
AudioIoCallback::mSilenceLevel
float mSilenceLevel
Definition: AudioIO.h:279
AudioIoCallback::mSeek
double mSeek
Definition: AudioIO.h:266
AudioIoCallback::mAudioThreadTrackBufferExchangeLoopActive
volatile bool mAudioThreadTrackBufferExchangeLoopActive
Definition: AudioIO.h:286
AudioIoCallback::AllTracksAlreadySilent
bool AllTracksAlreadySilent()
Definition: AudioIO.cpp:2904
AudioIoCallback::mLostCaptureIntervals
std::vector< std::pair< double, double > > mLostCaptureIntervals
Definition: AudioIO.h:324
Track::MonoChannel
@ MonoChannel
Definition: Track.h:278
AudioIoCallback::SendVuInputMeterData
void SendVuInputMeterData(const float *inputSamples, unsigned long framesPerBuffer)
Definition: AudioIO.cpp:2781
AudioIOBase::mOutputMeter
std::weak_ptr< Meter > mOutputMeter
Definition: AudioIOBase.h:256
PlaybackSchedule::GetTrackTime
double GetTrackTime() const
Get current track time value, unadjusted.
Definition: PlaybackSchedule.h:411
AudioIoCallback::GetListener
std::shared_ptr< AudioIOListener > GetListener() const
Definition: AudioIO.h:163
AudioIoCallback::TrackShouldBeSilent
bool TrackShouldBeSilent(const WaveTrack &wt)
Definition: AudioIO.cpp:2881
AudioIoCallback::mPlaybackSchedule
PlaybackSchedule mPlaybackSchedule
Definition: AudioIO.h:341
AudioIOBase::mStreamToken
volatile int mStreamToken
Definition: AudioIOBase.h:248
AudioIoCallback::mListener
std::weak_ptr< AudioIOListener > mListener
Definition: AudioIO.h:300
AudioIoCallback::AddToOutputChannel
void AddToOutputChannel(unsigned int chan, float *outputMeterFloats, float *outputFloats, const float *tempBuf, bool drop, unsigned long len, WaveTrack *vt)
Definition: AudioIO.cpp:2324
WaveTrack::GetChannelGain
float GetChannelGain(int channel) const
Definition: WaveTrack.cpp:505
AudioIoCallback::mNumPauseFrames
long mNumPauseFrames
How many frames of zeros were output due to pauses?
Definition: AudioIO.h:231
AudioIoCallback::TrackHasBeenFadedOut
bool TrackHasBeenFadedOut(const WaveTrack &wt)
Definition: AudioIO.cpp:2892
DoSoftwarePlaythrough
static void DoSoftwarePlaythrough(constSamplePtr inputBuffer, sampleFormat inputFormat, unsigned inputChannels, float *outputBuffer, unsigned long len)
Definition: AudioIO.cpp:2258
AudioIoCallback::CountSoloingTracks
unsigned CountSoloingTracks()
Definition: AudioIO.cpp:2860
Track::LeftChannel
@ LeftChannel
Definition: Track.h:276
PlaybackSchedule::TimeQueue::Consumer
double Consumer(size_t nSamples, double rate)
Find the track time value nSamples after the last consumed sample.
Definition: PlaybackSchedule.cpp:448