How to mix X channels into one channel

I am recently at ALSA and Linux,

How do I mix X channels into one channel using ALSA plugins in the recording path?

and

How to control volume with alsamixer for each channel?

I look at the http://www.alsa-project.org/alsa-doc/alsa-lib API but didn't find anything suitable, so I asked here. Please direct me to the right direction, code sample or tutorial. I have looked at SO too, but I am getting game path information.

+3


source to share


2 answers


You need the dmix plugin. It's quiet, easy to use. In /etc/asound.conf

pcm.<device_name> {
   type dmix        # plugin type
   ipc_key 321456   # any unique value through /etc/asound.conf
   slave {
      pcm "hw:0,0"  # Sound card name
      format S32_LE # That is you format
      rate 44100    # Sampling rate
      channels 2    # You channels count 
   }
}

      



After reboot, you will be able to open the device from different locations and alsa will mix their output. Here are some docs about it: http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html

+1


source


First, start with a device that allows multiple recording clients:

pcm.snooped {
    type dsnoop
    slave.pcm "hw:0"  # or whatever
}

      

Then extract the individual channels:

pcm.channel1 {
    type route
    slave {
        pcm snooped
        channels 2
    }
    ttable [ [ 1 0 ] ]
}

pcm.channel2 {
    type route
    slave {
        pcm snooped
        channels 2
    }
    ttable [ [ 0 1 ] ]
}

      

Then put a softvol

on each of them:



pcm.channel1_softvol {
    type softvol
    slave.pcm channel1
    control.name "Channel 1 Capture Volume"
}
pcm.channel2_softvol {
    type softvol
    slave.pcm channel2
    control.name "Channel 2 Capture Volume"
}

      

Then combine them into one device:

pcm.mixed_with_volumes {
    type multi
    slaves {
        a { pcm channel1_softvol channels 1 }
        b { pcm channel2_softvol channels 1 }
    }
    bindings [
        { slave a channel 0 }
        { slave b channel 0 }
    ]
}

      

... and use a plugin plug

to merge channels:

pcm.my_device {
    type plug
    slave.pcm mixed_with_volumes
    ttable [ [ 0.5 0.5 ] ]
}

      

0


source







All Articles