How many channels does one "crossfade track" use up?

Started by Monsieur OUXX, Sun 27/11/2016 17:57:09

Previous topic - Next topic

Monsieur OUXX

Spoiler

Consider this : you want n ambient sounds to play simultaneously.
By nature, an ambient sound will crossfade with itself, so that the repeating is seemless to the player's ear.

I've implemented this by using 2 channels per ambient sound: I simply play the sound twice (which implicitly uses 2 channels), with eRepeat parameter, so that the AudioClip repeats itself on eachc hannel. Those two identical AudioClips are shifted in time so that when the second one starts, the first one is around its middle. When one of the channels is reaching its end, the sound gets faded out by my script. Then when it's starting again, the volume is faded back in. This way, out of the two channels for this one ambient sound, there's always one that's being played full volume, and the other one that's near its end or start, that's being faded out or in.

That works well.

But that's a waste of channels. If I have n channels then I can play only n/2 ambient sounds.

Do you think there would be a clever way of using the "crossfade tracks" property of the AudioTypes to achieve the same feature? While asking the question I realize that the solution probably revolves around playing an ambient clip only once (no eRepeat), but then having the script check if it's reaching its end. By then, calling .Play on the same AudioClip would make it play again, but with crossfade.

HOWEVER, what I'm wondering, is this: Would that use the same AudioChannel (the crossfading is done by the engine internally to the channel) OR does it implicity use another channel, hence defeating the purpose of the idea?

[close]

Question: If you play an AudioClip that has an AudioType that was set up to "crossfade", does it use only one channel?
ANSWER: I've run some tests and the crossfade seems to be just a fade out at the end and a fade-in at the beginning. It seems to use only one channel. Am I correct?


See also (interesting thread about volume management on a crossfade track): http://www.adventuregamestudio.co.uk/forums/index.php?topic=50093.msg636482411#msg636482411
 

selmiak

can't you just make an audiofile that loops and repeat it in one channel? There you can fade it in by code and have it on endless repeat. The method you decribed with overlaying 2 soundfiles by 50% of course needs 2 soundchannels.

Monsieur OUXX

Quote from: selmiak on Sun 27/11/2016 20:22:29
can't you just make an audiofile that loops and repeat it in one channel?
But then there would be no crss fading, and if I recall my old tests correctly, AGS slips a very short silence inbetween each repeat (but I might be wrong -- that's why I'm asking and testing around). Also, the purpose here is to save development time by NOT having to make every ambient sound loop.

 

selmiak

I know AGS has sound stuttering issues when changing rooms, but when in the same room a flawless repeat without a short silence or crack or stutter inbetween is what I expect from the ambient sound engine, otherwise there is a serious bug in the audiosystem, but I think it works and you are overcomplicating things.
On a side note I know the guy who made most if not all ambient sounds for the 7cog, he is okay with looping ambient sounds and thinks playing the same ambient sound overlapping could sound even worse ;) 8-) (fedora icon)

Monsieur OUXX

Quote from: selmiak on Sun 27/11/2016 22:04:00
I know AGS has sound stuttering issues when changing rooms, but when in the same room a flawless repeat without a short silence or crack or stutter inbetween is what I expect from the ambient sound engine, otherwise there is a serious bug in the audiosystem, but I think it works and you are overcomplicating things.
On a side note I know the guy who made most if not all ambient sounds for the 7cog, he is okay with looping ambient sounds and thinks playing the same ambient sound overlapping could sound even worse ;) 8-) (fedora icon)

Selmiak I know you're up to making the sounds loop, but trust me, if I'm asking it's because I want to save as much work as possible, and I'm 99% sure the question is worth asking. The engine is flawless but the short loading time (if it really exists) might be an issue (except with the crossfade feature activated, hopefully). I'm running my own tests anyways.
 

selmiak

Sure, this is just my opionion mixed with some creative understanding of technology  ;-D
I'm also interested in what others think and wonder why I'm the only one to respond, please someone confirm there is no stuttering in the ambient sounds channel. I don't want to shut down your question in any way, it is a very good question, that's why I responded, but if you ask specifically for 7cog, well, read my previous posts...

Monsieur OUXX

I've run some tests and the crossfade seems:
- to be just a fade out at the end and a fade-in at the beginning. (no overlapping. Not a real crossfade)
- to use only one channel.

Am I correct? My ears might be betraying me.
 

Snarky

I did a very simple test, and can report:

