13#ifndef __AUDACITY_AUDIO_IO__
14#define __AUDACITY_AUDIO_IO__
43struct PaStreamCallbackTimeInfo;
72 std::vector<std::shared_ptr<const OtherPlayableSequence>>
102 const void *inputBuffer,
void *outputBuffer,
103 unsigned long framesPerBuffer,
104 const PaStreamCallbackTimeInfo *timeInfo,
120 unsigned long framesPerBuffer,
121 const PaStreamCallbackTimeInfo *timeInfo,
136 ? audioIO.mAudioIOExt.
end()
137 : audioIO.mAudioIOExt.
begin() }
141 friend inline
bool operator == (
144 return xx.mIterator == yy.mIterator;
152 std::vector<std::unique_ptr<AudioIOExtBase>>::const_iterator
mIterator;
170 {
return mListener.lock(); }
171 void SetListener(
const std::shared_ptr< AudioIOListener > &listener);
174 int CallbackDoSeek();
177 void CallbackCheckCompletion(
178 int &callbackReturn,
unsigned long len);
183 unsigned CountSoloingSequences();
189 bool AllSequencesAlreadySilent();
191 void CheckSoundActivatedRecordingLevel(
193 unsigned long framesPerBuffer
199 void AddToOutputChannel(
unsigned int chan,
200 float * outputMeterFloats,
201 float * outputFloats,
202 const float * tempBuf,
208 bool FillOutputBuffers(
210 unsigned long framesPerBuffer,
211 float *outputMeterFloats
213 void DrainInputBuffers(
215 unsigned long framesPerBuffer,
219 void UpdateTimePosition(
220 unsigned long framesPerBuffer
225 unsigned long framesPerBuffer,
226 float *outputMeterFloats
228 void SendVuInputMeterData(
229 const float *inputSamples,
230 unsigned long framesPerBuffer
232 void SendVuOutputMeterData(
233 const float *outputMeterFloats,
234 unsigned long framesPerBuffer
242 size_t GetCommonlyReadyPlayback();
244 size_t GetCommonlyWrittenForPlayback();
249#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
252 int mAILATotalAnalysis;
253 int mAILAAnalysisCounter;
255 double mAILAGoalPoint;
256 double mAILAGoalDelta;
257 double mAILAAnalysisTime;
258 double mAILALastStartTime;
259 double mAILAChangeFactor;
260 double mAILATopLevel;
261 double mAILAAnalysisEndTime;
262 double mAILAAbsolutStartTime;
263 unsigned short mAILALastChangeType;
267 std::atomic<bool> mFinishAudioThread{
false };
286 std::atomic<float> mMixerOutputVol{ 1.0 };
300 size_t mHardwarePlaybackLatencyFrames {};
316 double mCaptureRate{};
317 unsigned long long mLostSamples{ 0 };
327 void StartAudioThread();
328 void WaitForAudioThreadStarted();
329 void StopAudioThread();
330 void WaitForAudioThreadStopped();
332 void ProcessOnceAndWait( std::chrono::milliseconds sleepTime = std::chrono::milliseconds(50) );
336 std::atomic<bool> mForceFadeOut{
false };
345 static size_t MinValue(
349 return mMixerOutputVol.load(std::memory_order_relaxed); }
351 mMixerOutputVol.store(value, std::memory_order_relaxed); }
358 bool mUsingAlsa {
false };
359 bool mUsingJack {
false };
375 {
return mRecordingException; }
380 wxAtomicInt mRecordingException {};
382 { wxAtomicInc( mRecordingException ); }
384 {
if (mRecordingException) wxAtomicDec( mRecordingException ); }
388 bool mDetectDropouts{
true };
393 {
return mLostCaptureIntervals; }
396 bool mSimulateRecordingErrors{
false };
400 std::atomic<bool> mDetectUpstreamDropouts{
true };
438 std::shared_ptr<RealtimeEffectState>
446 std::shared_ptr<RealtimeEffectState>
453 std::shared_ptr<RealtimeEffectState> pState);
478 double t0,
double t1,
487 void StopStream()
override;
499 wxString LastPaErrorString();
503 {
return mOwningProject.lock(); }
506 void SetPaused(
bool state);
514 void SetMixer(
int inputSource,
float inputVolume,
515 float playbackVolume);
516 void GetMixer(
int *inputSource,
float *inputVolume,
517 float *playbackVolume);
524 bool InputMixerWorks();
530 wxArrayString GetInputSourceNames();
537 bool IsCapturing()
const;
547 #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
548 void AILAInitialize();
551 void AILAProcess(
double maxPeak);
552 void AILASetStartTime();
553 double AILAGetLastDecisionTime();
568 double GetBestRate(
bool capturing,
bool playing,
double sampleRate);
576 double GetStreamTime();
578 static void AudioThread(std::atomic<bool> &finish);
581 static void Deinit();
585 void DelayActions(
bool recording);
589 bool DelayingActions()
const;
606 unsigned int numPlaybackChannels,
unsigned int numCaptureChannels);
608 void SetOwningProject(
const std::shared_ptr<AudacityProject> &pProject );
609 void ResetOwningProject();
617 void SequenceBufferExchange();
620 void FillPlayBuffers();
621 void TransformPlayBuffers(
622 std::optional<RealtimeEffects::ProcessingScope> &
scope);
623 bool ProcessPlaybackSlices(
624 std::optional<RealtimeEffects::ProcessingScope> &pScope,
628 void DrainRecordBuffers();
635 size_t GetCommonlyFreePlayback();
643 size_t GetCommonlyAvailCapture();
650 bool AllocateBuffers(
658 void StartStreamCleanup(
bool bOnlyBuffers =
false);
663 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()
std::array< float, 2 > OldChannelGains
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::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
std::vector< OldChannelGains > mOldChannelGains
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::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
static CommandContext::TargetFactory::SubstituteInUnique< InteractiveOutputTargets > scope
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