| 1 |
/* praat_MultiSampledSpectrogram.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 2021-2023 David Weenink |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "praatM.h" |
| 20 |
|
| 21 |
#include "AnalyticSound.h" |
| 22 |
#include "ConstantQSpectrograms.h" |
| 23 |
#include "MultiSampledSpectrogram.h" |
| 24 |
#include "Sound_and_MultiSampledSpectrogram.h" |
| 25 |
#include "Spectrum_and_MultiSampledSpectrogram.h" |
| 26 |
|
| 27 |
DIRECT (CONVERT_EACH_TO_ONE__AnalyticSound_toIntensity) { |
| 28 |
CONVERT_EACH_TO_ONE (AnalyticSound) |
| 29 |
autoIntensity result = AnalyticSound_to_Intensity (me); |
| 30 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 31 |
} |
| 32 |
|
| 33 |
DIRECT (CONVERT_EACH_TO_ONE__AnalyticSound_toSound) { |
| 34 |
CONVERT_EACH_TO_ONE (AnalyticSound) |
| 35 |
autoSound result = AnalyticSound_to_Sound (me); |
| 36 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 37 |
} |
| 38 |
|
| 39 |
FORM (MODIFY_EACH_WEAK__MultiSampledSpectrogram_formula, U"MultiSampledSpectrogram: Formula", U"MultiSampledSpectrogram: Formula...") { |
| 40 |
FORMULA (formula, U"Formula", U"2 * self") |
| 41 |
OK |
| 42 |
DO |
| 43 |
MODIFY_EACH_WEAK (MultiSampledSpectrogram) |
| 44 |
MultiSampledSpectrogram_formula (me, formula, interpreter); |
| 45 |
MODIFY_EACH_WEAK_END |
| 46 |
} |
| 47 |
|
| 48 |
FORM (MODIFY_EACH_WEAK__MultiSampledSpectrogram_formula_part, U"MultiSampledSpectrogram: Formula (part)", U"MultiSampledSpectrogram: Formula...") { |
| 49 |
REAL (fromTime, U"From time", U"0.0") |
| 50 |
REAL (toTime, U"To time", U"0.0 (= all)") |
| 51 |
REAL (fromFrequency, U"From frequency (Hz)", U"100.0") |
| 52 |
REAL (toFrequency, U"To Frequency (Hz)", U"200.0") |
| 53 |
FORMULA (formula, U"Formula", U"2 * self") |
| 54 |
OK |
| 55 |
DO |
| 56 |
MODIFY_EACH_WEAK (MultiSampledSpectrogram) |
| 57 |
MultiSampledSpectrogram_formula_part (me, fromTime, toTime, fromFrequency, toFrequency, formula, interpreter); |
| 58 |
MODIFY_EACH_WEAK_END |
| 59 |
} |
| 60 |
|
| 61 |
FORM (GRAPHICS_EACH__ConstantQLog2FSpectrogram_paint, U"ConstantQLog2FSpectrogram: Paint", nullptr) { |
| 62 |
REAL (xmin, U"left Time range (s)", U"0.0") |
| 63 |
REAL (xmax, U"right Time range (s)", U"0.0 (= all)") |
| 64 |
REAL (ymin, U"left Frequency range (Hz)", U"0.0") |
| 65 |
REAL (ymax, U"right Frequency range (Hz)", U"0.0 (= auto)") |
| 66 |
POSITIVE (dBRange, U"Dynamic range (dB)", U"50.0") |
| 67 |
BOOLEAN (garnish, U"Garnish", true); |
| 68 |
OK |
| 69 |
DO |
| 70 |
GRAPHICS_EACH (ConstantQLog2FSpectrogram) |
| 71 |
ConstantQLog2FSpectrogram_paint (me, GRAPHICS, xmin, xmax, ymin, ymax, dBRange, garnish); |
| 72 |
GRAPHICS_EACH_END |
| 73 |
} |
| 74 |
|
| 75 |
DIRECT (CONVERT_EACH_TO_ONE__MultiSampledSpectrogram_to_Sound) { |
| 76 |
CONVERT_EACH_TO_ONE (MultiSampledSpectrogram) |
| 77 |
autoSound result = MultiSampledSpectrogram_to_Sound (me); |
| 78 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 79 |
} |
| 80 |
|
| 81 |
FORM (CONVERT_EACH_TO_ONE__MultiSampledSpectrogram_to_Sound_frequencyBin, U"MultiSampledSpectrogram: To Sound (frequencyBin)", nullptr) { |
| 82 |
NATURAL (frequencyBinNumber, U"Frequency bin number", U"1") |
| 83 |
OK |
| 84 |
DO |
| 85 |
CONVERT_EACH_TO_ONE (MultiSampledSpectrogram) |
| 86 |
autoSound result = MultiSampledSpectrogram_to_Sound_frequencyBin (me, frequencyBinNumber); |
| 87 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_",frequencyBinNumber) |
| 88 |
} |
| 89 |
|
| 90 |
DIRECT (CONVERT_EACH_TO_ONE__MultiSampledSpectrogram_to_Spectrum) { |
| 91 |
CONVERT_EACH_TO_ONE (MultiSampledSpectrogram) |
| 92 |
autoSpectrum result = MultiSampledSpectrogram_to_Spectrum (me); |
| 93 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 94 |
} |
| 95 |
|
| 96 |
FORM (CONVERT_EACH_TO_ONE__ConstantQLog2FSpectrogram_translateSpectrum, U"", nullptr) { |
| 97 |
REAL (fromTime, U"From time", U"0.0") |
| 98 |
REAL (toTime, U"To time", U"0.0 (= all)") |
| 99 |
REAL (fromFrequency, U"From frequency (Hz)", U"100.0") |
| 100 |
REAL (numberOfBins, U"Number of bins", U"5.0") |
| 101 |
OK |
| 102 |
DO |
| 103 |
CONVERT_EACH_TO_ONE (ConstantQLog2FSpectrogram) |
| 104 |
autoConstantQLog2FSpectrogram result = ConstantQLog2FSpectrogram_translateSpectrum (me, fromTime, toTime, fromFrequency, numberOfBins); |
| 105 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 106 |
} |
| 107 |
|
| 108 |
FORM (CONVERT_EACH_TO_ONE__Sound_to_ConstantQLog2FSpectrogram, U"Sound: To ConstantQLog2FSpectrogram", U"Sound: To ConstantQLog2FSpectrogram...") { |
| 109 |
POSITIVE (f1, U"Lowest frequency (Hz)", U"110.0 (=440*2^(-2))") |
| 110 |
REAL (fmax, U"Maximum frequency (Hz)", U"0.0 (= Nyquist)") |
| 111 |
NATURAL (numberOfFrequencyBinsPerOctave, U"Number of frequency bins / octave", U"24") |
| 112 |
POSITIVE (frequencyResolutionInBins, U"Frequency resolution (bins)", U"1.0") |
| 113 |
POSITIVE (timeOversamplingFactor, U"Time oversampling factor", U"1.0") |
| 114 |
CHOICE_ENUM (kSound_windowShape, filterShape, |
| 115 |
U"Filter shape", kSound_windowShape::DEFAULT) |
| 116 |
OK |
| 117 |
DO |
| 118 |
CONVERT_EACH_TO_ONE (Sound) |
| 119 |
autoConstantQLog2FSpectrogram result = Sound_to_ConstantQLog2FSpectrogram (me, f1, fmax, |
| 120 |
numberOfFrequencyBinsPerOctave, frequencyResolutionInBins, timeOversamplingFactor, filterShape |
| 121 |
); |
| 122 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 123 |
} |
| 124 |
|
| 125 |
DIRECT (CONVERT_EACH_TO_ONE__Sound_to_AnalyticSound) { |
| 126 |
CONVERT_EACH_TO_ONE (Sound) |
| 127 |
autoAnalyticSound result = Sound_to_AnalyticSound (me); |
| 128 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 129 |
} |
| 130 |
|
| 131 |
FORM (GRAPHICS_EACH__GaborSpectrogram_paint, U"GaborSpectrogram: Paint", nullptr) { |
| 132 |
REAL (xmin, U"left Time range (s)", U"0.0") |
| 133 |
REAL (xmax, U"right Time range (s)", U"0.0 (= all)") |
| 134 |
REAL (ymin, U"left Frequency range (Hz)", U"0.0") |
| 135 |
REAL (ymax, U"right Frequency range (Hz)", U"0.0 (= auto)") |
| 136 |
POSITIVE (dBRange, U"Dynamic range (dB)", U"50.0") |
| 137 |
BOOLEAN (garnish, U"Garnish", true); |
| 138 |
OK |
| 139 |
DO |
| 140 |
GRAPHICS_EACH (GaborSpectrogram) |
| 141 |
GaborSpectrogram_paint (me, GRAPHICS, xmin, xmax, ymin, ymax, dBRange, garnish); |
| 142 |
GRAPHICS_EACH_END |
| 143 |
} |
| 144 |
|
| 145 |
FORM (CONVERT_EACH_TO_ONE__Sound_to_GaborSpectrogram, U"Sound: To GaborSpectrogram", U"Sound: To ConstantQLog2FSpectrogram...") { |
| 146 |
REAL (fmax, U"Maximum frequency (Hz)", U"0.0 (= Nyquist)") |
| 147 |
POSITIVE (filterBandwidth, U"Filter bandwidth (Hz)", U"40.0") |
| 148 |
POSITIVE (frequencyStep, U"Frequency step (hz)", U"20.0") |
| 149 |
POSITIVE (timeOversamplingFactor, U"Time oversampling factor", U"1.0") |
| 150 |
CHOICE_ENUM (kSound_windowShape, filterShape, |
| 151 |
U"Filter shape", kSound_windowShape::DEFAULT) |
| 152 |
OK |
| 153 |
DO |
| 154 |
CONVERT_EACH_TO_ONE (Sound) |
| 155 |
autoGaborSpectrogram result = Sound_to_GaborSpectrogram (me, fmax, filterBandwidth, |
| 156 |
frequencyStep, timeOversamplingFactor, filterShape |
| 157 |
); |
| 158 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 159 |
} |
| 160 |
|
| 161 |
void praat_MultiSampledSpectrograms_generics (ClassInfo klas) { |
| 162 |
praat_addAction1 (klas, 0, U"Formula...", nullptr, 0, |
| 163 |
MODIFY_EACH_WEAK__MultiSampledSpectrogram_formula); |
| 164 |
praat_addAction1 (klas, 0, U"Formula (part)...", nullptr, 0, |
| 165 |
MODIFY_EACH_WEAK__MultiSampledSpectrogram_formula_part); |
| 166 |
praat_addAction1 (klas, 0, U"To Sound", nullptr, 0, |
| 167 |
CONVERT_EACH_TO_ONE__MultiSampledSpectrogram_to_Sound); |
| 168 |
praat_addAction1 (klas, 0, U"To Sound (frequencyBin)...", nullptr, 0, |
| 169 |
CONVERT_EACH_TO_ONE__MultiSampledSpectrogram_to_Sound_frequencyBin); |
| 170 |
praat_addAction1 (klas, 0, U"To Spectrum", nullptr, 0, |
| 171 |
CONVERT_EACH_TO_ONE__MultiSampledSpectrogram_to_Spectrum); |
| 172 |
} |
| 173 |
|
| 174 |
void praat_MultiSampledSpectrogram_init (); |
| 175 |
void praat_MultiSampledSpectrogram_init () { |
| 176 |
Thing_recognizeClassesByName (classAnalyticSound, classConstantQLog2FSpectrogram, classFrequencyBin, |
| 177 |
classGaborSpectrogram, classMultiSampledSpectrogram); |
| 178 |
|
| 179 |
praat_addAction1 (classAnalyticSound, 0, U"To Intensity", nullptr, 0, |
| 180 |
CONVERT_EACH_TO_ONE__AnalyticSound_toIntensity); |
| 181 |
praat_addAction1 (classAnalyticSound, 0, U"To Sound", nullptr, 0, |
| 182 |
CONVERT_EACH_TO_ONE__AnalyticSound_toSound); |
| 183 |
|
| 184 |
praat_addAction1 (classConstantQLog2FSpectrogram, 0, U"Paint...", nullptr, 0, |
| 185 |
GRAPHICS_EACH__ConstantQLog2FSpectrogram_paint); |
| 186 |
praat_MultiSampledSpectrograms_generics (classConstantQLog2FSpectrogram); |
| 187 |
praat_addAction1 (classConstantQLog2FSpectrogram, 0, U"Translate spectrum...", nullptr, 0, |
| 188 |
CONVERT_EACH_TO_ONE__ConstantQLog2FSpectrogram_translateSpectrum); |
| 189 |
|
| 190 |
praat_addAction1 (classSound, 0, U"To ConstantQLog2FSpectrogram...", U"To ComplexSpectrogram...", GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 191 |
CONVERT_EACH_TO_ONE__Sound_to_ConstantQLog2FSpectrogram); |
| 192 |
praat_addAction1 (classSound, 0, U"To AnalyticSound", U"Resample...", GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 193 |
CONVERT_EACH_TO_ONE__Sound_to_AnalyticSound); |
| 194 |
|
| 195 |
|
| 196 |
praat_addAction1 (classGaborSpectrogram, 0, U"Paint...", nullptr, 0, |
| 197 |
GRAPHICS_EACH__GaborSpectrogram_paint); |
| 198 |
praat_MultiSampledSpectrograms_generics (classGaborSpectrogram); |
| 199 |
praat_addAction1 (classSound, 0, U"To GaborSpectrogram...", U"To ComplexSpectrogram...", GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 200 |
CONVERT_EACH_TO_ONE__Sound_to_GaborSpectrogram); |
| 201 |
} |
| 202 |
|
| 203 |
/* End of file praat_MultiSampledSpectrogram.cpp */ |
| 204 |
|