From 850628275b765d2bca23eb3c0bb5e8f0c44ef045 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 30 May 2019 15:56:44 -0400 Subject: [PATCH] AudioIO.cpp does not depend on ProjectAudioIO.h and GetActiveProject --- src/AudioIO.cpp | 25 +++++++++++-------------- src/AudioIO.h | 11 +++++++---- src/Project.cpp | 10 ++++++++-- src/effects/Effect.cpp | 2 +- src/widgets/Meter.cpp | 3 +-- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index 079ded0ec..5cec8a9cd 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -455,7 +455,6 @@ TimeTrack and AudioIOListener and whether the playback is looped. #include "prefs/GUISettings.h" #include "Prefs.h" #include "Project.h" -#include "ProjectAudioIO.h" #include "TimeTrack.h" #include "WaveTrack.h" #include "AutoRecovery.h" @@ -1466,11 +1465,12 @@ static PaSampleFormat AudacityToPortAudioSampleFormat(sampleFormat format) } } -bool AudioIO::StartPortAudioStream(double sampleRate, +bool AudioIO::StartPortAudioStream(const AudioIOStartStreamOptions &options, unsigned int numPlaybackChannels, unsigned int numCaptureChannels, sampleFormat captureFormat) { + auto sampleRate = options.rate; #ifdef EXPERIMENTAL_MIDI_OUT mNumFrames = 0; mNumPauseFrames = 0; @@ -1486,7 +1486,7 @@ bool AudioIO::StartPortAudioStream(double sampleRate, mCallbackCount = 0; mAudioFramesPerBuffer = 0; #endif - mOwningProject = GetActiveProject(); + mOwningProject = options.pProject; // PRL: Protection from crash reported by David Bailes, involving starting // and stopping with frequent changes of active window, hard to reproduce @@ -1560,7 +1560,7 @@ bool AudioIO::StartPortAudioStream(double sampleRate, playbackParameters.suggestedLatency = isWASAPI ? 0.0 : latencyDuration/1000.0; } - mOutputMeter = ProjectAudioIO::Get( *mOwningProject ).GetPlaybackMeter(); + mOutputMeter = options.playbackMeter; } if( numCaptureChannels > 0) @@ -1590,8 +1590,7 @@ bool AudioIO::StartPortAudioStream(double sampleRate, else captureParameters.suggestedLatency = latencyDuration/1000.0; - SetCaptureMeter( mOwningProject, - ProjectAudioIO::Get( *mOwningProject ).GetCaptureMeter() ); + SetCaptureMeter( mOwningProject, options.captureMeter ); } SetMeters(); @@ -1678,7 +1677,7 @@ wxString AudioIO::LastPaErrorString() return wxString::Format(wxT("%d %s."), (int) mLastPaError, Pa_GetErrorText(mLastPaError)); } -void AudioIO::StartMonitoring(double sampleRate) +void AudioIO::StartMonitoring( const AudioIOStartStreamOptions &options ) { if ( mPortStreamV19 || mStreamToken ) return; @@ -1696,7 +1695,7 @@ void AudioIO::StartMonitoring(double sampleRate) // FIXME: TRAP_ERR StartPortAudioStream (a PaError may be present) // but StartPortAudioStream function only returns true or false. mUsingAlsa = false; - success = StartPortAudioStream(sampleRate, (unsigned int)playbackChannels, + success = StartPortAudioStream(options, (unsigned int)playbackChannels, (unsigned int)captureChannels, captureFormat); @@ -1738,8 +1737,6 @@ int AudioIO::StartStream(const TransportTracks &tracks, if( IsBusy() ) return 0; - const auto &sampleRate = options.rate; - // We just want to set mStreamToken to -1 - this way avoids // an extremely rare but possible race condition, if two functions // somehow called StartStream at the same time... @@ -1802,7 +1799,7 @@ int AudioIO::StartStream(const TransportTracks &tracks, mRecordingSchedule.mCrossfadeData.swap( *options.pCrossfadeData ); mListener = options.listener; - mRate = sampleRate; + mRate = options.rate; mSeek = 0; mLastRecordingOffset = 0; @@ -1877,7 +1874,7 @@ int AudioIO::StartStream(const TransportTracks &tracks, bool successAudio; - successAudio = StartPortAudioStream(sampleRate, playbackChannels, + successAudio = StartPortAudioStream(options, playbackChannels, captureChannels, captureFormat); #ifdef EXPERIMENTAL_MIDI_OUT @@ -1902,7 +1899,7 @@ int AudioIO::StartStream(const TransportTracks &tracks, return 0; } - if ( ! AllocateBuffers( options, tracks, t0, t1, sampleRate, scrubbing ) ) + if ( ! AllocateBuffers( options, tracks, t0, t1, options.rate, scrubbing ) ) return 0; if (mNumPlaybackChannels > 0) @@ -2677,7 +2674,7 @@ void AudioIO::StopStream() mInputMeter.Release(); mOutputMeter.Release(); - mOwningProject = NULL; + mOwningProject = nullptr; if (mListener && mNumCaptureChannels > 0) mListener->OnAudioIOStopRecording(); diff --git a/src/AudioIO.h b/src/AudioIO.h index af3185f7f..69b887aa7 100644 --- a/src/AudioIO.h +++ b/src/AudioIO.h @@ -116,8 +116,9 @@ using PRCrossfadeData = std::vector< std::vector < float > >; struct AudioIOStartStreamOptions { explicit - AudioIOStartStreamOptions(double rate_) - : timeTrack(NULL) + AudioIOStartStreamOptions(AudacityProject *pProject_, double rate_) + : pProject{ pProject_ } + , timeTrack(NULL) , listener(NULL) , rate(rate_) , playLooped(false) @@ -127,6 +128,8 @@ struct AudioIOStartStreamOptions , preRoll(0.0) {} + AudacityProject *pProject{}; + MeterPanel *captureMeter{}, *playbackMeter{}; TimeTrack *timeTrack; AudioIOListener* listener; double rate; @@ -810,7 +813,7 @@ public: * 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 */ - void StartMonitoring(double sampleRate); + void StartMonitoring( const AudioIOStartStreamOptions &options ); /** \brief Start recording or playing back audio * @@ -1101,7 +1104,7 @@ private: * if necessary. The captureFormat is used for recording only, the playback * being floating point always. Returns true if the stream opened sucessfully * and false if it did not. */ - bool StartPortAudioStream(double sampleRate, + bool StartPortAudioStream(const AudioIOStartStreamOptions &options, unsigned int numPlaybackChannels, unsigned int numCaptureChannels, sampleFormat captureFormat); diff --git a/src/Project.cpp b/src/Project.cpp index 8d7cb3eea..7d352c170 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -1356,8 +1356,11 @@ void AudacityProject::ApplyUpdatedTheme() AudioIOStartStreamOptions DefaultPlayOptions( AudacityProject &project ) { - AudioIOStartStreamOptions options { + auto &projectAudioIO = ProjectAudioIO::Get( project ); + AudioIOStartStreamOptions options { &project, ProjectSettings::Get( project ).GetRate() }; + options.captureMeter = projectAudioIO.GetCaptureMeter(); + options.playbackMeter = projectAudioIO.GetPlaybackMeter(); options.timeTrack = TrackList::Get( project ).GetTimeTrack(); options.listener = &project; return options; @@ -1366,12 +1369,15 @@ DefaultPlayOptions( AudacityProject &project ) AudioIOStartStreamOptions DefaultSpeedPlayOptions( AudacityProject &project ) { + auto &projectAudioIO = ProjectAudioIO::Get( project ); auto PlayAtSpeedRate = gAudioIO->GetBestRate( false, //not capturing true, //is playing ProjectSettings::Get( project ).GetRate() //suggested rate ); - AudioIOStartStreamOptions options{ PlayAtSpeedRate }; + AudioIOStartStreamOptions options{ &project, PlayAtSpeedRate }; + options.captureMeter = projectAudioIO.GetCaptureMeter(); + options.playbackMeter = projectAudioIO.GetPlaybackMeter(); options.timeTrack = TrackList::Get( project ).GetTimeTrack(); options.listener = &project; return options; diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index f2d07400c..0707714e1 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -2624,7 +2624,7 @@ void Effect::Preview(bool dryOnly) t1 = std::min(mT0 + previewLen, mT1); // Start audio playing - AudioIOStartStreamOptions options { rate }; + AudioIOStartStreamOptions options { nullptr, rate }; int token = gAudioIO->StartStream(tracks, mT0, t1, options); diff --git a/src/widgets/Meter.cpp b/src/widgets/Meter.cpp index 66bf4f846..e4c5ffdac 100644 --- a/src/widgets/Meter.cpp +++ b/src/widgets/Meter.cpp @@ -67,7 +67,6 @@ #include "../ImageManipulation.h" #include "../prefs/GUISettings.h" #include "../Project.h" -#include "../ProjectSettings.h" #include "../Prefs.h" #include "../ShuttleGui.h" @@ -1872,7 +1871,7 @@ void MeterPanel::StartMonitoring() if (start && !gAudioIO->IsBusy()){ AudacityProject *p = GetActiveProject(); if (p){ - gAudioIO->StartMonitoring( ProjectSettings::Get( *p ).GetRate()); + gAudioIO->StartMonitoring( DefaultPlayOptions( *p ) ); } mLayoutValid = false;