Audio not working the way it should be, please help

Hi fellow Corona users

I’m using a windows pc with Corona SDK starter and I’m having sound issues, can anyone help me out on this please?

In my main.lua I set up my sound table…

audio.reserveChannels( 9 )
soundTable = {
    ticktock = audio.loadSound( “sounds/countdown.ogg”, {channel=1} ),
        correctSound = audio.loadSound( “sounds/success.ogg”, {channel=2}  ),
        wrongSound = audio.loadSound( “sounds/negativebeep.ogg”, {channel=3}  ),
        chinkSound = audio.loadSound( “sounds/chink.ogg”, {channel=4}  ),
        backSound = audio.loadSound( “sounds/ambience.ogg”, {channel=5} ),
        whooshSound = audio.loadSound( “sounds/whoosh.ogg”, {channel=6}  ),
        passSound = audio.loadSound( “sounds/pass.ogg”, {channel=7}  ),
        menuSound = audio.loadSound( “sounds/menu.ogg”, {channel=8}  ),
        clickSound = audio.loadSound( “sounds/click.ogg”, {channel=9}  )
    }

In my level1.lua I play the ticktock sound…

audio.play( soundTable[“ticktock”], {channel=1} )

After a touch event I stop the ticktock sound…

audio.stop(1)

Looking through my code, after I stop channel 1, my code plays other sounds in this order:

audio.play( soundTable[“correctSound”], {channel=2} )

audio.play( soundTable[“chinkSound”], {channel = 4} )

Then I get this error…

Warning: audio error: Requested channel (3) is in use

I’m confused because I specifically assign channels to every sound when I play them.
The only sound I stop and start is channel 1, the ticktock sound.
Any ideas anyone?

Since I have had no luck with the above issue I tried another way and put the audio in a module and require it.

sfx.lua

local sfx = {}

audio.reserveChannels( 9 )

    sfx.ticktock = audio.loadSound( “sounds/countdown.ogg”, {channel=1} )
    sfx.correctSound = audio.loadSound( “sounds/success.ogg”, {channel=2} )
    sfx.wrongSound = audio.loadSound( “sounds/negativebeep.ogg”, {channel=3} )
    sfx.chingSound = audio.loadSound( “sounds/ching.ogg”, {channel=4} )
    sfx.backSound = audio.loadSound( “sounds/ambience.ogg”, {channel=5, loops=-1} )
    sfx.whooshSound = audio.loadSound( “sounds/whoosh.ogg”, {channel=6} )
    sfx.passSound = audio.loadSound( “sounds/pass.ogg”, {channel=7} )
    sfx.menuSound = audio.loadSound( “sounds/menu.ogg”, {channel=8} )
    sfx.clickSound = audio.loadSound( “sounds/click.ogg”, {channel=9} )

return sfx

Then in my level1.lua…

local sfx = require(“sfx”)

audio.play( sfx.ticktock ) – the sound effect plays fine

and use…

audio.stop( sfx.ticktock ) – to stop the sound effect

Now I get this error…

Passed unexpected parameter type to audio.stop()

It seems like whatever I try I keep getting stuck.

OK I’ve sorted it out, maybe this will help someone else in the same situation.

I assaigned a variable with the audio.play function…

ticktock = audio.play(sfx.ticktock)

then used the variable to stop the sound…

audio.stop( ticktock )

Job done!

Since I have had no luck with the above issue I tried another way and put the audio in a module and require it.

sfx.lua

local sfx = {}

audio.reserveChannels( 9 )

    sfx.ticktock = audio.loadSound( “sounds/countdown.ogg”, {channel=1} )
    sfx.correctSound = audio.loadSound( “sounds/success.ogg”, {channel=2} )
    sfx.wrongSound = audio.loadSound( “sounds/negativebeep.ogg”, {channel=3} )
    sfx.chingSound = audio.loadSound( “sounds/ching.ogg”, {channel=4} )
    sfx.backSound = audio.loadSound( “sounds/ambience.ogg”, {channel=5, loops=-1} )
    sfx.whooshSound = audio.loadSound( “sounds/whoosh.ogg”, {channel=6} )
    sfx.passSound = audio.loadSound( “sounds/pass.ogg”, {channel=7} )
    sfx.menuSound = audio.loadSound( “sounds/menu.ogg”, {channel=8} )
    sfx.clickSound = audio.loadSound( “sounds/click.ogg”, {channel=9} )

return sfx

Then in my level1.lua…

local sfx = require(“sfx”)

audio.play( sfx.ticktock ) – the sound effect plays fine

and use…

audio.stop( sfx.ticktock ) – to stop the sound effect

Now I get this error…

Passed unexpected parameter type to audio.stop()

It seems like whatever I try I keep getting stuck.

OK I’ve sorted it out, maybe this will help someone else in the same situation.

I assaigned a variable with the audio.play function…

ticktock = audio.play(sfx.ticktock)

then used the variable to stop the sound…

audio.stop( ticktock )

Job done!