Skip to content

Instantly share code, notes, and snippets.

@inoook
Created September 26, 2018 03:07
Show Gist options
  • Select an option

  • Save inoook/edd116d2c335a31cf9702a22f9dbeb0f to your computer and use it in GitHub Desktop.

Select an option

Save inoook/edd116d2c335a31cf9702a22f9dbeb0f to your computer and use it in GitHub Desktop.
既存のAudioチャンネルを別チャンネルへ転送
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 既存のチャンネルを別チャンネルへ転送
public class TransCh : MonoBehaviour {
[System.Serializable]
public class TransChannel
{
public int org = 0;
public int dst = 1;
public float orgVolume = 0;// 元の音量(完全移行する場合は0にして消す)
public float dstVolume = 1;// 移行先の音量
}
[SerializeField, Tooltip("デバッグ用:入力されているチャンネル確認用")] int debug_channelsCount;
[SerializeField] TransChannel[] transChannels;
void OnAudioFilterRead(float[] data, int channels)
{
debug_channelsCount = channels;
int leng = data.Length / channels;
for (var i = 0; i < leng; i++)
{
for (int j = 0; j < transChannels.Length; j++)
{
TransChannel tCh = transChannels[j];
if (tCh.org < channels && tCh.dst < channels)
{
int index = i * channels;
float orgData = data[index + tCh.org];
data[index + tCh.dst] = orgData * tCh.dstVolume;
data[index + tCh.org] = data[index + tCh.org] * tCh.orgVolume;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment