Audacity 3.2.0
|
A singleton object supporting queries of the state of any active audio streams, and audio device capabilities. More...
#include <AudioIOBase.h>
Public Member Functions | |
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) |
Static Public Member Functions | |
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... | |
Static Public Attributes | |
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 Protected Member Functions | |
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 | |
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 | |
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... | |
A singleton object supporting queries of the state of any active audio streams, and audio device capabilities.
Definition at line 102 of file AudioIOBase.h.
|
default |
|
virtualdefault |
|
delete |
|
staticprotected |
Definition at line 76 of file AudioIOBase.cpp.
Referenced by GetDeviceInfo(), getPlayDevIndex(), getRecordDevIndex(), and AudioIO::Init().
|
static |
Definition at line 94 of file AudioIOBase.cpp.
References ugAudioIO.
Referenced by AudioIOBusyPred(), AudioSetupToolBar::CommonMenuItemSteps(), LabelTrackView::DoCaptureKey(), Scrubber::DoKeyboardScrub(), AdornedRulerPanel::DoSelectionChange(), TransportUtilities::DoStartPlaying(), TransportUtilities::DoStopPlaying(), audacity::cloud::ShareAudioToolbar::EnableDisableButtons(), AudioSetupToolBar::EnableDisableButtons(), DeviceToolBar::EnableDisableButtons(), AudioIoCallback::FillOutputBuffers(), AudioIO::Get(), GetMIDIDeviceInfo(), ProjectAudioIO::IsAudioActive(), ScrubState::IsScrubbing(), anonymous_namespace{TransportMenus.cpp}::MakeReadyToPlay(), anonymous_namespace{HelpMenus.cpp}::OnAudioDeviceInfo(), DeviceToolBar::OnChoice(), ControlToolBar::OnKeyEvent(), TranscriptionToolBar::OnKeyEvent(), anonymous_namespace{NoteTrackMenuItems.cpp}::OnMidiDeviceInfo(), PrefsDialog::OnOK(), NyqBench::OnRunUpdate(), anonymous_namespace{SpectrumView.cpp}::SpectrogramSettingsHandler::OnSpectrogramSettings(), PausedFlag(), TranscriptionToolBar::PlayAtSpeed(), DeviceManager::Rescan(), ProjectAudioIO::SetCaptureMeter(), ProjectAudioIO::SetPlaybackMeter(), and ProjectAudioManager::StopIfPaused().
auto AudioIOBase::GetAllDeviceInfo | ( | ) |
Get diagnostic information for audio devices and also for extensions.
Definition at line 1055 of file AudioIOBase.cpp.
References wxT().
|
static |
Find the closest supported sample rate for given recording device.
Attempts to find the sample rate that is closest to the requested rate, and is supported by the recording device.
If device is not specified the currently selected device will be used.
Sample rate check order:
returns 0 if none is found or the input rate is invalid.
Definition at line 542 of file AudioIOBase.cpp.
References staffpad::vo::copy(), getRecordDevIndex(), IsCaptureRateSupported(), make_iterator_range(), mCachedCaptureRates, NumRatesToTry, and RatesToTry.
Referenced by AudioIO::GetBestRate().
|
static |
Find the closest supported sample rate for given playback device.
Attempts to find the sample rate that is closest to the requested rate, and is supported by the playback device.
If device is not specified the currently selected device will be used.
Sample rate check order:
returns 0 if none is found or the input rate is invalid.
Definition at line 505 of file AudioIOBase.cpp.
References staffpad::vo::copy(), getPlayDevIndex(), IsPlaybackRateSupported(), NumRatesToTry, and RatesToTry.
Referenced by AudioIO::GetBestRate().
|
static |
Find the closest supported sample rate for given playback and recording devices.
Attempts to find the sample rate that is closest to the requested rate, and is supported by both playback and recording devices.
If devices are not specified the currently selected devices will be used.
Sample rate check order:
returns 0 if none is found or the input rate is invalid.
Definition at line 590 of file AudioIOBase.cpp.
References staffpad::vo::copy(), getPlayDevIndex(), getRecordDevIndex(), IsCaptureRateSupported(), IsPlaybackRateSupported(), make_iterator_range(), mCachedSampleRates, NumRatesToTry, and RatesToTry.
Referenced by AudioIO::GetBestRate(), GetOptimalSupportedSampleRate(), and HandleDeviceChange().
wxString AudioIOBase::GetDeviceInfo | ( | ) | const |
Get diagnostic information on all the available audio I/O devices.
Definition at line 812 of file AudioIOBase.cpp.
References AudioIOLatencyCorrection, AudioIOPlaybackDevice, AudioIORecordingDevice, DeviceName(), Setting< T >::GetDefault(), GetSupportedCaptureRates(), GetSupportedPlaybackRates(), GetSupportedSampleRates(), HostName(), IsStreamActive(), name, Setting< T >::Read(), anonymous_namespace{ExportOpus.cpp}::supportedSampleRates, wxT(), and XO().
|
static |
Get a supported sample rate which can be used a an optimal default.
Currently, this uses the first supported rate in the list [44100, 48000, highest sample rate]. Used in Project as a default value for project rates if one cannot be retrieved from the preferences. So all in all not that useful or important really
Definition at line 669 of file AudioIOBase.cpp.
References GetClosestSupportedSampleRate().
|
staticprotected |
get the index of the device selected in the preferences.
If the device isn't found, returns -1
get the index of the supplied (named) playback device, or the device selected in the preferences if none given.
Pure utility function, but it comes round a number of times in the code and would be neater done once. If the device isn't found, return the default device index.
Definition at line 700 of file AudioIOBase.cpp.
References AudioIOHost, AudioIOPlaybackDevice, DeviceName(), and Setting< T >::Read().
Referenced by GetClosestSupportedPlaybackRate(), GetClosestSupportedSampleRate(), GetSupportedPlaybackRates(), GetSupportedSampleRates(), HandleDeviceChange(), AudioIO::Init(), IsPlaybackRateSupported(), AudioIO::StartPortAudioStream(), and AudioIO::ValidateDeviceNames().
|
staticprotected |
get the index of the supplied (named) recording device, or the device selected in the preferences if none given.
Pure utility function, but it comes round a number of times in the code and would be neater done once. If the device isn't found, return the default device index.
Definition at line 755 of file AudioIOBase.cpp.
References AudioIOHost, AudioIORecordingDevice, DeviceName(), and Setting< T >::Read().
Referenced by GetClosestSupportedCaptureRate(), GetClosestSupportedSampleRate(), GetSupportedCaptureRates(), GetSupportedSampleRates(), HandleDeviceChange(), AudioIO::Init(), IsCaptureRateSupported(), AudioIO::StartPortAudioStream(), and AudioIO::ValidateDeviceNames().
|
static |
Get a list of sample rates the input (recording) device supports.
If no information about available sample rates can be fetched, an empty list is returned.
You can explicitly give the index of the device. If you don't give it, the currently selected device from the preferences will be used.
Definition at line 485 of file AudioIOBase.cpp.
References getRecordDevIndex(), IsCaptureRateSupported(), and RatesToTry.
Referenced by GetDeviceInfo(), and GetSupportedSampleRates().
|
static |
Get a list of sample rates the output (playback) device supports.
If no information about available sample rates can be fetched, an empty list is returned.
You can explicitly give the index of the device. If you don't give it, the currently selected device from the preferences will be used.
Definition at line 465 of file AudioIOBase.cpp.
References getPlayDevIndex(), IsPlaybackRateSupported(), and RatesToTry.
Referenced by GetDeviceInfo(), and GetSupportedSampleRates().
|
static |
Get a list of sample rates the current input/output device combination supports.
Since there is no concept (yet) for different input/output sample rates, this currently returns only sample rates that are supported on both the output and input device. If no information about available sample rates can be fetched, it returns a default list. You can explicitly give the indexes of the playDevice/recDevice. If you don't give them, the selected devices from the preferences will be used.
Definition at line 640 of file AudioIOBase.cpp.
References getPlayDevIndex(), getRecordDevIndex(), GetSupportedCaptureRates(), and GetSupportedPlaybackRates().
Referenced by GetDeviceInfo().
void AudioIOBase::HandleDeviceChange | ( | ) |
update state after changing what audio devices are selected
Called when the devices stored in the preferences are changed to update the audio mixer capabilities
Definition at line 112 of file AudioIOBase.cpp.
References AudioIOLatencyCorrection, AudioIORecordingSourceIndex, GetClosestSupportedSampleRate(), Setting< T >::GetDefault(), getPlayDevIndex(), getRecordDevIndex(), IsStreamActive(), mCachedBestRateIn, mCurrentCaptureIndex, mCurrentPlaybackIndex, mInputMixerWorks, Setting< T >::Read(), and SetMixer().
Referenced by AudioIO::AudioIO().
|
staticprotected |
Definition at line 83 of file AudioIOBase.cpp.
Referenced by GetDeviceInfo(), and AudioIO::Init().
bool AudioIOBase::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.
This is used by TrackPanel to determine when a track has been completely recorded, and it's safe to flush to disk.
Definition at line 354 of file AudioIOBase.cpp.
References mStreamToken.
Referenced by AudioIOBusyPred(), and IsStreamActive().
bool AudioIOBase::IsBusy | ( | ) | const |
Returns true if audio i/o is busy starting, stopping, playing, or recording.
When this is false, it's safe to start playing or recording
Definition at line 328 of file AudioIOBase.cpp.
References mStreamToken.
Referenced by AudioIoCallback::SetListener(), and AudioIO::StartStream().
|
static |
Check if the specified sample rate is supported by a device.
Verifies if a recording device supports a given rate. If no device index is specified (devIndex == -1), the preferred device is used.
Definition at line 413 of file AudioIOBase.cpp.
References AudioIOLatencyDuration, AudioIORecordChannels, getRecordDevIndex(), make_iterator_range(), mCachedCaptureRates, Setting< T >::Read(), Setting< T >::ReadWithDefault(), and wxT().
Referenced by GetClosestSupportedCaptureRate(), GetClosestSupportedSampleRate(), and GetSupportedCaptureRates().
bool AudioIOBase::IsMonitoring | ( | ) | const |
Returns true if we're monitoring input (but not recording or playing actual audio)
Definition at line 359 of file AudioIOBase.cpp.
References mPortStreamV19, and mStreamToken.
Referenced by AudioIO::AudioThread().
bool AudioIOBase::IsPaused | ( | ) | const |
Find out if playback / recording is currently paused.
Definition at line 323 of file AudioIOBase.cpp.
References mPaused.
Referenced by AudioIoCallback::AudioCallback(), AudioIoCallback::CallbackCheckCompletion(), AudioIoCallback::CheckSoundActivatedRecordingLevel(), AudioIoCallback::FillOutputBuffers(), PausedFlag(), and AudioIO::SetPaused().
|
static |
Check if the specified playback rate is supported by a device.
Verifies if a playback device supports a given rate. If no device index is specified (devIndex == -1), the preferred device is used.
Definition at line 364 of file AudioIOBase.cpp.
References getPlayDevIndex(), make_iterator_range(), mCachedPlaybackRates, and wxT().
Referenced by GetClosestSupportedPlaybackRate(), GetClosestSupportedSampleRate(), and GetSupportedPlaybackRates().
bool AudioIOBase::IsStreamActive | ( | ) | const |
Returns true if the audio i/o is running at all, but not during cleanup.
Doesn't return true if the device has been closed but some disk i/o or cleanup is still going on. If you want to know if it's safe to start a NEW stream, use IsBusy()
Definition at line 336 of file AudioIOBase.cpp.
References mAudioIOExt, and mPortStreamV19.
Referenced by AudioIO::DrainRecordBuffers(), GetDeviceInfo(), AudioIO::GetStreamTime(), HandleDeviceChange(), AudioIO::IsCapturing(), and IsStreamActive().
bool AudioIOBase::IsStreamActive | ( | int | token | ) | const |
Definition at line 349 of file AudioIOBase.cpp.
References IsAudioTokenActive(), and IsStreamActive().
|
delete |
void AudioIOBase::SetCaptureMeter | ( | const std::shared_ptr< AudacityProject > & | project, |
const std::weak_ptr< Meter > & | meter | ||
) |
Definition at line 289 of file AudioIOBase.cpp.
References mInputMeter, mOwningProject, mRate, and project.
Referenced by AudioIO::StartPortAudioStream().
void AudioIOBase::SetMixer | ( | int | inputSource | ) |
Definition at line 103 of file AudioIOBase.cpp.
Referenced by HandleDeviceChange(), and AudioIO::SetMixer().
void AudioIOBase::SetPlaybackMeter | ( | const std::shared_ptr< AudacityProject > & | project, |
const std::weak_ptr< Meter > & | meter | ||
) |
Definition at line 306 of file AudioIOBase.cpp.
References mOutputMeter, mOwningProject, mRate, and project.
|
pure virtual |
Implemented in AudioIO.
|
protected |
This class needs to iterate this array for one limited purpose but does not populate it and does not give access to it except to subclasses
Definition at line 381 of file AudioIOBase.h.
Referenced by IsStreamActive().
|
staticprotected |
Definition at line 341 of file AudioIOBase.h.
Referenced by AudioIO::GetBestRate(), and HandleDeviceChange().
|
staticprotected |
Definition at line 337 of file AudioIOBase.h.
Referenced by GetClosestSupportedCaptureRate(), and IsCaptureRateSupported().
|
staticprotected |
Definition at line 336 of file AudioIOBase.h.
Referenced by IsPlaybackRateSupported().
|
staticprotected |
Definition at line 338 of file AudioIOBase.h.
Referenced by GetClosestSupportedSampleRate().
|
staticprotected |
Definition at line 340 of file AudioIOBase.h.
Referenced by HandleDeviceChange().
|
staticprotected |
Definition at line 339 of file AudioIOBase.h.
Referenced by HandleDeviceChange().
|
protected |
Definition at line 318 of file AudioIOBase.h.
Referenced by AudioIoCallback::SendVuInputMeterData(), SetCaptureMeter(), AudioIO::SetMeters(), AudioIO::StartPortAudioStream(), and AudioIO::StopStream().
|
protected |
Can we control the hardware input level?
This flag is set to true if using portmixer to control the input volume seems to be working (and so we offer the user the control), and to false (locking the control out) otherwise. This avoids stupid scaled clipping problems when trying to do software emulated input volume control
Definition at line 333 of file AudioIOBase.h.
Referenced by AudioIO::AudioIO(), AudioIO::GetMixer(), HandleDeviceChange(), and AudioIO::InputMixerWorks().
|
protected |
Definition at line 319 of file AudioIOBase.h.
Referenced by AudioIO::AudioIO(), AudioIoCallback::SendVuOutputMeterData(), AudioIO::SetMeters(), SetPlaybackMeter(), AudioIO::StartPortAudioStream(), and AudioIO::StopStream().
|
protected |
Definition at line 304 of file AudioIOBase.h.
Referenced by AudioIO::FillPlayBuffers(), AudioIO::IsAvailable(), AudioIO::ResetOwningProject(), SetCaptureMeter(), AudioIO::SetOwningProject(), AudioIO::SetPaused(), SetPlaybackMeter(), AudioIO::StartMonitoring(), AudioIO::StartPortAudioStream(), AudioIO::StartStream(), AudioIO::StopStream(), and AudioIO::~AudioIO().
|
protected |
True if audio playback is paused.
Definition at line 307 of file AudioIOBase.h.
Referenced by IsPaused(), and AudioIO::SetPaused().
|
protected |
Definition at line 316 of file AudioIOBase.h.
Referenced by AudioIO::AudioIO(), AudioIO::DelayingActions(), IsMonitoring(), IsStreamActive(), AudioIO::StartMonitoring(), AudioIO::StartPortAudioStream(), AudioIO::StartStream(), AudioIO::StartStreamCleanup(), and AudioIO::StopStream().
|
protected |
Audio playback rate in samples per second.
Read by worker threads but unchanging during playback
Definition at line 314 of file AudioIOBase.h.
Referenced by AudioIO::AllocateBuffers(), AudioIoCallback::AudioCallback(), AudioIoCallback::DrainInputBuffers(), AudioIO::DrainRecordBuffers(), SetCaptureMeter(), AudioIO::SetMeters(), SetPlaybackMeter(), AudioIO::StartMonitoring(), AudioIO::StartPortAudioStream(), AudioIO::StartStream(), AudioIO::StopStream(), and AudioIoCallback::UpdateTimePosition().
|
protected |
Read by worker threads but unchanging during playback
Definition at line 310 of file AudioIOBase.h.
Referenced by AudioIoCallback::AudioCallback(), AudioIoCallback::CallbackDoSeek(), AudioIoCallback::DrainInputBuffers(), AudioIoCallback::FillOutputBuffers(), IsAudioTokenActive(), IsBusy(), IsMonitoring(), AudioIO::StartMonitoring(), AudioIO::StartStream(), AudioIO::StartStreamCleanup(), AudioIO::StopStream(), and AudioIoCallback::UpdateTimePosition().
|
staticprotected |
How many sample rates to try.
Definition at line 376 of file AudioIOBase.h.
Referenced by GetClosestSupportedCaptureRate(), GetClosestSupportedPlaybackRate(), and GetClosestSupportedSampleRate().
|
static |
How many standard sample rates there are.
Definition at line 250 of file AudioIOBase.h.
Referenced by DevicePrefs::GetNamesAndLabels(), and ImportRawDialog::ImportRawDialog().
|
staticprotected |
Array of audio sample rates to try to use.
These are the rates we will check if a device supports, and is as long as I can think of (to try and work out what the card can do)
Definition at line 374 of file AudioIOBase.h.
Referenced by GetClosestSupportedCaptureRate(), GetClosestSupportedPlaybackRate(), GetClosestSupportedSampleRate(), GetSupportedCaptureRates(), and GetSupportedPlaybackRates().
|
static |
Array of common audio sample rates.
These are the rates we will always support, regardless of hardware support for them (by resampling in audacity if needed)
Definition at line 248 of file AudioIOBase.h.
Referenced by DevicePrefs::GetNamesAndLabels(), and ImportRawDialog::ImportRawDialog().
|
staticprotected |
Definition at line 300 of file AudioIOBase.h.
Referenced by AudioIO::Deinit(), Get(), and AudioIO::Init().