Audacity 3.2.0
|
AudioIO uses the PortAudio library to play and record sound. More...
#include <AudioIO.h>
Public Types | |
using | PostRecordingAction = std::function< void()> |
Public Types inherited from AudioIoCallback | |
using | RingBuffers = std::vector< std::unique_ptr< RingBuffer > > |
Public Types inherited from Observer::Publisher< AudioIOEvent > | |
using | message_type = AudioIOEvent |
using | CallbackReturn = std::conditional_t< true, void, bool > |
using | Callback = std::function< CallbackReturn(const AudioIOEvent &) > |
Type of functions that can be connected to the Publisher. More... | |
Public Member Functions | |
std::shared_ptr< RealtimeEffectState > | AddState (AudacityProject &project, ChannelGroup *pGroup, const PluginID &id) |
Forwards to RealtimeEffectManager::AddState with proper init scope. More... | |
std::shared_ptr< RealtimeEffectState > | ReplaceState (AudacityProject &project, ChannelGroup *pGroup, size_t index, const PluginID &id) |
Forwards to RealtimeEffectManager::ReplaceState with proper init scope. More... | |
void | RemoveState (AudacityProject &project, ChannelGroup *pGroup, std::shared_ptr< RealtimeEffectState > pState) |
Forwards to RealtimeEffectManager::RemoveState with proper init scope. More... | |
void | StartMonitoring (const AudioIOStartStreamOptions &options) |
Start up Portaudio for capture and recording as needed for input monitoring and software playthrough only. More... | |
int | StartStream (const TransportSequences &sequences, double t0, double t1, double mixerLimit, const AudioIOStartStreamOptions &options) |
Start recording or playing back audio. More... | |
void | StopStream () override |
Stop recording, playback or input monitoring. More... | |
void | SeekStream (double seconds) |
Move the playback / recording position of the current stream by the specified amount from where it is now. More... | |
void | CallAfterRecording (PostRecordingAction action) |
Enqueue action for main thread idle time, not before the end of any recording in progress. More... | |
wxString | LastPaErrorString () |
wxLongLong | GetLastPlaybackTime () const |
std::shared_ptr< AudacityProject > | GetOwningProject () const |
void | SetPaused (bool state, bool publish=false) |
Pause and un-pause playback and recording. More... | |
void | SetMixer (int inputSource, float inputVolume, float playbackVolume) |
void | GetMixer (int *inputSource, float *inputVolume, float *playbackVolume) |
bool | InputMixerWorks () |
Find out if the input hardware level control is available. More... | |
wxArrayString | GetInputSourceNames () |
Get the list of inputs to the current mixer device. More... | |
sampleFormat | GetCaptureFormat () |
size_t | GetNumPlaybackChannels () const |
size_t | GetNumCaptureChannels () const |
bool | IsCapturing () const |
bool | IsAvailable (AudacityProject &project) const |
Function to automatically set an acceptable volume. More... | |
double | GetBestRate (bool capturing, bool playing, double sampleRate) |
Return a valid sample rate that is supported by the current I/O device(s). More... | |
double | GetStreamTime () |
During playback, the sequence time most recently played. More... | |
void | DelayActions (bool recording) |
Public Member Functions inherited from AudioIoCallback | |
AudioIoCallback () | |
~AudioIoCallback () | |
int | AudioCallback (constSamplePtr inputBuffer, float *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, const PaStreamCallbackFlags statusFlags, void *userData) |
std::shared_ptr< AudioIOListener > | GetListener () const |
void | SetListener (const std::shared_ptr< AudioIOListener > &listener) |
int | CallbackDoSeek () |
void | CallbackCheckCompletion (int &callbackReturn, unsigned long len) |
unsigned | CountSoloingSequences () |
bool | SequenceShouldBeSilent (const PlayableSequence &ps) |
void | CheckSoundActivatedRecordingLevel (float *inputSamples, unsigned long framesPerBuffer) |
bool | FillOutputBuffers (float *outputFloats, unsigned long framesPerBuffer, float *outputMeterFloats) |
void | DrainInputBuffers (constSamplePtr inputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackFlags statusFlags, float *tempFloats) |
void | UpdateTimePosition (unsigned long framesPerBuffer) |
void | DoPlaythrough (constSamplePtr inputBuffer, float *outputBuffer, unsigned long framesPerBuffer, float *outputMeterFloats) |
void | SendVuInputMeterData (const float *inputSamples, unsigned long framesPerBuffer) |
void | SendVuOutputMeterData (const float *outputMeterFloats, unsigned long framesPerBuffer) |
size_t | GetCommonlyReadyPlayback () |
Get the number of audio samples ready in all of the playback buffers. More... | |
size_t | GetCommonlyWrittenForPlayback () |
void | StartAudioThread () |
void | WaitForAudioThreadStarted () |
void | StopAudioThread () |
void | WaitForAudioThreadStopped () |
void | ProcessOnceAndWait (std::chrono::milliseconds sleepTime=std::chrono::milliseconds(50)) |
bool | HasRecordingException () const |
const std::vector< std::pair< double, double > > & | LostCaptureIntervals () |
AudioIOExtRange | Extensions () |
Public Member Functions inherited from AudioIOBase | |
AudioIOBase () | |
virtual | ~AudioIOBase () |
AudioIOBase (const AudioIOBase &)=delete | |
AudioIOBase & | operator= (const AudioIOBase &)=delete |
void | SetCaptureMeter (const std::shared_ptr< AudacityProject > &project, const std::weak_ptr< Meter > &meter) |
void | SetPlaybackMeter (const std::shared_ptr< AudacityProject > &project, const std::weak_ptr< Meter > &meter) |
void | HandleDeviceChange () |
update state after changing what audio devices are selected More... | |
wxString | GetDeviceInfo () const |
Get diagnostic information on all the available audio I/O devices. More... | |
std::vector< AudioIODiagnostics > | GetAllDeviceInfo () |
Get diagnostic information for audio devices and also for extensions. More... | |
bool | IsPaused () const |
Find out if playback / recording is currently paused. More... | |
virtual void | StopStream ()=0 |
bool | IsBusy () const |
Returns true if audio i/o is busy starting, stopping, playing, or recording. More... | |
bool | IsStreamActive () const |
Returns true if the audio i/o is running at all, but not during cleanup. More... | |
bool | IsStreamActive (int token) const |
bool | IsAudioTokenActive (int token) const |
Returns true if the stream is active, or even if audio I/O is busy cleaning up its data or writing to disk. More... | |
bool | IsMonitoring () const |
Returns true if we're monitoring input (but not recording or playing actual audio) More... | |
void | SetMixer (int inputSource) |
Public Member Functions inherited from Observer::Publisher< AudioIOEvent > | |
Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={}) | |
Constructor supporting type-erased custom allocation/deletion. More... | |
Publisher (Publisher &&)=default | |
Publisher & | operator= (Publisher &&)=default |
Subscription | Subscribe (Callback callback) |
Connect a callback to the Publisher; later-connected are called earlier. More... | |
Subscription | Subscribe (Object &obj, Return(Object::*callback)(Args...)) |
Overload of Subscribe takes an object and pointer-to-member-function. More... | |
Static Public Member Functions | |
static AudioIO * | Get () |
static bool | ValidateDeviceNames (const wxString &play, const wxString &rec) |
Ensure selected device names are valid. More... | |
static void | AudioThread (std::atomic< bool > &finish) |
Sits in a thread loop reading and writing audio. More... | |
static void | Init () |
static void | Deinit () |
Static Public Member Functions inherited from AudioIOBase | |
static AudioIOBase * | Get () |
static std::vector< long > | GetSupportedPlaybackRates (int DevIndex=-1) |
Get a list of sample rates the output (playback) device supports. More... | |
static long | GetClosestSupportedPlaybackRate (int devIndex, long rate) |
Find the closest supported sample rate for given playback device. More... | |
static std::vector< long > | GetSupportedCaptureRates (int devIndex=-1) |
Get a list of sample rates the input (recording) device supports. More... | |
static long | GetClosestSupportedCaptureRate (int devIndex, long rate) |
Find the closest supported sample rate for given recording device. More... | |
static std::vector< long > | GetSupportedSampleRates (int playDevice=-1, int recDevice=-1) |
Get a list of sample rates the current input/output device combination supports. More... | |
static long | GetClosestSupportedSampleRate (int playDevice, int recDevice, long rate) |
Find the closest supported sample rate for given playback and recording devices. More... | |
static int | GetOptimalSupportedSampleRate () |
Get a supported sample rate which can be used a an optimal default. More... | |
static bool | IsPlaybackRateSupported (int devIndex, long rate) |
Check if the specified playback rate is supported by a device. More... | |
static bool | IsCaptureRateSupported (int devIndex, long rate) |
Check if the specified sample rate is supported by a device. More... | |
Private Member Functions | |
AudioIO () | |
~AudioIO () | |
void | StartThread () |
bool | DelayingActions () const |
void | SetMeters () |
Set the current VU meters - this should be done once after each call to StartStream currently. More... | |
bool | StartPortAudioStream (const AudioIOStartStreamOptions &options, unsigned int numPlaybackChannels, unsigned int numCaptureChannels) |
Opens the portaudio stream(s) used to do playback or recording (or both) through. More... | |
void | SetOwningProject (const std::shared_ptr< AudacityProject > &pProject) |
void | ResetOwningProject () |
void | SequenceBufferExchange () |
void | FillPlayBuffers () |
First part of SequenceBufferExchange. More... | |
bool | ProcessPlaybackSlices (std::optional< RealtimeEffects::ProcessingScope > &pScope, size_t available) |
void | DrainRecordBuffers () |
Second part of SequenceBufferExchange. More... | |
size_t | GetCommonlyFreePlayback () |
Get the number of audio samples free in all of the playback buffers. More... | |
size_t | GetCommonlyAvailCapture () |
Get the number of audio samples ready in all of the recording buffers. More... | |
bool | AllocateBuffers (const AudioIOStartStreamOptions &options, const TransportSequences &sequences, double t0, double t1, double sampleRate) |
Allocate RingBuffer structures, and others, needed for playback and recording. More... | |
void | StartStreamCleanup (bool bOnlyBuffers=false) |
Clean up after StartStream if it fails. More... | |
Private Attributes | |
std::mutex | mPostRecordingActionMutex |
PostRecordingAction | mPostRecordingAction |
bool | mDelayingActions { false } |
Additional Inherited Members | |
Public Attributes inherited from AudioIoCallback | |
int | mbHasSoloSequences |
int | mCallbackReturn |
long | mNumPauseFrames |
How many frames of zeros were output due to pauses? More... | |
std::thread | mAudioThread |
std::atomic< bool > | mFinishAudioThread { false } |
std::vector< std::unique_ptr< Resample > > | mResample |
RingBuffers | mCaptureBuffers |
RecordableSequences | mCaptureSequences |
std::vector< std::vector< float > > | mProcessingBuffers |
std::vector< std::vector< float > > | mMasterBuffers |
RingBuffers | mPlaybackBuffers |
ConstPlayableSequences | mPlaybackSequences |
float | mOldPlaybackVolume |
std::vector< SampleBuffer > | mScratchBuffers |
std::vector< float * > | mScratchPointers |
pointing into mScratchBuffers More... | |
std::vector< std::unique_ptr< Mixer > > | mPlaybackMixers |
std::atomic< float > | mMixerOutputVol { 1.0 } |
double | mFactor |
unsigned long | mMaxFramesOutput |
bool | mbMicroFades |
double | mSeek |
PlaybackPolicy::Duration | mPlaybackRingBufferSecs |
double | mCaptureRingBufferSecs |
size_t | mPlaybackSamplesToCopy |
Preferred batch size for replenishing the playback RingBuffer. More... | |
size_t | mHardwarePlaybackLatencyFrames {} |
Hardware output latency in frames. More... | |
size_t | mPlaybackQueueMinimum |
Occupancy of the queue we try to maintain, with bigger batches if needed. More... | |
double | mMinCaptureSecsToCopy |
bool | mSoftwarePlaythrough |
bool | mPauseRec |
True if Sound Activated Recording is enabled. More... | |
float | mSilenceLevel |
size_t | mNumCaptureChannels |
size_t | mNumPlaybackChannels |
sampleFormat | mCaptureFormat |
double | mCaptureRate {} |
unsigned long long | mLostSamples { 0 } |
std::atomic< bool > | mAudioThreadShouldCallSequenceBufferExchangeOnce |
std::atomic< bool > | mAudioThreadSequenceBufferExchangeLoopRunning |
std::atomic< bool > | mAudioThreadSequenceBufferExchangeLoopActive |
std::atomic< Acknowledge > | mAudioThreadAcknowledge |
std::atomic< bool > | mForceFadeOut { false } |
wxLongLong | mLastPlaybackTimeMillis |
double | mLastRecordingOffset |
Not (yet) used; should perhaps be atomic when it is. More... | |
PaError | mLastPaError |
bool | mSimulateRecordingErrors { false } |
std::atomic< bool > | mDetectUpstreamDropouts { true } |
Static Public Attributes inherited from AudioIoCallback | |
static int | mNextStreamToken = 0 |
Static Public Attributes inherited from AudioIOBase | |
static const int | StandardRates [] |
Array of common audio sample rates. More... | |
static const int | NumStandardRates = WXSIZEOF(AudioIOBase::StandardRates) |
How many standard sample rates there are. More... | |
Static Public Attributes inherited from Observer::Publisher< AudioIOEvent > | |
static constexpr bool | notifies_all |
Protected Member Functions inherited from AudioIoCallback | |
float | GetMixerOutputVol () |
void | SetMixerOutputVol (float value) |
void | SetRecordingException () |
void | ClearRecordingException () |
Protected Member Functions inherited from Observer::Publisher< AudioIOEvent > | |
CallbackReturn | Publish (const AudioIOEvent &message) |
Send a message to connected callbacks. More... | |
Static Protected Member Functions inherited from AudioIoCallback | |
static size_t | MinValue (const RingBuffers &buffers, size_t(RingBuffer::*pmf)() const) |
Static Protected Member Functions inherited from AudioIOBase | |
static wxString | DeviceName (const PaDeviceInfo *info) |
static wxString | HostName (const PaDeviceInfo *info) |
static int | getRecordDevIndex (const wxString &devName={}) |
get the index of the supplied (named) recording device, or the device selected in the preferences if none given. More... | |
static int | getPlayDevIndex (const wxString &devName={}) |
get the index of the device selected in the preferences. More... | |
Protected Attributes inherited from AudioIoCallback | |
std::weak_ptr< AudioIOListener > | mListener |
bool | mUsingAlsa { false } |
bool | mUsingJack { false } |
wxMutex | mSuspendAudioThread |
wxAtomicInt | mRecordingException {} |
std::vector< std::pair< double, double > > | mLostCaptureIntervals |
bool | mDetectDropouts { true } |
RecordingSchedule | mRecordingSchedule {} |
PlaybackSchedule | mPlaybackSchedule |
std::unique_ptr< TransportState > | mpTransportState |
Holds some state for duration of playback or recording. More... | |
Protected Attributes inherited from AudioIOBase | |
std::weak_ptr< AudacityProject > | mOwningProject |
std::atomic< bool > | mPaused { false } |
True if audio playback is paused. More... | |
int | mStreamToken { 0 } |
double | mRate |
Audio playback rate in samples per second. More... | |
PaStream * | mPortStreamV19 |
std::weak_ptr< Meter > | mInputMeter {} |
std::weak_ptr< Meter > | mOutputMeter {} |
bool | mInputMixerWorks |
Can we control the hardware input level? More... | |
std::vector< std::unique_ptr< AudioIOExtBase > > | mAudioIOExt |
Static Protected Attributes inherited from AudioIoCallback | |
static double | mCachedBestRateOut |
static bool | mCachedBestRatePlaying |
static bool | mCachedBestRateCapturing |
Static Protected Attributes inherited from AudioIOBase | |
static std::unique_ptr< AudioIOBase > | ugAudioIO |
static std::map< int, std::vector< long > > | mCachedPlaybackRates |
static std::map< int, std::vector< long > > | mCachedCaptureRates |
static std::map< std::pair< int, int >, std::vector< long > > | mCachedSampleRates |
static int | mCurrentPlaybackIndex { -1 } |
static int | mCurrentCaptureIndex { -1 } |
static double | mCachedBestRateIn { 0.0 } |
static const int | RatesToTry [] |
Array of audio sample rates to try to use. More... | |
static const int | NumRatesToTry = WXSIZEOF(AudioIOBase::RatesToTry) |
How many sample rates to try. More... | |
AudioIO uses the PortAudio library to play and record sound.
Great care and attention to detail are necessary for understanding and modifying this system. The code in this file is run from three different thread contexts: the UI thread, the disk thread (which this file creates and maintains; in the code, this is called the Audio Thread), and the PortAudio callback thread. To highlight this deliniation, the file is divided into three parts based on what thread context each function is intended to run in.
using AudioIO::PostRecordingAction = std::function<void()> |
|
private |
Definition at line 232 of file AudioIO.cpp.
References AudioIOPlaybackVolume, BasicUI::MessageBoxOptions::Caption(), eNone, AudioIOBase::HandleDeviceChange(), LAT1CTOWX, AudioIoCallback::mAudioThreadAcknowledge, AudioIoCallback::mAudioThreadSequenceBufferExchangeLoopActive, AudioIoCallback::mAudioThreadSequenceBufferExchangeLoopRunning, AudioIoCallback::mAudioThreadShouldCallSequenceBufferExchangeOnce, AudioIOBase::mInputMixerWorks, AudioIoCallback::mLastPaError, AudioIoCallback::mLastPlaybackTimeMillis, AudioIoCallback::mLastRecordingOffset, AudioIoCallback::mNumCaptureChannels, AudioIoCallback::mNumPauseFrames, AudioIOBase::mOutputMeter, AudioIOBase::mPortStreamV19, AudioIoCallback::mSilenceLevel, Setting< T >::Read(), AudioIoCallback::SetMixerOutputVol(), BasicUI::ShowMessageBox(), and XO().
Referenced by Init().
|
private |
Definition at line 314 of file AudioIO.cpp.
References AudioIoCallback::mAudioThread, AudioIoCallback::mFinishAudioThread, AudioIOBase::mOwningProject, and ResetOwningProject().
std::shared_ptr< RealtimeEffectState > AudioIO::AddState | ( | AudacityProject & | project, |
ChannelGroup * | pGroup, | ||
const PluginID & | id | ||
) |
Forwards to RealtimeEffectManager::AddState with proper init scope.
!result || result->GetEffect() != nullptr
Definition at line 347 of file AudioIO.cpp.
References RealtimeEffectManager::AddState(), RealtimeEffectManager::Get(), GetOwningProject(), AudioIoCallback::mpTransportState, and project.
Referenced by EffectUIHost::InitializeInstance().
|
private |
Allocate RingBuffer structures, and others, needed for playback and recording.
Returns true iff successful.
Definition at line 1166 of file AudioIO.cpp.
References DownmixStage::Discard, floatSample, PlaybackSchedule::GetPolicy(), PlaybackSchedule::TimeQueue::Init(), lrint, make_iterator_range(), AudioIoCallback::mCaptureBuffers, AudioIoCallback::mCaptureFormat, AudioIoCallback::mCaptureRingBufferSecs, AudioIoCallback::mFactor, AudioIoCallback::mHardwarePlaybackLatencyFrames, min(), AudioIoCallback::mMasterBuffers, AudioIoCallback::mMinCaptureSecsToCopy, AudioIoCallback::mNumCaptureChannels, AudioIoCallback::mNumPlaybackChannels, AudioIoCallback::mOldPlaybackVolume, AudioIoCallback::mPlaybackBuffers, AudioIoCallback::mPlaybackMixers, AudioIoCallback::mPlaybackQueueMinimum, AudioIoCallback::mPlaybackRingBufferSecs, AudioIoCallback::mPlaybackSamplesToCopy, AudioIoCallback::mPlaybackSchedule, AudioIoCallback::mPlaybackSequences, AudioIoCallback::mProcessingBuffers, AudioIOBase::mRate, AudioIoCallback::mResample, AudioIoCallback::mScratchBuffers, AudioIoCallback::mScratchPointers, PlaybackSchedule::mT0, PlaybackSchedule::mTimeQueue, TransportSequences::prerollSequences, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, BasicUI::ShowMessageBox(), StartStreamCleanup(), PlaybackPolicy::SuggestedBufferTimes(), TimeQueueGrainSize, and XO().
Referenced by StartStream().
|
static |
Sits in a thread loop reading and writing audio.
Definition at line 1771 of file AudioIO.cpp.
References eStart, eStop, Get(), PlaybackSchedule::GetPolicy(), AudioIOBase::IsMonitoring(), AudioIoCallback::mAudioThreadAcknowledge, AudioIoCallback::mAudioThreadSequenceBufferExchangeLoopActive, AudioIoCallback::mAudioThreadSequenceBufferExchangeLoopRunning, AudioIoCallback::mAudioThreadShouldCallSequenceBufferExchangeOnce, AudioIoCallback::mPlaybackSchedule, SequenceBufferExchange(), and PlaybackPolicy::SleepInterval().
Referenced by StartThread().
void AudioIO::CallAfterRecording | ( | PostRecordingAction | action | ) |
Enqueue action for main thread idle time, not before the end of any recording in progress.
This may be called from non-main threads
Definition at line 1138 of file AudioIO.cpp.
References BasicUI::CallAfter(), DelayingActions(), mPostRecordingAction, and mPostRecordingActionMutex.
|
static |
Definition at line 218 of file AudioIO.cpp.
References AudioIOBase::ugAudioIO.
Referenced by AudacityApp::OnExit().
void AudioIO::DelayActions | ( | bool | recording | ) |
For purposes of CallAfterRecording, treat time from now as if recording (when argument is true) or not necessarily so (false)
Definition at line 1128 of file AudioIO.cpp.
References mDelayingActions.
Referenced by StopStream().
|
private |
Definition at line 1133 of file AudioIO.cpp.
References mDelayingActions, AudioIoCallback::mNumCaptureChannels, and AudioIOBase::mPortStreamV19.
Referenced by CallAfterRecording().
|
private |
Second part of SequenceBufferExchange.
Definition at line 2213 of file AudioIO.cpp.
References SampleBuffer::Allocate(), ClearSamples(), RecordingSchedule::Consumed(), DefaultDelayedHandlerAction(), floatSample, anonymous_namespace{ExportPCM.cpp}::format, GetCommonlyAvailCapture(), AudioIoCallback::GetListener(), GuardedCall(), anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, AudioIOBase::IsStreamActive(), lrint, AudioIoCallback::mAudioThreadShouldCallSequenceBufferExchangeOnce, AudioIoCallback::mCaptureBuffers, AudioIoCallback::mCaptureFormat, AudioIoCallback::mCaptureRate, AudioIoCallback::mCaptureSequences, RecordingSchedule::mCrossfadeData, AudioIoCallback::mFactor, min(), RecordingSchedule::mLatencyCorrected, AudioIoCallback::mMinCaptureSecsToCopy, AudioIoCallback::mNumCaptureChannels, RecordingSchedule::mPosition, AudioIOBase::mRate, AudioIoCallback::mRecordingException, AudioIoCallback::mRecordingSchedule, AudioIoCallback::mResample, narrowestSampleFormat, SampleBuffer::ptr(), AudioIoCallback::SetRecordingException(), size, StopStream(), RecordingSchedule::ToConsume(), RecordingSchedule::ToDiscard(), and RecordingSchedule::TotalCorrection().
Referenced by SequenceBufferExchange().
|
private |
First part of SequenceBufferExchange.
Definition at line 1878 of file AudioIO.cpp.
References GetCommonlyFreePlayback(), AudioIoCallback::GetCommonlyWrittenForPlayback(), min(), AudioIoCallback::mNumPlaybackChannels, AudioIOBase::mOwningProject, AudioIoCallback::mPlaybackBuffers, AudioIoCallback::mPlaybackQueueMinimum, AudioIoCallback::mPlaybackSamplesToCopy, AudioIoCallback::mpTransportState, and ProcessPlaybackSlices().
Referenced by SequenceBufferExchange().
|
static |
Definition at line 126 of file AudioIO.cpp.
References AudioIOBase::Get().
Referenced by AdornedRulerPanel::AdornedRulerPanel(), audacityAudioCallback(), AudioThread(), Scrubber::CanScrub(), ProjectAudioManager::CanStopAudioStream(), CaptureNotBusyFlag(), EffectUIHost::CleanupRealtime(), Scrubber::ContinueScrubbingPoll(), DefaultSpeedPlayOptions(), anonymous_namespace{SelectMenus.cpp}::DoBoundaryMove(), PlayIndicatorOverlayBase::DoGetRectangle(), Scrubber::DoKeyboardScrub(), ProjectAudioManager::DoPlayStopSelect(), ProjectAudioManager::DoRecord(), PlayIndicatorOverlayBase::Draw(), EffectPreview(), ControlToolBar::EnableDisableButtons(), TranscriptionToolBar::EnableDisableButtons(), ScrubbingPlaybackPolicy::GetPlaybackSlice(), UpdateManager::GetUpdates(), HistoryDialog::HistoryDialog(), EffectUIHost::InitializeInstance(), Scrubber::MaybeStartScrubbing(), ProjectManager::New(), RealtimeEffectListWindow::OnAddEffectClicked(), anonymous_namespace{LabelMenus.cpp}::OnAddLabelPlaying(), ProjectAudioManager::OnAudioIOStopRecording(), anonymous_namespace{RealtimeEffectPanel.cpp}::RealtimeEffectControl::OnChangeButtonClicked(), ProjectManager::OnCloseWindow(), SelectActions::Handler::OnCursorPositionStore(), anonymous_namespace{PluginMenus.cpp}::OnDetectUpstreamDropouts(), TimeToolBar::OnIdle(), AudacityApp::OnKeyDown(), ProjectAudioManager::OnPause(), anonymous_namespace{TransportMenus.cpp}::OnPunchAndRoll(), SelectActions::Handler::OnSelectCursorStoredCursor(), SelectUtilities::OnSetRegion(), anonymous_namespace{PluginMenus.cpp}::OnSimulateRecordingErrors(), ProjectAudioManager::OnSoundActivationThreshold(), ProjectWindow::PlaybackScroller::OnTimer(), MixerBoard::OnTimer(), PlayIndicatorOverlay::OnTimer(), ProjectManager::OnTimer(), TrackPanel::OnTimer(), anonymous_namespace{ViewMenus.cpp}::OnZoomIn(), TransportUtilities::PlayCurrentRegionAndWait(), ProjectAudioManager::Playing(), ProjectAudioManager::PlayPlayRegion(), TransportUtilities::PlayPlayRegionAndWait(), TransportUtilities::RecordAndWait(), ProjectAudioManager::Recording(), anonymous_namespace{RealtimeEffectPanel.cpp}::RealtimeEffectControl::RemoveFromList(), ScrubbingPlaybackPolicy::RepositionPlayback(), TimerRecordDialog::RunWaitDialog(), anonymous_namespace{SelectMenus.cpp}::SeekWhenAudioActive(), MeterPanel::SetMixer(), Scrubber::StartKeyboardScrubbing(), MeterPanel::StartMonitoring(), StartMonitoring(), ControlToolBar::StartScrolling(), ProjectAudioManager::Stop(), MeterPanel::StopMonitoring(), Scrubber::StopScrubbing(), anonymous_namespace{PluginMenus.cpp}::ToolsMenu(), TrackPanel::TrackPanel(), MeterPanel::UpdateSelectedPrefs(), and MeterPanel::UpdateSliderControl().
double AudioIO::GetBestRate | ( | bool | capturing, |
bool | playing, | ||
double | sampleRate | ||
) |
Return a valid sample rate that is supported by the current I/O device(s).
The return from this function is used to determine the sample rate that audacity actually runs the audio I/O stream at. if there is no suitable rate available from the hardware, it returns 0. The sampleRate argument gives the desired sample rate (the rate of the audio to be handled, i.e. the currently Project Rate). capturing is true if the stream is capturing one or more audio channels, and playing is true if one or more channels are being played.
Definition at line 1709 of file AudioIO.cpp.
References AudioIOBase::GetClosestSupportedCaptureRate(), AudioIOBase::GetClosestSupportedPlaybackRate(), AudioIOBase::GetClosestSupportedSampleRate(), AudioIoCallback::mCachedBestRateCapturing, AudioIOBase::mCachedBestRateIn, AudioIoCallback::mCachedBestRateOut, AudioIoCallback::mCachedBestRatePlaying, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, and wxT().
Referenced by StartPortAudioStream().
|
inline |
|
private |
Get the number of audio samples ready in all of the recording buffers.
Returns the smallest of the number of samples available for storage in the recording buffers (i.e. the number of samples that can be read from all record buffers without underflow).
Definition at line 1864 of file AudioIO.cpp.
References RingBuffer::AvailForGet(), AudioIoCallback::mCaptureBuffers, and AudioIoCallback::MinValue().
Referenced by DrainRecordBuffers().
|
private |
Get the number of audio samples free in all of the playback buffers.
Returns the smallest of the buffer free space values in the event that they are different.
Definition at line 1846 of file AudioIO.cpp.
References RingBuffer::AvailForPut(), min(), AudioIoCallback::MinValue(), and AudioIoCallback::mPlaybackBuffers.
Referenced by FillPlayBuffers().
wxArrayString AudioIO::GetInputSourceNames | ( | ) |
Get the list of inputs to the current mixer device.
Returns an array of strings giving the names of the inputs to the soundcard mixer (driven by PortMixer)
Definition at line 432 of file AudioIO.cpp.
References wxT().
void AudioIO::GetMixer | ( | int * | inputSource, |
float * | inputVolume, | ||
float * | playbackVolume | ||
) |
Definition at line 400 of file AudioIO.cpp.
References AudioIoCallback::GetMixerOutputVol(), and AudioIOBase::mInputMixerWorks.
|
inline |
Definition at line 494 of file AudioIO.h.
Referenced by AddState(), RemoveState(), and ReplaceState().
double AudioIO::GetStreamTime | ( | ) |
During playback, the sequence time most recently played.
When playing looped, this will start from t0 again, too. So the returned time should be always between t0 and t1
Definition at line 1753 of file AudioIO.cpp.
References BAD_STREAM_TIME, PlaybackSchedule::GetSequenceTime(), AudioIOBase::IsStreamActive(), and AudioIoCallback::mPlaybackSchedule.
|
static |
Definition at line 190 of file AudioIO.cpp.
References AudioIO(), AudioIOHost, AudioIOPlaybackDevice, AudioIORecordingDevice, AudioIOBase::DeviceName(), audacity::BasicSettings::Flush(), AudioIOBase::getPlayDevIndex(), AudioIOBase::getRecordDevIndex(), gPrefs, AudioIOBase::HostName(), audacity::BasicSettings::Read(), safenew, AudioIOBase::ugAudioIO, Setting< T >::Write(), and wxT().
Referenced by AudacityApp::InitPart2().
bool AudioIO::InputMixerWorks | ( | ) |
Find out if the input hardware level control is available.
Checks the mInputMixerWorks variable, which is set up in AudioIOBase::HandleDeviceChange(). External people care, because we want to disable the UI if it doesn't work.
Definition at line 427 of file AudioIO.cpp.
References AudioIOBase::mInputMixerWorks.
bool AudioIO::IsAvailable | ( | AudacityProject & | project | ) | const |
Function to automatically set an acceptable volume.
Definition at line 1414 of file AudioIO.cpp.
References AudioIOBase::mOwningProject, and project.
bool AudioIO::IsCapturing | ( | ) | const |
Definition at line 3361 of file AudioIO.cpp.
References PlaybackSchedule::GetSequenceTime(), AudioIOBase::IsStreamActive(), AudioIoCallback::mPlaybackSchedule, RecordingSchedule::mPreRoll, AudioIoCallback::mRecordingSchedule, and PlaybackSchedule::mT0.
wxString AudioIO::LastPaErrorString | ( | ) |
Definition at line 754 of file AudioIO.cpp.
References AudioIoCallback::mLastPaError, and wxT().
Referenced by StartMonitoring().
|
private |
Definition at line 1958 of file AudioIO.cpp.
References floatSample, PlaybackSchedule::GetPolicy(), RealtimeEffectManager::MasterGroup, min(), AudioIoCallback::mMasterBuffers, AudioIoCallback::mNumPlaybackChannels, AudioIoCallback::mPlaybackBuffers, AudioIoCallback::mPlaybackMixers, AudioIoCallback::mPlaybackSchedule, AudioIoCallback::mPlaybackSequences, AudioIoCallback::mProcessingBuffers, AudioIoCallback::mScratchPointers, PlaybackSchedule::mTimeQueue, PlaybackSchedule::TimeQueue::Producer(), AudioIoCallback::SequenceShouldBeSilent(), size, and stackAllocate.
Referenced by FillPlayBuffers().
void AudioIO::RemoveState | ( | AudacityProject & | project, |
ChannelGroup * | pGroup, | ||
std::shared_ptr< RealtimeEffectState > | pState | ||
) |
Forwards to RealtimeEffectManager::RemoveState with proper init scope.
Definition at line 369 of file AudioIO.cpp.
References RealtimeEffectManager::Get(), GetOwningProject(), AudioIoCallback::mpTransportState, project, and RealtimeEffectManager::RemoveState().
Referenced by EffectUIHost::CleanupRealtime(), and anonymous_namespace{RealtimeEffectPanel.cpp}::RealtimeEffectControl::RemoveFromList().
std::shared_ptr< RealtimeEffectState > AudioIO::ReplaceState | ( | AudacityProject & | project, |
ChannelGroup * | pGroup, | ||
size_t | index, | ||
const PluginID & | id | ||
) |
Forwards to RealtimeEffectManager::ReplaceState with proper init scope.
!result || result->GetEffect() != nullptr
Definition at line 358 of file AudioIO.cpp.
References RealtimeEffectManager::Get(), GetOwningProject(), AudioIoCallback::mpTransportState, project, and RealtimeEffectManager::ReplaceState().
|
private |
Definition at line 770 of file AudioIO.cpp.
References AudioIOBase::mOwningProject.
Referenced by SetOwningProject(), StartPortAudioStream(), StopStream(), and ~AudioIO().
|
inline |
|
private |
Called in a loop from another worker thread that does not have the low-latency constraints of the PortAudio callback thread. Does less frequent and larger batches of work that may include memory allocations and database operations. RingBuffer objects mediate the transfer between threads, to overcome the mismatch of their batch sizes.
Definition at line 1872 of file AudioIO.cpp.
References DrainRecordBuffers(), and FillPlayBuffers().
Referenced by AudioThread().
|
private |
Set the current VU meters - this should be done once after each call to StartStream currently.
Definition at line 1420 of file AudioIO.cpp.
References AudioIOBase::mInputMeter, AudioIOBase::mOutputMeter, and AudioIOBase::mRate.
Referenced by StartPortAudioStream().
void AudioIO::SetMixer | ( | int | inputSource, |
float | inputVolume, | ||
float | playbackVolume | ||
) |
Definition at line 380 of file AudioIO.cpp.
References AudioIOPlaybackVolume, AudioIOBase::SetMixer(), AudioIoCallback::SetMixerOutputVol(), and Setting< T >::Write().
|
private |
Definition at line 759 of file AudioIO.cpp.
References AudioIOBase::mOwningProject, and ResetOwningProject().
Referenced by StartPortAudioStream().
void AudioIO::SetPaused | ( | bool | state, |
bool | publish = false |
||
) |
Pause and un-pause playback and recording.
Definition at line 1691 of file AudioIO.cpp.
References RealtimeEffectManager::Get(), AudioIOBase::IsPaused(), AudioIOBase::mOwningProject, AudioIOBase::mPaused, AudioIOEvent::PAUSE, and Observer::Publisher< AudioIOEvent >::Publish().
void AudioIO::StartMonitoring | ( | const AudioIOStartStreamOptions & | options | ) |
Start up Portaudio for capture and recording as needed for input monitoring and software playthrough only.
This uses the Default project sample format, current sample rate, and selected number of input channels to open the recording device and start reading input data. If software playthrough is enabled, it also opens the output device in stereo to play the data through
Definition at line 775 of file AudioIO.cpp.
References AudioIORecordChannels, Get(), AudioIoCallback::GetListener(), gPrefs, LastPaErrorString(), AudioIoCallback::mCaptureFormat, AudioIoCallback::mCaptureRate, AudioIoCallback::mLastPaError, AudioIOEvent::MONITOR, AudioIOBase::mOwningProject, AudioIOBase::mPortStreamV19, AudioIOBase::mRate, AudioIoCallback::mSoftwarePlaythrough, AudioIOBase::mStreamToken, AudioIoCallback::mUsingAlsa, ProjectFramePlacement(), Observer::Publisher< AudioIOEvent >::Publish(), audacity::BasicSettings::Read(), Setting< T >::Read(), QualitySettings::SampleFormatChoice(), BasicUI::ShowErrorDialog(), StartPortAudioStream(), wxT(), and XO().
|
private |
Opens the portaudio stream(s) used to do playback or recording (or both) through.
The sampleRate passed is the Project Rate of the active project. It may or may not be actually supported by playback or recording hardware currently in use (for many reasons). The number of Capture and Playback channels requested includes an allocation for doing software playthrough if necessary. The captureFormat is used for recording only, the playback being floating point always. Returns true if the stream opened successfully and false if it did not.
Definition at line 473 of file AudioIO.cpp.
References _, audacityAudioCallback(), AudacityToPortAudioSampleFormat(), AudioIOLatencyDuration, AudioIOStartStreamOptions::captureMeter, floatSample, GetBestRate(), AudioIOBase::getPlayDevIndex(), AudioIOBase::getRecordDevIndex(), DeviceManager::GetTimeSinceRescan(), DeviceManager::Instance(), int24Sample, lrint, AudioIoCallback::mCaptureFormat, AudioIoCallback::mHardwarePlaybackLatencyFrames, AudioIOBase::mInputMeter, AudioIoCallback::mLastPaError, AudioIoCallback::mNumCaptureChannels, AudioIoCallback::mNumPauseFrames, AudioIoCallback::mNumPlaybackChannels, AudioIOBase::mOutputMeter, AudioIOBase::mOwningProject, AudioIOBase::mPortStreamV19, AudioIOBase::mRate, AudioIoCallback::mSoftwarePlaythrough, AudioIoCallback::mUsingAlsa, AudioIoCallback::mUsingJack, AudioIOStartStreamOptions::playbackMeter, AudioIOStartStreamOptions::pProject, AudioIOStartStreamOptions::rate, Setting< T >::Read(), ResetOwningProject(), anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, AudioIOBase::SetCaptureMeter(), SetMeters(), and SetOwningProject().
Referenced by StartMonitoring(), and StartStream().
int AudioIO::StartStream | ( | const TransportSequences & | sequences, |
double | t0, | ||
double | t1, | ||
double | mixerLimit, | ||
const AudioIOStartStreamOptions & | options | ||
) |
Start recording or playing back audio.
Allocates buffers for recording and playback, gets the Audio thread to fill them, and sets the stream rolling. If successful, returns a token identifying this particular stream instance. For use with IsStreamActive()
p && p->FindChannelGroup()
for all pointers p
in sequences.playbackSequences
p != nullptr
for all pointers p
in sequences.captureSequences
mixerLimit | Time at which mixer stops producing, maybe > t1 |
Definition at line 825 of file AudioIO.cpp.
References AllocateBuffers(), AudioIOLatencyCorrection, AudioIOEvent::CAPTURE, TransportSequences::captureSequences, PlaybackSchedule::TimeQueue::Clear(), AudioIoCallback::ClearRecordingException(), DB_TO_LINEAR, DecibelScaleCutoff, AudioIoCallback::Extensions(), floatSample, AudioIoCallback::GetListener(), PlaybackSchedule::GetPolicy(), PlaybackSchedule::GetSequenceTime(), gPrefs, PlaybackSchedule::Init(), PlaybackPolicy::Initialize(), AudioIOBase::IsBusy(), LAT1CTOWX, AudioIOStartStreamOptions::listener, AudioIoCallback::mAudioThreadShouldCallSequenceBufferExchangeOnce, AudioIoCallback::mbMicroFades, AudioIoCallback::mCaptureBuffers, AudioIoCallback::mCaptureFormat, AudioIoCallback::mCaptureRate, AudioIoCallback::mCaptureSequences, RecordingSchedule::mCrossfadeData, AudioIoCallback::mDetectDropouts, RecordingSchedule::mDuration, AudioIoCallback::mForceFadeOut, min(), AudioIoCallback::mLastRecordingOffset, RecordingSchedule::mLatencyCorrection, AudioIoCallback::mListener, AudioIoCallback::mLostCaptureIntervals, AudioIoCallback::mLostSamples, AudioIoCallback::mNextStreamToken, AudioIoCallback::mNumCaptureChannels, AudioIoCallback::mNumPlaybackChannels, AudioIOBase::mOwningProject, AudioIoCallback::mPauseRec, AudioIoCallback::mPlaybackBuffers, AudioIoCallback::mPlaybackMixers, AudioIoCallback::mPlaybackSchedule, AudioIoCallback::mPlaybackSequences, AudioIOBase::mPortStreamV19, RecordingSchedule::mPreRoll, AudioIoCallback::mpTransportState, AudioIOBase::mRate, AudioIoCallback::mRecordingSchedule, AudioIoCallback::mResample, AudioIoCallback::mScratchBuffers, AudioIoCallback::mScratchPointers, AudioIoCallback::mSeek, AudioIoCallback::mSilenceLevel, AudioIoCallback::mSoftwarePlaythrough, AudioIOBase::mStreamToken, PlaybackSchedule::mTimeQueue, AudioIoCallback::mUsingAlsa, PlaybackPolicy::OffsetSequenceTime(), TransportSequences::otherPlayableSequences, AudioIOStartStreamOptions::pCrossfadeData, AudioIOEvent::PLAYBACK, TransportSequences::playbackSequences, AudioIOStartStreamOptions::playbackStreamPrimer, AudioIOStartStreamOptions::preRoll, PlaybackSchedule::TimeQueue::Prime(), AudioIOStartStreamOptions::pStartTime, Observer::Publisher< AudioIOEvent >::Publish(), AudioIOStartStreamOptions::rate, audacity::BasicSettings::Read(), Setting< T >::Read(), PlaybackSchedule::ResetMode(), PlaybackSchedule::SetSequenceTime(), BasicUI::ShowMessageBox(), SoundActivatedRecord, AudioIoCallback::StartAudioThread(), StartPortAudioStream(), StartStreamCleanup(), AudioIoCallback::StopAudioThread(), StopStream(), Verbatim(), AudioIoCallback::WaitForAudioThreadStarted(), WarningDialogKey(), and wxT().
|
private |
Clean up after StartStream if it fails.
If bOnlyBuffers is specified, it only cleans up the buffers.
Definition at line 1391 of file AudioIO.cpp.
References PlaybackSchedule::TimeQueue::Clear(), PlaybackPolicy::Finalize(), PlaybackSchedule::GetPolicy(), AudioIoCallback::mCaptureBuffers, AudioIoCallback::mPlaybackBuffers, AudioIoCallback::mPlaybackMixers, AudioIoCallback::mPlaybackSchedule, AudioIOBase::mPortStreamV19, AudioIoCallback::mpTransportState, AudioIoCallback::mResample, AudioIoCallback::mScratchBuffers, AudioIoCallback::mScratchPointers, AudioIOBase::mStreamToken, and PlaybackSchedule::mTimeQueue.
Referenced by AllocateBuffers(), and StartStream().
|
private |
Definition at line 309 of file AudioIO.cpp.
References AudioThread(), AudioIoCallback::mAudioThread, and AudioIoCallback::mFinishAudioThread.
|
overridevirtual |
Stop recording, playback or input monitoring.
Does quite a bit of housekeeping, including switching off monitoring, flushing recording buffers out to RecordableSequences, and applies latency correction to recorded sequences if necessary
Implements AudioIOBase.
Definition at line 1428 of file AudioIO.cpp.
References AudioIOLatencyDuration, BasicUI::CallAfter(), AudioIOEvent::CAPTURE, PlaybackSchedule::TimeQueue::Clear(), AudioIoCallback::ClearRecordingException(), DelayActions(), AudioIoCallback::Extensions(), PlaybackPolicy::Finalize(), AudioIoCallback::GetListener(), PlaybackSchedule::GetPolicy(), GuardedCall(), AudioIoCallback::mAudioThreadSequenceBufferExchangeLoopRunning, AudioIoCallback::mbMicroFades, AudioIoCallback::mCaptureBuffers, AudioIoCallback::mCaptureSequences, RecordingSchedule::mCrossfadeData, AudioIoCallback::mForceFadeOut, AudioIOBase::mInputMeter, AudioIoCallback::mLostCaptureIntervals, AudioIoCallback::mNumCaptureChannels, AudioIoCallback::mNumPlaybackChannels, AudioIOEvent::MONITOR, AudioIOBase::mOutputMeter, AudioIOBase::mOwningProject, AudioIoCallback::mPlaybackBuffers, AudioIoCallback::mPlaybackMixers, AudioIoCallback::mPlaybackSchedule, AudioIoCallback::mPlaybackSequences, AudioIOBase::mPortStreamV19, mPostRecordingAction, mPostRecordingActionMutex, AudioIoCallback::mpTransportState, AudioIOBase::mRate, AudioIoCallback::mRecordingSchedule, AudioIoCallback::mResample, AudioIoCallback::mScratchBuffers, AudioIoCallback::mScratchPointers, AudioIOBase::mStreamToken, AudioIoCallback::mSuspendAudioThread, PlaybackSchedule::mTimeQueue, AudioIOEvent::PLAYBACK, AudioIoCallback::ProcessOnceAndWait(), Observer::Publisher< AudioIOEvent >::Publish(), Setting< T >::Read(), KeyboardCapture::Release(), PlaybackSchedule::ResetMode(), ResetOwningProject(), AudioIoCallback::StopAudioThread(), and AudioIoCallback::WaitForAudioThreadStopped().
Referenced by DrainRecordBuffers(), and StartStream().
|
static |
Ensure selected device names are valid.
Definition at line 223 of file AudioIO.cpp.
References AudioIOBase::getPlayDevIndex(), and AudioIOBase::getRecordDevIndex().
|
private |
Definition at line 654 of file AudioIO.h.
Referenced by DelayActions(), and DelayingActions().
|
private |
Definition at line 652 of file AudioIO.h.
Referenced by CallAfterRecording(), and StopStream().
|
private |
Definition at line 651 of file AudioIO.h.
Referenced by CallAfterRecording(), and StopStream().