Testing Error with clearing buffer from source: Invalid OperationWarning: audio error: Failed to clear buffer from source: Invalid Operation

@Brent Sorrentino,

From my understanding, you’re saying that if I play a second sound on the same channel, then the second sound is supposed to override the first sound?

If that’s the case, that doesn’t happen. When I choose to play (as opposed to stopping it first), I get “Warning: audio error: Requested channel (0) is in use”.

If you replace the previously submitted main.lua in Audio Bug 3.zip with this new main.lua. It will replicate the issue.

@Brent Sorrentino and @Rob Miracle

I have attached a project that helps replicate the issue. Mash the button and you should eventually see the error in the terminal.

I’m getting the error when I’m using the sound module described here https://coronalabs.com/blog/2013/06/04/tutorial-handling-cross-scene-audio/ in a second scene.

It’s like this: Module is working fine in one scene when required at the top of the scene file. Then when moving to the next scene in composer I remove the sounds and I require the same module in the next scene and get the following error, when trying to use a sound there: “audio error: Could not bind data to source: Invalid Value” “Error: Over-disposing of the same audio data”. BTW: I’m using the normal Corona version and not the enterprise one.

@jhow,

If you’re just playing another sound on the same channel, why not just play it instead of stopping it first? The new instance should just play over top the previous instance.

Daniela,

Why are you removing sounds between scenes? Isn’t the goal for this module to use a common set of sounds across multiple scenes?

Brent

Brent,

I right now using the module in each scene by adding

local SM = require ("soundmodule")

at the top of each scene where I have to use the sounds.

But I thought it should be possible to dispose the sounds in the composer function scene:destroy anyway to save memory… and later the module is “loaded again” in a new scene where sound is needed. Isn’t this how it should work?

Right now I can’t dispose the sound in a scene without getting the error above when trying to use the sound in a “new” scene, after I have used dispose sound in the old scene.

How can I dispose the sounds from the module correctly and use the module again in a new scene when I need the sound?

Hi Daniela,

If, for example, you’re loading an audio file from the module like this (from the tutorial):

[lua]

sfx.boomSound = audio.loadSound( “audio/explosion2.wav” )

[/lua]

I would think you should just use a call like this to dispose of it, when you exit the scene you were using it in:

[lua]

audio.dispose( sfx.boomSound )

[/lua]

Are you doing something similar to that already?

Brent

A previous mention of earlier versions prompted me to dig back through Time Machine. I tried Build 2545 and found the same problem still occurred. I too am using Yosemite. Haven’t been brave enough to upgrade after all the bad comments on El Capitan! This audio issue makes testing a real pain.

I’ve reproduced this problem as simply as possible. I’m using OS X 10.10.5 and Corona Build 2830.

Repeated taps on the image can produce:

“17dTesting Error with clearing buffer from source: Invalid OperationWarning: audio error: Failed to clear buffer from source: Invalid Operation”

[lua]

local function play()

  audio.stop()

  local sound=audio.loadSound(“guitar.mp3”)

  audio.play(sound,{channel=1})

end

local img=display.newImageRect(“panda.png”,756,756)

img.x=display.contentCenterX; img.y=display.contentCenterY

img:addEventListener(“tap”,play)

[/lua]

Here are the two files if you want to exactly reproduce the problem:

mulawa.net/special/wip/panda.png

mulawa.net/special/wip/guitar.mp3

Hope this helps … Peter

Just confirming that I am unable to produce this problem on my iPad.

Yes, and it seems like this disposal is causing the problem and the sound in a new scene is not loaded again when requiring the module again. Is there an example somewhere how to handle sound disposal and scene changes correctly somewhere. This is really stuff causing headaches :wink:

Hi Daniela

When you require  a module it is executed only the first time you require it.

Requiring the same module again in another scene will not “reset” the module or execute it’s code again. It will just make the module available “as it was left the last time you used it”.

So in the first scene your module loads the sound and assigns it to sfx.boomSound

Then, when exiting the scene, you dispose the sound and sfx.boomSound becomes nil

Requiring the module again in the new scene will not load the sound again. you have to reload it explicitly.

You might have something like that in your module

sfx.loadBoomSound = function () sfx.boomSound = audio.loadSound( "audio/explosion2.wav" ) end

and call it when you enter the new scene to reload the sound again.

@Brent Sorrentino,

From my understanding, you’re saying that if I play a second sound on the same channel, then the second sound is supposed to override the first sound?

If that’s the case, that doesn’t happen. When I choose to play (as opposed to stopping it first), I get “Warning: audio error: Requested channel (0) is in use”.

If you replace the previously submitted main.lua in Audio Bug 3.zip with this new main.lua. It will replicate the issue.

I just wanted to confirm that this bug still exists. I’m using Build: 2016.2913.

 

