Audacity  3.0.3
Classes | Macros | Functions
AudioIO.cpp File Reference
#include "AudioIO.h"
#include "AudioIOExt.h"
#include "AudioIOListener.h"
#include "float_cast.h"
#include "DeviceManager.h"
#include <cfloat>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <numeric>
#include "portaudio.h"
#include <wx/app.h>
#include <wx/frame.h>
#include <wx/wxcrtvararg.h>
#include <wx/log.h>
#include <wx/textctrl.h>
#include <wx/timer.h>
#include <wx/intl.h>
#include <wx/debug.h>
#include "Meter.h"
#include "Mix.h"
#include "Resample.h"
#include "RingBuffer.h"
#include "Decibels.h"
#include "Prefs.h"
#include "Project.h"
#include "DBConnection.h"
#include "ProjectFileIO.h"
#include "ProjectWindows.h"
#include "ViewInfo.h"
#include "WaveTrack.h"
#include "effects/RealtimeEffectManager.h"
#include "QualitySettings.h"
#include "widgets/AudacityMessageBox.h"
#include "BasicUI.h"
#include "Gain.h"
#include <thread>
Include dependency graph for AudioIO.cpp:

Go to the source code of this file.


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...


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


int audacityAudioCallback (const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
static PaSampleFormat AudacityToPortAudioSampleFormat (sampleFormat format)
static void DoSoftwarePlaythrough (constSamplePtr inputBuffer, sampleFormat inputFormat, unsigned inputChannels, float *outputBuffer, unsigned long len)
void ClampBuffer (float *pBuffer, unsigned long len)

Macro Definition Documentation


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

Definition at line 2256 of file AudioIO.cpp.

Function Documentation

◆ audacityAudioCallback()

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.

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.

Definition at line 2277 of file AudioIO.cpp.

2281 {
2282  auto gAudioIO = AudioIO::Get();
2283  return gAudioIO->AudioCallback(
2284  static_cast<constSamplePtr>(inputBuffer),
2285  static_cast<float*>(outputBuffer), framesPerBuffer,
2286  timeInfo, statusFlags, userData);
2287 }

References AudioIO::Get().

Referenced by AudioIO::StartPortAudioStream().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AudacityToPortAudioSampleFormat()

static PaSampleFormat AudacityToPortAudioSampleFormat ( sampleFormat  format)

Definition at line 468 of file AudioIO.cpp.

469 {
470  switch(format) {
471  case int16Sample:
472  return paInt16;
473  case int24Sample:
474  return paInt24;
475  case floatSample:
476  default:
477  return paFloat32;
478  }
479 }

References floatSample, format, int16Sample, and int24Sample.

Referenced by AudioIO::StartPortAudioStream().

Here is the caller graph for this function:

◆ ClampBuffer()

void ClampBuffer ( float *  pBuffer,
unsigned long  len 

Definition at line 2365 of file AudioIO.cpp.

2365  {
2366  for(unsigned i = 0; i < len; i++)
2367  pBuffer[i] = wxClip( pBuffer[i], -1.0f, 1.0f);
2368 };

Referenced by AudioIoCallback::FillOutputBuffers().

Here is the caller graph for this function:

◆ DoSoftwarePlaythrough()

static void DoSoftwarePlaythrough ( constSamplePtr  inputBuffer,
sampleFormat  inputFormat,
unsigned  inputChannels,
float *  outputBuffer,
unsigned long  len 

Definition at line 2258 of file AudioIO.cpp.

2263 {
2264  for (unsigned int i=0; i < inputChannels; i++) {
2265  auto inputPtr = inputBuffer + (i * SAMPLE_SIZE(inputFormat));
2267  SamplesToFloats(inputPtr, inputFormat,
2268  outputBuffer + i, len, inputChannels, 2);
2269  }
2271  // One mono input channel goes to both output channels...
2272  if (inputChannels == 1)
2273  for (int i=0; i < len; i++)
2274  outputBuffer[2*i + 1] = outputBuffer[2*i];
2275 }

References SAMPLE_SIZE, and SamplesToFloats().

Referenced by AudioIoCallback::DoPlaythrough().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wxDEFINE_EVENT() [1/3]


◆ wxDEFINE_EVENT() [2/3]


◆ wxDEFINE_EVENT() [3/3]

#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:44
@ int24Sample
Definition: SampleFormat.h:33
void SamplesToFloats(constSamplePtr src, sampleFormat srcFormat, float *dst, size_t len, size_t srcStride, size_t dstStride)
Copy samples from any format into the widest format, which is 32 bit float, with no dithering.
Definition: SampleFormat.cpp:102
@ floatSample
Definition: SampleFormat.h:34
@ int16Sample
Definition: SampleFormat.h:32
const char * constSamplePtr
Definition: SampleFormat.h:50
int format
Definition: ExportPCM.cpp:56
static AudioIO * Get()
Definition: AudioIO.cpp:141