OpenAL Running out of channels?
BlitzMax Forums/BlitzMax Programming/OpenAL Running out of channels?
| ||
Ok more topics. (i have lot of problems :D) Just tested my project and i noticed that if there is many sounds going on. My friend reported this:Projectile flying sound doesn't work, and disables other sounds over time when multiple shots are fired? Too many overlapping sounds? Still, rocket works fine. I got same results, but not as often as my friend. I found this topic , but in topic there is 'crash'. http://www.blitzbasic.com/Community/posts.php?topic=87867 I am not having any crashes, but sounds got muted over time. So this is channel problem? I have lot's of channels in my project, because i need calculate sound volume from distance and etc.. Here is some code: Shot.sound = LoadSound(Shot.soundPath) Shot.soundVol = 1 - Distance#( myplayerX, myplayerY, X, Y ) / soundDivision Shot.soundChannel = CueSound(Shot.sound) SetChannelVolume( Shot.soundChannel , Shot.soundVol ) ResumeChannel Shot.soundChannel So any other way around? |
| ||
Limit the number of sounds you're playing. Keep an array of TChannels and cycle through the array when playing sounds. When you get to the end, go back to the start. This way, you'll never have more sounds playing than the number you specify, and old sounds get killed (if needed) to make way for new ones. Oh - one more thing. I've had situations where CueSound as you're using it, will fail sometimes. The way I found around it was thus: Shot.soundChannel = AllocChannel() CueSound(Shot.sound, Shot.SoundChannel) Shot.SoundChannel.Resume() Well, you get the idea. Haven't used Blitzmax in a while so you might have to iron out the creases. |
| ||
In another thread I created this code: https://github.com/GWRon/Dig/blob/master/base.sfx.channelpool.bmx Simple sample: https://github.com/GWRon/Dig/blob/master/samples/channelpool/channelpool.bmx Another user was using it (and had problems which were mostly based on the approach he took on "sound channels"): Community/posts.php?topic=104066 Basically it is something like what GfK suggested. You might limit the channels, and when requesting a specific channel it will return an already existing one instead. How to use such a thing? - have some protected channels for "unstoppable" things like background music, voice overs, main character sound effects, ... all other things (random sfx for accelerating vehicles etc) could get played on a limited amount of channels. If you need more channels than available, you might end up with some kind of software mixer (you directly write your sounds to the audio buffer and this resulting audio is played on a channel). bye Ron |
| ||
So i basicly have just few sound channels and use existing one to play.. let's say: all explosions. But is it possible to set channel volume for every sound, without interrupting other sounds playing in channel? |
| ||
The volume is done on a per-channel-basis. The only solution to overcome this limit it a software mixer. Check the mod-sources, somewhere was some kind of software mixer, just do not remember where. bye Ron |
| ||
Still not solved. I have still no idea how i can overcome this limit, i have lot's of sounds and all must play no matter what. Someone want to explain 'software mixer' in game development and give me example? |
| ||
I tried Derrons 'base.sfx.channelpool', but example gives Unhandled Exception:Attempt to access field or method of Null object. Debugger points this line:if GetPooledChannel("soundchannel1").Playing() then channel1 = "USED" Also when i delete those lines i can test it, but when i first press key '1' to play sound 1 on channel 1, it starts playing it, but when i press 'Q' to stop that sound in channel 1 it is not stopping. It only happens in channel which i play first. Any ideas? |
| ||
Could you try to lower the channel amount? in the sample code you find this lines: Repeat 'enable this to see how only one channel is used 'TChannelPool.channelLimit = 1 check what happens if you re-enable that line. if GetPooledChannel("soundchannel1").Playing() then channel1 = "USED"[ This means it was not even able to AllocChannel() the first channel... Does debugger mean the returned channel object is null ? As you said you commented the line out ... and it played a song, I am left puzzled. Is there someone out having the same trouble with that sample? bye Ron |
| ||
By enabling TChannelPool.channelLimit = 1It still gives me 'Unhandled Exception:Attempt to access field or method of Null object' At the same line. |
| ||
Looks like it works this way:If GetPooledChannel("soundchannel1") And GetPooledChannel("soundchannel1").Playing() Then channel1 = "USED" But still. Why can't i pause first sound. When first sound is played i can stop any channel. Edit: Nevermind now it works with code above. |
| ||
The problem with your code is: It only checks the first condition - and as this fails, it already skips the rest. Please try something like: If GetPooledChannel("soundchannel1") print "found valid channel" Else print "no valid channel found" EndIf If that already "fails", then The "GetPooledChannel("soundchannel1").Playing()" portion is never executed. bye Ron |
| ||
Is that problem, because it works. In my opinion it's better to avoid channel playing check if channel is Null. |
| ||
Did you do what I asked you for? No? In that case you would have seen that there is nothing returned in your case ;D - and you would have helped me to locate a bug. The problematic line is this: AddChannel(key, AllocChannel()) I planned to use it "chainable" (returning the added channel so you could AddChannel(bla).Play()) but I missed to return the channel within that method. So I replaced that with returning a boolean and changed the line of code in GetChannel(). Please download the new version at: https://github.com/GWRon/Dig/blob/master/base.sfx.channelpool.bmx and give it a whirl, hopefully it resolves the issue. bye Ron |
| ||
Thanks it solved it! Now i'll try implement this to my project and at least try to get all sounds work good. Sounds good already. Thanks again. |