a virtual stereo speaker system

Hi,

I want to create a virtual stereo speaker system in a scene.

  1. Take a single stereo audio clip as an input.

  2. Split the audio to left-right channels and assign them to left/right virtual speakers respectively.

  3. Play audio with 3D spatial effects from the 2 virtual speakers. i.e. there will be cross talk of the channels like real speakers.

First, I tried combining ‘Stereo Pan → Left/Right’ and ‘Spatial Blend → 3D’ , but resulted was not as I expected;
Stereo panning was ignored when Spatial blend was set 3D.

Then, I tried again by writing a channel splitting filter in ‘OnAudioFilterRead’ callback, muting one of the channel, but the result was again not I expected;
the filter was applied after the spatial blending.

Is there any solution to do this?

Is there a way to apply audio filters before the spatial blending?

Thanks!

AudioClip.Create and SetData soloed the problem.

   void Start()
    {
        int samples = audioClip.samples;
        int channels = audioClip.channels;
        int frequency = audioClip.frequency;

        Debug.Assert(channels == 2);

        _leftChannel = AudioClip.Create("Left Channel", samples, 1, frequency, false);
        _rightChannel = AudioClip.Create("Right Channel", samples, 1, frequency, false);
        foreach (var entry in speakers)
        {
            AssignAudioClip(entry.speaker, entry.channel);
        }

        // Copy the audio data from the original clip.
        var stereo_data = new float[samples * channels];
        audioClip.GetData(stereo_data, 0);
        SetMonoralData(_leftChannel, stereo_data, Channel.Left);
        SetMonoralData(_rightChannel, stereo_data, Channel.Right);

        _isPlaying = false;
    }

    void SetMonoralData(AudioClip clip, float[] stereo_data, Channel channel)
    {
        var mono_data = new float[clip.samples * 1];
        for (int i = 0; i < stereo_data.Length; i += 2)
        {
            switch (channel)
            {
                case Channel.Left:
                    mono_data[i / 2] = stereo_data*;*

break;
case Channel.Right:
mono_data[i / 2] = stereo_data[i + 1];
break;
case Channel.Stereo:
Debug.Log(“Invalid Channel setting”);
break;
}
}
clip.SetData(mono_data, 0);
}

Hi,
As I understand it, I think I might have a similar problem.
I want to simulate being deaf on 1 ear in a 3D environment with spatialized sound.

But I encounter the same problem as you - ‘Stereo Pan → Left/Right’ and ‘Spatial Blend → 3D’ does not work together.

But I don’t want to create audioclips - I have pre-recorded audioclips (e.g. a guy talking, and a car driving) - can I solve this problem?