0
0

Hi, how are you.

I have a doubt with theese two functions.

Suppose that I have a struct like this:

[code:2jobv326]struct key{
char *test
};

struct key k;
[/code:2jobv326]

And I want to share it. Well, i do this in a function:

[code:2jobv326]FMOD_Channel_SetUserData(channel, k);[/code:2jobv326]

And in other function i do this:

[code:2jobv326]struct key k;
FMOD_Channel_GetUserData(channel, (void**)&k;[/code:2jobv326]

When I finish using this structure in the function that retrieves data, i should
free the object with [code]free(k)[/clode]. If i don’t it, i do a memory leak?

Thanks!

  • You must to post comments
0
0

Hi icuurd12b42,

Thanks for your time and for your explanation. I understand it a little more =).

Regards,

  • You must to post comments
0
0

I think you may be going towards what I did. A sound having user data, where all channels created of this sound acess that data.

I store things like max volume for the sound in order to properly set the volume of a channel at runtime without overriding the sound volume preset by the user…

In my case a sound has extra properties which I use to tweak stuff in both sound functions and channels functions.

So in short, I use Sound::Set/GetUserData, not the channel version.

This how I do it in my dll wrapper it’s the C API, not the c++

[code:2vv2rviy]
//goto FMODSoundAdd where it is allocated and initialised
typedef struct myinfo
{
UINT effects;
char file[2048];
bool threed;
bool streamed;
float maxvolume;
float group;
FMOD_CHANNEL * channel;
FMOD_DSP * chorus;
FMOD_DSP * echo;
FMOD_DSP * flanger;
FMOD_DSP * gargle;
FMOD_DSP * reverb;
FMOD_DSP * compressor;
FMOD_DSP * equalizer;
float minmaxset;
float mind;
float maxd;
float coneset;
float insideconeangle;
float outsideconeangle;
float outsidevolume;
float maxdopplerset;
float maxdoppler;
float streamready;
bool gotlen;
UINT len;
FMOD_DSP * moreeffects[10];

} myinfo;
[/code:2vv2rviy]

