I’m trying to use the Dirac LE pitch-bending library with FMOD Ex and encountering some troubles. The fundamental problem is this: Dirac needs the ability to gather an arbitrary number of input samples for its processing, but when I use it in a DSP’s "read" callback function (from the dsp_custom FMOD example), I only have access to as many samples as the DSP forwards to the "myDSPCallback" function. Is there a way to access more samples than just the "length" number of samples supplied to myDSPCallback?
I’ve made slight modifications to the "dsp_custom" FMOD example, modifying the "myDSPCallback" function to call Dirac instead of decreasing the volume. As I understand it, the DSP calls its "read" callback function (myDSPCallback) to take samples from an input buffer, process them, and write them to an output buffer. The myDSPCallback callback function takes as arguments:
- FMOD_DSP_STATE *dsp_state
- float* inbuffer
- float* outbuffer
- unsigned int length
- int inchannels
- int outchannels
The purpose of this function is to perform processing on the "length" samples in inbuffer and write them to outbuffer. So I modified myDSPCallback to call Dirac, requesting that Dirac process "length" number of samples. However, Dirac will (at first) attempt to collect 5length samples from its own user-supplied readData function, then write out 1length processed samples as requested. Upon further calls to Dirac, it will write out the remaining 4length processed samples. This is a problem because Dirac expects to be able to collect 5length samples, but I only have 1*length in my inbuffer!
So — my DSP chain provides 1024 samples of input and expects me to produce 1024 samples of output. I do not have access to more than 1024 samples of input at a time. Given that I’m constrained in this way, can I use Dirac to produce the output? It seems like the answer is "no", because Dirac needs the ability to collect an arbitrary number of input samples (which it does using the user-provided readData function).
Any thoughts would be much appreciated.
- ustinjay asked 8 years ago
- You must login to post comments
Probably the best bet is to create your own ring buffer that is larger than the size of the buffer requested by DIRAC. Then have two position indices, 1 position for DIRAC which is initially set to 0 and then the other position for the actual audio input which would be set for 5 * the size of the data that the DSP callback receives.
[list:3dw669bk][:3dw669bk]On every call to the callback, you would fill the ring buffer starting at the 2nd index[/:m:3dw669bk]
[:3dw669bk]Then call DIRAC using the data from the ring buffer starting at the 1st index[/:m:3dw669bk]
[:3dw669bk]Then copy the resulting data from DIRAC back into the ring buffer, and subsequently back into your output.[/:m:3dw669bk]
[:3dw669bk]Finally, increase both indices by the number of samples the DSP callback is called with[/:m:3dw669bk][/list:u:3dw669bk]
Of course, this will work only if you are shifting pitch and not changing the speed (which would be handled by setting the frequency of the sound with FMOD). DIRAC should be returning the same exact amount of samples as you provide it, otherwise you may have some kind of weird race condition.
It is also possible you may actually need to ring buffers, one for input to DIRAC and one for output from DIRAC, that way your input doesn’t get hammered on by DIRAC.
Hope that helps.
- CuriousG answered 8 years ago
- You must login to post comments
Please login first to submit.