13#ifndef __AUDACITY_AUDIO_IO__
14#define __AUDACITY_AUDIO_IO__
43 std::vector < std::shared_ptr < const PlayableTrack > >;
52 std::vector < std::shared_ptr < WritableSampleTrack > >;
54struct PaStreamCallbackTimeInfo;
84 bool nonWaveToo =
false
118 const void *inputBuffer,
void *outputBuffer,
119 unsigned long framesPerBuffer,
120 const PaStreamCallbackTimeInfo *timeInfo,
136 unsigned long framesPerBuffer,
137 const PaStreamCallbackTimeInfo *timeInfo,
152 ? audioIO.mAudioIOExt.
end()
153 : audioIO.mAudioIOExt.
begin() }
157 friend inline
bool operator == (
160 return xx.mIterator == yy.mIterator;
168 std::vector<std::unique_ptr<AudioIOExtBase>>::const_iterator
mIterator;
186 {
return mListener.lock(); }
187 void SetListener(
const std::shared_ptr< AudioIOListener > &listener);
190 int CallbackDoSeek();
193 void CallbackCheckCompletion(
194 int &callbackReturn,
unsigned long len);
199 unsigned CountSoloingTracks();
203 bool TrackHasBeenFadedOut(
205 bool AllTracksAlreadySilent();
207 void CheckSoundActivatedRecordingLevel(
209 unsigned long framesPerBuffer
212 void AddToOutputChannel(
unsigned int chan,
213 float * outputMeterFloats,
214 float * outputFloats,
215 const float * tempBuf,
221 bool FillOutputBuffers(
223 unsigned long framesPerBuffer,
224 float *outputMeterFloats
226 void DrainInputBuffers(
228 unsigned long framesPerBuffer,
232 void UpdateTimePosition(
233 unsigned long framesPerBuffer
238 unsigned long framesPerBuffer,
239 float *outputMeterFloats
241 void SendVuInputMeterData(
242 const float *inputSamples,
243 unsigned long framesPerBuffer
245 void SendVuOutputMeterData(
246 const float *outputMeterFloats,
247 unsigned long framesPerBuffer
255 size_t GetCommonlyReadyPlayback();
257 size_t GetCommonlyWrittenForPlayback();
262#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
265 int mAILATotalAnalysis;
266 int mAILAAnalysisCounter;
268 double mAILAGoalPoint;
269 double mAILAGoalDelta;
270 double mAILAAnalysisTime;
271 double mAILALastStartTime;
272 double mAILAChangeFactor;
273 double mAILATopLevel;
274 double mAILAAnalysisEndTime;
275 double mAILAAbsolutStartTime;
276 unsigned short mAILALastChangeType;
280 std::atomic<bool> mFinishAudioThread{
false };
297 std::atomic<float> mMixerOutputVol{ 1.0 };
325 unsigned long long mLostSamples{ 0 };
335 void StartAudioThread();
336 void WaitForAudioThreadStarted();
337 void StopAudioThread();
338 void WaitForAudioThreadStopped();
340 void ProcessOnceAndWait( std::chrono::milliseconds sleepTime = std::chrono::milliseconds(50) );
344 std::atomic<bool> mForceFadeOut{
false };
355 return mMixerOutputVol.load(std::memory_order_relaxed); }
357 mMixerOutputVol.store(value, std::memory_order_relaxed); }
364 bool mUsingAlsa {
false };
380 {
return mRecordingException; }
385 wxAtomicInt mRecordingException {};
387 { wxAtomicInc( mRecordingException ); }
389 {
if (mRecordingException) wxAtomicDec( mRecordingException ); }
393 bool mDetectDropouts{
true };
398 {
return mLostCaptureIntervals; }
401 bool mSimulateRecordingErrors{
false };
405 std::atomic<bool> mDetectUpstreamDropouts{
true };
443 std::shared_ptr<RealtimeEffectState>
450 std::shared_ptr<RealtimeEffectState>
456 Track *pTrack, std::shared_ptr<RealtimeEffectState> pState);
475 double t0,
double t1,
484 void StopStream()
override;
496 wxString LastPaErrorString();
500 {
return mOwningProject.lock(); }
503 void SetPaused(
bool state);
511 void SetMixer(
int inputSource,
float inputVolume,
512 float playbackVolume);
513 void GetMixer(
int *inputSource,
float *inputVolume,
514 float *playbackVolume);
521 bool InputMixerWorks();
527 wxArrayString GetInputSourceNames();
534 bool IsCapturing()
const;
544 #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
545 void AILAInitialize();
548 void AILAProcess(
double maxPeak);
549 void AILASetStartTime();
550 double AILAGetLastDecisionTime();
565 double GetBestRate(
bool capturing,
bool playing,
double sampleRate);
573 double GetStreamTime();
575 static void AudioThread(std::atomic<bool> &finish);
578 static void Deinit();
582 void DelayActions(
bool recording);
586 bool DelayingActions()
const;
603 unsigned int numPlaybackChannels,
604 unsigned int numCaptureChannels,
607 void SetOwningProject(
const std::shared_ptr<AudacityProject> &pProject );
608 void ResetOwningProject();
616 void TrackBufferExchange();
619 void FillPlayBuffers();
620 void TransformPlayBuffers(
621 std::optional<RealtimeEffects::ProcessingScope> &
scope);
622 bool ProcessPlaybackSlices(
623 std::optional<RealtimeEffects::ProcessingScope> &pScope,
627 void DrainRecordBuffers();
634 size_t GetCommonlyFreePlayback();
642 size_t GetCommonlyAvailCapture();
649 bool AllocateBuffers(
651 const TransportTracks &tracks,
double t0,
double t1,
double sampleRate );
656 void StartStreamCleanup(
bool bOnlyBuffers =
false);
661 bool mDelayingActions{
false };
int audacityAudioCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
std::vector< std::shared_ptr< const SampleTrack > > SampleTrackConstArray
bool ValidateDeviceNames()
unsigned long PaStreamCallbackFlags
std::vector< std::shared_ptr< SampleTrack > > SampleTrackArray
std::vector< std::shared_ptr< const PlayableTrack > > PlayableTrackConstArray
static TransactionScope::Factory::Scope scope
Vector operator*(const Vector &left, const Vector &right)
Generalized interface for discovery of plug-ins for one protocol.
std::vector< std::shared_ptr< WritableSampleTrack > > WritableSampleTrackArray
bool operator!=(const WaveTrackLocation &a, const WaveTrackLocation &b)
This simplifies arrays of arrays, each array separately allocated with NEW[] But it might be better t...
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
A singleton object supporting queries of the state of any active audio streams, and audio device capa...
std::vector< std::unique_ptr< AudioIOExtBase > > mAudioIOExt
AudioIO uses the PortAudio library to play and record sound.
std::shared_ptr< AudacityProject > GetOwningProject() const
std::mutex mPostRecordingActionMutex
PostRecordingAction mPostRecordingAction
unsigned GetNumCaptureChannels() const
void SeekStream(double seconds)
Move the playback / recording position of the current stream by the specified amount from where it is...
sampleFormat GetCaptureFormat()
wxLongLong GetLastPlaybackTime() const
std::function< void()> PostRecordingAction
unsigned GetNumPlaybackChannels() const
std::vector< std::unique_ptr< AudioIOExtBase > >::const_iterator mIterator
ptrdiff_t difference_type
AudioIOExtIterator(AudioIoCallback &audioIO, bool end)
std::forward_iterator_tag iterator_category
AudioIoCallback is a class that implements the callback required by PortAudio. The callback needs to ...
static int mNextStreamToken
std::shared_ptr< AudioIOListener > GetListener() const
std::unique_ptr< TransportState > mpTransportState
Holds some state for duration of playback or recording.
const std::vector< std::pair< double, double > > & LostCaptureIntervals()
wxMutex mSuspendAudioThread
AudioIOExtRange Extensions()
float GetMixerOutputVol()
std::array< float, 2 > OldChannelGains
PlaybackSchedule mPlaybackSchedule
std::vector< float * > mScratchPointers
pointing into mScratchBuffers
std::atomic< Acknowledge > mAudioThreadAcknowledge
WritableSampleTrackArray mCaptureTracks
size_t mPlaybackSamplesToCopy
Preferred batch size for replenishing the playback RingBuffer.
std::atomic< bool > mAudioThreadTrackBufferExchangeLoopRunning
static double mCachedBestRateOut
std::vector< std::unique_ptr< Mixer > > mPlaybackMixers
PlaybackPolicy::Duration mPlaybackRingBufferSecs
std::atomic< bool > mAudioThreadTrackBufferExchangeLoopActive
void ClearRecordingException()
long mNumPauseFrames
How many frames of zeros were output due to pauses?
unsigned int mNumPlaybackChannels
void SetRecordingException()
std::atomic< bool > mAudioThreadShouldCallTrackBufferExchangeOnce
wxLongLong mLastPlaybackTimeMillis
bool HasRecordingException() const
std::vector< OldChannelGains > mOldChannelGains
static bool mCachedBestRatePlaying
bool mSoftwarePlaythrough
ArrayOf< std::unique_ptr< RingBuffer > > mCaptureBuffers
unsigned long mMaxFramesOutput
double mLastRecordingOffset
Not (yet) used; should perhaps be atomic when it is.
size_t mPlaybackQueueMinimum
Occupancy of the queue we try to maintain, with bigger batches if needed.
std::weak_ptr< AudioIOListener > mListener
ArrayOf< std::unique_ptr< Resample > > mResample
double mCaptureRingBufferSecs
unsigned int mNumCaptureChannels
void SetMixerOutputVol(float value)
std::vector< std::pair< double, double > > mLostCaptureIntervals
bool mPauseRec
True if Sound Activated Recording is enabled.
ArrayOf< std::unique_ptr< RingBuffer > > mPlaybackBuffers
double mMinCaptureSecsToCopy
std::vector< SampleBuffer > mScratchBuffers
SampleTrackConstArray mPlaybackTracks
static bool mCachedBestRateCapturing
sampleFormat mCaptureFormat
Functions for doing the mixdown of the tracks.
An object that sends messages to an open-ended list of subscribed callbacks.
AudioTrack subclass that can also be audibly replayed by the program.
std::chrono::duration< double > Duration
Brackets one block of processing in one thread.
Holds streamed audio samples.
Abstract base class for an object holding data associated with points on a time axis.
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
enum AudioIOEvent::Type type
AudacityProject * pProject
struct holding stream options, including a pointer to the time warp info and AudioIOListener and whet...
AudioIOExtIterator begin() const
AudioIOExtIterator end() const
AudioIOExtIterator second
SampleTrackConstArray prerollTracks
PlayableTrackConstArray otherPlayableTracks
TransportTracks()=default
WritableSampleTrackArray captureTracks
SampleTrackConstArray playbackTracks