"Could not allocate audio channel for this sound!" - how to fix?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

"Could not allocate audio channel for this sound!" - how to fix?

Post by Bugala »

I have a line like this:

Code: Select all

If IsSound() = True Then PlaySample(sampletoplay, {volume=vol})
in which I was hoping the IsSound() check would have fixed my problem, but it doesnt.

I keep getting this error "Could not allocate audio channel for this sound!" when there comes lots of sounds at same time.

Is there a way to prevent this problem, like is there a possibility to check if "PlaySample" command will fail in advance, which is what I tried with this IsSound()?
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: "Could not allocate audio channel for this sound!" - how to fix?

Post by Bugala »

Found this HaveFreeChannel() to solve the problem.

Now, another question.

Does amount of channels depend upon machine the software is running on, or is amount of channels a fixed amount always.

As in, will there always be only 8 channels for sound, regardless or the machine the software is running on?
plouf
Posts: 467
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: "Could not allocate audio channel for this sound!" - how to fix?

Post by plouf »

According to manual hollywood allocates 8 channels by default
So by defualt 8 chan is the top

Allocchannels command line command should be used if you need more
But "more" maybe hit aome limits (guess not sure) in paula based amigas for example
Christos
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: "Could not allocate audio channel for this sound!" - how to fix?

Post by jPV »

Bugala wrote: Mon Oct 24, 2022 3:56 pm Found this HaveFreeChannel() to solve the problem.
Or just do:
?PlaySample(sampletoplay, {volume=vol})

Then it doesn't exit the script even if it fails to play a sample, but this is useful only in the case when it's not important to hear the sample if there are others playing...
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: "Could not allocate audio channel for this sound!" - how to fix?

Post by Bugala »

Thats the problem. It is supposed not to crash with playsample, but it does.

I originally had just the playsample and it crashed, and for that reason I tried IsSound(), which didnt work, but this:

Code: Select all

If HaveFreeChannel() = True Then PlaySample(sampletoplay, {volume=vol})
fixes the problem, although some sounds are not played.
plouf
Posts: 467
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: "Could not allocate audio channel for this sound!" - how to fix?

Post by plouf »

Crash or exit with error ?

In that case you may disable exitonerror via error handlish library
Christos
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: "Could not allocate audio channel for this sound!" - how to fix?

Post by Bugala »

here is the full solution I used:

Code: Select all

samplechannelspriority = {}
For Local n = 1 To 8
	samplechannelspriority[n] = 0
Next

Function My_PlaySample(sampletoplay, priority, vol)
	Local n_channel = HaveFreeChannel()
	If n_channel > 0
		PlaySample(sampletoplay, {volume=vol, channel=n_channel})
		samplechannelspriority[n_channel] = priority
	Else
		Local usechannel = -1
		For Local n = 1 To TableItems(samplechannelspriority)
			If priority > samplechannelspriority[n] Then usechannel = n
		Next
		If usechannel > -1
			PlaySample(sampletoplay, {volume=vol, channel=usechannel})
			samplechannelspriority[usechannel] = priority
		EndIf
	EndIf
EndFunction
Notice the priority variable. This ones idea is that there can be lower priority and higher priority sounds.

If there are no free channels left, then it will compare the current playing channels how high their priority is, and if priority is higher than the current playing one, will instead force to play the new sample. And vice versa as in if the sound is lower priority sound and all other channels are already occupied with higher priority stuff, then it skips playing it at all.

Also, notice that for some reason Hollywood channel numbers start from 1 instead of 0.
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: "Could not allocate audio channel for this sound!" - how to fix?

Post by jPV »

Bugala wrote: Wed Oct 26, 2022 9:56 am Thats the problem. It is supposed not to crash with playsample, but it does.

I originally had just the playsample and it crashed
Please notice the "?" character in front of PlaySample in my example, when you use it Hollywood doesn't exit on errors with that command and continues the script execution. It would just skip the PlaySample line if there aren't free channels and your program would continue to work.
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: "Could not allocate audio channel for this sound!" - how to fix?

Post by Bugala »

Ah, thats a handy thing. Didnt know about that one.

Thanks from tip! Can use that in future.
Flinx
Posts: 188
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: "Could not allocate audio channel for this sound!" - how to fix?

Post by Flinx »

Bugala wrote: Wed Oct 26, 2022 7:18 pm Can use that in future.
You get an useful return value too, look at the docs.

OpenFile Example:

Code: Select all

err, id= ?OpenFile(Nil, FileName$,#MODE_READ)
If err<>#ERR_NONE
	Print(GetErrorName(err))
EndIf
Post Reply