I’m happy to hear it can’t be produced on iPad. Did anyone test Android? Does this happen only in the simulator?

A previous mention of earlier versions prompted me to dig back through Time Machine. I tried Build 2545 and found the same problem still occurred. I too am using Yosemite. Haven’t been brave enough to upgrade after all the bad comments on El Capitan! This audio issue makes testing a real pain.

I’ve reproduced this problem as simply as possible. I’m using OS X 10.10.5 and Corona Build 2830.

Repeated taps on the image can produce:

“17dTesting Error with clearing buffer from source: Invalid OperationWarning: audio error: Failed to clear buffer from source: Invalid Operation”

[lua]

local function play()

  audio.stop()

  local sound=audio.loadSound(“guitar.mp3”)

  audio.play(sound,{channel=1})

end

local img=display.newImageRect(“panda.png”,756,756)

img.x=display.contentCenterX; img.y=display.contentCenterY

img:addEventListener(“tap”,play)

[/lua]

Here are the two files if you want to exactly reproduce the problem:

mulawa.net/special/wip/panda.png

mulawa.net/special/wip/guitar.mp3

Hope this helps … Peter

Just confirming that I am unable to produce this problem on my iPad.

Hello, I’d like to bring this discussion back to life. Here’s a summary of the issue…

Background : This Corona project is used to demonstrate an issue that sometimes occur when trying to stop and play audio on a single channel.

Expected Behavior : When stopping a channel and then immediately playing audio on that same channel, the previous sound effect should stop and the new one should start.

Issue Description : Sometimes this expected behavior does not happen.

  • First, the audio playing will not stop.
  • Second, unable to play new audio on that particular channel until current audio is complete.
  • On the Corona Mac Simulator, comes with the following errors:
    • “17dTesting Error with clearing buffer from source: Invalid OperationWarning: audio error: Failed to clear buffer from source: Invalid Operation”
    • “Warning: audio error: Could not bind data to source: Invalid Operation”

Why is this important to fix?

  • People have been bringing this issue up for at least two years now.
  • Channels should work correctly. If a channel is stopped, it should stop. If we try to play a sound effect on that channel, that sound effect should work.
  • Hacking “work arounds” like using timers requires a lot of work. Not only do we now have to start and stop channels, but we also need to start and cancel timers to do something that should be extremely simple. Having all that timer maintenance is frustrating when this should literally be a two line behavior. (Assuming you have multiple characters and each character has it’s own channel… now each character also needs a timer just so that the audio/channel can work correctly)

Tested with   Corona 2016.2970 on :
Corona Mac Simulator :

  • Easily reproducible. Can reproduce in a matter of seconds
  • Errors/Warnings discussed above show in Console log

iPad Mini :

  • Harder to reproduce than Mac Simulator. But still reproducible.
  • Errors/Warnings discussed above do NOT show in Console log

Samsung Tab3 :

  • Unable to reproduce.
  • No Errors/Warnings discussed above
  • Sometimes the current audio will not stop and will have to wait a tiny bit. But, it is not the case that I need to wait until the current audio is 100% complete. The difference between this and the Mac and iPad tests is that if I keep pressing the button, eventually it will register and play the new sound effect. Whereas on the Mac and iPad, even if I keep pressing the button, it will not work until the current SFX is over.

Code to reproduce can be found here.

Bug report submitted (#6175112) .

I agree this is important. I don’t know if this helps but I’m pretty sure this issue did not happen in December 2015. I’m not sure which build I was using but probably it was recent at the time. I don’t remember experiencing this last year. Due to time constraints I had to put my project on hold. Now when I continue it almost a year later, I get the error all the time. Code-wise nothing has changed in my project.

Hi guys,

The engineers report that we haven’t changed our audio code in a long time, so I’m not sure why this issue seems to be happening “now but not before” for some users.

@jhow, thanks for filing the bug report. This is looking like a very complex multi-thread race condition only on some devices/platforms, so it could be very difficult to diagnose and solve.

Out of curiosity, may I ask whether you’re dedicating one sole channel for sound effects or for music? In all of my previous projects, I have dedicated (reserved) perhaps 1-3 channels for music tracks (background music, etc.), but I have left the audio engine open to choose its own open channels for sound effects because, simply put, it’s a lot easier for me to just let it handle that aspect itself. I’m not entirely sure what your own personal approach is, but that’s how I’ve always handled my audio setup.

Brent

Any news on this? I get exactly the same issue in the simulator, sporadically occurring when trying to start a sound playing whilst another is already playing. I am letting the audio engine choose the channel itself.

Corona Build = 2016.2948

OS = 10.11.3 El Capitan

17dTesting Error with clearing buffer from source: Invalid OperationWarning: audio error: Failed to clear buffer from source: Invalid Operation

 

Warning: audio error: Could not bind data to source: Invalid Operation