[code:2vv2rviy]
export double FMODSoundAdd(LPCSTR soundfile, double threed, double streamed)
{
if(!inited) {{FMODASSERT(FMOD_ERR_INITIALIZATION);}}
FMOD_SOUND *sound = NULL;

DWORD flags = FMOD_LOOP_NORMAL | FMOD_2D | FMOD_SOFTWARE|FMOD_ACCURATETIME;
if(threed)
{
    //MessageBoxA(GetActiveWindow(),soundfile,(LPCSTR)"3d",MB_ICONINFORMATION);
    flags = FMOD_LOOP_NORMAL | FMOD_3D | FMOD_SOFTWARE | FMOD_3D_LINEARROLLOFF|FMOD_ACCURATETIME;
}
else
{
    //      MessageBoxA(GetActiveWindow(),soundfile,(LPCSTR)"2D",MB_ICONINFORMATION);
}
if(streamed)
{
    FMODASSERT(FMOD_System_CreateStream(mainsystem, soundfile, flags, 0, &sound));
    //FMODASSERT(FMOD_System_CreateSound(mainsystem, soundfile, flags| FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound));
//char t[] = "123456789";
//wsprintf( t, "%ld", (int)sound);

// MessageBoxA(GetActiveWindow(),t,"",0);

}
else
{
    FMODASSERT(FMOD_System_CreateSound(mainsystem, soundfile, flags, 0, &sound));
}

if(sound == NULL) {{FMODASSERT(FMOD_ERR_INVALID_HANDLE);}}
//MessageBoxA(GetActiveWindow(),"2","",0);

myinfo *mi = (myinfo *)GlobalAllocPtr(GMEM_FIXED|GMEM_ZEROINIT,(sizeof(myinfo)));
//MessageBoxA(GetActiveWindow(),"3","",0);
if(mi == NULL) {FMODASSERT(FMOD_ERR_MEMORY);}
mi->maxvolume = 1;
strcpy(mi->file,soundfile);
mi->threed = threed != 0.0f;
mi->streamed = streamed != 0.0f;
//all other members set by GMEM_ZEROINIT
//MessageBoxA(GetActiveWindow(),"4","",0);

FMODASSERT(FMOD_Sound_SetUserData(sound, (void *)mi));
//MessageBoxA(GetActiveWindow(),"5","",0);

return (double) (DWORD) sound;

}
[/code:2vv2rviy]
[code:2vv2rviy]
export double FMODSoundFree(double sound)
{
if(!inited) {{FMODASSERT(FMOD_ERR_INITIALIZATION);}}
if(!(sound>0)){{FMODASSERT(FMOD_ERR_INVALID_HANDLE);}}
void *a = NULL;

FMOD_Sound_GetUserData((FMOD_SOUND *)(DWORD)sound, &a);
if(a!=NULL)
{

    myinfo *mi = (myinfo *) a;
    if(mi->effects)
    {
        if(mi->chorus)
        {
            FMOD_DSP_Release(mi->chorus);
        }
        if(mi->echo)
        {
            FMOD_DSP_Release(mi->echo);
        }
        if(mi->gargle)
        {
            FMOD_DSP_Release(mi->gargle);
        }
        if(mi->flanger)
        {
            FMOD_DSP_Release(mi->flanger);
        }
        if(mi->reverb)
        {
            FMOD_DSP_Release(mi->reverb);
        }
        if(mi->compressor)
        {
            FMOD_DSP_Release(mi->compressor);
        }
        if(mi->equalizer)
        {
           FMOD_DSP_Release(mi->equalizer);
        }
        for(int i =0; i<10; i++)
        {
            if(mi->moreeffects[i] != NULL) FMOD_DSP_Release(mi->moreeffects[i]);
        }
        GlobalFreePtr(a);
    }
}
DWORD t = GetTickCount()+5000;
do
{
    FMOD_OPENSTATE openstate = FMOD_OPENSTATE_READY;
    UINT result = FMOD_Sound_GetOpenState((FMOD_SOUND*)(DWORD)sound,&openstate, 0, 0);

    if (openstate == FMOD_OPENSTATE_READY || openstate == FMOD_OPENSTATE_ERROR || result != FMOD_OK || GetTickCount()>t)
    {
        break;
    }
    FMODUpdate();
    Sleep(10);
} while (1);
FMOD_Sound_Release((FMOD_SOUND*)(DWORD)sound);
return (double) 1;

}
[/code:2vv2rviy]

channel (I call them sound instances) accessing the sound info
[code:2vv2rviy]
export double FMODInstanceSetVolume(double instance, double volume)
{
if(!inited) {{FMODASSERT(FMOD_ERR_INITIALIZATION);}}
if(!(instance>0)){{FMODASSERT(FMOD_ERR_INVALID_HANDLE);}}

FMOD_SOUND * sound = NULL;
FMODASSERT(FMOD_Channel_GetCurrentSound((FMOD_CHANNEL *) (DWORD) instance, &sound));
if(sound == NULL) {{FMODASSERT(FMOD_ERR_INVALID_HANDLE);}}
void *a = NULL;
FMODASSERT(FMOD_Sound_GetUserData((FMOD_SOUND *) (DWORD) sound, &a));
if(a==NULL){{FMODASSERT(FMOD_ERR_INVALID_HANDLE);}}
myinfo *d = (myinfo*) a;
FMODASSERT(FMOD_Channel_SetVolume((FMOD_CHANNEL *) (DWORD) instance, max(0,min((float)volume, 1))*d->maxvolume));
return (double) 1;

}
[/code:2vv2rviy]

  • You must to post comments
0
0

Hi icuurd12b42, how are you.

I think understand you.

For every song that i reproduce, i share the data structure with the current channel.
Then, if I only want share the data structure with one channel and not with
all channels, should I release the data structure when I don’t need it?

thanks

  • You must to post comments
0
0

when you create a channel, you should allocate memory the size of your struct.
when you free a channel, you should first get the user info and free that

The way you have it now, all your channels share the same stucture info referenced by your k variable. if that is what you want then you dont need to free since that is a singleton on the global heap…

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.