Audacity  3.0.3
SpectrogramSettings.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 SpectrogramSettings.h
6 
7 Paul Licameli
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_SPECTROGRAM_SETTINGS__
12 #define __AUDACITY_SPECTROGRAM_SETTINGS__
13 
14 #include "Prefs.h"
15 #include "SampleFormat.h"
16 #include "RealFFTf.h"
17 
18 #undef SPECTRAL_SELECTION_GLOBAL_SWITCH
19 
20 class EnumValueSymbols;
21 struct FFTParam;
22 class NumberScale;
23 class SpectrumPrefs;
24 class wxArrayStringEx;
25 
26 class AUDACITY_DLL_API SpectrogramSettings : public PrefsListener
27 {
28  friend class SpectrumPrefs;
29 public:
30 
31  // Singleton for settings that are not per-track
32  class AUDACITY_DLL_API Globals
33  {
34  public:
35  static Globals &Get();
36  void SavePrefs();
37 
38 #ifdef SPECTRAL_SELECTION_GLOBAL_SWITCH
39  bool spectralSelection;
40 #endif
41 
42  private:
43  Globals();
44  void LoadPrefs();
45  };
46 
47  enum {
48  LogMinWindowSize = 3,
49  LogMaxWindowSize = 15,
50 
51  NumWindowSizes = LogMaxWindowSize - LogMinWindowSize + 1,
52  };
53 
54  // Do not assume that this enumeration will remain the
55  // same as NumberScaleType in future. That enum may become
56  // more general purpose.
57  typedef int ScaleType;
58  enum ScaleTypeValues : int {
65 
67  };
68 
69  static const EnumValueSymbols &GetScaleNames();
70  static const EnumValueSymbols &GetColorSchemeNames();
71  static const TranslatableStrings &GetAlgorithmNames();
72 
73  static SpectrogramSettings &defaults();
76  SpectrogramSettings& operator= (const SpectrogramSettings &other);
78 
79  bool IsDefault() const
80  {
81  return this == &defaults();
82  }
83 
84  bool Validate(bool quiet);
85  void LoadPrefs();
86  void SavePrefs();
87 
88  void UpdatePrefs() override;
89 
90  void InvalidateCaches();
91  void DestroyWindows();
92  void CacheWindows() const;
93  void ConvertToEnumeratedWindowSizes();
94  void ConvertToActualWindowSizes();
95 
96  // Need to be told what the bin unit is, as this structure does not know
97  // the rate
98  float findBin( float frequency, float binUnit ) const;
99 
100  // If "bins" is false, units are Hz
101  NumberScale GetScale( float minFreq, float maxFreq ) const;
102 
103  int minFreq;
104  int maxFreq;
105 
106  bool SpectralSelectionEnabled() const;
107 
108 public:
109  int range;
110  int gain;
112 
114 
115 private:
117 public:
118  size_t WindowSize() const { return windowSize; }
119 
120 private:
122 public:
123  size_t ZeroPaddingFactor() const {
124  return algorithm == algPitchEAC ? 1 : zeroPaddingFactor;
125  }
126 
127  size_t GetFFTLength() const; // window size (times zero padding, if STFT)
128  size_t NBins() const;
129 
130  enum ColorScheme : int {
131  // Keep in correspondence with AColor::colorSchemes, AColor::gradient_pre
132  csColorNew = 0,
136 
138  };
140 
141  class ColorSchemeEnumSetting : public EnumSetting< ColorScheme > {
143  void Migrate(wxString &value) override;
144  };
146 
148 
149 #ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
150  bool spectralSelection; // But should this vary per track? -- PRL
151 #endif
152 
153  typedef int Algorithm;
154  enum AlgorithmValues : int {
155  algSTFT = 0,
158 
160  };
162 
163 #ifdef EXPERIMENTAL_FFT_Y_GRID
164  bool fftYGrid;
165 #endif //EXPERIMENTAL_FFT_Y_GRID
166 
167 #ifdef EXPERIMENTAL_FIND_NOTES
168  bool fftFindNotes;
169  double findNotesMinA;
170  int numberOfMaxima;
171  bool findNotesQuantize;
172 #endif //EXPERIMENTAL_FIND_NOTES
173 
174  // Following fields are derived from preferences.
175 
176  // Variables used for computing the spectrum
177  mutable HFFT hFFT;
178  mutable Floats window;
179 
180  // Two other windows for computing reassigned spectrogram
181  mutable Floats tWindow; // Window times time parameter
182  mutable Floats dWindow; // Derivative of window
183 };
184 
185 extern AUDACITY_DLL_API IntSetting SpectrumMaxFreq;
186 
187 #endif
SpectrogramSettings::maxFreq
int maxFreq
Definition: SpectrogramSettings.h:104
SpectrogramSettings
Spectrogram settings, either for one track or as defaults.
Definition: SpectrogramSettings.h:27
SpectrogramSettings::stErb
@ stErb
Definition: SpectrogramSettings.h:63
SpectrogramSettings::windowType
int windowType
Definition: SpectrogramSettings.h:113
SpectrogramSettings::gain
int gain
Definition: SpectrogramSettings.h:110
IntSetting
Specialization of Setting for int.
Definition: Prefs.h:214
TranslatableStrings
std::vector< TranslatableString > TranslatableStrings
Definition: TranslatableString.h:295
SpectrogramSettings::colorSchemeSetting
static ColorSchemeEnumSetting colorSchemeSetting
Definition: SpectrogramSettings.h:145
SpectrogramSettings::stNumScaleTypes
@ stNumScaleTypes
Definition: SpectrogramSettings.h:66
SpectrogramSettings::ZeroPaddingFactor
size_t ZeroPaddingFactor() const
Definition: SpectrogramSettings.h:123
SpectrogramSettings::stMel
@ stMel
Definition: SpectrogramSettings.h:61
SpectrogramSettings::Globals
Definition: SpectrogramSettings.h:33
RealFFTf.h
TrackInfo::UpdatePrefs
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
SpectrogramSettings::ScaleTypeValues
ScaleTypeValues
Definition: SpectrogramSettings.h:58
SpectrogramSettings::range
int range
Definition: SpectrogramSettings.h:109
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
SpectrogramSettings::algorithm
Algorithm algorithm
Definition: SpectrogramSettings.h:161
PrefsListener
A listener notified of changes in preferences.
Definition: Prefs.h:392
SpectrogramSettings::stBark
@ stBark
Definition: SpectrogramSettings.h:62
SpectrogramSettings::csGrayscale
@ csGrayscale
Definition: SpectrogramSettings.h:134
SpectrogramSettings::Algorithm
int Algorithm
Definition: SpectrogramSettings.h:153
EnumValueSymbols
Definition: Prefs.h:239
SpectrogramSettings::windowSize
int windowSize
Definition: SpectrogramSettings.h:116
SpectrogramSettings::spectralSelection
bool spectralSelection
Definition: SpectrogramSettings.h:150
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
SpectrogramSettings::ColorScheme
ColorScheme
Definition: SpectrogramSettings.h:130
SpectrumMaxFreq
AUDACITY_DLL_API IntSetting SpectrumMaxFreq
Definition: SpectrogramSettings.cpp:31
SpectrogramSettings::AlgorithmValues
AlgorithmValues
Definition: SpectrogramSettings.h:154
SpectrumPrefs
A PrefsPanel for spectrum settings.
Definition: SpectrumPrefs.h:42
SpectrogramSettings::ScaleType
int ScaleType
Definition: SpectrogramSettings.h:57
SpectrogramSettings::csInvGrayscale
@ csInvGrayscale
Definition: SpectrogramSettings.h:135
SpectrogramSettings::WindowSize
size_t WindowSize() const
Definition: SpectrogramSettings.h:118
SpectrogramSettings::scaleType
ScaleType scaleType
Definition: SpectrogramSettings.h:147
SpectrogramSettings::stLinear
@ stLinear
Definition: SpectrogramSettings.h:59
SpectrogramSettings::csNumColorScheme
@ csNumColorScheme
Definition: SpectrogramSettings.h:137
SpectrogramSettings::stLogarithmic
@ stLogarithmic
Definition: SpectrogramSettings.h:60
SpectrogramSettings::colorScheme
ColorScheme colorScheme
Definition: SpectrogramSettings.h:139
SpectrogramSettings::IsDefault
bool IsDefault() const
Definition: SpectrogramSettings.h:79
FFTParam
Definition: RealFFTf.h:7
SpectrogramSettings::tWindow
Floats tWindow
Definition: SpectrogramSettings.h:181
SpectrogramSettings::algNumAlgorithms
@ algNumAlgorithms
Definition: SpectrogramSettings.h:159
SpectrogramSettings::algPitchEAC
@ algPitchEAC
Definition: SpectrogramSettings.h:157
SpectrogramSettings::window
Floats window
Definition: SpectrogramSettings.h:178
SpectrogramSettings::zeroPaddingFactor
int zeroPaddingFactor
Definition: SpectrogramSettings.h:121
SpectrogramSettings::algReassignment
@ algReassignment
Definition: SpectrogramSettings.h:156
SpectrogramSettings::ColorSchemeEnumSetting
Definition: SpectrogramSettings.h:141
HFFT
std::unique_ptr< FFTParam, FFTDeleter > HFFT
Definition: RealFFTf.h:22
EnumSetting
Adapts EnumSettingBase to a particular enumeration type.
Definition: Prefs.h:354
NumberScale
Definition: NumberScale.h:31
Prefs.h
SpectrogramSettings::hFFT
HFFT hFFT
Definition: SpectrogramSettings.h:177
SpectrogramSettings::dWindow
Floats dWindow
Definition: SpectrogramSettings.h:182
SpectrogramSettings::csColorTheme
@ csColorTheme
Definition: SpectrogramSettings.h:133
SpectrogramSettings::stPeriod
@ stPeriod
Definition: SpectrogramSettings.h:64
SpectrogramSettings::frequencyGain
int frequencyGain
Definition: SpectrogramSettings.h:111
SampleFormat.h
ArrayOf< float >
SpectrogramSettings::minFreq
int minFreq
Definition: SpectrogramSettings.h:103