I’d like to be able to control the volume level of a sound for each speaker independently (as opposed to just setting the pan). I’ve been able to do so using the following code (I’m using MinGW, hence the FMOD C interface):
FMOD_CHANNEL *channelLeft = 0, *channelRight = 0; // Separate channels to control the volume of the sound in the left and right speakers independently.
result = FMOD_System_Create(&system);
ERRCHECK(result); // For the sake of brevity, error checks are omitted from this point onward.
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
result = FMOD_System_CreateSound(system, "C:/Program Files (x86)/FMOD SoundSystem/FMOD Programmers API Windows/examples/media/drumloop.wav", FMOD_SOFTWARE, 0, &sound1);
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, true, &channelLeft);
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, true, &channelRight);
// The idea here to is limit each channel to one of the two speakers (by setting the pan) and then changing each channel’s volume independently
result = FMOD_Channel_SetPan(channelLeft, -1.f);
result = FMOD_Channel_SetPan(channelRight, 1.f);
// Ensure that the two channels are starting in sync (see http://www.fmod.org/forum/viewtopic.php?f=7&t=15864)
result = FMOD_System_LockDSP(system);
result = FMOD_Channel_SetPaused(channelLeft, false);
result = FMOD_Channel_SetPaused(channelRight, false);
result = FMOD_System_UnlockDSP(system);
// Unrelated initialization code omitted
// Main loop
// Volume levels in left and right speakers are computed independently volLeft = computeVolLeft(); volRight = computeVolRight(); result = FMOD_Channel_SetVolume(channelLeft, volLeft); result = FMOD_Channel_SetVolume(channelRight, volRight);
This works, but I’m rather skeptical about using two channels to play a single sound. Is there a better way to accomplish this effect? Any suggestions would be appreciated.
- TheCatProblem asked 4 years ago
Your current solution would work, but it is needlessly complicated, have you looked at Channel::setSpeakerMix? This allows you to control the volume of each output speaker, alternatively you could use Channel::setSpeakerLevels which allows you to reroute input channels to output speakers.
Please login first to submit.