Search Unity

How to play sound on left or right speaker only?

Discussion in 'Audio & Video' started by herpanda, Jan 5, 2015.

  1. herpanda

    herpanda

    Joined:
    Jan 1, 2014
    Posts:
    27
    Mod: Please delete thread, problem is with my computer's programs, not Unity.
    I checked my computer, other programs, and audio testers, and it seems a program called "SRS Premium Sound" under Realtek's settings is what caused the sound on both sides of the speakers. I guess the only way to fix this then would be to ask players to disable this program when playing haha... unless Unity has a way to mess with other exe processes :p


    Original Post:
    "If the sound is on the left of the audio source, I want it on the left speaker only. If it's on the right, then I want it on the right speaker only. I tried making it a 2D sound and setting the panning myself (audioSource.pan = -1 for left, audioSource.pan = 1 for right), but I can still hear the sound coming from the other speaker; quieter, but still audible. I then tried the "Pan 2D" slider under 2D Sound Settings in the Inspector, but it too still plays on both speakers with the same "loud in one, quiet in the other" volume.


    I also tried the 3D sound panning (Settings: Pan Level: 1 Spread: 0) but even though it pans left and right, the sound on the opposing speaker is still pretty loud.

    If it means anything, I am making a 2D game. Any help is greatly appreciated."
     
    Last edited: Jan 5, 2015
  2. tribio

    tribio

    Joined:
    Oct 5, 2013
    Posts:
    29
    Yeah! I need something similar too!
     
  3. ematsuno

    ematsuno

    Joined:
    Oct 13, 2015
    Posts:
    27
    You can do this with a monobehavior: Create a DSP (filter) by overriding the OnAudiofilterRead.
    The array data[] contains the PCM data for all of the channels; Each channel has its samples arranged in a sequential order
    l
    ///data[] represents all of the PCM Data from all of the channels.
    the indices are sequential, so you'd address it as such:

    void OnAudioFilterRead(float[] data, int channels)
    {
    for (int i = 0; i < data.Length; i += channels)
    {
    data[i ] = 0; // mute left channel
    }


    void OnAudioFilterRead(float[] data, int channels)
    {
    for (int i = 0; i < data.Length; i += channels)
    {
    data[i +1] = 0; // mute right channel
    }
    }

    ///void OnAudioFilterRead(float[] data, int channels)
    /// {
    /// for (int i = 0; i < data.Length; i += channels)
    /// {
    /// data[i +2] = 0; // mute 3rd channel
    ///}
    ///}
    https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnAudioFilterRead.html
     
    johnbrightnew01 likes this.
  4. jorrit-de-vries

    jorrit-de-vries

    Joined:
    Aug 7, 2009
    Posts:
    71
    You might want to turn off *Enable audio enhancements* under the Advanced Properties tab of the output device.