- Home /
Question by
KortaMusik · Oct 30, 2015 at 09:17 PM ·
audioaudiosourceproceduralprocedural generationprocedural-generation
Procedural Audio in 3D
I'm generating audio procedurally by using the OnAudioFilterRead but the output or the spatial blend is 2D. If I change it to 3D in the AudioSource it just won’t sound.
Does somebody knows how can I set this to have 3D sound properties?
void OnAudioFilterRead(float[] data, int channels)
{
// update increment in case frequency has changed
increment = frequency * 2 * Math.PI / sampling_frequency;
for (int i = 0; i < data.Length; i = i + channels)
{
phase = phase + increment;
// this is where we copy audio data to make them “available” to Unity
data[i] = (float)(gain*Math.Sin(phase));
// if we have stereo, we copy the mono data to each channel
if (channels == 2) data[i + 1] = data[i];
if (phase > 2 * Math.PI) phase = 0;
}
}
Comment