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

Author Topic: Restarting a sound produces an audible click  (Read 2154 times)

0 Members and 1 Guest are viewing this topic.

Kipernal

  • Newbie
  • *
  • Posts: 29
    • View Profile
Restarting a sound produces an audible click
« on: November 18, 2011, 11:20:16 am »
First off, if this has already been asked, I apologize, though I didn't find anything helpful through a search.

Whenever Play() restarts an already playing sound, an annoying, audible click is produced:



I won't claim to know much about how sounds work, but it looks like whatever interpolation algorithm is being used is getting some bad data between when the sound stops and when it stops, so its attempt to smooth the curve ends up with a sharp spike (i.e. instead of smoothing the curve to 0 it smooths it to -1, and then back to 0 when the sound restarts).  ...just a theory, though.  Like I said, I don't know much about the details of how this works.

Incidentally all the values for the played sound in this example are at the default (aside from its SoundBuffer), and I got this result in SFML 2 (I don't know about SFML 1).  It's also not an .ogg file.  Any help would be greatly appreciated.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Restarting a sound produces an audible click
« Reply #1 on: November 18, 2011, 11:32:15 am »
Could you please provide a complete and minimal example that reproduces the problem, and upload the corresponding audio file?
Laurent Gomila - SFML developer

Kipernal

  • Newbie
  • *
  • Posts: 29
    • View Profile
Restarting a sound produces an audible click
« Reply #2 on: November 18, 2011, 11:48:03 am »
Ah, sorry, I didn't think this problem needed one.

Code: [Select]
#include <SFML/Audio.hpp>
#include <SFML/Window.hpp>

sf::Window App;
sf::Sound testSound;

int main(int argc, char* argv[])
{
sf::SoundBuffer testBuffer;
App.Create(sf::VideoMode(800, 600), "Audio");
App.SetFramerateLimit(60);

testBuffer.LoadFromFile("test.wav");
testSound.SetBuffer(testBuffer);
while (App.IsOpened())
testSound.Play();
return 0;
}


As for the actual sound, it's here.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Restarting a sound produces an audible click
« Reply #3 on: November 25, 2011, 11:11:05 pm »
It's hard to test anything with this code and this sound. It's a very small sound, and all you do in your code is to restart it at a very high frequency, we can only hear the very first samples repeated again and again.

To hear a click you should:
- find a long (at least a few seconds) sound, made of a single frequency
- restart it only after a significant amount of time (like every second)
Laurent Gomila - SFML developer

 

anything