Bad sound quality using audio.loadStream - crackling noises

Hi!

I’m using audio.loadStream() to play the background music (mp3) in my app. However, there are frequent “short bursts” of crackling noises when I run the app in the simulator as well as on actual devices. It sounds like when you pull the plug of your headphones in the middle of a sound.

I have played the same audio file in the sample app Media/AudioPlayer with the same result. When I play the audio file with e.g. iTunes or any other media player on my Mac the noises are not there. Also, when I download the music file directly to a device, the noise is not there.

My conclusion is that something happens to the file when played “through Corona”. Has anyone had any similar issues?

Hi,

This issue can often be due to the compression and bitrate. Do you know offhand what those settings are?

-dev

I have tried with two different formats:

mp3 file

bit rate: 192 kbps

sample rate: 44,100 kHz

encoded with: LAME3.98

wav file

bit rate: 1 411 kbps

sample size: 16 bit

sample rate: 44,100 kHz

Hi,

Admittedly its been awhile since I’ve done any audio work, but you might try some different bitrates to experiment. 128kpbs / 22,050 MP3 might be a good test setting. Also make sure you’re not using “joint stereo” if that is an option.

Are you using Audacity as your editor by chance? Also what is the source material setting?

As a final note, I’d be happy to run it though some processing if its a file you are able to share.

-dev

I agree w/ @develephant

Re-code the files with Audacity and I think you’ll be good to go.

I’ve seen this when folks use certain stock sounds.

I actually used Audacity but you were right about the bit rate/sample rate. I set it to 22050 Hz (wav) and it worked like a charm. Can’t believe it was so simple…

Still, I’m curious: how come the file could be played back without any noises using iTunes or a media player but not in the Corona simulator? The audio drives and athe loudspeakers are the same. What differs?

The solution can’t be playing at lower quality. Let’s all lower our standards…ya that’s the way to go…if this is true, no one can make a mp3 player with corona or games that depend mostly on quality sound for immersing experience.

@carloscosta: I agree with you in theory and I would also like to know what the root problem is. However, since my game does not require hifi sound quality, this solution is good enough for me in this case. Again, it would have been better to resolve the actual problem but that might be out of scope even for Corona (e.g. if the problem resides within OpenAL).

Hi,

As far as my understanding, it comes down to whether the decoding is performed via hardware or software. On your desktop/laptop the decoding is generally done via the hardware (sound card) which can support more variations. On mobile this is a bit more tricky so most implementations are done via software decoding. With software decoders you are more limited to the supported variations, and generally they support the most standard.

22050 Hz and 44100 Hz are fairly standard. Using those along with a constant quality (not variable) of  64, 96, 128, 192, or 256 kpbs should always work in most cases. So in regards to the comment by @carloscosta, there isn’t always a need to lower the quality, but you should use the lowest quality based on the use case. In general for game effects 22050/96 mono should be plenty as most folks probably don’t play with headphones on, and most, if not all mobile devices contain a mono speaker.

Again, this is only what I have gathered over time. If anyone else can expound upon this, please do.

-dev

Hi,

This issue can often be due to the compression and bitrate. Do you know offhand what those settings are?

-dev

I have tried with two different formats:

mp3 file

bit rate: 192 kbps

sample rate: 44,100 kHz

encoded with: LAME3.98

wav file

bit rate: 1 411 kbps

sample size: 16 bit

sample rate: 44,100 kHz

Hi,

Admittedly its been awhile since I’ve done any audio work, but you might try some different bitrates to experiment. 128kpbs / 22,050 MP3 might be a good test setting. Also make sure you’re not using “joint stereo” if that is an option.

Are you using Audacity as your editor by chance? Also what is the source material setting?

As a final note, I’d be happy to run it though some processing if its a file you are able to share.

-dev

I agree w/ @develephant

Re-code the files with Audacity and I think you’ll be good to go.

I’ve seen this when folks use certain stock sounds.

I actually used Audacity but you were right about the bit rate/sample rate. I set it to 22050 Hz (wav) and it worked like a charm. Can’t believe it was so simple…

Still, I’m curious: how come the file could be played back without any noises using iTunes or a media player but not in the Corona simulator? The audio drives and athe loudspeakers are the same. What differs?

The solution can’t be playing at lower quality. Let’s all lower our standards…ya that’s the way to go…if this is true, no one can make a mp3 player with corona or games that depend mostly on quality sound for immersing experience.

@carloscosta: I agree with you in theory and I would also like to know what the root problem is. However, since my game does not require hifi sound quality, this solution is good enough for me in this case. Again, it would have been better to resolve the actual problem but that might be out of scope even for Corona (e.g. if the problem resides within OpenAL).

Hi,

As far as my understanding, it comes down to whether the decoding is performed via hardware or software. On your desktop/laptop the decoding is generally done via the hardware (sound card) which can support more variations. On mobile this is a bit more tricky so most implementations are done via software decoding. With software decoders you are more limited to the supported variations, and generally they support the most standard.

22050 Hz and 44100 Hz are fairly standard. Using those along with a constant quality (not variable) of  64, 96, 128, 192, or 256 kpbs should always work in most cases. So in regards to the comment by @carloscosta, there isn’t always a need to lower the quality, but you should use the lowest quality based on the use case. In general for game effects 22050/96 mono should be plenty as most folks probably don’t play with headphones on, and most, if not all mobile devices contain a mono speaker.

Again, this is only what I have gathered over time. If anyone else can expound upon this, please do.

-dev