1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-26 07:13:49 +01:00

Pitch is no longer a special view type... && bug fixes 1040, 1041

... It is a choice of algorithm in spectrogram settings, and any frequency
scale may be chosen with it.  Spectral selection works in it.
This commit is contained in:
Paul Licameli
2015-06-20 12:15:49 -04:00
parent 981acf0bd2
commit adb4a534e8
11 changed files with 125 additions and 59 deletions

View File

@@ -78,6 +78,7 @@ SpectrogramSettings::SpectrogramSettings(const SpectrogramSettings &other)
#ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
, spectralSelection(other.spectralSelection)
#endif
, algorithm(other.algorithm)
#ifdef EXPERIMENTAL_FFT_Y_GRID
, fftYGrid(other.fftYGrid)
#endif
@@ -114,6 +115,7 @@ SpectrogramSettings &SpectrogramSettings::operator= (const SpectrogramSettings &
#ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
spectralSelection = other.spectralSelection;
#endif
algorithm = other.algorithm;
#ifdef EXPERIMENTAL_FFT_Y_GRID
fftYGrid = other.fftYGrid;
#endif
@@ -144,12 +146,19 @@ namespace
static wxArrayString theArray;
return theArray;
}
wxArrayString &algorithmNamesArray()
{
static wxArrayString theArray;
return theArray;
}
}
//static
void SpectrogramSettings::InvalidateNames()
{
scaleNamesArray().Clear();
algorithmNamesArray().Clear();
}
//static
@@ -170,6 +179,20 @@ const wxArrayString &SpectrogramSettings::GetScaleNames()
return theArray;
}
//static
const wxArrayString &SpectrogramSettings::GetAlgorithmNames()
{
wxArrayString &theArray = algorithmNamesArray();
if (theArray.IsEmpty()) {
// Keep in correspondence with enum SpectrogramSettings::Algorithm:
theArray.Add(_("STFT"));
theArray.Add(_("Pitch (enhanced autocorrelation)"));
}
return theArray;
}
bool SpectrogramSettings::Validate(bool quiet)
{
if (!quiet &&
@@ -227,6 +250,9 @@ bool SpectrogramSettings::Validate(bool quiet)
ScaleType(std::max(0,
std::min(int(SpectrogramSettings::stNumScaleTypes) - 1,
int(scaleType))));
algorithm = Algorithm(
std::max(0, std::min(int(algNumAlgorithms) - 1, int(algorithm)))
);
ConvertToEnumeratedWindowSizes();
ConvertToActualWindowSizes();
@@ -259,6 +285,8 @@ void SpectrogramSettings::LoadPrefs()
spectralSelection = (gPrefs->Read(wxT("/Spectrum/EnableSpectralSelection"), 0L) != 0);
#endif
algorithm = Algorithm(gPrefs->Read(wxT("/Spectrum/Algorithm"), 0L));
#ifdef EXPERIMENTAL_FFT_Y_GRID
fftYGrid = (gPrefs->Read(wxT("/Spectrum/FFTYGrid"), 0L) != 0);
#endif //EXPERIMENTAL_FFT_Y_GRID
@@ -319,6 +347,8 @@ void SpectrogramSettings::SavePrefs()
gPrefs->Write(wxT("/Spectrum/EnableSpectralSelection"), spectralSelection);
#endif
gPrefs->Write(wxT("/Spectrum/Algorithm"), algorithm);
#ifdef EXPERIMENTAL_FFT_Y_GRID
gPrefs->Write(wxT("/Spectrum/FFTYGrid"), fftYGrid);
#endif //EXPERIMENTAL_FFT_Y_GRID
@@ -519,21 +549,21 @@ void SpectrogramSettings::SetLogMaxFreq(int freq)
logMaxFreq = freq;
}
int SpectrogramSettings::GetFFTLength(bool autocorrelation) const
int SpectrogramSettings::GetFFTLength() const
{
return windowSize
#ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
* (!autocorrelation ? zeroPaddingFactor : 1);
* ((algorithm == algSTFT) ? zeroPaddingFactor : 1);
#endif
;
}
NumberScale SpectrogramSettings::GetScale
(double rate, bool bins, bool autocorrelation) const
(double rate, bool bins) const
{
int minFreq, maxFreq;
NumberScaleType type = nstLinear;
const int half = GetFFTLength(autocorrelation) / 2;
const int half = GetFFTLength() / 2;
// Don't assume the correspondence of the enums will remain direct in the future.
// Do this switch.

View File

@@ -64,6 +64,7 @@ public:
static void InvalidateNames(); // in case of language change
static const wxArrayString &GetScaleNames();
static const wxArrayString &GetAlgorithmNames();
static SpectrogramSettings &defaults();
SpectrogramSettings();
@@ -87,7 +88,7 @@ public:
// If "bins" is false, units are Hz
NumberScale SpectrogramSettings::GetScale
(double rate, bool bins, bool autocorrelation) const;
(double rate, bool bins) const;
private:
int minFreq;
@@ -117,7 +118,7 @@ public:
int zeroPaddingFactor;
#endif
int GetFFTLength(bool autocorrelation) const; // window size (times zero padding, if STFT)
int GetFFTLength() const; // window size (times zero padding, if STFT)
bool isGrayscale;
@@ -127,6 +128,14 @@ public:
bool spectralSelection; // But should this vary per track? -- PRL
#endif
enum Algorithm {
algSTFT = 0,
algPitchEAC,
algNumAlgorithms,
};
Algorithm algorithm;
#ifdef EXPERIMENTAL_FFT_Y_GRID
bool fftYGrid;
#endif //EXPERIMENTAL_FFT_Y_GRID

View File

@@ -60,6 +60,7 @@ enum {
ID_WINDOW_TYPE,
ID_PADDING_SIZE,
ID_SCALE,
ID_ALGORITHM,
ID_MINIMUM,
ID_MAXIMUM,
ID_GAIN,
@@ -97,6 +98,8 @@ void SpectrumPrefs::Populate(int windowSize)
mScaleChoices = SpectrogramSettings::GetScaleNames();
mAlgorithmChoices = SpectrogramSettings::GetAlgorithmNames();
//------------------------- Main section --------------------
// Now construct the GUI itself.
ShuttleGui S(this, eIsCreating);
@@ -171,6 +174,7 @@ void SpectrumPrefs::PopulateOrExchange(ShuttleGui & S)
S.SetSizeHints(mTypeChoices);
#ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
mZeroPaddingChoiceCtrl =
S.Id(ID_PADDING_SIZE).TieChoice(_("&Zero padding factor") + wxString(wxT(":")),
mTempSettings.zeroPaddingFactor,
&mZeroPaddingChoices);
@@ -189,6 +193,11 @@ void SpectrumPrefs::PopulateOrExchange(ShuttleGui & S)
*(int*)&mTempSettings.scaleType,
&mScaleChoices);
mAlgorithmChoice =
S.Id(ID_ALGORITHM).TieChoice(_("Algorithm") + wxString(wxT(":")),
*(int*)&mTempSettings.algorithm,
&mAlgorithmChoices);
mMinFreq =
S.Id(ID_MINIMUM).TieNumericTextBox(_("Mi&nimum Frequency (Hz):"),
mTempSettings.minFreq,
@@ -275,6 +284,8 @@ void SpectrumPrefs::PopulateOrExchange(ShuttleGui & S)
}
S.EndMultiColumn();
EnableDisableSTFTOnlyControls();
mPopulating = false;
}
@@ -428,6 +439,24 @@ void SpectrumPrefs::OnDefaults(wxCommandEvent &)
}
}
void SpectrumPrefs::OnAlgorithm(wxCommandEvent &evt)
{
EnableDisableSTFTOnlyControls();
OnControl(evt);
}
void SpectrumPrefs::EnableDisableSTFTOnlyControls()
{
// Enable or disable other controls that are applicable only to STFT.
const bool STFT = (mAlgorithmChoice->GetSelection() == 0);
mGain->Enable(STFT);
mRange->Enable(STFT);
mFrequencyGain->Enable(STFT);
#ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
mZeroPaddingChoiceCtrl->Enable(STFT);
#endif
}
void SpectrumPrefs::OnApply(wxCommandEvent &)
{
if (Validate()) {
@@ -439,6 +468,7 @@ void SpectrumPrefs::OnApply(wxCommandEvent &)
BEGIN_EVENT_TABLE(SpectrumPrefs, PrefsPanel)
EVT_CHOICE(ID_WINDOW_SIZE, SpectrumPrefs::OnWindowSize)
EVT_CHECKBOX(ID_DEFAULTS, SpectrumPrefs::OnDefaults)
EVT_CHOICE(ID_ALGORITHM, SpectrumPrefs::OnAlgorithm)
// Several controls with common routine that unchecks the default box
EVT_CHOICE(ID_WINDOW_TYPE, SpectrumPrefs::OnControl)

View File

@@ -54,9 +54,12 @@ class SpectrumPrefs:public PrefsPanel
void OnControl(wxCommandEvent &event);
void OnWindowSize(wxCommandEvent &event);
void OnDefaults(wxCommandEvent&);
void OnAlgorithm(wxCommandEvent &);
void OnApply(wxCommandEvent &);
DECLARE_EVENT_TABLE()
void EnableDisableSTFTOnlyControls();
WaveTrack *const mWt;
bool mDefaulted;
@@ -70,12 +73,16 @@ class SpectrumPrefs:public PrefsPanel
#ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
int mZeroPaddingChoice;
wxChoice *mZeroPaddingChoiceCtrl;
wxArrayString mZeroPaddingChoices;
#endif
wxArrayString mTypeChoices;
wxArrayString mScaleChoices;
wxChoice *mAlgorithmChoice;
wxArrayString mAlgorithmChoices;
#ifdef EXPERIMENTAL_FIND_NOTES
wxTextCtrl *mFindNotesMinA;
@@ -98,5 +105,4 @@ public:
private:
WaveTrack *const mWt;
};
#endif

View File

@@ -68,9 +68,6 @@ void TracksPrefs::Populate()
mViewChoices.Add(_("Spectrum"));
mViewCodes.Add(WaveTrack::Spectrum);
mViewChoices.Add(_("Pitch (EAC)"));
mViewCodes.Add(int(WaveTrack::PitchDisplay));
//------------------------- Main section --------------------
// Now construct the GUI itself.
// Use 'eIsCreatingFromPrefs' so that the GUI is