0
0

Hi to all.
In my application (roller coaster simulation) I load some audio tracks and I play them when I need. This give to me some problems.
I firstly post some code:

[code:am9hb127]/*******************************************************
startPlay
*******************************************************/
void SoFMODSound::startPlay()
{
FMOD_RESULT result;
load();

result = sound->setMode(loop.getValue() ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
SoFMODSystem::ERRCHECK(result, FILE, LINE);

channel = SoFMODSystem::getInstance()->playSound(sound);

if (channel != null)
{
// channel->setPosition(0, FMOD_TIMEUNIT_MS);
// frequency
result = channel->getFrequency(&trackFrequency);
SoFMODSystem::ERRCHECK(result, FILE, LINE);

   result = channel->setFrequency( speed.getValue() * trackFrequency );
   SoFMODSystem::ERRCHECK(result, __FILE__, __LINE__);

   // volume
   float vol;
   result = channel->setVolume( volume.getValue() );
   SoFMODSystem::ERRCHECK(result, __FILE__, __LINE__);

   result = channel->getVolume( &vol );
   SoFMODSystem::ERRCHECK(result, __FILE__, __LINE__);

   // Doppler level
   result = channel->set3DDopplerLevel( dopplerLevel.getValue() );
   SoFMODSystem::ERRCHECK(result, __FILE__, __LINE__);

   result = channel->setPaused( false ); //must be the last.
   SoFMODSystem::ERRCHECK(result, __FILE__, __LINE__);

}
else
cout << "Error" << endl;
}
[/code:am9hb127]

the load routine called inside the startPlay it’s so
[code:am9hb127]/******************************************************
load: load the sound to be played
******************************************************/
void SoFMODSound::load()
{

FMOD_RESULT  result;

SoInput in;

if (in.openFile(filename.getValue().getString(), true) == true)
{
    result = SoFMODSystem::getInstance()-&gt;getSystem()-&gt;createSound(filename.getValue().getString(),
                                                               (FMOD_MODE)(FMOD_3D | FMOD_SOFTWARE),
                                                               0,
                                                               &amp;sound);
    SoFMODSystem::ERRCHECK(result, __FILE__, __LINE__);

    if (result == FMOD_OK)
    {
        printf(&quot;loaded sample '%s'\n&quot;,filename.getValue().getString());
        mediaLoaded = true;
    }
}
else
{
    printf(&quot;Could not open file %s\n&quot;, filename.getValue().getString());
    return;
}

}[/code:am9hb127]

I have the following problems:
1)I would modify my code to implement a sort of trigger (start playing when something happens and stop playing when I decide to stop. Something as an on/off
2)when I start the application and the sounds are loaded I listen a strange noise before the sound. Seems to me a crrrr and then start the sound. Maybe the track is not completely loaded from the hard disk? Or what’s happening?

Thanx
Franco

  • You must to post comments
0
0

I too have a similar problem with a strange glitchy noise at the start of playback.

It seems to only occur occasionally when using the FMOD_3D flag and having my listener behind the emitter.

I’m carrying out some basic loading of sounds using FMOD_SOFTWARE|FMOD_3D, as well as using standard initialisation.

FMOD init:
[code:3vr5elr0] sys->init(100,FMOD_INIT_NORMAL,0);
sys->set3DSettings(1.0f, 1.0f, 1.0f); [/code:3vr5elr0]

Loading the sound:

[code:3vr5elr0]result = fmodsys->createSound(waveFile, FMOD_SOFTWARE|FMOD_3D, 0, &fmodsnd);[/code:3vr5elr0]

Playing the file:
[code:3vr5elr0] result = fmodsys->playSound(FMOD_CHANNEL_FREE,vPlaylist[plCurrent],true,&fmodchn);
UpdateEmitterPos();
result = fmodsys->playSound(FMOD_CHANNEL_FREE,vPlaylist[plCurrent],false,&fmodchn);
[/code:3vr5elr0]

I’ve also tried using createStream, ogg files, wav files and mp3 files.

Any help would be very much appreciated.

TIA 😀

  • You must to post comments
0
0

You would need to post your code for "UpdateEmitterPos()" but it looks like you are playing two sounds, one paused, one not paused. You are losing access to your first sound since your are replacing its channel with the second.

The normal way to do what I think you want to do is go:
playSonud(….. someChannel) // must be started paused if you want to change settings without hearing noise
someChannel->set3DAttributes(….)
someChannel->setPaused(false) // must be last or you will hear it move

  • You must to post comments
0
0

[quote="mathew":xwp1b3kk]You would need to post your code for "UpdateEmitterPos()" but it looks like you are playing two sounds, one paused, one not paused. You are losing access to your first sound since your are replacing its channel with the second.

The normal way to do what I think you want to do is go:
playSonud(….. someChannel) // must be started paused if you want to change settings without hearing noise
someChannel->set3DAttributes(….)
someChannel->setPaused(false) // must be last or you will hear it move[/quote:xwp1b3kk]

Thanks for the speedy reply Matthew.

Yes, I was indeed playing the same sound twice. I dropped in the setPaused() function and it works a treat. I don’t for the life of me know know why I was doing it the other way!

Sorry for the newbie question and for hijacking this thread, but thanks a bunch!

  • You must to post comments
0
0

Not a problem, it’s good to see you have it working.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.