Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
Remove whitespace only changes
Browse files Browse the repository at this point in the history
Signed-off-by: Emily Mabrey <[email protected]>
  • Loading branch information
emabrey committed Aug 10, 2021
1 parent d4a560f commit d7695f3
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 91 deletions.
137 changes: 68 additions & 69 deletions src/AudioIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
********************************************************************//**
\class AudioIoCallback
\brief AudioIoCallback is a class that implements the callback required
by PortAudio. The callback needs to be responsive, has no GUI, and
\brief AudioIoCallback is a class that implements the callback required
by PortAudio. The callback needs to be responsive, has no GUI, and
copies data into and out of the sound card buffers. It also sends data
to the meters.
Expand Down Expand Up @@ -408,7 +408,7 @@ callbacks for these events.
*//****************************************************************//**
\class AudioIOStartStreamOptions
\brief struct holding stream options, including a pointer to the
\brief struct holding stream options, including a pointer to the
time warp info and AudioIOListener and whether the playback is looped.
*//*******************************************************************/
Expand Down Expand Up @@ -961,7 +961,7 @@ AudioIO::AudioIO()
wxASSERT(false);
}

// This ASSERT because of casting in the callback
// This ASSERT because of casting in the callback
// functions where we cast a tempFloats buffer to a (short*) buffer.
// We have to ASSERT in the GUI thread, if we are to see it properly.
wxASSERT( sizeof( short ) <= sizeof( float ));
Expand All @@ -986,8 +986,7 @@ AudioIO::AudioIO()
#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
mAILAActive = false;
#endif

mStreamToken = 0;
mStreamToken = 0;

mLastPaError = paNoError;

Expand All @@ -1004,18 +1003,18 @@ AudioIO::AudioIO()

PaError err = Pa_Initialize();

