SFML community forums

Help => Audio => Topic started by: JeZ-l-Lee on February 06, 2009, 04:00:59 am

Title: 1/2 Second Delay in Sound playing... Any Ideas ???
Post by: JeZ-l-Lee on February 06, 2009, 04:00:59 am
1/2 Second Delay in Sound playing... Any Ideas ???

Platform is Windows Vista 32bit

Code: [Select]
// Load a sound effect to play...
sf::SoundBuffer Buffer;
if (!Buffer.LoadFromFile("data/sound/Click.wav"))
return EXIT_FAILURE;

sf::Sound Sound;
Sound.SetBuffer(Buffer); // Buffer is a sf::SoundBuffer

//...

Sound.Play();


Here is the sound effect file:
http://silentheroproductions.com/files/Click.wav
Title: 1/2 Second Delay in Sound playing... Any Ideas ???
Post by: quasius on February 06, 2009, 04:50:14 am
It's most likely the time it takes to load the media from the hard drive.  If you load the sound ahead of when you need it, it should play immediately.
Title: 1/2 Second Delay in Sound playing... Any Ideas ???
Post by: JeZ-l-Lee on February 06, 2009, 04:35:54 pm
Quote from: "quasius"
It's most likely the time it takes to load the media from the hard drive.  If you load the sound ahead of when you need it, it should play immediately.



Hi,

No, I load the sound ahead of time outside the main game loop.
Then I play the sound in the main game loop (when [Spacebar] is pressed to skip screens.

Code: [Select]
// Load a sound effect to play...
sf::SoundBuffer Buffer;
if (!Buffer.LoadFromFile("data/sound/Click.wav"))
return EXIT_FAILURE;

sf::Sound Sound;
Sound.SetBuffer(Buffer); // Buffer is a sf::SoundBuffer

//===============================================================================================
while (visuals->App.IsOpened())
{
visuals->MilliSeconds = visuals->MyClock.GetElapsedTime();
visuals->NextFrameMS  = visuals->MilliSeconds + .01815;

visuals->FramesPerSecond++;

if (visuals->MilliSeconds >= visuals->NextSecond)
{
visuals->FPS_Array[visuals->FPS_ArrayIndex] = visuals->FramesPerSecond;

visuals->FramesPerSecond = 0;
visuals->NextSecond = visuals->MyClock.GetElapsedTime() + 1;

visuals->FPS_ArrayIndex++;
if (visuals->FPS_ArrayIndex > 9)  visuals->FPS_ArrayIndex = 0;
}

// Process events
sf::Event Event;
while (visuals->App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
visuals->App.Close();

if (Event.Type == sf::Event::KeyPressed)
{
if (Event.Key.Code == sf::Key::Space)
if (visuals->ScreenStatus == DisplayScreenForWhile)
{






//=============================================
Sound.Play(); //<-PLAY SOUND HERE (User pressed [Spacebar]...
//=============================================








visuals->ScreenStatusCounter = 1000;
}
}
}

if (visuals->ScreenToDisplay == SFMLInformationScreen)  DisplaySFMLInformationScreen();
else if (visuals->ScreenToDisplay == SilentHeroProductionsScreen)  DisplaySilentHeroProductionsScreen();
else if (visuals->ScreenToDisplay == TitleScreen)  DisplayTitleScreen();

uint16_t total = 0;
for (uint16_t index = 0; index < 10; index++)
{
total = total + visuals->FPS_Array[index];
}
total = total / 10;
sprintf(visuals->VariableText, "%d", total);
visuals->DrawTextOnScreenBuffer(visuals->VariableText, 22, sf::Color(0, 255, 0, 255), sf::Color(0, 0, 0, 255), true, 10, 10, TextLeft);

visuals->DisplayScreenBufferOnScreen();

visuals->MilliSeconds = visuals->MyClock.GetElapsedTime();
if (visuals->NextFrameMS > visuals->MilliSeconds) sf::Sleep(visuals->NextFrameMS - visuals->MilliSeconds);
}
//===============================================================================================
visuals->UnloadFontsFromMemory();

visuals->UnloadAllBMPsFromMemory();

//delete Buffer;


delete visuals;

return EXIT_SUCCESS;
}
// A 100% By JeZ+Lee and mattmatteh of Silent Hero Productions(R)...
Title: 1/2 Second Delay in Sound playing... Any Ideas ???
Post by: model76 on February 15, 2009, 10:08:49 pm
Maybe you are using a mega-huge buffer?
Title: 1/2 Second Delay in Sound playing... Any Ideas ???
Post by: Seby on May 20, 2009, 10:35:19 am
Hi,
I've got the same problem (with SFML1.4 / Ubuntu8.10 / 32 bits).
Has someone already solved the problem ?
Title: 1/2 Second Delay in Sound playing... Any Ideas ???
Post by: Laurent on May 20, 2009, 11:02:02 am
Have you tried the latest sources from SVN?
Title: 1/2 Second Delay in Sound playing... Any Ideas ???
Post by: Seby on May 20, 2009, 04:48:16 pm
Quote from: "Laurent"
Have you tried the latest sources from SVN?
No I haven't.
Do you mean the "delay" is a known problem, and that it is already solved ?
Title: 1/2 Second Delay in Sound playing... Any Ideas ???
Post by: Laurent on May 20, 2009, 04:52:50 pm
Quote
Do you mean the "delay" is a known problem, and that it is already solved ?

Not exactly, but there are many modifications to the audio code and this bug could have disappeared as a side effect.
If not, then I can start to investigate on this bug :)
Title: 1/2 Second Delay in Sound playing... Any Ideas ???
Post by: Seby on May 20, 2009, 11:00:22 pm
OK thanks, I'll give you feedback after I try the SVN version.
Title: 1/2 Second Delay in Sound playing... Any Ideas ???
Post by: Seby on May 22, 2009, 11:02:11 am
It seems the problem does not occur anymore with the last version (SVN).
Title: 1/2 Second Delay in Sound playing... Any Ideas ???
Post by: Laurent on May 22, 2009, 11:07:19 am
Great :)