Audacity  2.2.0
AudioIO.cpp File Reference
#include "Audacity.h"
#include "Experimental.h"
#include "AudioIO.h"
#include "float_cast.h"
#include <cfloat>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <wx/log.h>
#include <wx/textctrl.h>
#include <wx/msgdlg.h>
#include <wx/timer.h>
#include <wx/intl.h>
#include <wx/debug.h>
#include <wx/sstream.h>
#include <wx/txtstrm.h>
#include "AudacityApp.h"
#include "AudacityException.h"
#include "Mix.h"
#include "MixerBoard.h"
#include "Resample.h"
#include "RingBuffer.h"
#include "prefs/GUISettings.h"
#include "Prefs.h"
#include "Project.h"
#include "TimeTrack.h"
#include "WaveTrack.h"
#include "AutoRecovery.h"
#include "toolbars/ControlToolBar.h"
#include "widgets/Meter.h"
#include "tracks/ui/Scrubbing.h"

Classes

struct  AudioIO::ScrubQueue
 
struct  AudioIO::ScrubQueue::Entry
 
struct  AudioIO::ScrubQueue::Duration
 
class  AudioThread
 Defined different on Mac and other platforms (on Mac it does not use wxWidgets wxThread), this class sits in a thread loop reading and writing audio. More...
 

Macros

#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define ORIGINAL_DO_NOT_PLAY_ALL_MUTED_TRACKS_TO_END
 

Enumerations

enum  { MIDI_MINIMAL_LATENCY_MS = 1 }
 

Functions

 DEFINE_EVENT_TYPE (EVT_AUDIOIO_PLAYBACK)
 
 DEFINE_EVENT_TYPE (EVT_AUDIOIO_CAPTURE)
 
 DEFINE_EVENT_TYPE (EVT_AUDIOIO_MONITOR)
 
static double SystemTime (bool usingAlsa)
 
int audacityAudioCallback (const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
 
void InitAudioIO ()
 
void DeinitAudioIO ()
 
wxString DeviceName (const PaDeviceInfo *info)
 
wxString HostName (const PaDeviceInfo *info)
 
static PaSampleFormat AudacityToPortAudioSampleFormat (sampleFormat format)
 
static void DoSoftwarePlaythrough (const void *inputBuffer, sampleFormat inputFormat, unsigned inputChannels, float *outputBuffer, int len)
 
int audacityAudioCallback (const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *WXUNUSED(timeInfo), const PaStreamCallbackFlags WXUNUSED(statusFlags), void *WXUNUSED(userData))
 

Variables

std::unique_ptr< AudioIOugAudioIO
 
AudioIOgAudioIO {}
 
static double streamStartTime = 0
 

Macro Definition Documentation

#define MAX (   a,
 
)    ((a) > (b) ? (a) : (b))

Referenced by audacityAudioCallback().

#define ORIGINAL_DO_NOT_PLAY_ALL_MUTED_TRACKS_TO_END

Enumeration Type Documentation

anonymous enum
Enumerator
MIDI_MINIMAL_LATENCY_MS 

Function Documentation

int audacityAudioCallback ( const void *  inputBuffer,
void *  outputBuffer,
unsigned long  framesPerBuffer,
const PaStreamCallbackTimeInfo *  timeInfo,
PaStreamCallbackFlags  statusFlags,
void *  userData 
)

brief The function which is called from PortAudio's callback thread context to collect and deliver audio for / from the sound device.

This covers recording, playback, and doing both simultaneously. It is also invoked to do monitoring and software playthrough. Note that dealing with the two buffers needs some care to ensure that the right things happen for all possible cases.

Parameters
inputBufferBuffer of length framesPerBuffer containing samples from the sound card, or null if not capturing audio. Note that the data type will depend on the format of audio data that was chosen when the stream was created (so could be floats or various integers)
outputBufferUninitialised buffer of length framesPerBuffer which will be sent to the sound card after the callback, or null if not playing audio back.
framesPerBufferThe length of the playback and recording buffers
PaStreamCallbackTimeInfoPointer to PortAudio time information structure, which tells us how long we have been playing / recording
statusFlagsPortAudio stream status flags
userDatapointer to user-defined data structure. Provided for flexibility by PortAudio, but not used by Audacity - the data is stored in the AudioIO class instead.
int audacityAudioCallback ( const void *  inputBuffer,
void *  outputBuffer,
unsigned long  framesPerBuffer,
const PaStreamCallbackTimeInfo *  WXUNUSEDtimeInfo,
const PaStreamCallbackFlags   WXUNUSEDstatusFlags,
void *  WXUNUSEDuserData 
)

