-
Notifications
You must be signed in to change notification settings - Fork 4
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
Dsp::get_parameter_data usage for getting the FFT spectrum of a channel #5
Comments
I think this can be improved. There are two ways:
The first way is huge solution decision, now it impossible. But, I can try improve generator to eliminate unsafe blocks and deref pointers in wrapper. It will help a lot If you send me code examples where |
Here's a code snippet from my audio player written in C# (I used the official FMOD binding for C#): IntPtr fftData;
uint fftLength;
fftDSP.getParameterData((int)DSP_FFT.SPECTRUMDATA, out fftData, out fftLength);
DSP_PARAMETER_FFT fft = (DSP_PARAMETER_FFT)Marshal.PtrToStructure(fftData, typeof(DSP_PARAMETER_FFT));
fft.getSpectrum(ref spectrum);
if (fft.numchannels > 0)
{
for (int i = 0; i < values.GetLength(1); i++)
{
...
The same thing applies to C/C++: you call FMOD_DSP_PARAMETER_FFT *fft;
fftdsp->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void **)&fft, 0, 0, 0));
for (int channel = 0; channel < fft->numchannels; channels++)
{
for (int bin = 0; bin < fft->length; bin++)
{
float val = fft->spectrum[channel][bin];
}
} Hope that clears things up! |
Thanks, I'll try to fix it. |
The problem more difficult than I thought because of design So, there is no ease way to handle But I implemented let sound = system.create_sound("./data/beep.wav", FMOD_DEFAULT, None)?;
let channel = system.play_sound(sound, None, false)?;
let dsp = system.create_dsp_by_type(DspType::Fft)?;
channel.add_dsp(0, dsp)?;
while channel.is_playing()? {
// do something
}
let fft = DspParameterFft::try_from(dsp)?;
for channel in fft.spectrum.iter() {
let sum: f32 = channel.iter().sum();
println!("length: {}, sum: {}", fft.length, sum);
} |
There doesn't seem to be an easy way of accessing FFT spectrum information of a channel.
Dereferencing pointers to
libfmod::ffi::FMOD_DSP_PARAMETER_FFT
after receiving them via calls toDsp::get_parameter_data()
in unsafe blocks doesn't sound like the best idea (it doesn't even return any data anyway, which renders the whole procedure useless), while the FFT DSP feature of FMOD is one that does come in handy and should, in my opinion, be properly implemented as part of the binding.Is there something that could be done here to fix this?
The text was updated successfully, but these errors were encountered: