0
0

I apologize in advance if this question has already been answered.

I am trying to get simple 3d sound working with fmod

this is how I am initializing and playing the sound

Init:
[code:kcktenww]
init(void)
{
FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
FSOUND_SetDriver(0);

FSOUND_SetMixer(FSOUND_MIXER_AUTODETECT);
FSOUND_Init(44100, 32, 0);

temp = FSOUND_Sample_Load( FSOUND_UNMANAGED, "test.mp3",  FSOUND_HW3D  , 0, 0);
FSOUND_Sample_SetMinMaxDistance(temp, 4.0f, 100.0f); 
FSOUND_Sample_SetMode(temp, FSOUND_LOOP_NORMAL);

if (!temp)
{
    MessageBox(0, "no sound", "no sound", MB_OK);
}

FSOUND_3D_SetDistanceFactor(1.0f);
FSOUND_SetVolume(FSOUND_ALL, 255);      // go to max volume

float pos[3];
pos[0] = 0;
pos[1] = 0;
pos[2] = 0;

int channel = FSOUND_PlaySoundEx(FSOUND_FREE ,temp, 0, TRUE);
FSOUND_SetPriority(channel, 255);
FSOUND_3D_SetAttributes(channel, pos, 0);   
FSOUND_SetPaused(channel, FALSE);

FSOUND_SetSurround(channel, TRUE);
}
[/code:kcktenww]

Update:
[code:kcktenww]
void setListenerAttributes(float *pos, float forwardx, float forwardy, float forwardz, float upx, float upy, float upz)
{
FSOUND_3D_Listener_SetAttributes(pos, 0, forwardx, forwardy, forwardz, upx, upy, upz);

    FSOUND_Update();

}
[/code:kcktenww]

I have debugged the listenerAttributes with getListenerAtrributes and they are correct and the sound posisition is also correct. however I can move from side to side and there is no difference in left/right channel. Also I can get as far away from the sound as I want and it is still the same volume level.

If anyone could tell me anything that I am simply not doing I would greatly appreciate it

Also I have tried using the FSOUND_FORCE_MONO and it causes no sound at all to play, is this a known issue with fmod?

  • You must to post comments
0
0

There is nothing different from the 3d toutorial as far as I can see, actually that is what I was following to get as far as I did.

the code that I posted is everything I am doing to initalize, set up, and use fmod. I have checked that the listener and sound positions are set correctly and the velocity is left NULL to be ignored.

Yes, the sound I am playing is a stero sound, I remeber reading in the API docs that there is an issue with 3d sound and positional sound (which is why I tried the forcemono flag on sound load, but for some reason it causes sound not to play.

Is there a list of supported sound specs somewhere? ex: 16bit, mono, wav for 3d sound.

Also I tried loading the mp3 up into sound forge and saving it out as a mono mp3, but then fmod wouldnt play it at all again… that could be an issue with sound forge saving it out impropperly, or me intializing fmod improperly.

  • You must to post comments
0
0

Thanks brett, the problem was that it spawned multiple windows and I had not set the hwnd, I cant believe that was the problem and I had beating my head against it for almost a week.

  • You must to post comments
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…this is closest post I’ve found. 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:35y3tn8l]
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:35y3tn8l]
And the code concerned is:
[code:35y3tn8l]
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:35y3tn8l]

Any ideas to what I am doing wrong?

Thanks

  • You must to post comments
0
0

Hello

I seem to have a similar problem as DarkGod had… sadly not the same solution.
My problem is that I cant get my 3D sound to respond to listener position… when the sound is mp3. It works fine with wav but would like to make it work with mp3 as well.

Here are some of my code… really dont know what to post here but I hope someone can help me.

Init:
SoundManager::SoundManager(void)
{

if (!FSOUND_Init(32000, NUMBEROFCHANNELS, 0))
{
    printf(&quot;%s\n&quot;, FMOD_ErrorString(FSOUND_GetError()));
    exit(1);
}

mBulletTime = false;

mMusicVolume = 0.0;
mEffectVolume = 0.5;
mDialogueVolume = 0.0;

//have flipped these values around alot… no help :)
FSOUND_3D_SetDistanceFactor( 1 );
FSOUND_3D_SetRolloffFactor( 1000000 );

srand( unsigned( time_t(NULL) ) );
for( int i = 0; i &lt; 100; i++ )
    rand();

}
///Tried DarkGods sulotion…. sadly it didnt help
void SoundManager::setHWND( HWND *aHwnd )
{
FSOUND_SetHWND( aHwnd );
}

/////play effect (have checked that its set to 3D and the positions.. since it works with wav I guess thats not it )

bool SoundManager::playEffect( std::string aName, Vector3 aPos, bool a3DSound )
{
std::ofstream effectLog("EffectLog.txt", std::ios::app );
std::map< std::string, std::vector< std::string > >::iterator pos;
pos = mEffects.find( aName );
if( pos == mEffects.end() )
{
// Sound doesnt exist
return false;
}
else
{
int channel = DEFAULTCHANNEL;
for( int i = FIRSTEFFECTCHANNEL; i <= LASTEFFECTCHANNEL && channel == DEFAULTCHANNEL; i++ )
{
if( !FSOUND_IsPlaying( i ) )
{
channel = i;
}
}
if( channel == DEFAULTCHANNEL )
{
// No channels to play a sound in
return false;
}

    std::map&lt; int, FSOUND_SAMPLE* &gt;::iterator it;
    it = mSoundChannels.find( channel );
    if( it != mSoundChannels.end() )
    {
        FSOUND_Sample_Free( mSoundChannels.find( channel )-&gt;second );
        mSoundChannels.erase( mSoundChannels.find( channel ) );
    }

    FSOUND_SAMPLE *samp;
    int soundId = rand() % mEffects[ aName ].size();
    int error = 0;
    if( a3DSound )
    {
        samp = FSOUND_Sample_Load( channel, mEffects[ aName ][ soundId ].c_str(), FSOUND_HW3D | FSOUND_LOOP_OFF, 0, 0 );
        error = FSOUND_PlaySound( FSOUND_FREE, samp );
        if( error == -1 )
        {
            printf(&quot;ERROR: %s     \n&quot;, FMOD_ErrorString(FSOUND_GetError()));
            return false;
        }
        FSOUND_3D_SetAttributes( channel, aPos.ptr(), NULL );

        float *pos;
        pos = new float[3];
        FSOUND_3D_Listener_GetAttributes( pos, NULL, NULL, NULL, NULL, NULL, NULL, NULL );
        effectLog &lt;&lt; &quot;SX: &quot; &lt;&lt; aPos.x &lt;&lt; &quot;\tSY: &quot; &lt;&lt; aPos.y &lt;&lt; &quot;\tSZ: &quot; &lt;&lt; aPos.z &lt;&lt; &quot;\n&quot;;
        effectLog &lt;&lt; &quot;LX: &quot; &lt;&lt; pos[0] &lt;&lt; &quot;\tLY: &quot; &lt;&lt; pos[1] &lt;&lt; &quot;\tLZ: &quot; &lt;&lt; pos[2] &lt;&lt; &quot;\n&quot;;
    }
    else
    {
        samp = FSOUND_Sample_Load( channel, mEffects[ aName ][ soundId ].c_str(), FSOUND_2D | FSOUND_LOOP_OFF, 0, 0 );
        error = FSOUND_PlaySound( channel, samp );

    }

ifdef _DEBUG

if( samp == NULL )
{
printf("ERROR: %s \n", FMOD_ErrorString(FSOUND_GetError()));
return false;
}
if( error == -1 )
{
printf("ERROR: %s \n", FMOD_ErrorString(FSOUND_GetError()));
return false;
}

endif

    FSOUND_SetVolume( channel, int( mEffectVolume * 255.0 ) );
    if( mBulletTime )
    {
        int f = FSOUND_GetFrequency( channel );
        FSOUND_SetFrequency( channel, f * FREQUENCEVALUE );
    }

    mSoundChannels.insert( std::pair&lt; int, FSOUND_SAMPLE * &gt;( channel, samp ));
}
return true;

}

////update
void SoundManager::updateListener( Vector3 aPos, Vector3 aForward, Vector3 aTop )
{
FSOUND_3D_Listener_SetAttributes( aPos.ptr(), NULL, aForward.x, aForward.y, aForward.z, aTop.x, aTop.y, aTop.z );
FSOUND_Update();
}

ps. I am sorry if this have been posted somewhere else… didnt find it and have been looking for a solution to this since yeasterday with a friend but no luck on either documentations or internet.

EDIT:
Ok… just whondering something. Is there some special steps to take when playing with mp3’s? I tried to make the volume go down acording to distance… nothing happend. Then I forced the volume to 0 but still no change and the effect still plays. So just whondering what I am fialing at when it comes to mp3 :)

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.