0
0

I am using FMOD to emulate sound in a windows build version of a cell phone game. All this really means to you is that I must follow this process:

1) Take sounds in their cell phone format and open them with the windows build
2) Call various routines in code to format/decompress the sound in memory into raw format that is playable by FMOD
3) Somehow make FMOD use the resulted buffer of raw data as a sound.

Currently, I have to use .WAV versions of the sounds, thus having duplicates of every sound. I do not know how to make FMOD create a Sound object based on a memory buffer full of raw sound data. Currently, createSound accepts a filename. I would like to know if there’s a way to make it accept a memory buffer.

Thanks!

  • You must to post comments
0
0

Figured it out.

Quote from FMOD Documentation:[quote:f6x5x0nu]FMOD_OPENMEMORY

“name_or_data” will be interpreted as a pointer to memory instead of filename for creating sounds. Use FMOD_CREATESOUNDEXINFO to specify length.
[/quote:f6x5x0nu]

  • You must to post comments
0
0

Even though I finally know how to create a Sound object via audio data in memory, System::createSound() now returns FMOD_ERR_FORMAT when I call it.

The format of the data is very simple in memory. The first XX bytes are the size of the data, beyond this header is nothing but raw WAV data. This raw data is in the buffer I send to FMOD’s System::createSound() function.

Here is a bit of code:

[code:2pnow46m]
FMOD::Sound* newsound = NULL;
FMOD_RESULT err;
char* data;
int length;

// First, load the compressed w8z file and load the raw data into memory
LoadWav8(soundFile, &data, length);

if(!data || !length)
    return;

// Second, format an FMOD structure to describe the raw WAV data
FMOD_CREATESOUNDEXINFO sndinfo = {0};

sndinfo.cbsize      = sizeof(sndinfo);
sndinfo.length      = length;

// Third, create an FMOD::Sound object for the playable raw data
err = mSystem->createSound(data, mSoundFlags, &sndinfo, &newsound);[/code:2pnow46m]

LoadWav8() is a function which basically decompresses the raw data into memory. Thus, when this function returns, the variable ‘data’ will contain a pointer to the raw data, and the variable ‘length’ will be the length of this data block.

I see no reason why FMOD shouldn’t be able to recognize the data format. It’s nothing but raw data, you can’t get much simplier than that…

Any help is greatly appreciated.

::EDIT::

You’ll also be interested in seeing this data member as well:
[code:2pnow46m]mSoundFlags = FMOD_SOFTWARE | FMOD_2D | FMOD_LOOP_NORMAL | FMOD_OPENMEMORY;[/code:2pnow46m]

  • You must to post comments
0
0

Once again I find myself posting too early lol.

Problem solved again, I had to use FMOD_OPENRAW.

  • You must to post comments
0
0

I’m trying to do something similar, but am getting "Unwanted file access occured" on FMOD_System_CreateSoundEx and "An invalid object handle was used" on FMOD_System_PlaySound.

What I want to eventually do here is a synthesized sound that is calculated continuously (it’s always changing so a short usercreatedsound type of thing isn’t quite what I need). I could do it with Win32API functions by filling the sound buffer manually a chunk at a time while it was playing, but am not having any luck finding a way to do it with fmod although I know it’s possible of course.

Perhaps for that I need to use sound::lock and sound::unlock to pass in data for fmod to play? Any tips or links to other posts that show a way to do it would be greatly appreciated. I’m still searching the forums, but haven’t found what I’m looking for just yet.

Thanks

[code:1luyw7e6]

DECLARE FUNCTION FMOD_System_CreateSoundEx LIB "fmodex.dll" ALIAS "FMOD_System_CreateSound" (BYVAL system AS LONG, BYVAL name_or_data AS DWORD, BYVAL mode AS DWORD, BYREF exinfo AS FMOD_CREATESOUNDEXINFO, BYREF sound AS LONG) AS DWORD

DIM ExInfo AS FMOD_CREATESOUNDEXINFO
ExInfo.cbsize = SIZEOF(FMOD_CREATESOUNDEXINFO)
ExInfo.fileoffset = 0
ExInfo.length = frequency * channels * 2 * 2
ExInfo.numchannels = channels
ExInfo.defaultfrequency = frequency
ExInfo.format = %FMOD_SOUND_FORMAT_PCM16
ExInfo.initialsubsound = 0
ExInfo.numsubsounds = 0
ExInfo.inclusionlist = 0
ExInfo.inclusionlistnum = 0
ExInfo.pcmreadcallback = 0’CODEPTR(pcmreadcallback)
ExInfo.pcmsetposcallback = 0’CODEPTR(pcmsetposcallback)
ExInfo.nonblockcallback = 0
ExInfo.dlsname = 0
ExInfo.encryptionkey = 0
ExInfo.maxpolyphony = 0
ExInfo.userdata = 0

FMOD_System_Create system
FMOD_System_GetVersion system, version
result = FMOD_System_Init(system, 32, %FMOD_INIT_NORMAL, %NULL)
FMOD_LOOP_NORMAL OR %FMOD_HARDWARE
mode = %FMOD_2D OR %FMOD_DEFAULT OR %FMOD_OPENMEMORY OR %FMOD_LOOP_NORMAL OR %FMOD_HARDWARE

‘//Create a block of memory and fill it with data to play.
DIM SoundData(ExInfo.length) AS LONG
LOCAL i AS LONG

FOR i = 0 TO ExInfo.length
SoundData(i) = RND(32000) ‘SIN(i) * 32767
NEXT

DIM Address AS LONG PTR
Address = VARPTR(SoundData(0))

result = FMOD_System_CreateSoundEx(system, Address, MODE , ExInfo, sound1)
IF result THEN MSGBOX FORMAT$(result,"#")

result = FMOD_System_PlaySound(system, %FMOD_CHANNEL_FREE, sound1, 0, channel)
IF result THEN MSGBOX FORMAT$(result,"#")

DIM SoundPosition AS VECTOR3D
DIM SoundVelocity AS VECTOR3D
DIM SoundForward AS VECTOR3D
DIM SoundUp AS VECTOR3D
SoundForward.z = 1
SoundUp.y = 1

FMOD_Channel_Set3DAttributes channel,SoundPosition,SoundVelocity
FMOD_System_Set3DListenerAttributes system,0,SoundPosition,SoundVelocity,SoundForward,SoundUp
[/code:1luyw7e6]

  • You must to post comments
0
0

There is an example called usercreated sound which you should probably look at. This is not really related to this thread.

  • You must to post comments
0
0

Thanks, Brett. I tried that, but unfortunately the user created sound calls the callback function only a few times (filling the buffer one time only, perhaps) and then stops, but I need it to continuously call it, or need another way of accomplishing this.

I posted about it here: http://52.88.2.202/forum/viewtopic.php?t=6155

Thanks for your help.

  • You must to post comments
0
0

not if it is a stream, it is impossible for an infinite stream to only read once, because you’d not hear any new data. The user created sound example is constantly feeding in new data. You are debugging it incorrectly.

  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.