Audio problem

I’m developing a small game and I have a few .ogg and .m4a audio files that are below one second long. When user clicks on an image, one of these short sounds is played at random (there are five different versions of the sound). 

However, quite often if the image is clicked repeatedly fast, a following error occurs in the console and no sounds are played after this has happened (all future tries will end up with this same error)

Warning: audio error: alBufferData failed: Invalid Operation

Warning: audio error: Could not get data for streamed PlayChannel: 

Notice that no PlayChannel is mentioned in the error message.

I trigger the play call like this:

audio.play(file, {onComplete=coinCompleted, fadein=0})    

Any ideas?

Maybe when the image is clicked you can remove the event listener (disabling further clicks), then add the event listener back in your coinCompleted function?  

That’s one option, but I was wondering what is cause behind this as I presume that there shouldn’t be anything wrong the actual concept behind this (that simultaneous sounds are being played on different channels if clicks are made in short repetitions). As the sounds are only below one second long, there shouldn’t be a situation where there would be more than 5 playing at the same time, because I’m not really clicking it insanely fast. 

So it would be nice to know if this is a bug or what is causing this error in the first place.

Hi @matti.paalanen,

How are you loading these sounds? Via audio.loadSoud() or audio.loadStream()? Why are you specifying a “fadeIn” of 0 milliseconds? Are you loading these sounds in advance, or trying to (perhaps) play them before they’re fully loaded?

Best regards,

Brent

Ah, good point, I am actually using the loadStream(), I’m going to try and preload the short sounds with loadSound() and see if that helps with this phenomenon! The fadeIn 0 was mentioned in some thread so I just tried it to see if would help, but I’ll remove it.

This corrected the problem, thank you! I guess when you are too tired to understand even the simple API right, you’d better go to sleep instead of write more code :slight_smile:

Good to hear it’s working! And yes, sleep is good for coders, even though we would like to stay awake 24 hours to code more. :slight_smile:

Brent

Maybe when the image is clicked you can remove the event listener (disabling further clicks), then add the event listener back in your coinCompleted function?  

That’s one option, but I was wondering what is cause behind this as I presume that there shouldn’t be anything wrong the actual concept behind this (that simultaneous sounds are being played on different channels if clicks are made in short repetitions). As the sounds are only below one second long, there shouldn’t be a situation where there would be more than 5 playing at the same time, because I’m not really clicking it insanely fast. 

So it would be nice to know if this is a bug or what is causing this error in the first place.

Hi @matti.paalanen,

How are you loading these sounds? Via audio.loadSoud() or audio.loadStream()? Why are you specifying a “fadeIn” of 0 milliseconds? Are you loading these sounds in advance, or trying to (perhaps) play them before they’re fully loaded?

Best regards,

Brent

Ah, good point, I am actually using the loadStream(), I’m going to try and preload the short sounds with loadSound() and see if that helps with this phenomenon! The fadeIn 0 was mentioned in some thread so I just tried it to see if would help, but I’ll remove it.

This corrected the problem, thank you! I guess when you are too tired to understand even the simple API right, you’d better go to sleep instead of write more code :slight_smile:

Good to hear it’s working! And yes, sleep is good for coders, even though we would like to stay awake 24 hours to code more. :slight_smile:

Brent