mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-25 16:48:44 +02:00
AudioIO.cpp does not depend on ProjectAudioIO.h and GetActiveProject
This commit is contained in:
parent
e5cf2165d1
commit
850628275b
@ -455,7 +455,6 @@ TimeTrack and AudioIOListener and whether the playback is looped.
|
|||||||
#include "prefs/GUISettings.h"
|
#include "prefs/GUISettings.h"
|
||||||
#include "Prefs.h"
|
#include "Prefs.h"
|
||||||
#include "Project.h"
|
#include "Project.h"
|
||||||
#include "ProjectAudioIO.h"
|
|
||||||
#include "TimeTrack.h"
|
#include "TimeTrack.h"
|
||||||
#include "WaveTrack.h"
|
#include "WaveTrack.h"
|
||||||
#include "AutoRecovery.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 numPlaybackChannels,
|
||||||
unsigned int numCaptureChannels,
|
unsigned int numCaptureChannels,
|
||||||
sampleFormat captureFormat)
|
sampleFormat captureFormat)
|
||||||
{
|
{
|
||||||
|
auto sampleRate = options.rate;
|
||||||
#ifdef EXPERIMENTAL_MIDI_OUT
|
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||||
mNumFrames = 0;
|
mNumFrames = 0;
|
||||||
mNumPauseFrames = 0;
|
mNumPauseFrames = 0;
|
||||||
@ -1486,7 +1486,7 @@ bool AudioIO::StartPortAudioStream(double sampleRate,
|
|||||||
mCallbackCount = 0;
|
mCallbackCount = 0;
|
||||||
mAudioFramesPerBuffer = 0;
|
mAudioFramesPerBuffer = 0;
|
||||||
#endif
|
#endif
|
||||||
mOwningProject = GetActiveProject();
|
mOwningProject = options.pProject;
|
||||||
|
|
||||||
// PRL: Protection from crash reported by David Bailes, involving starting
|
// PRL: Protection from crash reported by David Bailes, involving starting
|
||||||
// and stopping with frequent changes of active window, hard to reproduce
|
// 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;
|
playbackParameters.suggestedLatency = isWASAPI ? 0.0 : latencyDuration/1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mOutputMeter = ProjectAudioIO::Get( *mOwningProject ).GetPlaybackMeter();
|
mOutputMeter = options.playbackMeter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( numCaptureChannels > 0)
|
if( numCaptureChannels > 0)
|
||||||
@ -1590,8 +1590,7 @@ bool AudioIO::StartPortAudioStream(double sampleRate,
|
|||||||
else
|
else
|
||||||
captureParameters.suggestedLatency = latencyDuration/1000.0;
|
captureParameters.suggestedLatency = latencyDuration/1000.0;
|
||||||
|
|
||||||
SetCaptureMeter( mOwningProject,
|
SetCaptureMeter( mOwningProject, options.captureMeter );
|
||||||
ProjectAudioIO::Get( *mOwningProject ).GetCaptureMeter() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetMeters();
|
SetMeters();
|
||||||
@ -1678,7 +1677,7 @@ wxString AudioIO::LastPaErrorString()
|
|||||||
return wxString::Format(wxT("%d %s."), (int) mLastPaError, Pa_GetErrorText(mLastPaError));
|
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 )
|
if ( mPortStreamV19 || mStreamToken )
|
||||||
return;
|
return;
|
||||||
@ -1696,7 +1695,7 @@ void AudioIO::StartMonitoring(double sampleRate)
|
|||||||
// FIXME: TRAP_ERR StartPortAudioStream (a PaError may be present)
|
// FIXME: TRAP_ERR StartPortAudioStream (a PaError may be present)
|
||||||
// but StartPortAudioStream function only returns true or false.
|
// but StartPortAudioStream function only returns true or false.
|
||||||
mUsingAlsa = false;
|
mUsingAlsa = false;
|
||||||
success = StartPortAudioStream(sampleRate, (unsigned int)playbackChannels,
|
success = StartPortAudioStream(options, (unsigned int)playbackChannels,
|
||||||
(unsigned int)captureChannels,
|
(unsigned int)captureChannels,
|
||||||
captureFormat);
|
captureFormat);
|
||||||
|
|
||||||
@ -1738,8 +1737,6 @@ int AudioIO::StartStream(const TransportTracks &tracks,
|
|||||||
if( IsBusy() )
|
if( IsBusy() )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const auto &sampleRate = options.rate;
|
|
||||||
|
|
||||||
// We just want to set mStreamToken to -1 - this way avoids
|
// We just want to set mStreamToken to -1 - this way avoids
|
||||||
// an extremely rare but possible race condition, if two functions
|
// an extremely rare but possible race condition, if two functions
|
||||||
// somehow called StartStream at the same time...
|
// somehow called StartStream at the same time...
|
||||||
@ -1802,7 +1799,7 @@ int AudioIO::StartStream(const TransportTracks &tracks,
|
|||||||
mRecordingSchedule.mCrossfadeData.swap( *options.pCrossfadeData );
|
mRecordingSchedule.mCrossfadeData.swap( *options.pCrossfadeData );
|
||||||
|
|
||||||
mListener = options.listener;
|
mListener = options.listener;
|
||||||
mRate = sampleRate;
|
mRate = options.rate;
|
||||||
|
|
||||||
mSeek = 0;
|
mSeek = 0;
|
||||||
mLastRecordingOffset = 0;
|
mLastRecordingOffset = 0;
|
||||||
@ -1877,7 +1874,7 @@ int AudioIO::StartStream(const TransportTracks &tracks,
|
|||||||
|
|
||||||
bool successAudio;
|
bool successAudio;
|
||||||
|
|
||||||
successAudio = StartPortAudioStream(sampleRate, playbackChannels,
|
successAudio = StartPortAudioStream(options, playbackChannels,
|
||||||
captureChannels, captureFormat);
|
captureChannels, captureFormat);
|
||||||
#ifdef EXPERIMENTAL_MIDI_OUT
|
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||||
|
|
||||||
@ -1902,7 +1899,7 @@ int AudioIO::StartStream(const TransportTracks &tracks,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! AllocateBuffers( options, tracks, t0, t1, sampleRate, scrubbing ) )
|
if ( ! AllocateBuffers( options, tracks, t0, t1, options.rate, scrubbing ) )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (mNumPlaybackChannels > 0)
|
if (mNumPlaybackChannels > 0)
|
||||||
@ -2677,7 +2674,7 @@ void AudioIO::StopStream()
|
|||||||
|
|
||||||
mInputMeter.Release();
|
mInputMeter.Release();
|
||||||
mOutputMeter.Release();
|
mOutputMeter.Release();
|
||||||
mOwningProject = NULL;
|
mOwningProject = nullptr;
|
||||||
|
|
||||||
if (mListener && mNumCaptureChannels > 0)
|
if (mListener && mNumCaptureChannels > 0)
|
||||||
mListener->OnAudioIOStopRecording();
|
mListener->OnAudioIOStopRecording();
|
||||||
|
@ -116,8 +116,9 @@ using PRCrossfadeData = std::vector< std::vector < float > >;
|
|||||||
struct AudioIOStartStreamOptions
|
struct AudioIOStartStreamOptions
|
||||||
{
|
{
|
||||||
explicit
|
explicit
|
||||||
AudioIOStartStreamOptions(double rate_)
|
AudioIOStartStreamOptions(AudacityProject *pProject_, double rate_)
|
||||||
: timeTrack(NULL)
|
: pProject{ pProject_ }
|
||||||
|
, timeTrack(NULL)
|
||||||
, listener(NULL)
|
, listener(NULL)
|
||||||
, rate(rate_)
|
, rate(rate_)
|
||||||
, playLooped(false)
|
, playLooped(false)
|
||||||
@ -127,6 +128,8 @@ struct AudioIOStartStreamOptions
|
|||||||
, preRoll(0.0)
|
, preRoll(0.0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
AudacityProject *pProject{};
|
||||||
|
MeterPanel *captureMeter{}, *playbackMeter{};
|
||||||
TimeTrack *timeTrack;
|
TimeTrack *timeTrack;
|
||||||
AudioIOListener* listener;
|
AudioIOListener* listener;
|
||||||
double rate;
|
double rate;
|
||||||
@ -810,7 +813,7 @@ public:
|
|||||||
* selected number of input channels to open the recording device and start
|
* selected number of input channels to open the recording device and start
|
||||||
* reading input data. If software playthrough is enabled, it also opens
|
* reading input data. If software playthrough is enabled, it also opens
|
||||||
* the output device in stereo to play the data through */
|
* 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
|
/** \brief Start recording or playing back audio
|
||||||
*
|
*
|
||||||
@ -1101,7 +1104,7 @@ private:
|
|||||||
* if necessary. The captureFormat is used for recording only, the playback
|
* if necessary. The captureFormat is used for recording only, the playback
|
||||||
* being floating point always. Returns true if the stream opened sucessfully
|
* being floating point always. Returns true if the stream opened sucessfully
|
||||||
* and false if it did not. */
|
* and false if it did not. */
|
||||||
bool StartPortAudioStream(double sampleRate,
|
bool StartPortAudioStream(const AudioIOStartStreamOptions &options,
|
||||||
unsigned int numPlaybackChannels,
|
unsigned int numPlaybackChannels,
|
||||||
unsigned int numCaptureChannels,
|
unsigned int numCaptureChannels,
|
||||||
sampleFormat captureFormat);
|
sampleFormat captureFormat);
|
||||||
|
@ -1356,8 +1356,11 @@ void AudacityProject::ApplyUpdatedTheme()
|
|||||||
AudioIOStartStreamOptions
|
AudioIOStartStreamOptions
|
||||||
DefaultPlayOptions( AudacityProject &project )
|
DefaultPlayOptions( AudacityProject &project )
|
||||||
{
|
{
|
||||||
AudioIOStartStreamOptions options {
|
auto &projectAudioIO = ProjectAudioIO::Get( project );
|
||||||
|
AudioIOStartStreamOptions options { &project,
|
||||||
ProjectSettings::Get( project ).GetRate() };
|
ProjectSettings::Get( project ).GetRate() };
|
||||||
|
options.captureMeter = projectAudioIO.GetCaptureMeter();
|
||||||
|
options.playbackMeter = projectAudioIO.GetPlaybackMeter();
|
||||||
options.timeTrack = TrackList::Get( project ).GetTimeTrack();
|
options.timeTrack = TrackList::Get( project ).GetTimeTrack();
|
||||||
options.listener = &project;
|
options.listener = &project;
|
||||||
return options;
|
return options;
|
||||||
@ -1366,12 +1369,15 @@ DefaultPlayOptions( AudacityProject &project )
|
|||||||
AudioIOStartStreamOptions
|
AudioIOStartStreamOptions
|
||||||
DefaultSpeedPlayOptions( AudacityProject &project )
|
DefaultSpeedPlayOptions( AudacityProject &project )
|
||||||
{
|
{
|
||||||
|
auto &projectAudioIO = ProjectAudioIO::Get( project );
|
||||||
auto PlayAtSpeedRate = gAudioIO->GetBestRate(
|
auto PlayAtSpeedRate = gAudioIO->GetBestRate(
|
||||||
false, //not capturing
|
false, //not capturing
|
||||||
true, //is playing
|
true, //is playing
|
||||||
ProjectSettings::Get( project ).GetRate() //suggested rate
|
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.timeTrack = TrackList::Get( project ).GetTimeTrack();
|
||||||
options.listener = &project;
|
options.listener = &project;
|
||||||
return options;
|
return options;
|
||||||
|
@ -2624,7 +2624,7 @@ void Effect::Preview(bool dryOnly)
|
|||||||
t1 = std::min(mT0 + previewLen, mT1);
|
t1 = std::min(mT0 + previewLen, mT1);
|
||||||
|
|
||||||
// Start audio playing
|
// Start audio playing
|
||||||
AudioIOStartStreamOptions options { rate };
|
AudioIOStartStreamOptions options { nullptr, rate };
|
||||||
int token =
|
int token =
|
||||||
gAudioIO->StartStream(tracks, mT0, t1, options);
|
gAudioIO->StartStream(tracks, mT0, t1, options);
|
||||||
|
|
||||||
|
@ -67,7 +67,6 @@
|
|||||||
#include "../ImageManipulation.h"
|
#include "../ImageManipulation.h"
|
||||||
#include "../prefs/GUISettings.h"
|
#include "../prefs/GUISettings.h"
|
||||||
#include "../Project.h"
|
#include "../Project.h"
|
||||||
#include "../ProjectSettings.h"
|
|
||||||
#include "../Prefs.h"
|
#include "../Prefs.h"
|
||||||
#include "../ShuttleGui.h"
|
#include "../ShuttleGui.h"
|
||||||
|
|
||||||
@ -1872,7 +1871,7 @@ void MeterPanel::StartMonitoring()
|
|||||||
if (start && !gAudioIO->IsBusy()){
|
if (start && !gAudioIO->IsBusy()){
|
||||||
AudacityProject *p = GetActiveProject();
|
AudacityProject *p = GetActiveProject();
|
||||||
if (p){
|
if (p){
|
||||||
gAudioIO->StartMonitoring( ProjectSettings::Get( *p ).GetRate());
|
gAudioIO->StartMonitoring( DefaultPlayOptions( *p ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
mLayoutValid = false;
|
mLayoutValid = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user