SFML community forums
Help => Audio => Topic started by: shahn on April 09, 2010, 05:57:55 pm
-
Hi!
I am using sfml-audio to play some sounds and there seems to be a delay between the call to Sound.Play() and the actual playing of the sound. My estimate is, that the delay is ~250 ms long (but that's of course hard to measure). This problem shows in Windows XP, on a linux system the same code plays sounds without the delay.
When I try to play the sound looped (as suggested in another thread for a similar problem) there is no gap.
Is this a problem with sfml, OpenAL or something else?
Any help appreciated.
Sönke
System info:
Windows XP
SFML-1.6
gcc-4.4.0
sound format: .wav
-
Can you show the relevant code?
Do you use the openal32 DLL provided in the SFML SDK?
-
The code is something like this:
#include <iostream>
using namespace std;
#include <SFML/Audio.hpp>
void debug(string msg) {
cout << msg << "\n";
};
int main() {
sf::SoundBuffer buffer = sf::SoundBuffer();
if (!buffer.LoadFromFile("sound.wav")) {
debug("error in SFML-AUDIO::cpp::loadFromFile");
};
sf::Sound sound = sf::Sound();
sound.SetBuffer(buffer);
for (int i = 0; i < 10; i++) {
sound.Play();
debug("Play() called");
Sleep(2000);
};
};
(note: Sleep() is from the Win32 api, not sf::Sleep() from sfml.)
Of course, it's not that exact to just look at the console and try to see (and hear) a delay between the console output and the sound, but it's definitely a much smaller delay on Linux.
Additionally I wrote a testing program that triggers a sound for every keystroke. It uses Qt and is written in Haskell (calling sfml-audio functions via minimal bindings), so I won't post it here (unless someone wants me to). With this interactive program it's easy to verify, that sound playback is not as snappy as it should be.
Do you use the openal32 DLL provided in the SFML SDK?
I hope so. I put the open32.dll-file that comes with sfml into the same folder as the executable. (And I get an error if I don't. But there is another openal32.dll on my system and I am always confused where windows looks for dlls.)
Thanks for your quick help.
-
Hmm... I don't know. Does it happen with SFML 1.5? SFML 2.0? :D
-
With SFML 1.5 the problem is the same.
I didn't manage to compile the SFML 2.0 snapshot yet. I will look into that tomorrow... Is the snapshot created every day from svn?
-
Is the snapshot created every day from svn?
Yep. I don't even manage that, it is done by the sourceforge servers.
-
Yay, it works!
With the sfml2 svn snapshot there is no notable delay. I am looking for a platform independent sound library for some time now, so sfml made my day! Also the separation between the different modules of sfml (system, audio, etc.) comes in really handy in my case.
Many thanks!
-
Yay, it works!
With the sfml2 svn snapshot there is no notable delay.
Unfortunately I can't share the joy. We are using SFML for audio experiments in psychology and recently came along the same problem of the constant delay. In SFML 2.0 the delay is the same as in 1.4 and 1.6 - a constant ~186ms. We checked it with a voice-key.
The timing is extremly crucial to our experiments do you have any idea how to avoid the delay?
Here is my the test loop. The voice-key is activated over the parallel port:
for( int i = 0 ; i < 10 ; i++ ) {
cout << "After each tone start voicekey- reaction time is measured and should be 0ms gemessen." << endl;
Clock.Reset() ;
if( !( Stimulus.GetStatus() == sf::Sound::Playing ) ) {
Stimulus.Play();
}
do {
taste = ReadTaste() ; // read out parallel port informationen
} while( taste == 255 ) ; // while voice-key is not activated
rt = Clock.GetElapsedTime()*1000.0f ;
WaitUntilMS( Clock, 1000 ) ;
cout << rt << endl;
}
WaitForMS( 1000 ) ;
I'd be happy for any suggestions!
-
Which revision of SFML 2 are you using? On which OS?
-
Which revision of SFML 2 are you using? On which OS?
SFML yesterdays SVN version, so I think 2.0 (sorry for such beginners statement)
Windows XP
Code::Blocks with mingcc4.4
-
SFML yesterdays SVN version, so I think 2.0 (sorry for such beginners statement)
Hum... how did you get the sources, and which part of the repository did you compile? Maybe you're still using an SFML 1.x version, because both 1.x and 2.0 exist on the repository. SFML 2 is located under /branches/sfml2 while SFML 1.x (currently 1.7) is under /trunk.
-
Maybe you're still using an SFML 1.x version, because both 1.x and 2.0 exist on the repository. SFML 2 is located under /branches/sfml2 while SFML 1.x (currently 1.7) is under /trunk.
That seems plausible, I compiled 1.7 then. I'll try the other and run the test again.
Thanx!!
-
Maybe you're still using an SFML 1.x version, because both 1.x and 2.0 exist on the repository. SFML 2 is located under /branches/sfml2 while SFML 1.x (currently 1.7) is under /trunk.
That seems plausible, I compiled 1.7 then. I'll try the other and run the test again.
Thanx!!
Okay, I did compile SFML2.0 correctly now, but the problem is the same: We still have a constant delay of ~186ms from calling Sound.Play() until the sound actually starts :cry: .
-
Do you use the OpenAL DLL provided by SFML?
Are you sure that you really use SFML2 (did you have to change something in your source code)?
-
Do you use the OpenAL DLL provided by SFML?
Are you sure that you really use SFML2 (did you have to change something in your source code)?
yep, I really do have to change a lot of stuff (for now I commented the matter irrelevant things out), so I am sure, that I do use SFML2.0
Updating the OpenAL DLL reduced the constant delay we measure to ~89ms.