If you create a seamlessly looping track in an audio editor and set it to play on a loop (aTrack01.Play(eAudioPriorityHigh, eRepeat);), AGS will play it seamlessly. At least with the OGG track I tested with. If you just want ongoing ambient audio, this is the way to do it, since it requires only one audio channel and no further coding.

If you set the game to crossfade the music (SetGameOption(OPT_CROSSFADEMUSIC, 1);), then if you call Play() on another music track while one is playing, it will in fact "really" crossfade them. I can't verify that it's using only one channel, but it works even if you have set Music to use only one channel, so I would assume so.

The crossfade uses linear (dB) volume fading; because of how the decibel scale work, this means there's a "dip" in the volume during the fade (to maintain constant mixed volume, AGS would have to use a logarithmic volume curve for the fade). Depending on the characteristics of the track you're fading between, this can make it sound like the old track fades out first before the new track fades in, but it is in fact happening at the same time.

HandsFree

Quote from: selmiak on Mon 28/11/2016 11:04:54please someone confirm there is no stuttering in the ambient sounds channel.
I had the stuttering when I used an mp3 file. With ogg everything always plays seamless in my experience.

morganw

Quote from: Snarky on Mon 28/11/2016 17:02:56
I can't verify that it's using only one channel, but it works even if you have set Music to use only one channel, so I would assume so.
I've just done a quick test, crossfading two (music) audio clips with only a single music channel available.
Code: ags
//return the first channel index for a given audioclip
int get_audioclip_channel(AudioClip* audioClip)
{
  int index = 0;
  while (index != System.AudioChannelCount)
  {
    AudioChannel* audioChannel = System.AudioChannels[index];
    if (audioChannel.IsPlaying && audioChannel.PlayingClip == audioClip)
      return index;
    index ++;
  }
  
  return -1;
}

This returns -1 for the audio clip that is fading out, and the actual channel number for the one that is fading in. So if it using another channel it's not accessible. System.AudioChannelCount still returns 8 during the crossfade, so I would guess that it isn't wasting a channel to do the crossfade.

Quote from: HandsFree on Mon 28/11/2016 18:44:55
Quote from: selmiak on Mon 28/11/2016 11:04:54please someone confirm there is no stuttering in the ambient sounds channel.
I had the stuttering when I used an mp3 file. With ogg everything always plays seamless in my experience.
Yes, I think MP3 files are unlikely to loop seamlessly because of the way the data is padded. I've also had no issues when looping OGG audio, so I would stick with that.

Monsieur OUXX

Quote from: Snarky on Mon 28/11/2016 17:02:56
The crossfade uses linear (dB) volume fading; because of how the decibel scale work, this means there's a "dip" in the volume during the fade (to maintain constant mixed volume, AGS would have to use a logarithmic volume curve for the fade).
I learnt something! Cool.

Quote from: HandsFree on Mon 28/11/2016 18:44:55
With ogg everything always plays seamless in my experience.
I learnt seomething!!! Cool cool.

Quote from: morganw on Mon 28/11/2016 20:59:45
This returns -1 for the audio clip that is fading out, and the actual channel number for the one that is fading in. So if it using another channel it's not accessible. System.AudioChannelCount still returns 8 during the crossfade, so I would guess that it isn't wasting a channel to do the crossfade.
I think your test is valid (good to know that a channel can be "lost" by an AudioClip even though it's still hears but already being faded out). However, about System.AudioChannelCount: isn't it supposed to be the total number of channels, at all times (constant) ?

 

morganw

Quote from: Monsieur OUXX on Mon 28/11/2016 22:09:13
However, about System.AudioChannelCount: isn't it supposed to be the total number of channels, at all times (constant) ?
Yes, as far as I know it's always constant but since the manual isn't entirely specific about it, and the way the crossfade works isn't documented at all, I thought I'd check that it remained at 8 during whilst the two music tracks were playing. There is always the possibility that it is using an idle channel, but it's hidden from any of the audio functions, I guess someone would have to check the code to clarify (it's probably quite hard to playback 8 sounds at once and also hear that a crossfade is still working).

Monsieur OUXX

Quote from: morganw on Mon 28/11/2016 22:42:06
(it's probably quite hard to playback 8 sounds at once and also hear that a crossfade is still working).
you could set the volume of all but one to 0.

Another thing is puzzling me about the audio Channels (see the other thread I just started to count them manually)
 

SMF spam blocked by CleanTalk