0
0

Hi,
I’m trying to make FMOD work with my freeware game project. Problem is that I can’t figure out how to change the sound effects volume for played samples. I’m initializing FMOD for 8 channels at 44100Hz. I use channel 2 for stream1 and channel 3 for stream 2 ogg music play (they don’t play simultanously though) and channel 4 for samples. Only 1 sample is played at a time, so there is no need to use more channels. For obvious reasons I want to control the volume of those 3 channels. So far everything works great, but the FSOUND_SetVolume (4, fx_volume) function does not seem to affect my channel nr 4. Well, to be precise it does affect channel 4 (tested with FSOUND_GetVolume), but as soon as a sample is played on that channel, it’s volume goes back to 255 (my initial value set with FSOUND_SetSFXMasterVolume). The strange thing is that changing volumes for channels 2 and 3 (ogg streams) works correctly. Am I doing something wrong? I even tryed the FSOUND_SetVolumeAbsolute function but still it doesn’t work as expected.

Here’s some code I do during init to load streams and samples. This section is executed only once. Later new samples and streams are loaded and old ones are freed as the game takes place :

[code:1b390gjo]

/*
LOAD SONGS
*/

fmod_main = FSOUND_Stream_Open("mogg\12th.ogg", FSOUND_LOOP_NORMAL, 0, 0); // only for the intro
if (!fmod_main) {
wsprintf(buf, FMOD_ErrorString(FSOUND_GetError()));
MessageBox(NULL, buf, "FMOD sound system error", MB_OK );
free_all();
return FALSE;
}
fmod_menu = FSOUND_Stream_Open("mogg\sl2.ogg", FSOUND_LOOP_NORMAL, 0, 0);
if (!fmod_menu) {
wsprintf(buf, FMOD_ErrorString(FSOUND_GetError()));
MessageBox(NULL, buf, "FMOD sound system error", MB_OK );
free_all();
return FALSE;
}

/*
LOAD SAMPLES
*/
fmod_menuhit = FSOUND_Sample_Load(FSOUND_UNMANAGED, "sound\hit.wav", FSOUND_NORMAL, 0, 0);
if (!fmod_menuhit) {
wsprintf(buf, FMOD_ErrorString(FSOUND_GetError()));
MessageBox(NULL, buf, "FMOD sound system error", MB_OK );
free_all();
return FALSE;
}
FSOUND_Sample_SetMode(fmod_menuhit, FSOUND_LOOP_OFF);

fmod_menuret = FSOUND_Sample_Load(FSOUND_UNMANAGED, "sound\ret.wav", FSOUND_NORMAL, 0, 0);
if (!fmod_menuret) {
wsprintf(buf, FMOD_ErrorString(FSOUND_GetError()));
MessageBox(NULL, buf, "FMOD sound system error", MB_OK );
free_all();
return FALSE;
}
FSOUND_Sample_SetMode(fmod_menuret, FSOUND_LOOP_OFF);

fmod_thunder = FSOUND_Sample_Load(FSOUND_UNMANAGED, "sound\thunder.wav", FSOUND_NORMAL, 0, 0);
if (!fmod_thunder) {
wsprintf(buf, FMOD_ErrorString(FSOUND_GetError()));
MessageBox(NULL, buf, "FMOD sound system error", MB_OK );
free_all();
return FALSE;
}
FSOUND_Sample_SetMaxPlaybacks(fmod_thunder, 1);
FSOUND_Sample_SetMode(fmod_thunder, FSOUND_LOOP_OFF);

/*
SET MUSIC AND FX VOLUMES
*/
FSOUND_SetSFXMasterVolume(255); // set max volume on default
FSOUND_SetVolumeAbsolute(4, fx_volume); // channel 4 is for samples
FSOUND_SetVolumeAbsolute(2, bgm_volume); // channel 2 is for menu stream
FSOUND_SetVolumeAbsolute(3, bgm_volume); // channel 3 is music streams
FSOUND_SetPan(4, FSOUND_STEREOPAN);
FSOUND_SetPan(2, FSOUND_STEREOPAN);
FSOUND_SetPan(3, FSOUND_STEREOPAN);
[/code:1b390gjo]

And this is how I want to change samples volume from my game menu (btw flip2 is my own SVGA library working correctly) :

[code:1b390gjo]
// FX volume
fx_volume = FSOUND_GetVolume(4);
flip2_SetWriteTextPosition(88,80);
flip2_WriteTextSVGA("FX volume", white_color);

// FX volume bar (1)
flip2_SetWriteTextPosition(48,112);
if (mouse_xpos > (f2mx0 + 48 – 8) && mouse_xpos < (f2mx0 + 48 + 16) && mouse_ypos > (f2my0 + 112 – 8) && mouse_ypos < (f2my0 + 112 + 16))
if (mouse_leftbtn) {
flip2_WriteCharSVGA(17, red_color);
// change fx volume
fx_volume -= 21;
if (fx_volume < 0) fx_volume = 0;
FSOUND_SetVolumeAbsolute(4, fx_volume);

fx_volume = FSOUND_GetVolume(4); // fx_volume = 234 here

     FSOUND_PlaySoundEx(4, fmod_menuhit, NULL, FALSE);

fx_volume = FSOUND_GetVolume(4); // fx_volume = 255 here (why ?)

     while (mouse_leftbtn) GetMouse(flip2_client_hwnd);
  } else {
     flip2_WriteCharSVGA(17, yellow_color);
  }

else {
flip2_WriteCharSVGA(17, white_color);
}

[/code:1b390gjo]

  • You must to post comments
0
0

Allright, I managed to solve all my problems. I use FSOUND_SetSFXMasterVolume for all FX channels. But in my case only channel 4 will be affected because I also use FSOUND_SetVolumeAbsolute (instead of FSOUND_SetVolume) for channels 2 and 3 to control them independently.

  • You must to post comments
0
0

Many thanks for your answer.
As I can understand from FMOD documentation, the first 8 channels (if I initialize the sound system with FSOUND_Init(44100, 8, 0) will be software channels and the rest hardware channels (if there are any). That’s why I thought I can use absolute channel numbers 0 – 7 to play sounds and streams. Please correct me if I’m wrong.

  • You must to post comments
0
0

You do, when you call FSOUND_PlaySoundEx(4, fmod_menuhit, NULL, FALSE);

But you get the handle and pass that to the other functions like Volume
and Panning, ect…

You can use FSOUND_FREE to have fmod pick a channel for you. But you still
need the handle.

Handle1 = FSOUND_PlaySoundEx(FSOUND_FREE, fmod_menuhit, NULL, FALSE);

  • You must to post comments
0
0

Yes, now I understand perfectly how it works. The FSOUND_SetVolume function worked on streams because they were played for a longer amount of time (the volume was changed while the stream was played). But I figured out that by using FSOUND_SetSFXMasterVolume to control short samples and FSOUND_SetVolumeAbsolute to control streams played on a specific channel works just like I wanted at the begining so I will probably leave it like this.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.