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

Author Topic: delay in Sound.Play() (Windows XP)  (Read 10520 times)

0 Members and 3 Guests are viewing this topic.

shahn

  • Newbie
  • *
  • Posts: 16
    • View Profile
delay in Sound.Play() (Windows XP)
« 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
delay in Sound.Play() (Windows XP)
« Reply #1 on: April 09, 2010, 06:12:40 pm »
Can you show the relevant code?

Do you use the openal32 DLL provided in the SFML SDK?
Laurent Gomila - SFML developer

shahn

  • Newbie
  • *
  • Posts: 16
    • View Profile
delay in Sound.Play() (Windows XP)
« Reply #2 on: April 09, 2010, 07:00:59 pm »
The code is something like this:

Code: [Select]

#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.

Quote

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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
delay in Sound.Play() (Windows XP)
« Reply #3 on: April 09, 2010, 07:04:19 pm »
Hmm... I don't know. Does it happen with SFML 1.5? SFML 2.0? :D
Laurent Gomila - SFML developer

shahn

  • Newbie
  • *
  • Posts: 16
    • View Profile
delay in Sound.Play() (Windows XP)
« Reply #4 on: April 12, 2010, 01:55:57 pm »
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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
delay in Sound.Play() (Windows XP)
« Reply #5 on: April 12, 2010, 02:50:49 pm »
Quote
Is the snapshot created every day from svn?

Yep. I don't even manage that, it is done by the sourceforge servers.
Laurent Gomila - SFML developer

shahn

  • Newbie
  • *
  • Posts: 16
    • View Profile
delay in Sound.Play() (Windows XP)
« Reply #6 on: April 15, 2010, 05:02:08 pm »
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!

katrin

  • Newbie
  • *
  • Posts: 17
    • View Profile
delay in Sound.Play() (Windows XP)
« Reply #7 on: June 11, 2010, 09:26:18 am »
Quote from: "shahn"
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:

 
Code: [Select]


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!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
delay in Sound.Play() (Windows XP)
« Reply #8 on: June 11, 2010, 09:42:36 am »
Which revision of SFML 2 are you using? On which OS?
Laurent Gomila - SFML developer

katrin

  • Newbie
  • *
  • Posts: 17
    • View Profile
delay in Sound.Play() (Windows XP)
« Reply #9 on: June 11, 2010, 10:10:38 am »
Quote from: "Laurent"
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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
delay in Sound.Play() (Windows XP)
« Reply #10 on: June 11, 2010, 10:15:41 am »
Quote
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.
Laurent Gomila - SFML developer

katrin

  • Newbie
  • *
  • Posts: 17
    • View Profile
delay in Sound.Play() (Windows XP)
« Reply #11 on: June 11, 2010, 10:52:29 am »
Quote from: Laurent
Quote
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!!

katrin

  • Newbie
  • *
  • Posts: 17
    • View Profile
delay in Sound.Play() (Windows XP)
« Reply #12 on: June 11, 2010, 02:16:40 pm »
Quote from: katrin
Quote from: "Laurent"
Quote
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: .

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
delay in Sound.Play() (Windows XP)
« Reply #13 on: June 11, 2010, 03:20:53 pm »
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)?
Laurent Gomila - SFML developer

katrin

  • Newbie
  • *
  • Posts: 17
    • View Profile
delay in Sound.Play() (Windows XP)
« Reply #14 on: June 11, 2010, 04:44:19 pm »
Quote from: "Laurent"
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.