There seems to be a range of values that can cause a crash if used in .setPitch for an sf::Sound. It looks like 50-51 is a problem area. Lower and higher than the range both seem fine. After further testing, it seems that the bit rate of the wave file is related and slightly adjusts the problem area.
I tested a range of values with four different sound files: two at 352kbps and two at 705kbps. The sounds with equal bit rates gave identical results.
Here's the code:
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
int main()
{
sf::Window window(sf::VideoMode(800, 600), ".setPitch Test");
sf::SoundBuffer soundBuffer;
sf::Sound sound;
if (!soundBuffer.loadFromFile("sample.wav"))
return -1;
sound.setBuffer(soundBuffer);
// "1" is a wave file with a bit rate of 352kbps (tested two different sounds)
// "2" is a wave file with a bit rate of 705kbps (tested two different sounds)
// uncomment only one of the follow lines:
//sound.setPitch(48); // works
//sound.setPitch(49); // works 1 - crashes 2
//sound.setPitch(49.25); // works 1 - crashes 2
//sound.setPitch(49.5); // works 1 - crashes 2
//sound.setPitch(49.75); // works 1 - crashes 2
//sound.setPitch(49.9); // works 1 - crashes 2
//sound.setPitch(49.904); // works 1 - crashes 2
//sound.setPitch(49.9045); // works 1 - crashes 2
//sound.setPitch(49.9047); // works 1 - crashes 2
//sound.setPitch(49.9048); // crashes
//sound.setPitch(49.905); // crashes
//sound.setPitch(49.91); // crashes
//sound.setPitch(49.95); // crashes
//sound.setPitch(50); // crashes
//sound.setPitch(51); // crashes
//sound.setPitch(51.1); // crashes
//sound.setPitch(51.15); // crashes
//sound.setPitch(51.152); // crashes 1 - works 2
//sound.setPitch(51.1523); // crashes 1 - works 2
//sound.setPitch(51.1524); // works
//sound.setPitch(51.1525); // works
//sound.setPitch(51.153); // works
//sound.setPitch(51.155); // works
//sound.setPitch(51.16); // works
//sound.setPitch(51.17); // works
//sound.setPitch(51.2); // works
//sound.setPitch(51.25); // works
//sound.setPitch(51.5); // works
//sound.setPitch(51.75); // works
//sound.setPitch(52); // works
//sound.setPitch(53); // works
//sound.setPitch(54); // works
sound.play();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.display();
}
return 0;
}
If you use this code, you can uncomment one of the .setPitch lines to test that value.
Does it crash in the same area for everyone? Does it only crash for me? Why is the bit rate related? Why does it work fine above and below these values?