From b54f56fba0832b53f4365a50337798b89d1824ba Mon Sep 17 00:00:00 2001 From: David Bailes Date: Thu, 7 Jun 2018 14:42:39 +0100 Subject: [PATCH] Bug 1879 - Audacity resets project rate without warning. These were the steps to reproduce: Remember that the Realtek card in my new HP laptop *only* runs at 48000 1) Clear out the entire Audacity config/settings folder for virgin running 2) Launch Audacity audacity-2.3.0-alpha-20-a22be24ae3a224c90688504f8ff323c41f8c9c35 3) set recording for WASAPI/loopback (or WASAPI/mic) 4) press Record 5) Track records properly 6) rate shown in TCP is 44100 7) Project rate at bottom left shows 44100 8) Exit Audacity 9) Relaunch Audacity 10) Project rate at bottom left now shows 48000 11) Press Record 12) Track records OK - but at 48000 obviously The problem: the default sample rate is read in like this: gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), &mRate, AudioIO::GetOptimalSupportedSampleRate()); - the default is not fixed, it can vary with host/device. Fix: Ensure that there is always an entry for the default sample rate in audacity.cfg --- src/Project.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Project.cpp b/src/Project.cpp index 884ee29a1..7f8dea4cd 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -924,7 +924,6 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, : wxFrame(parent, id, _TS("Audacity"), pos, size), mViewInfo(0.0, 1.0, ZoomInfo::GetDefaultZoom()), mbLoadedFromAup( false ), - mRate((double) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), AudioIO::GetOptimalSupportedSampleRate())), mDefaultFormat(QualityPrefs::SampleFormatChoice()), mSnapTo(gPrefs->Read(wxT("/SnapTo"), SNAP_OFF)), mSelectionFormat( NumericTextCtrl::LookupFormat( @@ -938,6 +937,14 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT("")) ) ), mUndoManager(std::make_unique()) { + if (!gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), &mRate, AudioIO::GetOptimalSupportedSampleRate())) { + // The default given above can vary with host/devices. So unless there is an entry for + // the default sample rate in audacity.cfg, Audacity can open with a rate which is different + // from the rate with which it closed. See bug 1879. + gPrefs->Write(wxT("/SamplingRate/DefaultProjectSampleRate"), mRate); + gPrefs->Flush(); + } + mTracks = TrackList::Create(); #ifdef EXPERIMENTAL_DA2