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 #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
121 private:
122  int zeroPaddingFactor;
123 public:
124  size_t ZeroPaddingFactor() const {
125  return algorithm == algPitchEAC ? 1 : zeroPaddingFactor;
126  }
127 #endif
128 
129  size_t GetFFTLength() const; // window size (times zero padding, if STFT)
130  size_t NBins() const;
131 
132  enum ColorScheme : int {
133  // Keep in correspondence with AColor::colorSchemes, AColor::gradient_pre
134  csColorNew = 0,
138 
140  };
142 
143  class ColorSchemeEnumSetting : public EnumSetting< ColorScheme > {
145  void Migrate(wxString &value) override;
146  };
148 
150 
151 #ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
152  bool spectralSelection; // But should this vary per track? -- PRL
153 #endif
154 
155  typedef int Algorithm;
156  enum AlgorithmValues : int {
157  algSTFT = 0,
160 
162  };
164 
165 #ifdef EXPERIMENTAL_FFT_Y_GRID
166  bool fftYGrid;
167 #endif //EXPERIMENTAL_FFT_Y_GRID
168 
169 #ifdef EXPERIMENTAL_FIND_NOTES
170  bool fftFindNotes;
171  double findNotesMinA;
172  int numberOfMaxima;
173  bool findNotesQuantize;
174 #endif //EXPERIMENTAL_FIND_NOTES
175 
176  // Following fields are derived from preferences.
177 
178  // Variables used for computing the spectrum
179  mutable HFFT hFFT;
180  mutable Floats window;
181 
182  // Two other windows for computing reassigned spectrogram
183  mutable Floats tWindow; // Window times time parameter
184  mutable Floats dWindow; // Derivative of window
185 };
186 #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
TranslatableStrings
std::vector< TranslatableString > TranslatableStrings
Definition: TranslatableString.h:295
SpectrogramSettings::colorSchemeSetting
static ColorSchemeEnumSetting colorSchemeSetting
Definition: SpectrogramSettings.h:147
SpectrogramSettings::stNumScaleTypes
@ stNumScaleTypes
Definition: SpectrogramSettings.h:66
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:163
PrefsListener
A listener notified of changes in preferences.
Definition: Prefs.h:389
SpectrogramSettings::stBark
@ stBark
Definition: SpectrogramSettings.h:62
SpectrogramSettings::csGrayscale
@ csGrayscale
Definition: SpectrogramSettings.h:136
SpectrogramSettings::Algorithm
int Algorithm
Definition: SpectrogramSettings.h:155
EnumValueSymbols
Definition: Prefs.h:239
SpectrogramSettings::windowSize
int windowSize
Definition: SpectrogramSettings.h:116
SpectrogramSettings::spectralSelection
bool spectralSelection
Definition: SpectrogramSettings.h:152
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:132
SpectrogramSettings::AlgorithmValues
AlgorithmValues
Definition: SpectrogramSettings.h:156
SpectrumPrefs
A PrefsPanel for spectrum settings.
Definition: SpectrumPrefs.h:42
SpectrogramSettings::ScaleType
int ScaleType
Definition: SpectrogramSettings.h:57
SpectrogramSettings::csInvGrayscale
@ csInvGrayscale
Definition: SpectrogramSettings.h:137
SpectrogramSettings::WindowSize
size_t WindowSize() const
Definition: SpectrogramSettings.h:118
SpectrogramSettings::scaleType
ScaleType scaleType
Definition: SpectrogramSettings.h:149
SpectrogramSettings::stLinear
@ stLinear
Definition: SpectrogramSettings.h:59
SpectrogramSettings::csNumColorScheme
@ csNumColorScheme
Definition: SpectrogramSettings.h:139
SpectrogramSettings::stLogarithmic
@ stLogarithmic
Definition: SpectrogramSettings.h:60
SpectrogramSettings::colorScheme
ColorScheme colorScheme
Definition: SpectrogramSettings.h:141
SpectrogramSettings::IsDefault
bool IsDefault() const
Definition: SpectrogramSettings.h:79
FFTParam
Definition: RealFFTf.h:7
SpectrogramSettings::tWindow
Floats tWindow
Definition: SpectrogramSettings.h:183
SpectrogramSettings::algNumAlgorithms
@ algNumAlgorithms
Definition: SpectrogramSettings.h:161
SpectrogramSettings::algPitchEAC
@ algPitchEAC
Definition: SpectrogramSettings.h:159
SpectrogramSettings::window
Floats window
Definition: SpectrogramSettings.h:180
SpectrogramSettings::algReassignment
@ algReassignment
Definition: SpectrogramSettings.h:158
SpectrogramSettings::ColorSchemeEnumSetting
Definition: SpectrogramSettings.h:143
HFFT
std::unique_ptr< FFTParam, FFTDeleter > HFFT
Definition: RealFFTf.h:22
EnumSetting
Adapts EnumSettingBase to a particular enumeration type.
Definition: Prefs.h:351
NumberScale
Definition: NumberScale.h:32
Prefs.h
SpectrogramSettings::hFFT
HFFT hFFT
Definition: SpectrogramSettings.h:179
SpectrogramSettings::dWindow
Floats dWindow
Definition: SpectrogramSettings.h:184
SpectrogramSettings::csColorTheme
@ csColorTheme
Definition: SpectrogramSettings.h:135
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