Audio has no free channels?

Hi, 

Our app sometimes has an issue (on iOS, Android, and in simulator) where all 32 channels indicate that they are playing, paused, and active at once. We are positive that this is not because we have 32 sounds playing at once. When this happens, we get some strange numbers from audio:

audio.countTotalChannels() --> returns -1.

audio.countReservedChannels() --> returns -1.

All the other audio.countXXX functions return 0. We have 9 reserved channels in our app, though this seems like an unrelated fact.

On one occasion, after 4 minutes of this behavior, our app created an alert with native.showAlert – and upon completion of the alert, may sounds played at the same time – as though they had been clogged up somehow. Has anyone else seen this behavior? Does it seem like we’re causing it, or is -1 a “normal” number to get for  audio.countTotalChannels()? Is it possible this might happen as a result of a native.showAlert for any reason? It seems like a bug.

I have the log from the aforementioned occasion, and have attached it. But it’s quite long, and I’m not sure exactly where the event occurred. Maybe it will help?

I should note that calling audio.stop on every channel does not fix the issue.

Thanks.

Tell me more about your sounds?  Are you trimming off the dead space at the beginning and end of the sounds? Many audio artists will leave a little blank sound at the beginning and a second or so of dead sound at the end. Corona is going to play the whole sound file and if you’re playing a lot of explosions in rapid successions and the sound is silent for a second or two, you can quickly run out of channels. You only have 22 free.

It might be helpful to share your code on where you’re finding a free channel and playing the sound.

Rob

Hi, Rob – thanks for getting back to me.

I’ve attached a log from a situation where the bug happened in the simulator – it has crashed, but restarting the project caused sound to work again with the same audio file paths. As you can see, when it fails to play a sound, the warning: Feb 23 03:06:27.833 WARNING: lib/audio/sfx.lua:42: audio.loadSound() failed to create sound ‘audio/sfx/mp3/hot3.mp3’ is shown in the console.

Our sounds are fairly trim, and there’s no dead space that I can see (we have a lot of sound files, but the longest one, aside from music, is about 10 seconds). But the problem is not that it’s silent for a second or two after we play sounds (and we’re not playing 22 at once, so far as I can tell – more like 5). It’s being silent for far longer than the duration of any of our sounds. This sound is actually a recent problem – and our sounds haven’t changed for months, according to the bitbucket repo.

When we play the sound, this code runs:
 

 -- set volume         audio.setVolume(volume, {channel=channel})         -- self pitch         local source = audio.getSourceFromChannel(channel)         al.Source(source, al.PITCH, 1.0)         local channelOr0         if not muted then              channelOr0 = audio.play(sounds[key], {channel=channel})             if channelOr0 == 0 then                 reportErrorToElastic{                     errorMessage = "Could not play sound on channel. Key = " .. tostring(key) .. ". (Channel = " .. tostring(channel) .."). " .. DataDumper(sounds[key])                 }             end         end         local duration          if sounds[key] then             duration = audio.getDuration(sounds[key])         else             print("can't find " .. key .." duration")             duration = 1500         end

Does this help? Thanks again!

loadSound() failing is different from play() failing.  i’d perhaps tackle the “why aren’t my audio files LOADING?” problem first.

fe, are you properly disposing of old ones?  audio can consume a fair amount once uncompressed, maybe just a memory problem?

once you’ve got a valid handle for a properly loaded audio file, THEN tackle the “why won’t it play” problem. (because obviously if it isn’t loaded then it’s GUARANTEED not to play, right? so first things first)

I occasionally see audio.loadSound() failed to create sound in sim for absolutely no reason.

@sphere game studios you mean, for a whole simulator session? and then when you reload it works again?

@davebollinger, yes, I agree, and I’ll check this out and get back to you here. hopefully figuring this bit out will tell me why there are -1 total channels?

Hi, I checked to see what was happening when it was loading – I found that it was trying to load something at the correct location, but sometimes failing. For example, one file is at: audio/music/caf/billyrobot.caf, and my folder structure is shown in the attached picture – it’s the same as that path. When I reload, it tells me it’s looking at the same path, but it finds the sound and plays it with no issue. So I don’t know WHAT is going on. It seems like it can’t find the file occasionally.

Can you create a simple demo problem that reproduces this?

Rob

Tell me more about your sounds?  Are you trimming off the dead space at the beginning and end of the sounds? Many audio artists will leave a little blank sound at the beginning and a second or so of dead sound at the end. Corona is going to play the whole sound file and if you’re playing a lot of explosions in rapid successions and the sound is silent for a second or two, you can quickly run out of channels. You only have 22 free.

It might be helpful to share your code on where you’re finding a free channel and playing the sound.

Rob

Hi, Rob – thanks for getting back to me.

I’ve attached a log from a situation where the bug happened in the simulator – it has crashed, but restarting the project caused sound to work again with the same audio file paths. As you can see, when it fails to play a sound, the warning: Feb 23 03:06:27.833 WARNING: lib/audio/sfx.lua:42: audio.loadSound() failed to create sound ‘audio/sfx/mp3/hot3.mp3’ is shown in the console.

Our sounds are fairly trim, and there’s no dead space that I can see (we have a lot of sound files, but the longest one, aside from music, is about 10 seconds). But the problem is not that it’s silent for a second or two after we play sounds (and we’re not playing 22 at once, so far as I can tell – more like 5). It’s being silent for far longer than the duration of any of our sounds. This sound is actually a recent problem – and our sounds haven’t changed for months, according to the bitbucket repo.

When we play the sound, this code runs:
 

 -- set volume         audio.setVolume(volume, {channel=channel})         -- self pitch         local source = audio.getSourceFromChannel(channel)         al.Source(source, al.PITCH, 1.0)         local channelOr0         if not muted then              channelOr0 = audio.play(sounds[key], {channel=channel})             if channelOr0 == 0 then                 reportErrorToElastic{                     errorMessage = "Could not play sound on channel. Key = " .. tostring(key) .. ". (Channel = " .. tostring(channel) .."). " .. DataDumper(sounds[key])                 }             end         end         local duration          if sounds[key] then             duration = audio.getDuration(sounds[key])         else             print("can't find " .. key .." duration")             duration = 1500         end

Does this help? Thanks again!

loadSound() failing is different from play() failing.  i’d perhaps tackle the “why aren’t my audio files LOADING?” problem first.

fe, are you properly disposing of old ones?  audio can consume a fair amount once uncompressed, maybe just a memory problem?

once you’ve got a valid handle for a properly loaded audio file, THEN tackle the “why won’t it play” problem. (because obviously if it isn’t loaded then it’s GUARANTEED not to play, right? so first things first)

I occasionally see audio.loadSound() failed to create sound in sim for absolutely no reason.

@sphere game studios you mean, for a whole simulator session? and then when you reload it works again?

@davebollinger, yes, I agree, and I’ll check this out and get back to you here. hopefully figuring this bit out will tell me why there are -1 total channels?

Hi, I checked to see what was happening when it was loading – I found that it was trying to load something at the correct location, but sometimes failing. For example, one file is at: audio/music/caf/billyrobot.caf, and my folder structure is shown in the attached picture – it’s the same as that path. When I reload, it tells me it’s looking at the same path, but it finds the sound and plays it with no issue. So I don’t know WHAT is going on. It seems like it can’t find the file occasionally.

Can you create a simple demo problem that reproduces this?

Rob