1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-06 23:02:42 +02:00

Bug 1932 - (Residual) Fix stopping behavior with Play-At-Speed.

1. The rate actually used by the sound card now sets the stopping sample number.
2. The tolerance in the 'stop position' is additionally trimmed to 20 samples.
This commit is contained in:
James Crook 2018-08-19 10:37:43 +01:00
parent aaad7dd08d
commit 3bb48a21df
4 changed files with 32 additions and 16 deletions

View File

@ -483,22 +483,23 @@ class AUDACITY_DLL_API AudioIO final {
void SetCaptureMeter(AudacityProject *project, MeterPanel *meter);
void SetPlaybackMeter(AudacityProject *project, MeterPanel *meter);
/** \brief Return a valid sample rate that is supported by the current I/O
* device(s).
*
* The return from this function is used to determine the sample rate that
* audacity actually runs the audio I/O stream at. if there is no suitable
* rate available from the hardware, it returns 0.
* The sampleRate argument gives the desired sample rate (the rate of the
* audio to be handeled, i.e. the currently Project Rate).
* capturing is true if the stream is capturing one or more audio channels,
* and playing is true if one or more channels are being played. */
double GetBestRate(bool capturing, bool playing, double sampleRate);
private:
/** \brief Set the current VU meters - this should be done once after
* each call to StartStream currently */
void SetMeters();
/** \brief Return a valid sample rate that is supported by the current I/O
* device(s).
*
* The return from this function is used to determine the sample rate that
* audacity actually runs the audio I/O stream at. if there is no suitable
* rate available from the hardware, it returns 0.
* The sampleRate argument gives the desired sample rate (the rate of the
* audio to be handeled, i.e. the currently Project Rate).
* capturing is true if the stream is capturing one or more audio channels,
* and playing is true if one or more channels are being played. */
double GetBestRate(bool capturing, bool playing, double sampleRate);
/** \brief Opens the portaudio stream(s) used to do playback or recording
* (or both) through.

View File

@ -1306,6 +1306,20 @@ AudioIOStartStreamOptions AudacityProject::GetDefaultPlayOptions()
return options;
}
AudioIOStartStreamOptions AudacityProject::GetSpeedPlayOptions()
{
auto PlayAtSpeedRate = gAudioIO->GetBestRate(
false, //not capturing
true, //is playing
GetRate() //suggested rate
);
AudioIOStartStreamOptions options{ PlayAtSpeedRate };
options.timeTrack = GetTracks()->GetTimeTrack();
options.listener = this;
return options;
}
void AudacityProject::UpdatePrefsVariables()
{
gPrefs->Read(wxT("/AudioFiles/ShowId3Dialog"), &mShowId3Dialog, true);

View File

@ -188,6 +188,7 @@ class AUDACITY_DLL_API AudacityProject final : public wxFrame,
virtual void ApplyUpdatedTheme();
AudioIOStartStreamOptions GetDefaultPlayOptions();
AudioIOStartStreamOptions GetSpeedPlayOptions();
TrackList *GetTracks() { return mTracks.get(); }
const TrackList *GetTracks() const { return mTracks.get(); }

View File

@ -462,7 +462,7 @@ bool Scrubber::StartSpeedPlay(double speed, double time0, double time1)
mMaxSpeed = speed;
mDragging = false;
AudioIOStartStreamOptions options(mProject->GetDefaultPlayOptions());
AudioIOStartStreamOptions options(mProject->GetSpeedPlayOptions());
options.pScrubbingOptions = &mOptions;
options.timeTrack = NULL;
mOptions.startClockTimeMillis = ::wxGetLocalTimeMillis();
@ -499,11 +499,11 @@ bool Scrubber::StartSpeedPlay(double speed, double time0, double time1)
});
mScrubSpeedDisplayCountdown = 0;
// last buffer should not be any bigger than this.
double lastBuffer = (2 * ScrubPollInterval_ms) / 1000.0;
// Aim to stop within 20 samples of correct position.
double stopTolerance = 20.0 / options.rate;
mScrubToken =
// Reduce time by 'lastBuffer' fudge factor, so that the Play will stop.
ctb->PlayPlayRegion(SelectedRegion(time0, time1-lastBuffer), options,
// Reduce time by 'stopTolerance' fudge factor, so that the Play will stop.
ctb->PlayPlayRegion(SelectedRegion(time0, time1-stopTolerance), options,
PlayMode::normalPlay, appearance, backwards);
if (mScrubToken >= 0) {