0
0

I am truly stumped as to why I can’t get 3d sound working :-( … I have tried both moving the sound by changing values SOUND_3D_SetAttributes and by using the listener using FSOUND_3D_Listener_SetAttributes but when the sound is played there is no different whats so ever with the music being played. I’ve spent hours looking through the forums and have changed my code around many times with no luck…the closest post I’ve found to my problem was http://52.88.2.202/forum/viewtopic.php?p=36550#36550 ..When I make the changes suggested here by settting FSOUND_SetHWND to null (not sure what else to set it with?), using
FSOUND_INIT_GLOBALFOCUS in init(), and using FSOUND_FORCEMONO I get no sound at all…

I intialise FMOD by:
[code:2xeagibp]
FMOD.RESULT result;
int retrycount = 0;
FMODWrap.PPC.FSOUND_SetHWND(IntPtr.Zero);
while (!FMODWrap.PPC.FSOUND_Init(22500, 32, 0x0002) && retrycount < 10)
{
System.Threading.Thread.Sleep(100);
retrycount++;
}
if (retrycount == 10)
{
result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError();
ERRCHECK(result);
}
[/code:2xeagibp]
And the code concerned is:
[code:2xeagibp]
FMOD.RESULT result;
soundStream = FMODWrap.PPC.GetStream(songPath);
soundHandle = FMODWrap.PPC.FSOUND_Stream_Open(soundStream,
(uint)(FMODWrap.PPC.Modes.CREATESTREAM|FMODWrap.PPC.Modes.FSOUND_FORCEMONO),
0, 0);
if (soundHandle == IntPtr.Zero)
{
result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError();
ERRCHECK(result);
}

   //  Play sounds at certain positions
  pos1.x = 200.0f * DISTANCEFACTOR; pos1.y = 0.0f; pos1.z = 200.0f;
  vel1.x = 0.0f; vel1.y = 0.0f; vel1.z = 0.0f;

  channel = FMODWrap.PPC.FSOUND_Stream_PlayEx((int)(FMODWrap.PPC.CHANNELINDEX.FSOUND_FREE), soundHandle, (IntPtr)null, true);
  if (channel == -1)
  {
    ERRCHECK(FMOD.RESULT.ERR_PLAY_FAILED);
  }

  tryMe = FMODWrap.PPC.FSOUND_SetVolume(channel, 255);
  if (!tryMe)
  {
    result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError();
    ERRCHECK(result);
  }
 tryMe = FMODWrap.PPC.FSOUND_3D_SetAttributes(channel,ref pos1, ref vel1);
 if (!tryMe)
 {
   result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError();
   ERRCHECK(result);
 }
 listenerpos.x = 0.0f;
 listenerpos.y = 0.0f;
 listenerpos.z = 0.0f;
 tryMe = FMODWrap.PPC.Set3dListenerAttributes(ref listenerpos, ref vel1, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);
  if (!tryMe)
 {
   result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError();
   ERRCHECK(result);
 }

tryMe = FMODWrap.PPC.FSOUND_SetPaused(channel, false);
 if (!tryMe)
 {
   result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError();
   ERRCHECK(result);
 }

[/code:2xeagibp]

Any ideas to what I am doing wrong?

Thanks

  • You must to post comments
0
0

Is there anyone out there that can help????? Brett? Andrew? Anyone…

I’ve been stuck on this for over two weeks now and i’m really stumped 😥

I’ve tried running the examples (3d and 3d2) but they don’t seem to run on my device (HTC Touch Cruise) or on the WM6 emulator 😥

Something which I’ve noticed today is that when FSOUND_Stream_Open() is called without FSOUND_FORCEMONO and I check for errors, FMOD_ERR_INVALID_PARAM is returned even though the song still plays? Is this related?

  • You must to post comments
0
0

Are you calling FSOUND_Update every frame?

FSOUND_SetHWND is not used in Windows CE

Try running some code in windows xp first.

  • You must to post comments
0
0

Hi Brett,

I have based the layout of my code on the 3d example given in csharp for FMODEX, and the code from the 3d example for fmodce.

I have a timer set to 49 [code:23s3hjyc] this.timer.Interval = 49;[/code:23s3hjyc]where FSOUND_Update() is called.

I moved all the 3d sound elements to one method to see if I could get it to work (the code above), with no joy 😥 if I move everything back following the same layout as the example for FMODEX with a few changes, sound plays (without any 3d effects ) when all the parameters passed into FSOUND_3D_SetAttributes() are zero:

[code:23s3hjyc]pos.x = 0.0f * DISTANCESCALE; pos.y = 0.0f; pos.z = 0.0f * DISTANCESCALE;
vel.x = 0.0f; vel.y = 0.0f; vel.z = 0.0f;
tryMe = FMODWrap.PPC.FSOUND_3D_SetAttributes(channel, ref pos, ref vel);[/code:23s3hjyc]

when I change them back to those in the 3d example (for fmod ce), I hear nothing:

[code:23s3hjyc]

pos.x = -10.0f * DISTANCESCALE; pos.y = -0.0f; pos.z = 1.0f * DISTANCESCALE;
vel.x = 0.0f; vel.y = 0.0f; vel.z = 0.0f;

[/code:23s3hjyc]

Any ideas as to why this maybe?

  • You must to post comments
0
0

It works!!!! after two weeks of nothing…3d sound finally works!

Since the original post a lot of my code has changed so I’m not sure exactly which part solved the problem, but here is how it looks now:

[code:3nltx5gb]
Intialise fmod by:

  FMOD.RESULT result;
  int retrycount = 0;
  IntPtr hwnd = FMODWrap.PPC.FindWindow(null, &quot;TheApp&quot;)
  FMODWrap.PPC.FSOUND_SetHWND(hwnd);
  while (!FMODWrap.PPC.FSOUND_Init(22500, 32, 0x0002) &amp;&amp; retrycount &lt; 10)
  {
    System.Threading.Thread.Sleep(100);
    retrycount++;
  }
  if (retrycount == 10)
  {
    result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError();
    ERRCHECK(result);
   } 

[/code:3nltx5gb]

[code:3nltx5gb]
FMOD.RESULT result;
soundStream = FMODWrap.PPC.GetStream(songPath);
soundHandle = FMODWrap.PPC.FSOUND_Stream_Open(soundStream,
(uint)(FMODWrap.PPC.Modes.CREATESTREAM | FMODWrap.PPC.Modes.FSOUND_NORMAL | FMODWrap.PPC.Modes.FSOUND_FORCEMONO),
0, 0);
if (soundHandle == IntPtr.Zero)
{
result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError();
ERRCHECK(result);
}

tryMe = FMODWrap.PPC.SetMinMaxDistance(channel, 4.0f * DISTANCESCALE, 1000.0f * DISTANCESCALE);
if (!tryMe)
{
result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError(();
ERRCHECK(result);
}

  channel = FMODWrap.PPC.FSOUND_Stream_PlayEx((int)(FMODWrap.PPC.CHANNELINDEX.FSOUND_FREE), soundHandle, (IntPtr)null, true);
  if (channel == -1)
  {
    ERRCHECK(FMOD.RESULT.ERR_PLAY_FAILED);
  }

  tryMe = FMODWrap.PPC.FSOUND_SetVolume(channel, 255);
  if (!tryMe)
  {
    result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError();
    ERRCHECK(result);
  }

FMODWrap.PPC.VECTOR pos = new FMODWrap.PPC.VECTOR();
FMODWrap.PPC.VECTOR vel = new FMODWrap.PPC.VECTOR();
pos.x = -10.0f * DISTANCEFACTOR; pos.y = -0.0f; pos.z = 0.0f;
vel.x = 0.0f; vel.y = 0.0f; vel.z = 0.0f;

 tryMe = FMODWrap.PPC.FSOUND_3D_SetAttributes(channel,ref pos1, ref vel1);
 if (!tryMe)
 {
   result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError();
   ERRCHECK(result);
 }

tryMe = FMODWrap.PPC.FSOUND_SetPaused(channel, false);
 if (!tryMe)
 {
   result = (FMOD.RESULT)FMODWrap.PPC.FSOUND_GetError();
   ERRCHECK(result);
 } 

FMODWrap.PPC.FSOUND_Update();
result = (FMOD.RESULT)FMODWrap.PPC.getError();
ERRCHECK(result);

[/code:3nltx5gb]

and in timer1_tick:

[code:3nltx5gb]
FMODWrap.PPC.VECTOR forward = new FMODWrap.PPC.VECTOR();
forward.x = 0.0f; forward.y = 0.0f; forward.z = 1.0f;

  FMODWrap.PPC.VECTOR up = new FMODWrap.PPC.VECTOR();
  up.x = 0.0f; up.y = 1.0f; up.z = 0.0f;

  FMODWrap.PPC.VECTOR vel = new FMODWrap.PPC.VECTOR();

  if (listenerflag)
  {
    playing=true;
    listenerpos.x = ((float)Math.Sin(t * 0.05f) * 33.0f * DISTANCEFACTOR);
    trackBarPosition.Value = (int)listenerpos.x;
  }

  // ********* NOTE ******* READ NEXT COMMENT!!!!!
  // vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
  vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME);
  vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME);
  vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME);

  // store pos for next time
  lastpos.x = listenerpos.x;
  lastpos.y = listenerpos.y;
  lastpos.z = listenerpos.z;

  tryMe = FMODWrap.PPC.Set3dListenerAttributes(ref listenerpos, ref vel, 0, 0, 1.0f, 0, 1.0f, 0);
  if (!tryMe)
  {
    result = (FMOD.RESULT)FMODWrap.PPC.getError();
    ERRCHECK(result);
  }

  t += (30 * (1.0f / (float)INTERFACE_UPDATETIME));    // t is just a time value .. it increments in 30m/s steps in this example
  FMODWrap.PPC.FSOUND_Update();
  result = (FMOD.RESULT)FMODWrap.PPC.getError();
  ERRCHECK(result);

[/code:3nltx5gb]

Admittedly the sound quality is really bad now. The song sounds like its been slowed down and distorted. Is this due to forcing the stream to mono? Is there anyway to improve it? Will changing the speakermode, the Doppler Factor, the Roll off Factor, or setting the Frequency help? Please excuse my naivety, I don’t know much about audio 😳

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.