Audacity  3.0.3
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes | Friends | List of all members
SpectrogramSettings Class Reference

Spectrogram settings, either for one track or as defaults. More...

#include <SpectrogramSettings.h>

Inheritance diagram for SpectrogramSettings:
[legend]
Collaboration diagram for SpectrogramSettings:
[legend]

Classes

class  ColorSchemeEnumSetting
 
class  Globals
 

Public Types

enum  { LogMinWindowSize = 3, LogMaxWindowSize = 15, NumWindowSizes = LogMaxWindowSize - LogMinWindowSize + 1 }
 
enum  ScaleTypeValues : int {
  stLinear, stLogarithmic, stMel, stBark,
  stErb, stPeriod, stNumScaleTypes
}
 
enum  ColorScheme : int {
  csColorNew = 0, csColorTheme, csGrayscale, csInvGrayscale,
  csNumColorScheme
}
 
enum  AlgorithmValues : int { algSTFT = 0, algReassignment, algPitchEAC, algNumAlgorithms }
 
typedef int ScaleType
 
typedef int Algorithm
 

Public Member Functions

 SpectrogramSettings ()
 
 SpectrogramSettings (const SpectrogramSettings &other)
 
SpectrogramSettingsoperator= (const SpectrogramSettings &other)
 
 ~SpectrogramSettings ()
 
bool IsDefault () const
 
bool Validate (bool quiet)
 
void LoadPrefs ()
 
void SavePrefs ()
 
void UpdatePrefs () override
 
void InvalidateCaches ()
 
void DestroyWindows ()
 
void CacheWindows () const
 
void ConvertToEnumeratedWindowSizes ()
 
void ConvertToActualWindowSizes ()
 
float findBin (float frequency, float binUnit) const
 
NumberScale GetScale (float minFreq, float maxFreq) const
 
bool SpectralSelectionEnabled () const
 
size_t WindowSize () const
 
size_t GetFFTLength () const
 
size_t NBins () const
 
- Public Member Functions inherited from PrefsListener
 PrefsListener ()
 
virtual ~PrefsListener ()
 

Static Public Member Functions

static const EnumValueSymbolsGetScaleNames ()
 
static const EnumValueSymbolsGetColorSchemeNames ()
 
static const TranslatableStringsGetAlgorithmNames ()
 
static SpectrogramSettingsdefaults ()
 
- Static Public Member Functions inherited from PrefsListener
static void Broadcast (int id=0)
 Call this static function to notify all PrefsListener objects. More...
 

Public Attributes

int minFreq
 
int maxFreq
 
int range
 
int gain
 
int frequencyGain
 
int windowType
 
ColorScheme colorScheme
 
ScaleType scaleType
 
bool spectralSelection
 
Algorithm algorithm
 
HFFT hFFT
 
Floats window
 
Floats tWindow
 
Floats dWindow
 

Static Public Attributes

static ColorSchemeEnumSetting colorSchemeSetting
 

Private Attributes

int windowSize
 

Friends

class SpectrumPrefs
 

Additional Inherited Members

- Protected Member Functions inherited from PrefsListener
virtual void UpdateSelectedPrefs (int id)
 

Detailed Description

Spectrogram settings, either for one track or as defaults.

Definition at line 26 of file SpectrogramSettings.h.

Member Typedef Documentation

◆ Algorithm

Definition at line 155 of file SpectrogramSettings.h.

◆ ScaleType

Definition at line 57 of file SpectrogramSettings.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
LogMinWindowSize 
LogMaxWindowSize 
NumWindowSizes 

Definition at line 47 of file SpectrogramSettings.h.

47  {
48  LogMinWindowSize = 3,
49  LogMaxWindowSize = 15,
50 
52  };

◆ AlgorithmValues

Enumerator
algSTFT 
algReassignment 
algPitchEAC 
algNumAlgorithms 

Definition at line 156 of file SpectrogramSettings.h.

156  : int {
157  algSTFT = 0,
159  algPitchEAC,
160 
162  };

◆ ColorScheme

Enumerator
csColorNew 
csColorTheme 
csGrayscale 
csInvGrayscale 
csNumColorScheme 

Definition at line 132 of file SpectrogramSettings.h.

132  : int {
133  // Keep in correspondence with AColor::colorSchemes, AColor::gradient_pre
134  csColorNew = 0,
135  csColorTheme,
136  csGrayscale,
138 
140  };

◆ ScaleTypeValues

Enumerator
stLinear 
stLogarithmic 
stMel 
stBark 
stErb 
stPeriod 
stNumScaleTypes 

Definition at line 58 of file SpectrogramSettings.h.

58  : int {
59  stLinear,
61  stMel,
62  stBark,
63  stErb,
64  stPeriod,
65 
67  };

Constructor & Destructor Documentation

◆ SpectrogramSettings() [1/2]

SpectrogramSettings::SpectrogramSettings ( )

