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

Author Topic: Music popping while playing encrypted OGG files  (Read 3064 times)

0 Members and 1 Guest are viewing this topic.

Raptormeat

  • Newbie
  • *
  • Posts: 4
    • View Profile
Music popping while playing encrypted OGG files
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10924
    • View Profile
    • development blog
    • Email
AW: Music popping while playing encrypted OGG files
« Reply #1 on: September 18, 2016, 11:52:19 am »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: Music popping while playing encrypted OGG files
« Reply #2 on: September 18, 2016, 01:27:46 pm »
IMO your decryption algorithm may be too slow, could you post it and some encrypted ogg file?

Raptormeat

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: AW: Music popping while playing encrypted OGG files
« Reply #3 on: September 20, 2016, 03:48:15 am »
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?

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

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 878
    • View Profile
Re: Music popping while playing encrypted OGG files
« Reply #4 on: September 20, 2016, 03:09:03 pm »
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

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: AW: Music popping while playing encrypted OGG files
« Reply #5 on: September 20, 2016, 08:09:43 pm »
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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10924
    • View Profile
    • development blog
    • Email
AW: Re: AW: Music popping while playing encrypted OGG files
« Reply #6 on: September 20, 2016, 09:43:51 pm »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything