praat / praat

Praat: Doing Phonetics By Computer

Home Page:http://www.praat.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] The numberOfFourierSamples may be changed after a window function is applied to the sound data in the menu command "View spectral slice“

fncokg opened this issue · comments

The sound editor has a menu command View spectral slice, which calls the Sound_and_Spectrum to do FFT. However, I noticed in the codes of this command, the selection was first applied to a window, and then passed to Sound_and_Spectrum with the fast argument set to true.

static void CONVERT_DATA_TO_ONE__ViewSpectralSlice (SoundAnalysisArea me, EDITOR_ARGS) {
CONVERT_DATA_TO_ONE
const double start = ( my startSelection() == my endSelection() ?
my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::GAUSSIAN ? my startSelection() - my instancePref_spectrogram_windowLength() :
my startSelection() - my instancePref_spectrogram_windowLength() / 2 : my startSelection()
);
const double finish = ( my startSelection() == my endSelection() ?
my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::GAUSSIAN ? my endSelection() + my instancePref_spectrogram_windowLength() :
my endSelection() + my instancePref_spectrogram_windowLength() / 2 : my endSelection()
);
autoSound sound = extractSound (me, start, finish);
Sound_multiplyByWindow (sound.get(),
my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::SQUARE ? kSound_windowShape::RECTANGULAR :
my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::HAMMING ? kSound_windowShape::HAMMING :
my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::BARTLETT ? kSound_windowShape::TRIANGULAR :
my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::WELCH ? kSound_windowShape::PARABOLIC :
my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::HANNING ? kSound_windowShape::HANNING :
my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::GAUSSIAN ? kSound_windowShape::GAUSSIAN_2 : kSound_windowShape::RECTANGULAR
);
autoSpectrum result = Sound_to_Spectrum (sound.get(), true);
CONVERT_DATA_TO_ONE_END (Melder_cat (( my data() ? my data() -> name.get() : U"untitled" ),
U"_", Melder_fixed (0.5 * (my startSelection() + my endSelection()), 3)))
}

However, with fast set to true, the numberOfFourierSamples is likely to be changed:
const integer numberOfFourierSamples = ( fast ? Melder_iroundUpToPowerOfTwo (my nx) : my nx );

This doesn't matter when the function is used to perform FFT to a whole sound, but in the case of the View spectral slice call, the data passed in has already been added to a window. In this situation, narrowing the numberOfFourierSamples is problematic.

The solution is setting the fast argument in this line to false to avoid narrowing the numberOfFourierSamples.

autoSpectrum result = Sound_to_Spectrum (sound.get(), true);

This will not, in most cases, cause a speed concern, since the command View spectral slice is usually used to analyze a small segment of sounds.