0
0

Hi to all,
can I have a very little example of using of the routines

[code:p4spe8zg]DSP::setUserData
DSP::getUserData[/code:p4spe8zg]

to pass something (a number, a character, or something else) to a dsp callback?
I’m desperate, I don’t get help from the mailing list and I can not advance with my work.

I tried with no success.

Regards,
Franco

  • You must to post comments
0
0

setup the dsp like this
[code:2sx4xk35]
int number = 1;

...

FMOD_DSP_DESCRIPTION dspdesc;

memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION));
strcpy(dspdesc.name, "MyDSP");
dspdesc.channels = 0;
dspdesc.read = dspReadCallback;
dspdesc.userdata = (void *)&number;
//dspdesc.userdata = (void *)this; // passing the class you are in

result = system->createDSP(&dspdesc, &m_dsp));
ERRCHECK(result);
[/code:2sx4xk35]
in your callback
[code:2sx4xk35]
FMOD_RESULT F_CALLBACK dspReadCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
{
FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance;
int *number;
//MyClass *myClass;
thisdsp->getUserData((void **)&number);
//thisdsp->getUserData((void **)&myClass);

int copy = *number; // copy is now 1
//myClass->doSomething();

return FMOD_OK;
}[/code:2sx4xk35]

  • You must to post comments
0
0

[quote="mylo":81j0ou8b]setup the dsp like this
[code:81j0ou8b]
int number = 1;

...

FMOD_DSP_DESCRIPTION dspdesc;

memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION));
strcpy(dspdesc.name, "MyDSP");
dspdesc.channels = 0;
dspdesc.read = dspReadCallback;
dspdesc.userdata = (void *)&number;
//dspdesc.userdata = (void *)this; // passing the class you are in

result = system->createDSP(&dspdesc, &m_dsp));
ERRCHECK(result);
[/code:81j0ou8b]
in your callback
[code:81j0ou8b]
FMOD_RESULT F_CALLBACK dspReadCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
{
FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance;
int *number;
//MyClass *myClass;
thisdsp->getUserData((void **)&number);
//thisdsp->getUserData((void **)&myClass);

int copy = *number; // copy is now 1
//myClass->doSomething();

return FMOD_OK;
}[/code:81j0ou8b][/quote:81j0ou8b]

Hi I tried to comvert your example and pass a buffer (for example a string buffer or a int buffer) but I get always a segmentation fault. Can you please change your example to send a buffer instead a single value?
Regards,
Franco

  • You must to post comments
0
0

As mentioned in the other thread that advice is wrong. It is pointing to the stack probably.

It should look more like this
[code:2n76dx3w]
int number = 1;

...

FMOD_DSP_DESCRIPTION dspdesc;

memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION));
strcpy(dspdesc.name, "MyDSP");
dspdesc.channels = 0;
dspdesc.read = dspReadCallback;
dspdesc.userdata = (void *)number;
//dspdesc.userdata = (void *)this; // passing the class you are in

result = system->createDSP(&dspdesc, &m_dsp));
ERRCHECK(result);
[/code:2n76dx3w]

now userdata should be a pointer of value 0x00000001

in your callback
[code:2n76dx3w]
FMOD_RESULT F_CALLBACK dspReadCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
{
FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance;
void *number;
//MyClass *myClass;
thisdsp->getUserData(&number);
//thisdsp->getUserData((void **)&myClass);

int copy = (int)number; // copy is now 1
//myClass->doSomething();

return FMOD_OK;
}[/code:2n76dx3w]

  • You must to post comments
0
0

[quote="brett":3upj50mb]As mentioned in the other thread that advice is wrong. It is pointing to the stack probably.

It should look more like this
[code:3upj50mb]
int number = 1;

...

FMOD_DSP_DESCRIPTION dspdesc;

memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION));
strcpy(dspdesc.name, "MyDSP");
dspdesc.channels = 0;
dspdesc.read = dspReadCallback;
dspdesc.userdata = (void *)number;
//dspdesc.userdata = (void *)this; // passing the class you are in

result = system->createDSP(&dspdesc, &m_dsp));
ERRCHECK(result);
[/code:3upj50mb]

now userdata should be a pointer of value 0x00000001

in your callback
[code:3upj50mb]
FMOD_RESULT F_CALLBACK dspReadCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
{
FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance;
void *number;
//MyClass *myClass;
thisdsp->getUserData(&number);
//thisdsp->getUserData((void **)&myClass);

int copy = (int)number; // copy is now 1
//myClass->doSomething();

return FMOD_OK;
}[/code:3upj50mb][/quote:3upj50mb]

Brett,
so the value stored in number (in this case 1) is converted in an address value right?

  • You must to post comments
0
0

[quote="brett":kff12x21]As mentioned in the other thread that advice is wrong. It is pointing to the stack probably.

It should look more like this
[code:kff12x21]
int number = 1;

...

FMOD_DSP_DESCRIPTION dspdesc;

memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION));
strcpy(dspdesc.name, "MyDSP");
dspdesc.channels = 0;
dspdesc.read = dspReadCallback;
dspdesc.userdata = (void *)number;
//dspdesc.userdata = (void *)this; // passing the class you are in

result = system->createDSP(&dspdesc, &m_dsp));
ERRCHECK(result);
[/code:kff12x21]

now userdata should be a pointer of value 0x00000001

in your callback
[code:kff12x21]
FMOD_RESULT F_CALLBACK dspReadCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
{
FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance;
void *number;
//MyClass *myClass;
thisdsp->getUserData(&number);
//thisdsp->getUserData((void **)&myClass);

int copy = (int)number; // copy is now 1
//myClass->doSomething();

return FMOD_OK;
}[/code:kff12x21][/quote:kff12x21]

Brett,
I need perform operations on the buffer I have to pass to the callback.
Do you suggest to do a local copy of the buffer (in the callback), do the operations on the copy and finally do a memcpy to the original or is better to operate directly on the original buffer?
Regards,
Franco

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.