Comments (4)
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.
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.
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.
Thanks, I'll try to fix it.
from libfmod.
Related Issues (13)
- A lot of functions do not return the correct types or take incorrect parameters HOT 3
- Destination is always `../libfmod` HOT 1
- Correct generation of array arguments
- failed to select a version for the requirement libfmod
- Get location of Fmod libraries from environment HOT 1
- Linux/macOS support, idiomatic linkage HOT 5
- Cannot create sound from byte array HOT 7
- Generated code handling value conversions and pointers is incorrect HOT 3
- Unsafe precondition violations in Rust 1.78.0 HOT 6
- Linking FMOD libraries should not be required HOT 6
- Separate crate for FMOD plugins development HOT 2
- IntoStringError on custom DSP example HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libfmod.