13#ifndef __AUDACITY_AUDIO_IO__
14#define __AUDACITY_AUDIO_IO__
43struct PaStreamCallbackTimeInfo;
73 std::vector<std::shared_ptr<const OtherPlayableSequence>>
103 const void *inputBuffer,
void *outputBuffer,
104 unsigned long framesPerBuffer,
105 const PaStreamCallbackTimeInfo *timeInfo,
121 unsigned long framesPerBuffer,
122 const PaStreamCallbackTimeInfo *timeInfo,
137 ? audioIO.mAudioIOExt.
end()
138 : audioIO.mAudioIOExt.
begin() }
142 friend inline
bool operator == (
145 return xx.mIterator == yy.mIterator;
153 std::vector<std::unique_ptr<AudioIOExtBase>>::const_iterator
mIterator;
171 {
return mListener.lock(); }
172 void SetListener(
const std::shared_ptr< AudioIOListener > &listener);
175 int CallbackDoSeek();
178 void CallbackCheckCompletion(
179 int &callbackReturn,
unsigned long len);
184 unsigned CountSoloingSequences();
188 void CheckSoundActivatedRecordingLevel(
190 unsigned long framesPerBuffer
193 bool FillOutputBuffers(
195 unsigned long framesPerBuffer,
196 float *outputMeterFloats
198 void DrainInputBuffers(
200 unsigned long framesPerBuffer,
204 void UpdateTimePosition(
205 unsigned long framesPerBuffer
210 unsigned long framesPerBuffer,
211 float *outputMeterFloats
213 void SendVuInputMeterData(
214 const float *inputSamples,
215 unsigned long framesPerBuffer
217 void SendVuOutputMeterData(
218 const float *outputMeterFloats,
219 unsigned long framesPerBuffer
227 size_t GetCommonlyReadyPlayback();
229 size_t GetCommonlyWrittenForPlayback();
234#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
237 int mAILATotalAnalysis;
238 int mAILAAnalysisCounter;
240 double mAILAGoalPoint;
241 double mAILAGoalDelta;
242 double mAILAAnalysisTime;
243 double mAILALastStartTime;
244 double mAILAChangeFactor;
245 double mAILATopLevel;
246 double mAILAAnalysisEndTime;
247 double mAILAAbsolutStartTime;
248 unsigned short mAILALastChangeType;
252 std::atomic<bool> mFinishAudioThread{
false };
277 std::atomic<float> mMixerOutputVol{ 1.0 };
291 size_t mHardwarePlaybackLatencyFrames {};
307 double mCaptureRate{};
308 unsigned long long mLostSamples{ 0 };
318 void StartAudioThread();
319 void WaitForAudioThreadStarted();
320 void StopAudioThread();
321 void WaitForAudioThreadStopped();
323 void ProcessOnceAndWait( std::chrono::milliseconds sleepTime = std::chrono::milliseconds(50) );
327 std::atomic<bool> mForceFadeOut{
false };
336 static size_t MinValue(
340 return mMixerOutputVol.load(std::memory_order_relaxed); }
342 mMixerOutputVol.store(value, std::memory_order_relaxed); }
349 bool mUsingAlsa {
false };
350 bool mUsingJack {
false };
366 {
return mRecordingException; }
371 wxAtomicInt mRecordingException {};
373 { wxAtomicInc( mRecordingException ); }
375 {
if (mRecordingException) wxAtomicDec( mRecordingException ); }
379 bool mDetectDropouts{
true };
384 {
return mLostCaptureIntervals; }
387 bool mSimulateRecordingErrors{
false };
391 std::atomic<bool> mDetectUpstreamDropouts{
true };
429 std::shared_ptr<RealtimeEffectState>
437 std::shared_ptr<RealtimeEffectState>
444 std::shared_ptr<RealtimeEffectState> pState);
469 double t0,
double t1,
478 void StopStream()
override;
490 wxString LastPaErrorString();
494 {
return mOwningProject.lock(); }
497 void SetPaused(
bool state,
bool publish =
false);
505 void SetMixer(
int inputSource,
float inputVolume,
506 float playbackVolume);
507 void GetMixer(
int *inputSource,
float *inputVolume,
508 float *playbackVolume);
515 bool InputMixerWorks();
521 wxArrayString GetInputSourceNames();
528 bool IsCapturing()
const;
538 #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
539 void AILAInitialize();
542 void AILAProcess(
double maxPeak);
543 void AILASetStartTime();
544 double AILAGetLastDecisionTime();
559 double GetBestRate(
bool capturing,
bool playing,
double sampleRate);
567 double GetStreamTime();
569 static void AudioThread(std::atomic<bool> &finish);
572 static void Deinit();
576 void DelayActions(
bool recording);
580 bool DelayingActions()
const;
597 unsigned int numPlaybackChannels,
unsigned int numCaptureChannels);
599 void SetOwningProject(
const std::shared_ptr<AudacityProject> &pProject );
600 void ResetOwningProject();
608 void SequenceBufferExchange();
611 void FillPlayBuffers();
613 bool ProcessPlaybackSlices(
614 std::optional<RealtimeEffects::ProcessingScope> &pScope,
618 void DrainRecordBuffers();
625 size_t GetCommonlyFreePlayback();
633 size_t GetCommonlyAvailCapture();
640 bool AllocateBuffers(
648 void StartStreamCleanup(
bool bOnlyBuffers =
false);
653 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