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

Author Topic: Delay when using sf::Sound  (Read 4864 times)

0 Members and 1 Guest are viewing this topic.

Alvaro

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Delay when using sf::Sound
« on: October 31, 2013, 07:28:37 pm »
Hi,

I am getting a large delay (about 0.2 seconds) when trying to play a sound using sf::Sound.

I am using SFML 2.1 with Ubuntu 13.10 Linux in VirtualBox, with a MacBook Air running OSX 10.9 as the host. I tried installing XCode 5 and SFML 2.1 on the OSX directly and then there is no appreciable delay. I am pretty confident at this point that my program is correct (it's a simple test and I am a competent programmer, plus it works fine on OSX, as I just explained). So it must be something with the OpenAL driver in my Linux installation , or something of that sort (and this is the type of thing where I am not competent at all).

Does anyone have any ideas on how to fix this, or where to even begin to look? I will continue programming on OSX for the time being, but I really like programming on Linux much better, and it would be nice if SFML 2.1 could be used in my VirtualBox setup.

Thanks!


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Delay when using sf::Sound
« Reply #1 on: October 31, 2013, 08:37:42 pm »
Even if you're a damn good programmer it can't hurt to show your code ;)
Laurent Gomila - SFML developer

Alvaro

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Delay when using sf::Sound
« Reply #2 on: October 31, 2013, 08:41:27 pm »
True that. I'll make a minimal program that shows the problem and post it here.

Alvaro

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Delay when using sf::Sound
« Reply #3 on: November 01, 2013, 02:42:15 am »
Here it goes. I removed most of what was unrelated to the problem, and I verified that the problem is still there.

#include <iostream>
#include <cstdlib>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>

int main() {
  sf::Window window;
  window.create(sf::VideoMode(800,600), "SFML Audio Test");
 
  // Load sound data
  sf::SoundBuffer sample_sb;
  if (!sample_sb.loadFromFile("sfx/Sample.wav")) {
    std::cerr << "Can't open \"sfx/Sample.wav\"\n";
    std::exit(1);
  }
  sf::Sound sound;
  sound.setBuffer(sample_sb);
 
  while (window.isOpen()) {
    // Process events
    sf::Event event;
    while (window.pollEvent(event)) {
      switch (event.type) {
      case sf::Event::Closed:
        window.close();
        break;
      case sf::Event::KeyPressed:
        switch (event.key.code) {
        case sf::Keyboard::Escape:
          window.close();
          break;
        case sf::Keyboard::Space:
          sound.play();
        default:;
        }
        break;
      default:;
      }
    }
  }
}
 
« Last Edit: November 01, 2013, 08:06:09 am by Laurent »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Delay when using sf::Sound
« Reply #4 on: November 01, 2013, 07:21:18 am »
With delay I assume you mean that it takes a bit when pressing space for thd sound to start?

I further assume that you've already made sure it's not the event propagation that's delayed, right?

Again to clearify the issue only exists in the VM?
Did you run other sound applications in there, my first guess would go to your VM lagging behind somehow...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Alvaro

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: AW: Delay when using sf::Sound
« Reply #5 on: November 01, 2013, 12:27:03 pm »
With delay I assume you mean that it takes a bit when pressing space for thd sound to start?
Yes.

Quote
I further assume that you've already made sure it's not the event propagation that's delayed, right?
Yes, my full code has visual feedback and that works just fine.

Quote
Again to clearify the issue only exists in the VM?
Yes.

Quote
Did you run other sound applications in there, my first guess would go to your VM lagging behind somehow...
Rats! I thought I had checked this, but I just checked again, and there's my delay. Sorry for wasting everybody's time. [Walks away in shame]

I looked around the web for reports of delays in Ubuntu and found that removing PulseAudio fixes my problem.

Thank you all for your time.