References ClearSamples(), TimeTrack::ComputeWarpedLength(), CopySamples(), DoSoftwarePlaythrough(), gAudioIO, EffectManager::Get(), GetActiveProject(), WaveTrack::GetChannel(), WaveTrack::GetChannelGain(), AudacityProject::GetControlToolBar(), Track::GetLinked(), Meter::GetMaxPeak(), PlayableTrack::GetMute(), Track::GetSelected(), PlayableTrack::GetSolo(), Meter::IsMeterDisabled(), AudioIO::IsPaused(), Track::LeftChannel, AudioIO::LimitStreamTime(), AudioIO::mAudioThreadFillBuffersLoopActive, AudioIO::mAudioThreadFillBuffersLoopRunning, AudioIO::mAudioThreadShouldCallFillBuffersOnce, MAX, AudioIO::mCaptureBuffers, AudioIO::mCaptureFormat, AudioIO::mEmulateMixerOutputVol, min(), AudioIO::mInputMeter, AudioIO::mLastPlaybackTimeMillis, AudioIO::mLastRecordingOffset, AudioIO::mLostSamples, AudioIO::mMixerOutputVol, AudioIO::mNumCaptureChannels, AudioIO::mNumPlaybackChannels, Track::MonoChannel, AudioIO::mOutputMeter, AudioIO::mPaused, AudioIO::mPauseRec, AudioIO::mPlaybackBuffers, AudioIO::mPlaybackMixers, AudioIO::mPlaybackTracks, AudioIO::mPlayMode, AudioIO::mPortStreamV19, AudioIO::mRate, AudioIO::mScrubQueue, AudioIO::mSeek, AudioIO::mSilenceLevel, AudioIO::mSoftwarePlaythrough, AudioIO::mStreamToken, AudioIO::mSuspendAudioThread, AudioIO::mT0, AudioIO::mT1, AudioIO::mTime, AudioIO::mTimeTrack, AudioIO::mUpdateMeters, AudioIO::mUpdatingMeters, AudioIO::mUsingAlsa, AudioIO::mWarpedTime, ControlToolBar::Pause(), AudioIO::PLAY_LOOPED, AudioIO::PLAY_SCRUB, AudioIO::PLAY_STRAIGHT, EffectManager::RealtimeProcess(), EffectManager::RealtimeProcessEnd(), EffectManager::RealtimeProcessStart(), AudioIO::ReversedTime(), Track::RightChannel, TimeTrack::SolveWarpedLength(), SystemTime(), Meter::UpdateDisplay(), and USE_MIDI_THREAD.

static PaSampleFormat AudacityToPortAudioSampleFormat ( sampleFormat  format)
static
DEFINE_EVENT_TYPE ( EVT_AUDIOIO_PLAYBACK  )
DEFINE_EVENT_TYPE ( EVT_AUDIOIO_CAPTURE  )
DEFINE_EVENT_TYPE ( EVT_AUDIOIO_MONITOR  )
void DeinitAudioIO ( )

Referenced by AudacityApp::OnExit().

wxString DeviceName ( const PaDeviceInfo *  info)
static void DoSoftwarePlaythrough ( const void *  inputBuffer,
sampleFormat  inputFormat,
unsigned  inputChannels,
float *  outputBuffer,
int  len 
)
static

References CopySamples().

Referenced by audacityAudioCallback().

wxString HostName ( const PaDeviceInfo *  info)
static double SystemTime ( bool  usingAlsa)
static

Variable Documentation

AudioIO* gAudioIO {}

Referenced by audacityAudioCallback(), ControlToolBar::CanStopAudioStream(), Scrubber::ContinueScrubbingPoll(), CreateNewAudacityProject(), LabelTrack::DoCaptureKey(), AudacityProject::DoPlayStopSelect(), PlayIndicatorOverlayBase::Draw(), DeviceToolBar::EnableDisableButtons(), ControlToolBar::EnableDisableButtons(), AudioThread::Entry(), AudacityProject::GetUpdateFlags(), InitAudioIO(), EffectUIHost::Initialize(), WaveTrackMenuTable::InitMenu(), AudacityProject::IsAudioActive(), AudacityProject::MakeReadyToPlay(), Scrubber::MaybeStartScrubbing(), AudacityProject::OnAddLabelPlaying(), AudacityProject::OnAudioDeviceInfo(), AudacityProject::OnBoundaryMove(), DeviceToolBar::OnChoice(), AudacityProject::OnCloseWindow(), AudacityProject::OnCursorPositionStore(), EffectUIHost::OnFFwd(), AudacityApp::OnKeyDown(), ControlToolBar::OnKeyEvent(), TranscriptionToolBar::OnKeyEvent(), Meter::OnMeterUpdate(), PrefsDialog::OnOK(), ControlToolBar::OnPause(), EffectUIHost::OnPlay(), AudacityProject::OnPlayStop(), AudacityProject::OnPlayStopSelect(), ControlToolBar::OnRecord(), EffectUIHost::OnRewind(), AudacityProject::OnSelectCursorStoredCursor(), AudacityProject::OnSetLeftSelection(), AudacityProject::OnSetRightSelection(), WaveTrackMenuTable::OnSpectrogramSettings(), AudacityProject::OnStopSelect(), LyricsWindow::OnTimer(), PlayIndicatorOverlay::OnTimer(), ViewInfo::OnTimer(), MixerBoard::OnTimer(), TrackPanel::OnTimer(), AudacityProject::OnTimer(), ControlToolBar::Pause(), TranscriptionToolBar::PlayAtSpeed(), ControlToolBar::PlayPlayRegion(), MixerToolBar::Populate(), Effect::Preview(), AudacityProject::PushState(), DeviceManager::Rescan(), AudacityProject::SeekLeftOrRight(), AudacityProject::SetCaptureMeter(), MixerToolBar::SetMixer(), AudacityProject::SetPlaybackMeter(), MixerToolBar::SetToolTips(), Meter::StartMonitoring(), ControlToolBar::StartScrolling(), AudioIO::StartStream(), Meter::StopMonitoring(), ControlToolBar::StopPlaying(), AudacityProject::TP_DisplaySelection(), AudacityProject::TP_DisplayStatusMessage(), MixerToolBar::UpdateControls(), MixerToolBar::UpdatePrefs(), AudacityProject::ZoomInByFactor(), AudioIO::~AudioIO(), and Meter::~Meter().

double streamStartTime = 0
static

Referenced by SystemTime().

std::unique_ptr<AudioIO> ugAudioIO