SFML community forums
Help => Audio => Topic started 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
// 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
-
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.
-
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.
// 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)...
-
Maybe you are using a mega-huge buffer?
-
Hi,
I've got the same problem (with SFML1.4 / Ubuntu8.10 / 32 bits).
Has someone already solved the problem ?
-
Have you tried the latest sources from SVN?
-
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 ?
-
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 :)
-
OK thanks, I'll give you feedback after I try the SVN version.
-
It seems the problem does not occur anymore with the last version (SVN).
-
Great :)