- Home /
Adaptive audio/Channel switching
Hi, I'm wanting to use a multi-channel audio files for a game in Unity. The file would contain multiple channels, which would be pairs of L/R combiniations of adaptive music. For example, channels 1 & 2 would be L/R track 1, channels 3 & 4 would be L/R track 2.
You can create these tracks in FMOD, and Unity uses FMOD for its audio, however, for the life of me, I can't find how to turn certain channels on and turn other channels off, to get the desired effect.
Answer by Andrew_Johnson · Jun 22, 2016 at 04:07 PM
I've done something similar with swapping between 2 channels, and this link was very helpful. To change the volume between 2 channels I used the code:
for (var i = 0; i < data.Length; i = i + channels)
{
data[i] = (float)(data[i] * vol);
data[i + 1] = (float)(data[i + 1] * (1-vol));
}
"vol" is a public variable between 0 and 1 that you can set with a script. My guess for how it would work for 4 channels is:
for (var i = 0; i < data.Length; i = i + 4)
{
data[i] = (float)(data[i] * vol);
data[i + 1] = (float)(data[i + 1] * vol);
data[i + 2] = (float)(data[i + 2] * (1-vol));
data[i + 3] = (float)(data[i + 3] * (1-vol));
}
I know it's 4 years late but I'm tired of finding questions I want to ask un-answered in my search results and at least the next person to come across this will find an answer.
Your answer
Follow this Question
Related Questions
Playing sounds to specific output channels 1 Answer
Calculating rhythm of any music? 3 Answers
How To Turn Off Sound For Certain Objects? 1 Answer
unity won't play sounds i implement 1 Answer
Audio not coming out of speakers 1 Answer