[ 物联网篇 ] 26 -ALSA Plug 中 multi 的应用

TODO

pcm.quad {
    type multi
    slaves.a.pcm "plughw:3,0"
    slaves.a.channels 6
    slaves.b.pcm "plughw:1,0"
    slaves.b.channels 2
    bindings.0.slave a
    bindings.0.channel 0
    bindings.1.slave a
    bindings.1.channel 1
    bindings.2.slave a
    bindings.2.channel 2
    bindings.3.slave a
    bindings.3.channel 3
    bindings.4.slave a
    bindings.4.channel 4
    bindings.5.slave a
    bindings.5.channel 5
    bindings.6.slave b
    bindings.6.channel 0
    bindings.7.slave b
    bindings.7.channel 1
}

参考

https://stackoverflow.com/questions/5126169/programmatically-merging-two-pieces-of-audio/5126209#5126209

http://blog.bjornroche.com/2013/05/the-abcs-of-pcm-uncompressed-digital.html

https://bootlin.com/blog/audio-multi-channel-routing-and-mixing-using-alsalib/

https://alsa.opensrc.org/MultipleCards

https://www.alsa-project.org/wiki/Asoundrc

https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html

How can I use ALSA dmix and multi plugins together?

// 挺高级的用法
# thx
# http://wiki.ubuntuusers.de/.asoundrc
# http://alsa.opensrc.org/Dmix
# http://forums.linuxmint.com/viewtopic.php?f=196&t=94877

pcm.snd_card {
    type hw
    card 1
    device 0
}

# allows multiple programs to output sound simultanously ("software mixing")
pcm.dmixer {
    type dmix
    ipc_key 1024
    ipc_perm 0666 # allow other users
    slave.pcm "out"
    slave {
        period_time 0
        period_size 1024
        buffer_size 4096
        ### if having problems
        # rate 44100
        ### some sound cards need the exact data format
        # format S32_LE
        ### Available formats: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE
        ###                    U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE
        ###                    FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE
        ###                    IEC958_SUBFRAME_LE IEC958_SUBFRAME_BE MU_LAW
        ###                    A_LAW IMA_ADPCM MPEG GSM
        channels 2 # must match bindings
    }
    bindings {
        0 0
        1 1
    }
}

# allows multiple programs to capture simultaneously
pcm.dsnooper {
    type dsnoop
    ipc_key 2048
    ipc_perm 0666 
    slave.pcm "snd_card"
    slave 
    {
        period_time 0
        period_size 1024
        buffer_size 4096
        channels 2 
    }
    bindings {
        0 0
        1 1
    }
}

pcm.!default {
    type asym
    playback.pcm "dmixer"
    capture.pcm "dsnooper"
}

pcm.out {
    type plug
    slave.pcm {
        type multi
        slaves {
            a { channels 2 pcm "snd_card" }
            b { channels 2 pcm "hw:Loopback,0,0" }
        }
        bindings {
            0 { slave a channel 0 }
            1 { slave a channel 1 }
            2 { slave b channel 0 }
            3 { slave b channel 1 }
        }
    }
    ttable [
        [ 1 0 1 0 ]   # left  -> a.left,  b.left
        [ 0 1 0 1 ]   # right -> a.right, b.right
    ]
}

# In case I ever want to use PulseAudio, for bluetooth speakers or such.
#pcm.!default {
#    type pulse
#}
#ctl.!default {
#    type pulse
#}

[!default] → multi → dmix → hw [normal]
                   ↳ dmix → hw [loopback]

#ALSA配置#如何在asound.conf中同时使用MMAP模式和Ladspa插件

# duplicate audio to both devices
pcm.!default plug:both

ctl.!default {
  type hw
  card SB
}

pcm.both {
  type route;
  slave.pcm {
      type multi;
      slaves.a.pcm "sblive";
      slaves.b.pcm "onboard";
      slaves.a.channels 2;
      slaves.b.channels 4;
      bindings.0.slave a;
      bindings.0.channel 0;
      bindings.1.slave a;
      bindings.1.channel 1;

      bindings.2.slave b;
      bindings.2.channel 0;
      bindings.3.slave b;
      bindings.3.channel 1;
      bindings.4.slave b;
      bindings.4.channel 2;
      bindings.5.slave b;
      bindings.5.channel 3;
  }

  ttable.0.0 1;
  ttable.1.1 1;

  ttable.0.2 1; # front left
  ttable.1.3 1; # front right
  ttable.0.4 1; # copy front left to rear left
  ttable.1.5 1; # copy front right to rear right
}

ctl.both {
  type hw;
  card Live;
}

pcm.onboard {
   type dmix
   ipc_key 1024
   slave {
       pcm "hw:0,1"
       period_time 0
       period_size 2048
       buffer_size 65536
       buffer_time 0
       periods 128
       rate 48000
       channels 4
    }
    bindings {
       0 0
       1 1
       2 2
       3 3
    }
}

pcm.sblive {
   type dmix
   ipc_key 2048
   slave {
       pcm "hw:1,0"
       period_time 0
       period_size 2048
       buffer_size 65536
       buffer_time 0
       periods 128
       rate 48000
       channels 2
    }
    bindings {
       0 0
       1 1
    }
}

ctl.onboard {
   type hw
   card "SB"
}

ctl.sblive {
   type hw
   card "Live"
}

参考http://www.6by9.net/output-to-multiple-audio-devices-with-alsa/

你可能感兴趣的:([,工作积累,])