0
0

Hi, I’m a musician playing around with computer generated music. I’ve been trying to use FMODex for this purpose but I felt that the documentation cannot sufficiently cover one part: I want to create sounds where the PCM samples are computer-generated or provided by the user with some manual methods.

How is it possible to create an FMOD sound out of custom samples?

I believe that was possible quite easily in FMOD 3.75 with FSOUND_SampleAlloc and then Upload or something like that, but then FMOD 3.75 makes weird pauses and "scratches" when playing even mp3 or wav files…

Thank you in advance
Nick

  • You must to post comments
0
0

OK, I found something but I’m still having trouble. I’m using this code:

[quote:2wpwl54u]
memset(&exinfo,0,sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.length = len;
exinfo.numchannels = 1;
exinfo.defaultfrequency = 10;
exinfo.format = FMOD_SOUND_FORMAT_PCM8;
result = soundSystem->createSound(data, FMOD_SOFTWARE | FMOD_OPENUSER , &exinfo, &sample);
ERRCHECK(result);

result = sample->setMode(FMOD_LOOP_OFF);
ERRCHECK(result);

[/quote:2wpwl54u]

to create a sound with raw data inside pointer [i:2wpwl54u]data[/i:2wpwl54u] but createSound() returns
[quote:2wpwl54u]FMOD error! (37) An invalid parameter was passed to this function.[/quote:2wpwl54u]

I’ve tried changing the parameters, comment them out one-by-one but still the same error. Any ideas?

Anyway standard way to load custom PCM data from memory?

  • You must to post comments
0
0

You need to set the ‘cbsize’ member of the EXINFO structure:
[code:3ln2510u]exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);[/code:3ln2510u]

  • You must to post comments
0
0

OK. Done!

No more errors but still no sound! This is the renewed code:

[quote:19d6wn4u]
memset(&exinfo,0,sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.length = len;
exinfo.numchannels = 1;
exinfo.defaultfrequency = 44100;
exinfo.format = FMOD_SOUND_FORMAT_PCM8;

result = soundSystem->createSound((const char*)data, FMOD_SOFTWARE | FMOD_OPENUSER , &exinfo, &sample);

ERRCHECK(result);

result = sample->setMode(FMOD_LOOP_NORMAL);
ERRCHECK(result);
unsigned int t;

result = sample->lock(0,len,(void**)&data,NULL,&t,0);
ERRCHECK(result);

[/quote:19d6wn4u]

data is an unsigned char array filled with constant 200 value…I think something’s wrong with the way I use lock function because it seems that the data is not loaded correctly into the FMODSound structure. If I replace the createSound with one that opens an existing mp3 file the music is played perfectly with the rest of the settings as they are…

  • You must to post comments
0
0

A constant value of 200 won’t give you any sound. Sound is formed by the variation of the signal over time. Try filling it with a sine wave.

Also, have a look at the usercreatedsound example, which, I think, will give you a better idea of how to go about doing what you’re trying to accomplish. Generally, dynamically-generated sounds are created using the pcmreadcallback in the CREATESOUNDEXINFO structure, which lets you write your own function to fill in the audio data.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.