Definition at line 58 of file SpectrogramSettings.cpp.

59 {
60  LoadPrefs();
61 }

References LoadPrefs().

Here is the call graph for this function:

◆ SpectrogramSettings() [2/2]

SpectrogramSettings::SpectrogramSettings ( const SpectrogramSettings other)

Definition at line 63 of file SpectrogramSettings.cpp.

64  : minFreq(other.minFreq)
65  , maxFreq(other.maxFreq)
66  , range(other.range)
67  , gain(other.gain)
69  , windowType(other.windowType)
70  , windowSize(other.windowSize)
71 #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
72  , zeroPaddingFactor(other.zeroPaddingFactor)
73 #endif
74  , colorScheme(other.colorScheme)
75  , scaleType(other.scaleType)
76 #ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
78 #endif
79  , algorithm(other.algorithm)
80 #ifdef EXPERIMENTAL_FFT_Y_GRID
81  , fftYGrid(other.fftYGrid)
82 #endif
83 #ifdef EXPERIMENTAL_FIND_NOTES
84  , fftFindNotes(other.fftFindNotes)
85  , findNotesMinA(other.findNotesMinA)
86  , numberOfMaxima(other.numberOfMaxima)
87  , findNotesQuantize(other.findNotesQuantize)
88 #endif
89 
90  // Do not copy these!
91  , hFFT{}
92  , window{}
93  , tWindow{}
94  , dWindow{}
95 {
96 }

◆ ~SpectrogramSettings()

SpectrogramSettings::~SpectrogramSettings ( )

Definition at line 472 of file SpectrogramSettings.cpp.

473 {
474  DestroyWindows();
475 }

References DestroyWindows().

Here is the call graph for this function:

Member Function Documentation

◆ CacheWindows()

void SpectrogramSettings::CacheWindows ( ) const

Definition at line 542 of file SpectrogramSettings.cpp.

543 {
544  if (hFFT == NULL || window == NULL) {
545 
546  double scale;
547  auto factor = ZeroPaddingFactor();
548  const auto fftLen = WindowSize() * factor;
549  const auto padding = (WindowSize() * (factor - 1)) / 2;
550 
551  hFFT = GetFFT(fftLen);
552  RecreateWindow(window, WINDOW, fftLen, padding, windowType, windowSize, scale);
553  if (algorithm == algReassignment) {
554  RecreateWindow(tWindow, TWINDOW, fftLen, padding, windowType, windowSize, scale);
555  RecreateWindow(dWindow, DWINDOW, fftLen, padding, windowType, windowSize, scale);
556  }
557  }
558 }

References algorithm, algReassignment, anonymous_namespace{SpectrogramSettings.cpp}::DWINDOW, dWindow, GetFFT(), hFFT, anonymous_namespace{SpectrogramSettings.cpp}::RecreateWindow(), anonymous_namespace{SpectrogramSettings.cpp}::TWINDOW, tWindow, anonymous_namespace{SpectrogramSettings.cpp}::WINDOW, window, windowSize, WindowSize(), and windowType.

Here is the call graph for this function:

◆ ConvertToActualWindowSizes()

void SpectrogramSettings::ConvertToActualWindowSizes ( )

Definition at line 584 of file SpectrogramSettings.cpp.

585 {
587 #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
588  zeroPaddingFactor = 1 << zeroPaddingFactor;
589 #endif
590 }

References LogMinWindowSize, and windowSize.

Referenced by SpectrumPrefs::Preview(), SpectrumPrefs::Validate(), and Validate().

Here is the caller graph for this function:

◆ ConvertToEnumeratedWindowSizes()

void SpectrogramSettings::ConvertToEnumeratedWindowSizes ( )

Definition at line 560 of file SpectrogramSettings.cpp.

561 {
562  unsigned size;
563  int logarithm;
564 
565  logarithm = -LogMinWindowSize;
566  size = unsigned(windowSize);
567  while (size > 1)
568  size >>= 1, ++logarithm;
569  windowSize = std::max(0, std::min(NumWindowSizes - 1, logarithm));
570 
571 #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
572  // Choices for zero padding begin at 1
573  logarithm = 0;
574  size = unsigned(zeroPaddingFactor);
575  while (zeroPaddingFactor > 1)
576  zeroPaddingFactor >>= 1, ++logarithm;
577  zeroPaddingFactor = std::max(0,
579  logarithm
580  ));
581 #endif
582 }

References LogMaxWindowSize, LogMinWindowSize, min(), NumWindowSizes, and windowSize.

Referenced by SpectrumPrefs::OnDefaults(), SpectrumPrefs::Preview(), SpectrumPrefs::Validate(), and Validate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ defaults()

SpectrogramSettings & SpectrogramSettings::defaults ( )
static

Definition at line 133 of file SpectrogramSettings.cpp.

