1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

AudioIOStartStreamOptions includes the sample rate

This commit is contained in:
Paul Licameli 2016-05-19 16:26:20 -04:00
parent 5997beec9d
commit 36e5b4fbbc
5 changed files with 16 additions and 11 deletions

View File

@ -1520,12 +1520,14 @@ int AudioIO::StartStream(const WaveTrackArray &playbackTracks,
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
const NoteTrackArray &midiPlaybackTracks, const NoteTrackArray &midiPlaybackTracks,
#endif #endif
double sampleRate, double t0, double t1, double t0, double t1,
const AudioIOStartStreamOptions &options) const AudioIOStartStreamOptions &options)
{ {
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...

View File

@ -88,9 +88,11 @@ DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_AUDIOIO_MONITOR, -1);
// To avoid growing the argument list of StartStream, add fields here // To avoid growing the argument list of StartStream, add fields here
struct AudioIOStartStreamOptions struct AudioIOStartStreamOptions
{ {
AudioIOStartStreamOptions() explicit
AudioIOStartStreamOptions(double rate_)
: timeTrack(NULL) : timeTrack(NULL)
, listener(NULL) , listener(NULL)
, rate(rate_)
, playLooped(false) , playLooped(false)
, cutPreviewGapStart(0.0) , cutPreviewGapStart(0.0)
, cutPreviewGapLen(0.0) , cutPreviewGapLen(0.0)
@ -106,6 +108,7 @@ struct AudioIOStartStreamOptions
TimeTrack *timeTrack; TimeTrack *timeTrack;
AudioIOListener* listener; AudioIOListener* listener;
double rate;
bool playLooped; bool playLooped;
double cutPreviewGapStart; double cutPreviewGapStart;
double cutPreviewGapLen; double cutPreviewGapLen;
@ -163,9 +166,8 @@ class AUDACITY_DLL_API AudioIO final {
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
const NoteTrackArray &midiTracks, const NoteTrackArray &midiTracks,
#endif #endif
double sampleRate, double t0, double t1, double t0, double t1,
const AudioIOStartStreamOptions &options = const AudioIOStartStreamOptions &options);
AudioIOStartStreamOptions());
/** \brief Stop recording, playback or input monitoring. /** \brief Stop recording, playback or input monitoring.
* *

View File

@ -1131,7 +1131,7 @@ AudacityProject::~AudacityProject()
AudioIOStartStreamOptions AudacityProject::GetDefaultPlayOptions() AudioIOStartStreamOptions AudacityProject::GetDefaultPlayOptions()
{ {
AudioIOStartStreamOptions options; AudioIOStartStreamOptions options { GetRate() };
options.timeTrack = GetTracks()->GetTimeTrack(); options.timeTrack = GetTracks()->GetTimeTrack();
options.listener = this; options.listener = this;
return options; return options;

View File

@ -2534,7 +2534,7 @@ void Effect::Preview(bool dryOnly)
double previewLen; double previewLen;
gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &previewLen, 6.0); gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &previewLen, 6.0);
double rate = mProjectRate; const double rate = mProjectRate;
if (isNyquist && isGenerator) { if (isNyquist && isGenerator) {
previewDuration = CalcPreviewInputLength(previewLen); previewDuration = CalcPreviewInputLength(previewLen);
@ -2637,12 +2637,13 @@ void Effect::Preview(bool dryOnly)
NoteTrackArray empty; NoteTrackArray empty;
#endif #endif
// Start audio playing // Start audio playing
AudioIOStartStreamOptions options { rate };
int token = int token =
gAudioIO->StartStream(playbackTracks, recordingTracks, gAudioIO->StartStream(playbackTracks, recordingTracks,
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
empty, empty,
#endif #endif
rate, mT0, t1); mT0, t1, options);
if (token) { if (token) {
int previewing = eProgressSuccess; int previewing = eProgressSuccess;

View File

@ -634,7 +634,7 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
NoteTrackArray(), NoteTrackArray(),
#endif #endif
p->GetRate(), tcp0, tcp1, myOptions); tcp0, tcp1, myOptions);
} else } else
{ {
// Cannot create cut preview tracks, clean up and exit // Cannot create cut preview tracks, clean up and exit
@ -655,7 +655,7 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
t->GetNoteTrackArray(false), t->GetNoteTrackArray(false),
#endif #endif
p->GetRate(), t0, t1, options); t0, t1, options);
} }
if (token != 0) { if (token != 0) {
success = true; success = true;
@ -1085,7 +1085,7 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
midiTracks, midiTracks,
#endif #endif
p->GetRate(), t0, t1, options); t0, t1, options);
bool success = (token != 0); bool success = (token != 0);