if (err != paNoError) {
auto errStr = XO("Could not find any audio devices.\n");
errStr += XO("You will not be able to play or record audio.\n\n");
const wxString paErrStr = LAT1CTOWX(Pa_GetErrorText(err));
if (!paErrStr.empty())
errStr += XO("Error: %s").Format(paErrStr);
// XXX: we are in libaudacity, popping up dialogs not allowed! A
// long-term solution will probably involve exceptions
AudacityMessageBox(
errStr,
XO("Error Initializing Audio"),
wxICON_ERROR | wxOK);
if (err != paNoError) {
auto errStr = XO("Could not find any audio devices.\n");
errStr += XO("You will not be able to play or record audio.\n\n");
const wxString paErrStr = LAT1CTOWX(Pa_GetErrorText(err));
if (!paErrStr.empty())
errStr += XO("Error: %s").Format(paErrStr);
// XXX: we are in libaudacity, popping up dialogs not allowed! A
// long-term solution will probably involve exceptions
AudacityMessageBox(
errStr,
XO("Error Initializing Audio"),
wxICON_ERROR|wxOK);

// Since PortAudio is not initialized, all calls to PortAudio
// functions will fail. This will give reasonable behavior, since
Expand All @@ -1026,19 +1025,19 @@ AudioIO::AudioIO()
#ifdef EXPERIMENTAL_MIDI_OUT
PmError pmErr = Pm_Initialize();

if (pmErr != pmNoError) {
auto errStr =
XO("There was an error initializing the midi i/o layer.\n");
errStr += XO("You will not be able to play midi.\n\n");
const wxString pmErrStr = LAT1CTOWX(Pm_GetErrorText(pmErr));
if (!pmErrStr.empty())
errStr += XO("Error: %s").Format(pmErrStr);
// XXX: we are in libaudacity, popping up dialogs not allowed! A
// long-term solution will probably involve exceptions
AudacityMessageBox(
errStr,
XO("Error Initializing Midi"),
wxICON_ERROR | wxOK);
if (pmErr != pmNoError) {
auto errStr =
XO("There was an error initializing the midi i/o layer.\n");
errStr += XO("You will not be able to play midi.\n\n");
const wxString pmErrStr = LAT1CTOWX(Pm_GetErrorText(pmErr));
if (!pmErrStr.empty())
errStr += XO("Error: %s").Format(pmErrStr);
// XXX: we are in libaudacity, popping up dialogs not allowed! A
// long-term solution will probably involve exceptions
AudacityMessageBox(
errStr,
XO("Error Initializing Midi"),
wxICON_ERROR|wxOK);

// Same logic for PortMidi as described above for PortAudio
}
Expand Down Expand Up @@ -1253,13 +1252,13 @@ bool AudioIO::StartPortAudioStream(const AudioIOStartStreamOptions &options,
mRate = GetBestRate(numCaptureChannels > 0, numPlaybackChannels > 0, sampleRate);

// July 2016 (Carsten and Uwe)
// BUG 193: Tell PortAudio sound card will handle 24 bit (under DirectSound) using
// BUG 193: Tell PortAudio sound card will handle 24 bit (under DirectSound) using
// userData.
int captureFormat_saved = captureFormat;
// Special case: Our 24-bit sample format is different from PortAudio's
// 3-byte packed format. So just make PortAudio return float samples,
// since we need float values anyway to apply the gain.
// ANSWER-ME: So we *never* actually handle 24-bit?! This causes mCapture to
// ANSWER-ME: So we *never* actually handle 24-bit?! This causes mCapture to
// be set to floatSample below.
// JKC: YES that's right. Internally Audacity uses float, and float has space for
// 24 bits as well as exponent. Actual 24 bit would require packing and
Expand Down Expand Up @@ -1358,7 +1357,7 @@ bool AudioIO::StartPortAudioStream(const AudioIOStartStreamOptions &options,
#endif

// July 2016 (Carsten and Uwe)
// BUG 193: Possibly tell portAudio to use 24 bit with DirectSound.
// BUG 193: Possibly tell portAudio to use 24 bit with DirectSound.
int userData = 24;
int* lpUserData = (captureFormat_saved == int24Sample) ? &userData : NULL;

Expand Down Expand Up @@ -1473,7 +1472,7 @@ void AudioIO::StartMonitoring( const AudioIOStartStreamOptions &options )

// FIXME: TRAP_ERR PaErrorCode 'noted' but not reported in StartMonitoring.
// Now start the PortAudio stream!
// TODO: ? Factor out and reuse error reporting code from end of
// TODO: ? Factor out and reuse error reporting code from end of
// AudioIO::StartStream?
mLastPaError = Pa_StartStream( mPortStreamV19 );

Expand Down Expand Up @@ -1706,7 +1705,7 @@ int AudioIO::StartStream(const TransportTracks &tracks,
mPlaybackMixers[ii]->Reposition( time );
mPlaybackSchedule.RealTimeInit( time );
}

// Now that we are done with SetTrackTime():
mTimeQueue.mLastTime = mPlaybackSchedule.GetTrackTime();
if (mTimeQueue.mData)
Expand Down Expand Up @@ -1857,7 +1856,7 @@ bool AudioIO::AllocateBuffers(
// more frequent polling of the mouse
playbackTime =
lrint(options.pScrubbingOptions->delay * mRate) / mRate;

wxASSERT( playbackTime >= 0 );
mPlaybackSamplesToCopy = playbackTime * mRate;

Expand Down Expand Up @@ -2005,7 +2004,7 @@ bool AudioIO::AllocateBuffers(
}
}
} while(!bDone);

success = true;
return true;
}
Expand Down Expand Up @@ -2179,15 +2178,15 @@ void AudioIO::StopStream()
// Re-enable system sleep
wxPowerResource::Release(wxPOWER_RESOURCE_SCREEN);
#endif

if( mAudioThreadFillBuffersLoopRunning)
{
// PortAudio callback can use the information that we are stopping to fade
// out the audio. Give PortAudio callback a chance to do so.
mAudioThreadFillBuffersLoopRunning = false;
auto latency = static_cast<long>(AudioIOLatencyDuration.Read());
// If we can gracefully fade out in 200ms, with the faded-out play buffers making it through
// the sound card, then do so. If we can't, don't wait around. Just stop quickly and accept
// the sound card, then do so. If we can't, don't wait around. Just stop quickly and accept
// there will be a click.
if( mbMicroFades && (latency < 150 ))
wxMilliSleep( latency + 50);
Expand Down Expand Up @@ -2305,7 +2304,7 @@ void AudioIO::StopStream()
#endif

auto pListener = GetListener();

// If there's no token, we were just monitoring, so we can
// skip this next part...
if (mStreamToken > 0) {
Expand Down Expand Up @@ -2373,7 +2372,7 @@ void AudioIO::StopStream()
} );
}


if (!mLostCaptureIntervals.empty())
{
// This scope may combine many splittings of wave tracks
Expand Down Expand Up @@ -2427,7 +2426,7 @@ void AudioIO::StopStream()
e.SetInt(false);
wxTheApp->ProcessEvent(e);
}

if (mNumCaptureChannels > 0)
{
wxCommandEvent e(wasMonitoring ? EVT_AUDIOIO_MONITOR : EVT_AUDIOIO_CAPTURE);
Expand Down Expand Up @@ -2820,7 +2819,7 @@ void AudioIO::FillBuffers()
// wxASSERT(put == frames);
// but we can't assert in this thread
wxUnusedVar(put);
}
}
}

