[FEATURE REQUEST]:More than 16 sound channels.

Started by FanOfHumor, Fri 31/12/2021 00:55:28

Previous topic - Next topic

FanOfHumor

I kind of feel a little weird saying this since I already talked to Crimson Wizard about this but I didnt know where to ask him this. I noticed some music based game ideas never happen or are just not fully functional when made in ags.
For an example of why more than 16 channels are needed. I will give a story idea.
Supposing  a  game had a virtual piano that was controlled by keyboard input for every note.
If the user was to make a chord or play too fast before the channels freed up the game would crash.
I know the reason it isnt needed that much is because many channels at once would be an incoherent mess.
but with music this is different.Notes merge through channels to create music.
I dont know if there could be any other reason than this but you know the more room for creativity could make more room for new ideas.I know that this is a bit ridiculous to think about 20 or 30 channels but im just suggesting it. Even if not to be built into ags just a module or plugin would be plenty.
This may or may not have much of a use but I leave it up to you to think about it.

         
             -Pajama Sam
 

Crimson Wizard

#1
I think that the number of channels is an issue in the first place because of how AGS system works: right now is made so that the channel always have a one individual clip bound to it, and also the script channel directly corresponds to the sound source object in the sound library we're using.

If this system was changed to something different, e.g. allowing multiple clip playbacks going into the same channel, then the channel number would be much less of an issue (or not at all). For example, the above case of piano simulation could be rather solved if there was a Sound Mixer API, where you could merge multiple sounds on the same output channel (guess the meaning of a "channel" would change also in such case).

So I believe that instead of keeping increasing sound channels in its current form, it might be more optimal to redesign the system into something that allows more flexibility with the sound.

There has been a topic opened couple of years back, but unfortunately everything is postponed:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=56079.0


Quote from: Pajama Sam on Fri 31/12/2021 00:55:28
If the user was to make a chord or play too fast before the channels freed up the game would crash.

It should not crash, unless there's some mistake either in script or in the engine. Could you post an example of the game that crashes?

FanOfHumor

#2
How would I do that I dont have cloud storage or anything I dont even have a place like facebook.
also I cant get to the files right at this moment.
So all I can do is try to make up the script here since it is the very basic playing a sound when a key is pressed.

Code: ags


if(IsKeyPressed(eKeyC))
{
    anoteC.Play();
}
if(IsKeyPressed(eKeyD))
{
    anoteD.Play();
}
if(IsKeyPressed(eKeyE))
{
    anoteE.Play();
}
And so on... in repeatedly execute

I could very much be wrong in my thinking.
I didnt attempt this much because I could never get past the crashing when simply tapping the key faster than super slow.
The error assosiated with this is the invalid channel id error.
I could be very much wrong in my thinking.
It just seems that this should not crash the game.Unless if it was taking up the channels.
Do you know what this could be?

If this would take something major to fix it. Then I would be fine with just forgetting about it.

QuoteSo I believe that instead of keeping increasing sound channels in its current form, it might be more optimal to redesign the system into something that allows more flexibility with the sound.

There has been a topic opened couple of years back, but unfortunately everything is postponed:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=56079.0


Oh sorry I didnt see the rest of your post. I kind of thought that there must be a better sound system.

Crimson Wizard

Normally, if the audio type runs out of channels, then it either replaces one of the active sounds with the new one, or does not play a new one at all (this depends on clip priority setting).
Game crash would mean that something is wrong.

Regarding game upload, there is a number of free file host services, personally I know Dropbox, Mediafire and Google drive, but there should be many more.

FanOfHumor

#4
I'm suprised! I didn't know those places were free.I should use that to backup my game.
As for the music game, I made many different attempts at a music game using sound and it always was the same thing.
After all those new game attempts I just deleted them because it was stored on someone else's computer.
The script wasn't anything different than what I showed you.But i'm sorry to say I don't have these examples anymore.
I do have one example left but that one is so confusing from my attempting to vary the pitch of one sound.
There is no use in looking at that game because looking for the problem would be like looking for a needle in a haystack.

I want to suggest making ags able to vary the pitch of a sound.Should I start a new topic or ask you here?

FanOfHumor

#5
Okay I just remade the entire music game I had and now it doesnt crash.I must have been using an apha version of ags.The game does what you said. It only plays a sound if it has channels.Which is more of a reason to have more.With this simple script I was unable to play more than one note before the channels were full.
if you would like to see for yourself the game is right here.

https://www.mediafire.com/file/x8qy6clvy6yuib3/VP.zip/file

this link last for only 14 days.

Im sure that more channels on the ags sound system would be a problem so whatever happens is fine with me.

Snarky

Quote from: Pajama Sam on Fri 31/12/2021 16:37:32
With this simple script I was unable to play more than one note before the channels were full.

That's because you have coded it wrong. You have the code in repeatedly_execute(), which means that it runs (by default) 40 times per second. So if you press one key and keep it pressed for two tenths of a second, it will start playing 8 copies of the same audio clip, using up all the audio channels (or I guess half of them in the newest version). To make it work cleanly, you have to check whether the clip is already playing (or whether the keyboard key was already pressed last game cycle) before you start playing it again.

FanOfHumor

#7
Now I see-
so you cant play a sound in repeatedly execute.
Then this wouldnt require more channels but a different script.
I can see that in the newest version 16 channels is plenty for anything as long as it isnt in repeatedly execute.

Now that that's solved I wanted to suggest a script that can modify a sound as the game is running.
Such as-

Code: ags

function object_AnyClick()
{
   Sound.Pitch=-or+ number;
}

or
Code: ags

function object_AnyClick()
{
   Sound.FadeIn=-or+ number;
   Sound.FadeOut=-or+ number;
}

or
Code: ags

function object_AnyClick()
{
   Sound.Reverse=true;
}

Do you think these things could be useful in some way. Or is this already a module or plugin?

Crimson Wizard

#8
In AGS currently the sounds are modified by accessing the channel they are played on.
At the moment it is possible to change Volume and Speed.

Here's the related articles in the manual:
https://adventuregamestudio.github.io/ags-manual/AudioChannel.html



Quote from: Pajama Sam on Fri 31/12/2021 18:40:33
so you cant play a sound in repeatedly execute.

You can, but if you do that unconditionally, then it will start over every game frame.
What Snarky said is that your script logic should be fixed, for example to not replay same sound until the previous instance has stopped.

EDIT: or, alternatively, you may play looping sound as Sound.Play(eAudioPriorityNormal, eRepeat), and stop it when the player releases the key.

SMF spam blocked by CleanTalk