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 };
439 std::shared_ptr<RealtimeEffectState>
448 std::shared_ptr<RealtimeEffectState>
455 std::shared_ptr<RealtimeEffectState> pState);
481 double t0,
double t1,
490 void StopStream()
override;
502 wxString LastPaErrorString();
506 {
return mOwningProject.lock(); }
509 void SetPaused(
bool state);
517 void SetMixer(
int inputSource,
float inputVolume,
518 float playbackVolume);
519 void GetMixer(
int *inputSource,
float *inputVolume,
520 float *playbackVolume);
527 bool InputMixerWorks();
533 wxArrayString GetInputSourceNames();
540 bool IsCapturing()
const;
550 #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
551 void AILAInitialize();
554 void AILAProcess(
double maxPeak);
555 void AILASetStartTime();
556 double AILAGetLastDecisionTime();
571 double GetBestRate(
bool capturing,
bool playing,
double sampleRate);
579 double GetStreamTime();
581 static void AudioThread(std::atomic<bool> &finish);
584 static void Deinit();
588 void DelayActions(
bool recording);
592 bool DelayingActions()
const;
609 unsigned int numPlaybackChannels,
unsigned int numCaptureChannels);
611 void SetOwningProject(
const std::shared_ptr<AudacityProject> &pProject );
612 void ResetOwningProject();
620 void SequenceBufferExchange();
623 void FillPlayBuffers();
624 void TransformPlayBuffers(
625 std::optional<RealtimeEffects::ProcessingScope> &
scope);
626 bool ProcessPlaybackSlices(
627 std::optional<RealtimeEffects::ProcessingScope> &pScope,
631 void DrainRecordBuffers();
638 size_t GetCommonlyFreePlayback();
646 size_t GetCommonlyAvailCapture();
653 bool AllocateBuffers(
661 void StartStreamCleanup(
bool bOnlyBuffers =
false);
666 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
static AudioUnitEffectsModule::Factory::SubstituteInUnique< AudioUnitEffect > scope
Vector operator*(const Vector &left, const Vector &right)
Generalized interface for discovery of plug-ins for one protocol.
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.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
constexpr auto sampleRate
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