available -= frames;
Expand Down Expand Up @@ -3274,7 +3273,7 @@ void AudioIoCallback::GetNextEvent()
if (mNextEvent) {
mNextEventTime = (mNextIsNoteOn ? mNextEvent->time :
mNextEvent->get_end_time()) + nextOffset;;
}
}
if (mNextEventTime > (mPlaybackSchedule.mT1 + midiLoopOffset)){ // terminate playback at mT1
mNextEvent = &gAllNotesOff;
mNextEventTime = mPlaybackSchedule.mT1 + midiLoopOffset - ALG_EPS;
Expand Down Expand Up @@ -3824,7 +3823,7 @@ bool AudioIoCallback::FillOutputBuffers(
return false;
if( !outputBuffer )
return false;
if(numPlaybackChannels <= 0)
if(numPlaybackChannels <= 0)
return false;

float *outputFloats = (float *)outputBuffer;
Expand Down Expand Up @@ -3855,7 +3854,7 @@ bool AudioIoCallback::FillOutputBuffers(
// The drop and dropQuickly booleans are so named for historical reasons.
// JKC: The original code attempted to be faster by doing nothing on silenced audio.
// This, IMHO, is 'premature optimisation'. Instead clearer and cleaner code would
// simply use a gain of 0.0 for silent audio and go on through to the stage of
// simply use a gain of 0.0 for silent audio and go on through to the stage of
// applying that 0.0 gain to the data mixed into the buffer.
// Then (and only then) we would have if needed fast paths for:
// - Applying a uniform gain of 0.0.
Expand Down Expand Up @@ -3900,7 +3899,7 @@ bool AudioIoCallback::FillOutputBuffers(

if (dropQuickly) {
len = mPlaybackBuffers[t]->Discard(toGet);
// keep going here.
// keep going here.
// we may still need to issue a paComplete.
} else {
const auto ptrToSample = (samplePtr)bufHelper.get()->tempBufs[chanCnt];
Expand Down Expand Up @@ -4000,7 +3999,7 @@ void AudioIoCallback::UpdateTimePosition(unsigned long framesPerBuffer)
// Copy from PortAudio to our input buffers.
//
void AudioIoCallback::FillInputBuffers(
const void *inputBuffer,
const void *inputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackFlags statusFlags,
float * tempFloats
Expand Down Expand Up @@ -4071,10 +4070,10 @@ void AudioIoCallback::FillInputBuffers(
wxPrintf(wxT("lost %d samples\n"), (int)(framesPerBuffer - len));
}

if (len <= 0)
if (len <= 0)
return;

// We have an ASSERT in the AudioIO constructor to alert us to
// We have an ASSERT in the AudioIO constructor to alert us to
// possible issues with the (short*) cast. We'd have a problem if
// sizeof(short) > sizeof(float) since our buffers are sized for floats.
for(unsigned t = 0; t < numCaptureChannels; t++) {
Expand Down Expand Up @@ -4111,7 +4110,7 @@ void AudioIoCallback::FillInputBuffers(
} // switch

// JKC: mCaptureFormat must be for samples with sizeof(float) or
// fewer bytes (because tempFloats is sized for floats). All
// fewer bytes (because tempFloats is sized for floats). All
// formats are 2 or 4 bytes, so we are OK.
const auto put =
mCaptureBuffers[t]->Put(
Expand Down Expand Up @@ -4157,7 +4156,7 @@ void OldCodeToCalculateLatency()
// return true, IFF we have fully handled the callback.
// Prime the output buffer with 0's, optionally adding in the playthrough.
void AudioIoCallback::DoPlaythrough(
const void *inputBuffer,
const void *inputBuffer,
void *outputBuffer,
unsigned long framesPerBuffer,
float *outputMeterFloats
Expand Down Expand Up @@ -4194,7 +4193,7 @@ void AudioIoCallback::DoPlaythrough(
// Also computes rms
void AudioIoCallback::SendVuInputMeterData(
float *inputSamples,
unsigned long framesPerBuffer
unsigned long framesPerBuffer
)
{
const auto numCaptureChannels = mNumCaptureChannels;
Expand Down Expand Up @@ -4235,7 +4234,7 @@ void AudioIoCallback::SendVuOutputMeterData(
return;
if( mOutputMeter->IsMeterDisabled() )
return;
if( !outputMeterFloats)
if( !outputMeterFloats)
return;

// Get here if playback meter is live
Expand Down Expand Up @@ -4289,7 +4288,7 @@ unsigned AudioIoCallback::CountSoloingTracks(){
// TODO: Consider making the two Track status functions into functions of
// WaveTrack.

// true IFF the track should be silent.
// true IFF the track should be silent.
// The track may not yet be silent, since it may still be
// fading out.
bool AudioIoCallback::TrackShouldBeSilent( const WaveTrack &wt )
Expand Down Expand Up @@ -4320,8 +4319,8 @@ bool AudioIoCallback::AllTracksAlreadySilent()
const bool dropAllQuickly = std::all_of(
mPlaybackTracks.begin(), mPlaybackTracks.end(),
[&]( const std::shared_ptr< WaveTrack > &vt )
{ return
TrackShouldBeSilent( *vt ) &&
{ return
TrackShouldBeSilent( *vt ) &&
TrackHasBeenFadedOut( *vt ); }
);
return dropAllQuickly;
Expand Down Expand Up @@ -4351,9 +4350,9 @@ int AudioIoCallback::AudioCallback(const void *inputBuffer, void *outputBuffer,
// but it does nothing unless we have EXPERIMENTAL_MIDI_OUT
// TODO: Possibly rename variables to make it clearer which ones are MIDI specific
// and which ones affect all audio.
ComputeMidiTimings(
timeInfo,
framesPerBuffer
ComputeMidiTimings(
timeInfo,
framesPerBuffer
);
#ifndef USE_MIDI_THREAD
if (mMidiStream)
Expand All @@ -4369,10 +4368,10 @@ int AudioIoCallback::AudioCallback(const void *inputBuffer, void *outputBuffer,
float *tempFloats = (float *)alloca(framesPerBuffer*sizeof(float)*
MAX(numCaptureChannels,numPlaybackChannels));

bool bVolEmulationActive =
bool bVolEmulationActive =
(outputBuffer && mEmulateMixerOutputVol && mMixerOutputVol != 1.0);
// outputMeterFloats is the scratch pad for the output meter.
// we can often reuse the existing outputBuffer and save on allocating
// outputMeterFloats is the scratch pad for the output meter.
// we can often reuse the existing outputBuffer and save on allocating
// something new.
float *outputMeterFloats = bVolEmulationActive ?
(float *)alloca(framesPerBuffer*numPlaybackChannels * sizeof(float)) :
Expand All @@ -4397,10 +4396,10 @@ int AudioIoCallback::AudioCallback(const void *inputBuffer, void *outputBuffer,

// This function may queue up a pause or resume.
// TODO this is a bit dodgy as it toggles the Pause, and
// relies on an idle event to have handled that, so could
// relies on an idle event to have handled that, so could
// queue up multiple toggle requests and so do nothing.
// Eventually it will sort itself out by random luck, but
// the net effect is a delay in starting/stopping sound activated
// the net effect is a delay in starting/stopping sound activated
// recording.
CheckSoundActivatedRecordingLevel(
inputSamples,
Expand All @@ -4411,7 +4410,7 @@ int AudioIoCallback::AudioCallback(const void *inputBuffer, void *outputBuffer,
// Initialise output buffer to zero or to playthrough data.
// Initialise output meter values.
DoPlaythrough(
inputBuffer,
inputBuffer,
outputBuffer,
framesPerBuffer,
outputMeterFloats);
Expand All @@ -4433,7 +4432,7 @@ int AudioIoCallback::AudioCallback(const void *inputBuffer, void *outputBuffer,

// To capture input into track (sound from microphone)
FillInputBuffers(
inputBuffer,
inputBuffer,
framesPerBuffer,
statusFlags,
tempFloats);
Expand Down Expand Up @@ -4508,7 +4507,7 @@ void AudioIoCallback::CallbackCheckCompletion(
done = mPlaybackSchedule.PlayingAtSpeed()
// some leftover length allowed in this case
|| (mPlaybackSchedule.PlayingStraight() && len == 0);
if(!done)
if(!done)
return;

#ifdef EXPERIMENTAL_MIDI_OUT
Expand Down
Loading

0 comments on commit d7695f3

Please sign in to comment.