134 {
135  static SpectrogramSettings instance;
136  return instance;
137 }

Referenced by SpectrumPrefs::Commit(), WaveTrack::GetIndependentSpectrogramSettings(), WaveTrack::GetSpectrogramSettings(), SpectrumPrefs::OnDefaults(), SpectrumPrefs::Preview(), SpectrumPrefs::Rollback(), and UpdatePrefs().

Here is the caller graph for this function:

◆ DestroyWindows()

void SpectrogramSettings::DestroyWindows ( )

Definition at line 477 of file SpectrogramSettings.cpp.

478 {
479  hFFT.reset();
480  window.reset();
481  dWindow.reset();
482  tWindow.reset();
483 }

References dWindow, hFFT, tWindow, and window.

Referenced by InvalidateCaches(), operator=(), and ~SpectrogramSettings().

Here is the caller graph for this function:

◆ findBin()

float SpectrogramSettings::findBin ( float  frequency,
float  binUnit 
) const

Definition at line 592 of file SpectrogramSettings.cpp.

593 {
594  float linearBin = frequency / binUnit;
595  if (linearBin < 0)
596  return -1;
597  else
598  return linearBin;
599 }

◆ GetAlgorithmNames()

const TranslatableStrings & SpectrogramSettings::GetAlgorithmNames ( )
static

Definition at line 200 of file SpectrogramSettings.cpp.

201 {
202  static const TranslatableStrings results{
203  // Keep in correspondence with enum SpectrogramSettings::Algorithm:
204  XO("Frequencies") ,
205  /* i18n-hint: the Reassignment algorithm for spectrograms */
206  XO("Reassignment") ,
207  /* i18n-hint: EAC abbreviates "Enhanced Autocorrelation" */
208  XO("Pitch (EAC)") ,
209  };
210  return results;
211 }

References XO.

Referenced by SpectrumPrefs::PopulateOrExchange().

Here is the caller graph for this function:

◆ GetColorSchemeNames()

const EnumValueSymbols & SpectrogramSettings::GetColorSchemeNames ( )
static

Definition at line 159 of file SpectrogramSettings.cpp.

160 {
161  static const EnumValueSymbols result{
162  // Keep in correspondence with enum SpectrogramSettings::ColorScheme:
163  /* i18n-hint: New color scheme for spectrograms */
164  { wxT("SpecColorNew"), XC("Color (default)", "spectrum prefs") },
165  /* i18n-hint: Classic color scheme(from theme) for spectrograms */
166  { wxT("SpecColorTheme"), XC("Color (classic)", "spectrum prefs") },
167  /* i18n-hint: Grayscale color scheme for spectrograms */
168  { wxT("SpecGrayscale"), XC("Grayscale", "spectrum prefs") },
169  /* i18n-hint: Inverse grayscale color scheme for spectrograms */
170  { wxT("SpecInvGrayscale"), XC("Inverse grayscale", "spectrum prefs") },
171  };
172 
173  wxASSERT(csNumColorScheme == result.size());
174  static_assert(csNumColorScheme == AColor::colorSchemes, "Broken correspondence");
175 
176  return result;
177 }

References AColor::colorSchemes, csNumColorScheme, and XC.

Referenced by SetTrackVisualsCommand::DefineParams(), SpectrogramSettings::ColorSchemeEnumSetting::Migrate(), SetTrackVisualsCommand::PopulateOrExchange(), and SpectrumPrefs::PopulateOrExchange().

Here is the caller graph for this function:

◆ GetFFTLength()

size_t SpectrogramSettings::GetFFTLength ( ) const

Definition at line 601 of file SpectrogramSettings.cpp.

602 {
603 #ifndef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
604  return windowSize;
605 #else
606  return windowSize * ((algorithm != algPitchEAC) ? zeroPaddingFactor : 1);
607 #endif
608 }

References algorithm, algPitchEAC, and windowSize.

Referenced by SpectrumVZoomHandle::DoZoom(), and NBins().

Here is the caller graph for this function:

◆ GetScale()

NumberScale SpectrogramSettings::GetScale ( float  minFreq,
float  maxFreq 
) const

Definition at line 616 of file SpectrogramSettings.cpp.

617 {
618  NumberScaleType type = nstLinear;
619 
620  // Don't assume the correspondence of the enums will remain direct in the future.
621  // Do this switch.
622  switch (scaleType) {
623  default:
624  wxASSERT(false);
625  case stLinear:
626  type = nstLinear; break;
627  case stLogarithmic:
628  type = nstLogarithmic; break;
629  case stMel:
630  type = nstMel; break;
631  case stBark:
632  type = nstBark; break;
633  case stErb:
634  type = nstErb; break;
635  case stPeriod:
636  type = nstPeriod; break;
637  }
638 
639  return NumberScale(type, minFreqIn, maxFreqIn);
640 }

