SFML community forums
Help => Audio => Topic started by: Raptormeat on September 18, 2016, 01:41:14 am
-
Hey there! Thanks again for this great library! I have a game which uses SFML for audio, and I've had this odd problem for a few years now where the music makes a cracking / popping sound randomly.
The music is encoded in OGG files which are decrypted using a custom sf::InputStream as far as I can tell nothing is out of the ordinary there.
The weird thing is that this problem seems to be made worse with high CPU load. My game is eating up a lot of cycles, I guess. If I "relax" the CPU usage by calling Sleep() every once in a while, the problem is made better. Users with lower-spec machines tell me the problem is worse for them.
Can anyone help think of reasons why this could possibly be happening? I know that there is a problem with OGG files needing normalization, but I'm not sure if that's my problem as it doesn't sound random or affected by CPU load the way my issue does.
-
First you should try and rule out that it's not an issue with your decryption/streaming by for example loading the sound data directly from disk.
Secondly you should rule out that it's not just your OGG files, by trying some other OGG files from other locations.
At high CPU utilization it might also be that the music thread isn't getting enough CPU time.
-
IMO your decryption algorithm may be too slow, could you post it and some encrypted ogg file?
-
At high CPU utilization it might also be that the music thread isn't getting enough CPU time.
Thanks for writing back! If this is the issue, is there anything I can do about it? Is there something like a buffer size I can increase?
I had seen elsewhere that Laurent posted that the music has a 1 second buffer. Is it possible that SFML waits long enough to replenish this buffer that a few miliseconds might make a difference?
IMO your decryption algorithm may be too slow, could you post it and some encrypted ogg file?
It's possible. Basically how it works is in my filestream's read() function, I call std::fread() to load up the desired amount of data, then I run through it and XOR it with a (looping) array of pre-computed values. Sounds pretty simple but who knows.
-
Use a sound generator (e.g. the one built into Audacity) to create a specific and known sound clip. For example, a 4 kHz sine wave. Throw that into your program and then record that output with Audacity. You should then be able to have a look at the waveform and see whether it's clean or not
-
It's possible. Basically how it works is in my filestream's read() function, I call std::fread() to load up the desired amount of data, then I run through it and XOR it with a (looping) array of pre-computed values. Sounds pretty simple but who knows.
Can you load whole file at the beginning, decrypt it and then pass already decrypted data? XOR is pretty slow and using it while playing sound can cause such problems.
-
XOR is pretty slow
In which world? ;)
XOR is pretty much a single CPU instruction (+ loading of the data).
But I think it's clear by now, that he should first try that the special loading isn't the issue.