Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: 1/2 Second Delay in Sound playing... Any Ideas ???  (Read 10046 times)

0 Members and 1 Guest are viewing this topic.

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
1/2 Second Delay in Sound playing... Any Ideas ???
« 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
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
1/2 Second Delay in Sound playing... Any Ideas ???
« Reply #1 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.

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
1/2 Second Delay in Sound playing... Any Ideas ???
« Reply #2 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)...
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
1/2 Second Delay in Sound playing... Any Ideas ???
« Reply #3 on: February 15, 2009, 10:08:49 pm »
Maybe you are using a mega-huge buffer?

Seby

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
1/2 Second Delay in Sound playing... Any Ideas ???
« Reply #4 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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
1/2 Second Delay in Sound playing... Any Ideas ???
« Reply #5 on: May 20, 2009, 11:02:02 am »
Have you tried the latest sources from SVN?
Laurent Gomila - SFML developer

Seby

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
1/2 Second Delay in Sound playing... Any Ideas ???
« Reply #6 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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
1/2 Second Delay in Sound playing... Any Ideas ???
« Reply #7 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 :)
Laurent Gomila - SFML developer

Seby

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
1/2 Second Delay in Sound playing... Any Ideas ???
« Reply #8 on: May 20, 2009, 11:00:22 pm »
OK thanks, I'll give you feedback after I try the SVN version.

Seby

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
1/2 Second Delay in Sound playing... Any Ideas ???
« Reply #9 on: May 22, 2009, 11:02:11 am »
It seems the problem does not occur anymore with the last version (SVN).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
1/2 Second Delay in Sound playing... Any Ideas ???
« Reply #10 on: May 22, 2009, 11:07:19 am »
Great :)
Laurent Gomila - SFML developer

 

anything