References nstBark, nstErb, nstLinear, nstLogarithmic, nstMel, nstPeriod, scaleType, stBark, stErb, stLinear, stLogarithmic, stMel, and stPeriod.

Referenced by SpectrumVRulerControls::DoUpdateVRuler(), and SpectrumVZoomHandle::DoZoom().

Here is the caller graph for this function:

◆ GetScaleNames()

const EnumValueSymbols & SpectrogramSettings::GetScaleNames ( )
static

Definition at line 140 of file SpectrogramSettings.cpp.

141 {
142  static const EnumValueSymbols result{
143  // Keep in correspondence with enum SpectrogramSettings::ScaleType:
144  XO("Linear") ,
145  XO("Logarithmic") ,
146  /* i18n-hint: The name of a frequency scale in psychoacoustics */
147  XO("Mel") ,
148  /* i18n-hint: The name of a frequency scale in psychoacoustics, named for Heinrich Barkhausen */
149  XO("Bark") ,
150  /* i18n-hint: The name of a frequency scale in psychoacoustics, abbreviates Equivalent Rectangular Bandwidth */
151  XO("ERB") ,
152  /* i18n-hint: Time units, that is Period = 1 / Frequency */
153  XO("Period") ,
154  };
155  return result;
156 }

References XO.

Referenced by BeginSection(), and SpectrumPrefs::PopulateOrExchange().

Here is the caller graph for this function:

◆ InvalidateCaches()

void SpectrogramSettings::InvalidateCaches ( )

Definition at line 467 of file SpectrogramSettings.cpp.

468 {
469  DestroyWindows();
470 }

References DestroyWindows().

Referenced by LoadPrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsDefault()

bool SpectrogramSettings::IsDefault ( ) const
inline

Definition at line 79 of file SpectrogramSettings.h.

80  {
81  return this == &defaults();
82  }

◆ LoadPrefs()

void SpectrogramSettings::LoadPrefs ( )

Definition at line 284 of file SpectrogramSettings.cpp.

285 {
286  minFreq = gPrefs->Read(wxT("/Spectrum/MinFreq"), 0L);
287 
288  maxFreq = gPrefs->Read(wxT("/Spectrum/MaxFreq"), 8000L);
289 
290  range = gPrefs->Read(wxT("/Spectrum/Range"), 80L);
291  gain = gPrefs->Read(wxT("/Spectrum/Gain"), 20L);
292  frequencyGain = gPrefs->Read(wxT("/Spectrum/FrequencyGain"), 0L);
293 
294  windowSize = gPrefs->Read(wxT("/Spectrum/FFTSize"), 1024);
295 
296 #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
297  zeroPaddingFactor = gPrefs->Read(wxT("/Spectrum/ZeroPaddingFactor"), 1);
298 #endif
299 
300  gPrefs->Read(wxT("/Spectrum/WindowType"), &windowType, eWinFuncHann);
301 
303 
304  scaleType = ScaleType(gPrefs->Read(wxT("/Spectrum/ScaleType"), 0L));
305 
306 #ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
307  spectralSelection = (gPrefs->Read(wxT("/Spectrum/EnableSpectralSelection"), 1L) != 0);
308 #endif
309 
310  algorithm = Algorithm(gPrefs->Read(wxT("/Spectrum/Algorithm"), 0L));
311 
312 #ifdef EXPERIMENTAL_FFT_Y_GRID
313  fftYGrid = (gPrefs->Read(wxT("/Spectrum/FFTYGrid"), 0L) != 0);
314 #endif //EXPERIMENTAL_FFT_Y_GRID
315 
316 #ifdef EXPERIMENTAL_FIND_NOTES
317  fftFindNotes = (gPrefs->Read(wxT("/Spectrum/FFTFindNotes"), 0L) != 0);
318  findNotesMinA = gPrefs->Read(wxT("/Spectrum/FindNotesMinA"), -30.0);
319  numberOfMaxima = gPrefs->Read(wxT("/Spectrum/FindNotesN"), 5L);
320  findNotesQuantize = (gPrefs->Read(wxT("/Spectrum/FindNotesQuantize"), 0L) != 0);
321 #endif //EXPERIMENTAL_FIND_NOTES
322 
323  // Enforce legal values
324  Validate(true);
325 
327 }

References algorithm, colorScheme, colorSchemeSetting, eWinFuncHann, frequencyGain, gain, gPrefs, InvalidateCaches(), maxFreq, minFreq, range, EnumSetting< Enum >::ReadEnum(), scaleType, spectralSelection, Validate(), windowSize, and windowType.

Referenced by SpectrumPrefs::Commit(), and SpectrogramSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NBins()

size_t SpectrogramSettings::NBins ( ) const

Definition at line 610 of file SpectrogramSettings.cpp.

611 {
612  // Omit the Nyquist frequency bin
613  return GetFFTLength() / 2;
614 }

References GetFFTLength().

