Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fncokg opened this issue Feb 5, 2024 · 0 comments

Comments

@fncokg
Copy link

fncokg commented Feb 5, 2024

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.

@fncokg fncokg changed the title [Bug] Change numberOfFourierSamples after a window function is applied in "View spectral slice“ [Bug] The numberOfFourierSamples is changed after a window function is applied in "View spectral slice“ Feb 5, 2024
@fncokg fncokg changed the title [Bug] The numberOfFourierSamples is changed after a window function is applied in "View spectral slice“ [Bug] The numberOfFourierSamples may be changed after a window function is applied in "View spectral slice“ Feb 5, 2024
@fncokg fncokg changed the title [Bug] The numberOfFourierSamples may be changed after a window function is applied in "View spectral slice“ [Bug] The numberOfFourierSamples may be changed after a window function is applied to the sound data in the menu command "View spectral slice“ Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant