0
0

I am playing some *.wav files and need to perform certain operations according to the position of the corresponding channels. I’m using and update function that is called 60 times per second and the positions read are like this:

position: 1881
position: 1881
position: 1881
position: 3763
position: 3763
position: 3763
position: 5644
position: 5644

As you can see by the times read, my update function is being called between two and three times while one buffer block is filled. This is more than is needed. I would like to some how set a callback that notifies me every time the DSP unit fills the buffer again.

I’m still not sure that I understand about the DSP units but I guess there is on unit by default if the user doesn’t creates a custom one. And this unit is processing the *.wav files I provide. As I understand a DSP unit processes the sound by filling a buffer with 1024 samples and when that block of samples has already ended then fills the next one an so on. In my case the position read changes by 1881 samples which is the result of 1024 * 44100 Hz / 24000 Hz (working on IPhone).

I think I don’t need to create a new DSP unit for that but I’m just starting here and I’m not sure. Should I use [i:8nxa94ak]system->getDSPHead(&myDSP)[/i:8nxa94ak] and the set a read callback to [i:8nxa94ak]myDSP[/i:8nxa94ak] some how? – I haven’t been able to do that :(. Or I do need to create a new one?

Any guide would be very appreciated!

  • You must to post comments
0
0

————————- SOLUTION:

I think I solved it, I’m posting the solution:

When I initialize FMOD system:

[code:2402p2gy]
// Get the master DSP
FMOD::DSP *masterDSP;
ERRCHECK(system->getDSPHead(&masterDSP));

// Create a DSP to serve as a timer on buffer block fill.
FMOD_DSP_DESCRIPTION timerDSPDescription; 
memset(&timerDSPDescription, 0, sizeof(FMOD_DSP_DESCRIPTION)); 
strcpy(timerDSPDescription.name, "Timer DSP"); 
// Use 0 to process whatever number of channels is currently in the network.
timerDSPDescription.channels = 0;
// Set the callback function.
timerDSPDescription.read = DSP_READ_CALLBACK;
// I need a reference to the object in which I am (SoundManager).
timerDSPDescription.userdata = (void *)self; 
FMOD::DSP *timerDSP;
ERRCHECK(system->createDSP(&timerDSPDescription, &timerDSP));

// Add and activate the timer DSP.
ERRCHECK(masterDSP->addInput(timerDSP, NULL));
ERRCHECK(timerDSP->setActive(true));

[/code:2402p2gy]

This is my callback function:

[code:2402p2gy]
FMOD_RESULT F_CALLBACK DSP_READ_CALLBACK(FMOD_DSP_STATE *dsp_state,
float * inbuffer,
float * outbuffer,
unsigned int length,
int inchannels,
int outchannels)
{
SoundManager *manager;

FMOD::DSP *timerDSP = (FMOD::DSP *)dsp_state->instance;
ERRCHECK(timerDSP->getUserData((void **)&manager));

FMOD::Channel *channel = [manager getChannel];
unsigned int position;

if(channel)
{
    ERRCHECK(channel->getPosition(&position, FMOD_TIMEUNIT_PCM));
    NSLog(@"DSP_READ_CALLBACK position: %i", position);
}

return FMOD_OK;

}
[/code:2402p2gy]

Now the position reading is like this:

position: 1881
position: 3763
position: 5644
position: 7526
position: 9407

Hope someone finds this useful.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.