Here is the call graph for this function:

◆ operator=()

SpectrogramSettings & SpectrogramSettings::operator= ( const SpectrogramSettings other)

Definition at line 98 of file SpectrogramSettings.cpp.

99 {
100  if (this != &other) {
101  minFreq = other.minFreq;
102  maxFreq = other.maxFreq;
103  range = other.range;
104  gain = other.gain;
106  windowType = other.windowType;
107  windowSize = other.windowSize;
108 #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
109  zeroPaddingFactor = other.zeroPaddingFactor;
110 #endif
111  colorScheme = other.colorScheme;
112  scaleType = other.scaleType;
113 #ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
115 #endif
116  algorithm = other.algorithm;
117 #ifdef EXPERIMENTAL_FFT_Y_GRID
118  fftYGrid = other.fftYGrid;
119 #endif
120 #ifdef EXPERIMENTAL_FIND_NOTES
121  fftFindNotes = other.fftFindNotes;
122  findNotesMinA = other.findNotesMinA;
123  numberOfMaxima = other.numberOfMaxima;
124  findNotesQuantize = other.findNotesQuantize;
125 #endif
126 
127  // Invalidate the caches
128  DestroyWindows();
129  }
130  return *this;
131 }

References algorithm, colorScheme, DestroyWindows(), frequencyGain, gain, maxFreq, minFreq, range, scaleType, spectralSelection, windowSize, and windowType.

Here is the call graph for this function:

◆ SavePrefs()

void SpectrogramSettings::SavePrefs ( )

Definition at line 329 of file SpectrogramSettings.cpp.

330 {
331  gPrefs->Write(wxT("/Spectrum/MinFreq"), minFreq);
332  gPrefs->Write(wxT("/Spectrum/MaxFreq"), maxFreq);
333 
334  // Nothing wrote these. They only varied from the linear scale bounds in-session. -- PRL
335  // gPrefs->Write(wxT("/SpectrumLog/MaxFreq"), logMinFreq);
336  // gPrefs->Write(wxT("/SpectrumLog/MinFreq"), logMaxFreq);
337 
338  gPrefs->Write(wxT("/Spectrum/Range"), range);
339  gPrefs->Write(wxT("/Spectrum/Gain"), gain);
340  gPrefs->Write(wxT("/Spectrum/FrequencyGain"), frequencyGain);
341 
342  gPrefs->Write(wxT("/Spectrum/FFTSize"), windowSize);
343 
344 #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
345  gPrefs->Write(wxT("/Spectrum/ZeroPaddingFactor"), zeroPaddingFactor);
346 #endif
347 
348  gPrefs->Write(wxT("/Spectrum/WindowType"), windowType);
349 
351 
352  gPrefs->Write(wxT("/Spectrum/ScaleType"), (int) scaleType);
353 
354 #ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
355  gPrefs->Write(wxT("/Spectrum/EnableSpectralSelection"), spectralSelection);
356 #endif
357 
358  gPrefs->Write(wxT("/Spectrum/Algorithm"), (int) algorithm);
359 
360 #ifdef EXPERIMENTAL_FFT_Y_GRID
361  gPrefs->Write(wxT("/Spectrum/FFTYGrid"), fftYGrid);
362 #endif //EXPERIMENTAL_FFT_Y_GRID
363 
364 #ifdef EXPERIMENTAL_FIND_NOTES
365  gPrefs->Write(wxT("/Spectrum/FFTFindNotes"), fftFindNotes);
366  gPrefs->Write(wxT("/Spectrum/FindNotesMinA"), findNotesMinA);
367  gPrefs->Write(wxT("/Spectrum/FindNotesN"), numberOfMaxima);
368  gPrefs->Write(wxT("/Spectrum/FindNotesQuantize"), findNotesQuantize);
369 #endif //EXPERIMENTAL_FIND_NOTES
370 }

References algorithm, colorScheme, colorSchemeSetting, frequencyGain, gain, gPrefs, maxFreq, minFreq, range, scaleType, spectralSelection, windowSize, windowType, and EnumSetting< Enum >::WriteEnum().

Referenced by SpectrumPrefs::Commit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SpectralSelectionEnabled()

bool SpectrogramSettings::SpectralSelectionEnabled ( ) const

Definition at line 642 of file SpectrogramSettings.cpp.

643 {
644 #ifdef SPECTRAL_SELECTION_GLOBAL_SWITCH
645  return Globals::Get().spectralSelection;
646 #else
647  return spectralSelection;
648 #endif
649 }

References SpectrogramSettings::Globals::Get(), and spectralSelection.

Referenced by NyquistEffect::ProcessOne().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdatePrefs()

void SpectrogramSettings::UpdatePrefs ( )
overridevirtual

Implements PrefsListener.

Definition at line 373 of file SpectrogramSettings.cpp.

