13#ifndef __AUDACITY_AUDIO_IO__
14#define __AUDACITY_AUDIO_IO__
44struct PaStreamCallbackTimeInfo;
74 std::vector<std::shared_ptr<const OtherPlayableSequence>>
104 const void *inputBuffer,
void *outputBuffer,
105 unsigned long framesPerBuffer,
106 const PaStreamCallbackTimeInfo *timeInfo,
122 unsigned long framesPerBuffer,
123 const PaStreamCallbackTimeInfo *timeInfo,
138 ? audioIO.mAudioIOExt.
end()
139 : audioIO.mAudioIOExt.
begin() }
143 friend inline
bool operator == (
146 return xx.mIterator == yy.mIterator;
154 std::vector<std::unique_ptr<AudioIOExtBase>>::const_iterator
mIterator;
172 {
return mListener.lock(); }
173 void SetListener(
const std::shared_ptr< AudioIOListener > &listener);
176 int CallbackDoSeek();
179 void CallbackCheckCompletion(
180 int &callbackReturn,
unsigned long len);
185 unsigned CountSoloingSequences();
189 void CheckSoundActivatedRecordingLevel(
191 unsigned long framesPerBuffer
194 bool FillOutputBuffers(
196 unsigned long framesPerBuffer,
197 float *outputMeterFloats
199 void DrainInputBuffers(
201 unsigned long framesPerBuffer,
205 void UpdateTimePosition(
206 unsigned long framesPerBuffer
211 unsigned long framesPerBuffer,
212 float *outputMeterFloats
214 void SendVuInputMeterData(
215 const float *inputSamples,
216 unsigned long framesPerBuffer
218 void SendVuOutputMeterData(
219 const float *outputMeterFloats,
220 unsigned long framesPerBuffer
228 size_t GetCommonlyReadyPlayback();
230 size_t GetCommonlyWrittenForPlayback();
235#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
238 int mAILATotalAnalysis;
239 int mAILAAnalysisCounter;
241 double mAILAGoalPoint;
242 double mAILAGoalDelta;
243 double mAILAAnalysisTime;
244 double mAILALastStartTime;
245 double mAILAChangeFactor;
246 double mAILATopLevel;
247 double mAILAAnalysisEndTime;
248 double mAILAAbsolutStartTime;
249 unsigned short mAILALastChangeType;
253 std::atomic<bool> mFinishAudioThread{
false };
278 std::atomic<float> mMixerOutputVol{ 1.0 };
292 size_t mHardwarePlaybackLatencyFrames {};
308 double mCaptureRate{};
309 unsigned long long mLostSamples{ 0 };
319 void StartAudioThread();
320 void WaitForAudioThreadStarted();
321 void StopAudioThread();
322 void WaitForAudioThreadStopped();
324 void ProcessOnceAndWait( std::chrono::milliseconds sleepTime = std::chrono::milliseconds(50) );
328 std::atomic<bool> mForceFadeOut{
false };
337 static size_t MinValue(
341 return mMixerOutputVol.load(std::memory_order_relaxed); }
343 mMixerOutputVol.store(value, std::memory_order_relaxed); }
350 bool mUsingAlsa {
false };
351 bool mUsingJack {
false };
367 {
return mRecordingException; }
372 wxAtomicInt mRecordingException {};
374 { wxAtomicInc( mRecordingException ); }
376 {
if (mRecordingException) wxAtomicDec( mRecordingException ); }
380 bool mDetectDropouts{
true };
385 {
return mLostCaptureIntervals; }
388 bool mSimulateRecordingErrors{
false };
392 std::atomic<bool> mDetectUpstreamDropouts{
true };
430 std::shared_ptr<RealtimeEffectState>
438 std::shared_ptr<RealtimeEffectState>
445 std::shared_ptr<RealtimeEffectState> pState);
470 double t0,
double t1,
479 void StopStream()
override;
491 wxString LastPaErrorString();
495 {
return mOwningProject.lock(); }
498 void SetPaused(
bool state,
bool publish =
false);
506 void SetMixer(
int inputSource,
float inputVolume,
507 float playbackVolume);
508 void GetMixer(
int *inputSource,
float *inputVolume,
509 float *playbackVolume);
516 bool InputMixerWorks();
522 wxArrayString GetInputSourceNames();
529 bool IsCapturing()
const;
539 #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
540 void AILAInitialize();
543 void AILAProcess(
double maxPeak);
544 void AILASetStartTime();
545 double AILAGetLastDecisionTime();
560 double GetBestRate(
bool capturing,
bool playing,
double sampleRate);
568 double GetStreamTime();
570 static void AudioThread(std::atomic<bool> &finish);
573 static void Deinit();
577 void DelayActions(
bool recording);
581 bool DelayingActions()
const;
598 unsigned int numPlaybackChannels,
unsigned int numCaptureChannels);
600 void SetOwningProject(
const std::shared_ptr<AudacityProject> &pProject );
601 void ResetOwningProject();
609 void SequenceBufferExchange();
612 void FillPlayBuffers();
614 bool ProcessPlaybackSlices(
615 std::optional<RealtimeEffects::ProcessingScope> &pScope,
619 void DrainRecordBuffers();
626 size_t GetCommonlyFreePlayback();
634 size_t GetCommonlyAvailCapture();
641 bool AllocateBuffers(
649 void StartStreamCleanup(
bool bOnlyBuffers =
false);
654 bool mDelayingActions{
false };
int audacityAudioCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
AUDIO_IO_API BoolSetting SoundActivatedRecord
bool ValidateDeviceNames()
unsigned long PaStreamCallbackFlags
std::vector< std::shared_ptr< RecordableSequence > > RecordableSequences
std::vector< std::shared_ptr< const PlayableSequence > > ConstPlayableSequences
Generalized interface for discovery of plug-ins for one protocol.
auto operator*(PffftAlignedCount x, Integral y) -> std::enable_if_t< std::is_unsigned_v< Integral > &&sizeof(Integral)<=sizeof(size_t), PffftAlignedCount >
bool operator!=(const WaveTrackLocation &a, const WaveTrackLocation &b)
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
size_t GetNumPlaybackChannels() 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
size_t GetNumCaptureChannels() 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 ...
std::atomic< bool > mAudioThreadSequenceBufferExchangeLoopRunning
static int mNextStreamToken
std::shared_ptr< AudioIOListener > GetListener() const
size_t mNumPlaybackChannels
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()
std::atomic< bool > mAudioThreadShouldCallSequenceBufferExchangeOnce
std::vector< std::unique_ptr< Resample > > mResample
float GetMixerOutputVol()
PlaybackSchedule mPlaybackSchedule
std::vector< float * > mScratchPointers
pointing into mScratchBuffers
std::atomic< Acknowledge > mAudioThreadAcknowledge
size_t mPlaybackSamplesToCopy
Preferred batch size for replenishing the playback RingBuffer.
static double mCachedBestRateOut
std::vector< std::unique_ptr< Mixer > > mPlaybackMixers
PlaybackPolicy::Duration mPlaybackRingBufferSecs
std::vector< std::vector< float > > mProcessingBuffers
std::atomic< bool > mAudioThreadSequenceBufferExchangeLoopActive
void ClearRecordingException()
long mNumPauseFrames
How many frames of zeros were output due to pauses?
void SetRecordingException()
wxLongLong mLastPlaybackTimeMillis
bool HasRecordingException() const
RingBuffers mCaptureBuffers
static bool mCachedBestRatePlaying
bool mSoftwarePlaythrough
RecordableSequences mCaptureSequences
RingBuffers mPlaybackBuffers
std::vector< std::unique_ptr< RingBuffer > > RingBuffers
unsigned long mMaxFramesOutput
ConstPlayableSequences mPlaybackSequences
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
double mCaptureRingBufferSecs
size_t mNumCaptureChannels
void SetMixerOutputVol(float value)
std::vector< std::vector< float > > mMasterBuffers
std::vector< std::pair< double, double > > mLostCaptureIntervals
bool mPauseRec
True if Sound Activated Recording is enabled.
double mMinCaptureSecsToCopy
std::vector< SampleBuffer > mScratchBuffers
static bool mCachedBestRateCapturing
sampleFormat mCaptureFormat
This specialization of Setting for bool adds a Toggle method to negate the saved value.
Functions for doing the mixdown of the tracks.
An object that sends messages to an open-ended list of subscribed callbacks.
This is defined just to enable dynamic_cast on it.
std::chrono::duration< double > Duration
Brackets one block of processing in one thread.
Holds streamed audio samples.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
constexpr auto sampleRate
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept
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
RecordableSequences captureSequences
ConstPlayableSequences prerollSequences
std::vector< std::shared_ptr< const OtherPlayableSequence > > otherPlayableSequences
ConstPlayableSequences playbackSequences