Giter Club home page Giter Club logo

Comments (4)

lebedec avatar lebedec commented on August 28, 2024 1

The problem more difficult than I thought because of design FMOD_DSP_GetParameterData.
This function too generic and used not only for any DSP type but for any user defined data.
Also FMOD do not provide any typing info for safe pointer casting.

So, there is no ease way to handle *c_void. I have no idea how to implement this without reworking high level design of library.

But I implemented TryFrom trait specific for DspParameterFft to simplify safe usage. Hope that it helps you:

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);
}

from libfmod.

lebedec avatar lebedec commented on August 28, 2024

I think this can be improved.

There are two ways:

  • Add a new abstraction layer, another wrapper to implement special cases like this manually.
  • Improve a generator. Although the library is fully generated, I made a some preparations that allow to override the generation results.

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 FMOD_DSP_PARAMETER_FFT parameter is used (any C/C++ code possible) or write your vision of Dsp::get_parameter_data() function signature and usage for example.

from libfmod.

fililip avatar fililip commented on August 28, 2024

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++)
  {
    ...

IntPtr is the "safe" pointer type in C#.
The DSP_PARAMTER_FFT.getSpectum() function in the C# binding returns the .spectrum parameter of the structure (float[][]).

The same thing applies to C/C++: you call getParameterData() with a pointer to an instance of that structure cast to void** to get your FFT data, so something along the lines of:

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!

from libfmod.

lebedec avatar lebedec commented on August 28, 2024

Thanks, I'll try to fix it.

from libfmod.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.