374 {
375  if (minFreq == defaults().minFreq) {
376  gPrefs->Read(wxT("/Spectrum/MinFreq"), &minFreq, 0L);
377  }
378 
379  if (maxFreq == defaults().maxFreq) {
380  gPrefs->Read(wxT("/Spectrum/MaxFreq"), &maxFreq, 8000L);
381  }
382 
383  if (range == defaults().range) {
384  gPrefs->Read(wxT("/Spectrum/Range"), &range, 80L);
385  }
386 
387  if (gain == defaults().gain) {
388  gPrefs->Read(wxT("/Spectrum/Gain"), &gain, 20L);
389  }
390 
392  gPrefs->Read(wxT("/Spectrum/FrequencyGain"), &frequencyGain, 0L);
393  }
394 
395  if (windowSize == defaults().windowSize) {
396  gPrefs->Read(wxT("/Spectrum/FFTSize"), &windowSize, 1024);
397  }
398 
399 #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
400  if (zeroPaddingFactor == defaults().zeroPaddingFactor) {
401  gPrefs->Read(wxT("/Spectrum/ZeroPaddingFactor"), &zeroPaddingFactor, 1);
402  }
403 #endif
404 
405  if (windowType == defaults().windowType) {
406  gPrefs->Read(wxT("/Spectrum/WindowType"), &windowType, eWinFuncHann);
407  }
408 
409  if (colorScheme == defaults().colorScheme) {
411  }
412 
413  if (scaleType == defaults().scaleType) {
414  int temp;
415  gPrefs->Read(wxT("/Spectrum/ScaleType"), &temp, 0L);
416  scaleType = ScaleType(temp);
417  }
418 
419 #ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
421  int temp;
422  gPrefs->Read(wxT("/Spectrum/EnableSpectralSelection"), &temp, 1L);
423  spectralSelection = (temp != 0);
424  }
425 #endif
426 
427  if (algorithm == defaults().algorithm) {
428  int temp;
429  gPrefs->Read(wxT("/Spectrum/Algorithm"), &temp, 0L);
430  algorithm = Algorithm(temp);
431  }
432 
433 #ifdef EXPERIMENTAL_FFT_Y_GRID
434  if (fftYGrid == defaults().fftYGrid) {
435  int temp;
436  gPrefs->Read(wxT("/Spectrum/FFTYGrid"), &temp, 0L);
437  fftYGrid = (temp != 0);
438  }
439 #endif //EXPERIMENTAL_FFT_Y_GRID
440 
441 #ifdef EXPERIMENTAL_FIND_NOTES
442  if (fftFindNotes == defaults().fftFindNotes) {
443  int temp;
444  gPrefs->Read(wxT("/Spectrum/FFTFindNotes"), &temp, 0L);
445  fftFindNotes = (temp != 0);
446  }
447 
448  if (findNotesMinA == defaults().findNotesMinA) {
449  gPrefs->Read(wxT("/Spectrum/FindNotesMinA"), &findNotesMinA, -30.0);
450  }
451 
452  if (numberOfMaxima == defaults().numberOfMaxima) {
453  numberOfMaxima = gPrefs->Read(wxT("/Spectrum/FindNotesN"), &numberOfMaxima, 5L);
454  }
455 
456  if (findNotesQuantize == defaults().findNotesQuantize) {
457  int temp;
458  gPrefs->Read(wxT("/Spectrum/FindNotesQuantize"), &temp, 0L);
459  findNotesQuantize = (temp != 0);
460  }
461 #endif //EXPERIMENTAL_FIND_NOTES
462 
463  // Enforce legal values
464  Validate(true);
465 }

References algorithm, colorScheme, colorSchemeSetting, defaults(), eWinFuncHann, frequencyGain, gain, gPrefs, maxFreq, minFreq, range, EnumSetting< Enum >::ReadEnum(), scaleType, spectralSelection, Validate(), windowSize, and windowType.

Here is the call graph for this function:

◆ Validate()

bool SpectrogramSettings::Validate ( bool  quiet)

Definition at line 213 of file SpectrogramSettings.cpp.

214 {
215  if (!quiet &&
216  maxFreq < 100) {
217  AudacityMessageBox( XO("Maximum frequency must be 100 Hz or above") );
218  return false;
219  }
220  else
221  maxFreq = std::max(100, maxFreq);
222 
223  if (!quiet &&
224  minFreq < 0) {
225  AudacityMessageBox( XO("Minimum frequency must be at least 0 Hz") );
226  return false;
227  }
228  else
229  minFreq = std::max(0, minFreq);
230 
231  if (!quiet &&
232  maxFreq <= minFreq) {
234 "Minimum frequency must be less than maximum frequency") );
235  return false;
236  }
237  else
238  maxFreq = std::max(1 + minFreq, maxFreq);
239 
240  if (!quiet &&
241  range <= 0) {
242  AudacityMessageBox( XO("The range must be at least 1 dB") );
243  return false;
244  }
245  else
246  range = std::max(1, range);
247 
248  if (!quiet &&
249  frequencyGain < 0) {
250  AudacityMessageBox( XO("The frequency gain cannot be negative") );
251  return false;
252  }
253  else if (!quiet &&
254  frequencyGain > 60) {
256 "The frequency gain must be no more than 60 dB/dec") );
257  return false;
258  }
259  else
260  frequencyGain =
261  std::max(0, std::min(60, frequencyGain));
262 
263  // The rest are controlled by drop-down menus so they can't go wrong
264  // in the Preferences dialog, but we also come here after reading fom saved
265  // preference files, which could be or from future versions. Validate quietly.
266  windowType =
267  std::max(0, std::min(NumWindowFuncs() - 1, windowType));
268  scaleType =
269  ScaleType(std::max(0,
271  (int)(scaleType))));
273  std::max(0, std::min<int>(csNumColorScheme-1, colorScheme))
274  );
276  std::max(0, std::min((int)(algNumAlgorithms) - 1, (int)(algorithm)))
277  );
280 
281  return true;
282 }

References algNumAlgorithms, algorithm, AudacityMessageBox(), colorScheme, ConvertToActualWindowSizes(), ConvertToEnumeratedWindowSizes(), csNumColorScheme, frequencyGain, maxFreq, min(), minFreq, NumWindowFuncs(), range, scaleType, stNumScaleTypes, windowType, and XO.

Referenced by LoadPrefs(), UpdatePrefs(), and SpectrumPrefs::Validate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WindowSize()

size_t SpectrogramSettings::WindowSize ( ) const
inline

Definition at line 118 of file SpectrogramSettings.h.

118 { return windowSize; }

Referenced by CacheWindows().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ SpectrumPrefs

friend class SpectrumPrefs
friend

Definition at line 28 of file SpectrogramSettings.h.

Member Data Documentation

◆ algorithm

Algorithm SpectrogramSettings::algorithm

◆ colorScheme

ColorScheme SpectrogramSettings::colorScheme

◆ colorSchemeSetting

SpectrogramSettings::ColorSchemeEnumSetting SpectrogramSettings::colorSchemeSetting
static
Initial value:
{
wxT("/Spectrum/ColorScheme"),
}

Definition at line 147 of file SpectrogramSettings.h.

Referenced by LoadPrefs(), SavePrefs(), and UpdatePrefs().

◆ dWindow

Floats SpectrogramSettings::dWindow
mutable

Definition at line 184 of file SpectrogramSettings.h.

Referenced by CacheWindows(), and DestroyWindows().

◆ frequencyGain

int SpectrogramSettings::frequencyGain

◆ gain

int SpectrogramSettings::gain

◆ hFFT

HFFT SpectrogramSettings::hFFT
mutable

Definition at line 179 of file SpectrogramSettings.h.

Referenced by CacheWindows(), and DestroyWindows().

◆ maxFreq

int SpectrogramSettings::maxFreq

◆ minFreq

int SpectrogramSettings::minFreq

◆ range

int SpectrogramSettings::range

◆ scaleType

ScaleType SpectrogramSettings::scaleType

◆ spectralSelection

bool SpectrogramSettings::spectralSelection

◆ tWindow

Floats SpectrogramSettings::tWindow
mutable

Definition at line 183 of file SpectrogramSettings.h.

Referenced by CacheWindows(), and DestroyWindows().

◆ window

Floats SpectrogramSettings::window
mutable

◆ windowSize

int SpectrogramSettings::windowSize
private

◆ windowType

int SpectrogramSettings::windowType

The documentation for this class was generated from the following files:
nstMel
@ nstMel
Definition: NumberScale.h:21
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
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption=XO("Message"), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: AudacityMessageBox.h:20
SpectrogramSettings::windowType
int windowType
Definition: SpectrogramSettings.h:113
SpectrogramSettings::gain
int gain
Definition: SpectrogramSettings.h:110
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
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::LogMinWindowSize
@ LogMinWindowSize
Definition: SpectrogramSettings.h:48
anonymous_namespace{SpectrogramSettings.cpp}::WINDOW
@ WINDOW
Definition: SpectrogramSettings.cpp:488
SpectrogramSettings::Validate
bool Validate(bool quiet)
Definition: SpectrogramSettings.cpp:213
NumWindowFuncs
int NumWindowFuncs()
Definition: FFT.cpp:329
SpectrogramSettings::stMel
@ stMel
Definition: SpectrogramSettings.h:61
nstLinear
@ nstLinear
Definition: NumberScale.h:19
XO
#define XO(s)
Definition: Internat.h:31
XC
#define XC(s, c)
Definition: Internat.h:37
SpectrogramSettings::GetColorSchemeNames
static const EnumValueSymbols & GetColorSchemeNames()
Definition: SpectrogramSettings.cpp:159
SpectrogramSettings::range
int range
Definition: SpectrogramSettings.h:109
SpectrogramSettings::DestroyWindows
void DestroyWindows()
Definition: SpectrogramSettings.cpp:477
SpectrogramSettings::algorithm
Algorithm algorithm
Definition: SpectrogramSettings.h:163
eWinFuncHann
@ eWinFuncHann
Definition: FFT.h:114
SpectrogramSettings::stBark
@ stBark
Definition: SpectrogramSettings.h:62
anonymous_namespace{SpectrogramSettings.cpp}::DWINDOW
@ DWINDOW
Definition: SpectrogramSettings.cpp:488
SpectrogramSettings::csGrayscale
@ csGrayscale
Definition: SpectrogramSettings.h:136
SpectrogramSettings::Algorithm
int Algorithm
Definition: SpectrogramSettings.h:155
EnumValueSymbols
Definition: Prefs.h:239
SpectrogramSettings::algSTFT
@ algSTFT
Definition: SpectrogramSettings.h:157
SpectrogramSettings::windowSize
int windowSize
Definition: SpectrogramSettings.h:116
SpectrogramSettings::spectralSelection
bool spectralSelection
Definition: SpectrogramSettings.h:152
SpectrogramSettings::ColorScheme
ColorScheme
Definition: SpectrogramSettings.h:132
SpectrogramSettings::NumWindowSizes
@ NumWindowSizes
Definition: SpectrogramSettings.h:51
SpectrogramSettings::Globals::Get
static Globals & Get()
Definition: SpectrogramSettings.cpp:52
SpectrogramSettings::InvalidateCaches
void InvalidateCaches()
Definition: SpectrogramSettings.cpp:467
SpectrogramSettings::GetFFTLength
size_t GetFFTLength() const
Definition: SpectrogramSettings.cpp:601
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
anonymous_namespace{SpectrogramSettings.cpp}::RecreateWindow
void RecreateWindow(Floats &window, int which, size_t fftLen, size_t padding, int windowType, size_t windowSize, double &scale)
Definition: SpectrogramSettings.cpp:489
SpectrogramSettings::csNumColorScheme
@ csNumColorScheme
Definition: SpectrogramSettings.h:139
SpectrogramSettings::stLogarithmic
@ stLogarithmic
Definition: SpectrogramSettings.h:60
SpectrogramSettings::LoadPrefs
void LoadPrefs()
Definition: SpectrogramSettings.cpp:284
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
SpectrogramSettings::colorScheme
ColorScheme colorScheme
Definition: SpectrogramSettings.h:141
nstPeriod
@ nstPeriod
Definition: NumberScale.h:24
nstBark
@ nstBark
Definition: NumberScale.h:22
EnumSetting::ReadEnum
Enum ReadEnum() const
Definition: Prefs.h:370
nstLogarithmic
@ nstLogarithmic
Definition: NumberScale.h:20
SpectrogramSettings::LogMaxWindowSize
@ LogMaxWindowSize
Definition: SpectrogramSettings.h:49
SpectrogramSettings::tWindow
Floats tWindow
Definition: SpectrogramSettings.h:183
SpectrogramSettings::algNumAlgorithms
@ algNumAlgorithms
Definition: SpectrogramSettings.h:161
nstErb
@ nstErb
Definition: NumberScale.h:23
SpectrogramSettings::algPitchEAC
@ algPitchEAC
Definition: SpectrogramSettings.h:159
SpectrogramSettings::window
Floats window
Definition: SpectrogramSettings.h:180
anonymous_namespace{SpectrogramSettings.cpp}::TWINDOW
@ TWINDOW
Definition: SpectrogramSettings.cpp:488
SpectrogramSettings::algReassignment
@ algReassignment
Definition: SpectrogramSettings.h:158
AColor::colorSchemes
static const int colorSchemes
Definition: AColor.h:126
SpectrogramSettings::ConvertToActualWindowSizes
void ConvertToActualWindowSizes()
Definition: SpectrogramSettings.cpp:584
NumberScale
Definition: NumberScale.h:32
NumberScaleType
NumberScaleType
Definition: NumberScale.h:18
GetFFT
HFFT GetFFT(size_t fftlen)
Definition: RealFFTf.cpp:105
SpectrogramSettings::csColorNew
@ csColorNew
Definition: SpectrogramSettings.h:134
SpectrogramSettings::ConvertToEnumeratedWindowSizes
void ConvertToEnumeratedWindowSizes()
Definition: SpectrogramSettings.cpp:560
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
EnumSetting::WriteEnum
bool WriteEnum(Enum value)
Definition: Prefs.h:382
SpectrogramSettings::defaults
static SpectrogramSettings & defaults()
Definition: SpectrogramSettings.cpp:133
SpectrogramSettings::minFreq
int minFreq
Definition: SpectrogramSettings.h:103