0
0

I’m using FMOD 3.62 for Windows on a W2K platform.
I’m loading a sample as a 2d sound, then later trying to reload it as a 3d sound without re-opening the original file. My code works fine for mono sounds, but it crashes on stereo sounds, even though I use the FSOUND_FORCEMONO flag.

Here’s the code boiled down to the essentials:
[code:uqoap43h]
int main(int argc, char* argv[])
{
char* fileToLoad = "musicloop.wav";
FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
FSOUND_Init(44100, 16, 0);

// put file in memory to simulate
// the fact that my real data is coming from a big bundle file.
My_FileHandle file = MyFileOpen(fileToLoad);
int size = MyFileGetSize(file);
char* data = (char*) malloc(size);
MyFileRead(file, data, size);

//create 2D sample
FSOUND_SAMPLE* sample;
sample = FSOUND_Sample_Load( FSOUND_FREE, data, FSOUND_LOADMEMORY | FSOUND_2D, size);
free(data); //release the extra memory
PlayAWhile(sample);

//Turn it into 2D
FSOUND_SAMPLE* newSample;
void *start, *wrap;
unsigned int l1, l2;
unsigned int mode = FSOUND_Sample_GetMode(sample);
mode &= ~(FSOUND_2D); 
mode |= (FSOUND_HW3D);
if (mode & FSOUND_STEREO) { mode |= FSOUND_FORCEMONO; }

FSOUND_Sample_Lock(sample, 0, size, &start, &wrap, &l1, &l2);

//!! The followning line will crash for stereo samples 
newSample = FSOUND_Sample_Load( FSOUND_FREE, (const char*)start, FSOUND_LOADMEMORY | FSOUND_LOADRAW | mode, l1);
FSOUND_Sample_Unlock(sample, start, wrap, l1, l2);

PlayAWhile(newSample);

}

void PlayAWhile(FSOUND_SAMPLE* s)
{
int channel = FSOUND_PlaySound(FSOUND_FREE, s);
for (int i=0;i<100;i++)
{
FSOUND_Update();
Sleep(33);
}
FSOUND_StopSound(channel);
}
[/code:uqoap43h]

With a stereo wave file, i get “Unhandled exception at 0x78002727 in fmodtest.exe: 0xC0000005: Access violation writing location 0x00000000.”
Any idea why this is happening? I can rewrite my app to work around this, but I’d rather not have to…

Thanks,
-Adam

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.