0
0

I’m writing a wrapper around fmod for my own evil purposes…

I have 2d and 3d sounds. I’m deferring all the FMOD changes until a commit call at the end of
each frame. A gross simplification of my code looks something like:
[code:3n9qw30l]
MYSound_SetPan(MY_Sound* s, int pan)
{
if (s->flags& FSOUND_2D)
{
s->command |= PAN;
s->pan = pan;
}
}

MySound_SetPosition(MY_Sound* s, Vector3d pos)
{
if (!(s->flags& FSOUND_2D))
{
s->command |= POS3D;
s->position = pos;
}
}

MYSound_Commit()
{
//For s = All Sounds
{
if (s->command & PLAY) s->channel = FSOUND_PlaySoundEx(FSOUND_FREE, s->sample, NULL, TRUE);
if (s->channel != UNUSED)
{
if (s->command & PAN) FSOUND_SetPan(s->channel, s->pan);
if (s->command & POS3D) FSOUND_3D_SetAttributes(s->channel, s->position, ...);
//... similar code for volume, pitch, etc
}
s->command = 0;
}
FSOUND_Update();
}

TestMain()
{
//...
while (!done)
{
//...
if (trigger==DO_PAN) MySound_SetPan(s, 255);
MYSound_Commit();
}
}
[/code:3n9qw30l]

My issue is that when I try to pan a sound, it doesn’t have any noticable effect. At least not in realtime. But when I step through in the debugger, the sound does move to the right immediately on the FSOUND_SetPan call. Then one or two steps after the FSOUND_Update, it moves back to center, even though my code has not made any more sound related calls. It appears that a FMOD thread is overriding my command.

If I remove the FSOUND_Update() call, the pan works fine for 2d sounds, but then none of the 3d position effects work for 3d sounds.
What could I have done to make FSOUND_Update() override my FSOUND_SetPan() calls? I am setting the sample’s defaults with FSOUND_Sample_SetDefaults, could that have an effect?

  • You must to post comments
0
0

I think you misunderstood, I guess I cut out too much code. Sorry.

I have some 2d samples (created with FSOUND_2D) and some 3d samples(created with default flags, so software 3D).
I am only setting pan on the 2d sounds.
I am only setting 3d attributes on the 3d sounds.

If I call FSOUND_Update(), the 3d positioning works correctly for the 3d sounds, but the 2d sound’s pan is getting overridden, back to center.
If I do not call FSOUND_Update(), the Pan works fine, but the 3d sounds are not positioned.
I’ll work on creating a minimal case that shows the issue. I should be able to use both 2d and 3d sounds at the same time, shouldn’t I?

  • You must to post comments
0
0

Ok, here’s a compile-able file that illustrates my issue. It does not Pan left when FSOUND_SetPan is called.
One interesting thing: this code fails to pan with a mono sample, but it does work with a stereo sample loaded using the FSOUND_FORCEMONO flags.

[code:10tere6j]#include <stdlib.h>

include <stdio.h>

include "fmod.h"

include "Windows.h"

void PlayAWhile(FSOUND_SAMPLE* s, bool Is2d)
{
int channel = FSOUND_PlaySound(FSOUND_FREE, s);
float vector[3]={-10,0,0};
for (int i=0;i<200;i++) {
if (i==100) {
if (Is2d){
printf("Panning Left\n");
FSOUND_SetPan(channel, 0);
}
else {
printf("Moving Left\n");
FSOUND_3D_SetAttributes(channel, vector, vector );
//moves left and pitches down.
}
}
FSOUND_Update(); //remove this line to make the pan work, but disable 3d.
Sleep(33);
}
FSOUND_StopSound(channel);
}

int main(int argc, char* argv[])
{
float center[3] = {0};
char* fileToLoad = "siren.wav"; //22K,16 bit mono, looping wav.
FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
FSOUND_Init(44100, 16, 0);
FSOUND_3D_Listener_SetAttributes(center, center, 0,0,1.0, 0,1.0,0);

//create 2D and 3d sample
FSOUND_SAMPLE *sample2d, *sample3d;
sample2d = FSOUND_Sample_Load(FSOUND_FREE, fileToLoad, FSOUND_2D, 0);
sample3d = FSOUND_Sample_Load(FSOUND_FREE, fileToLoad, 0, 0);

printf(&quot;Starting 2d\n&quot;);
PlayAWhile(sample2d, true);
printf(&quot;Starting 3d\n&quot;);
PlayAWhile(sample3d, false);

}
[/code:10tere6j]

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.