python - ALSA & Python - 捕获多个单声道音频输入

标签 python linux audio ubuntu alsa

我正在使用 python 音频 alsa 库与我的 M-Audio Delta 1010LT PCI 音频接口(interface)交互。此音频接口(interface)有 8 个模拟输入。我想分析一个特定单声道输入的信号。正在识别卡片:

cat /proc/asound/cards 0 [M1010LT        ]: ICE1712 - M Audio Delta 1010LT
                  M Audio Delta 1010LT at 0xa000, irq 18

之后,我使用“amixer”命令列出了所有设备名称(此处显示输入 ADC)

...
Simple mixer control 'ADC',0
Capabilities: volume volume-joined penum
Playback channels: Mono
Capture channels: Mono
Limits: 0 - 164
Mono: 142 [87%] [7.50dB]
Simple mixer control 'ADC',1
Capabilities: volume volume-joined penum
Playback channels: Mono
Capture channels: Mono
Limits: 0 - 164
Mono: 164 [100%] [18.50dB]
Simple mixer control 'ADC',2
Capabilities: volume volume-joined penum
Playback channels: Mono
Capture channels: Mono
Limits: 0 - 164
Mono: 164 [100%] [18.50dB]
Simple mixer control 'ADC',3
Capabilities: volume volume-joined penum
Playback channels: Mono
Capture channels: Mono
Limits: 0 - 164
Mono: 164 [100%] [18.50dB]
Simple mixer control 'ADC',4
Capabilities: volume volume-joined penum
Playback channels: Mono
Capture channels: Mono
Limits: 0 - 164
Mono: 164 [100%] [18.50dB]
Simple mixer control 'ADC',5
Capabilities: volume volume-joined penum
Playback channels: Mono
Capture channels: Mono
Limits: 0 - 164
Mono: 164 [100%] [18.50dB]
Simple mixer control 'ADC',6
Capabilities: volume volume-joined penum
Playback channels: Mono
Capture channels: Mono
Limits: 0 - 164
Mono: 164 [100%] [18.50dB]
Simple mixer control 'ADC',7
Capabilities: volume volume-joined penum
Playback channels: Mono
Capture channels: Mono
Limits: 0 - 164
Mono: 164 [100%] [18.50dB]
...

之后我使用命令“arecord -l”列出了录音硬件设备

arecord -l**** List of CAPTURE Hardware Devices ****
card 0: M1010LT [M Audio Delta 1010LT], device 0: ICE1712 multi [ICE1712 multi]
Subdevices: 1/1
Subdevice #0: subdevice #0

我说的对吗?这是否只显示 1 个录音子设备?不应该显示 8 吗?

我还安装了 Mudita24 - 一个 envy24 可视化混音器。有了这个,我可以完美地调整和监控所有输入 channel 的电平。

之后,我使用 GStreamer 进行了一些测试,效果也很好:

gst-launch-0.10 alsasrc card-name=0 device-name='ADC 0' ! queue ! alsasink card-name=0 device-name='DAC 0'

但是我在使用以下卡和设备描述符来处理 python 的 alsa 中的某个单声道时遇到了麻烦:

'default'  // This one get's me channel 1 & 2 MIXED (I'd like to get them as seperated mono inputs)
'hw:0,0'   // recognizes device but the input value is 0
'hw:0,0,0' // returns same as hw:0,0
'hw:0,0,1' // Device or resource busy (pretty much every other value than 0 returns this)
'hw:0,1'   // No such file or directory

如何使用 ALSA 处理特定的单声道输入 channel ?这是我正在使用的 python 库:link

这就是我尝试为每个 channel 创 build 备的方式:

pcm.one_channel {
@args [ CHANNEL ]
@args.CHANNEL { type integer }
type dsnoop
ipc_key 20130206
slave {
    pcm "hw:0"
    channels 12
    rate 44000
}
bindings [ $CHANNEL ]
}

pcm.two_channel {
    @args [ CHANNEL ]
    @args.CHANNEL { type integer }
    type dsnoop
    ipc_key 20130206
    slave {
        pcm "hw:0"
        channels 12
        rate 44000
    }
    bindings [ $CHANNEL ]
}

pcm.three_channel {
    @args [ CHANNEL ]
    @args.CHANNEL { type integer }
    type dsnoop
    ipc_key 20130206
    slave {
        pcm "hw:0"
        channels 12
        rate 44000
    }
    bindings [ $CHANNEL ]
}

pcm.four_channel {
    @args [ CHANNEL ]
    @args.CHANNEL { type integer }
    type dsnoop
    ipc_key 20130206
    slave {
        pcm "hw:0"
        channels 12
        rate 44000
    }
    bindings [ $CHANNEL ]
}

pcm.five_channel {
    @args [ CHANNEL ]
    @args.CHANNEL { type integer }
    type dsnoop
    ipc_key 20130206
    slave {
        pcm "hw:0"
        channels 12
        rate 44000
    }
    bindings [ $CHANNEL ]
}

我是否正确解读了您的建议?我也一直在网上寻找这个并找到了这张卡的另外两个 .asoundrc(遗憾的是也不起作用)。

#
# M-Audio Delta 1010
#

pcm.ice1712_capture {
    type dsnoop
    ipc_key 1024
    slave {
        pcm "hw:0"
        period_size 0
        buffer_size 65536
        rate 44100
        channels 10
        format "S16_LE"
    }
}

pcm.ice1712_playback {
    type dsnoop
    ipc_key 1024
    slave {
        pcm "hw:0"
        period_size 0
        buffer_size 65536
        rate 44100
        channels 10
        format "S16_LE"
    }
}

pcm.ice1712_duplex {
    type asym
    playback.pcm ice1712_playback
    capture.pcm ice1712_capture
}

pcm.ch1 {
    type plug
    ttable.0.0 1
    slave.pcm ice1712_duplex
}

pcm.ch2 {
    type plug
    ttable.1.1 1
    slave.pcm ice1712_duplex
}

pcm.ch3 {
    type plug
    ttable.0.2 1
    slave.pcm ice1712_duplex
}

pcm.ch4 {
    type plug
    ttable.1.3 1
    slave.pcm ice1712_duplex
}

pcm.ice1712_ch5 {
    type plug
    ttable.0.4 1
    slave.pcm ice1712_duplex
}

pcm.ice1712_ch6 {
    type plug
    ttable.1.5 1
    slave.pcm ice1712_duplex
}

pcm.ice1712_ch7 {
    type plug
    ttable.0.6 1
    slave.pcm ice1712_duplex
}

pcm.ice1712_ch8 {
    type plug
    ttable.1.7 1
    slave.pcm ice1712_duplex
}

pcm.ice1712_ch9 {
    type plug
    ttable.0.8 1
    slave.pcm ice1712_duplex
}

pcm.ice1712_ch10 {
    type plug
    ttable.1.9 1
    slave.pcm ice1712_duplex
}

还有一个:

pcm.multi_capture {
    type multi
    slaves.a.pcm hw:0 
    slaves.a.channels 12

# First 8 channels of first soundcard (capture)
    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 a
    bindings.6.channel 6
    bindings.7.slave a
    bindings.7.channel 7

# S/PDIF section. Uncomment bindings if required.

# S/PDIF first soundcard (capture)
    #bindings.16.slave a
    #bindings.16.channel 8
    #bindings.17.slave a
    #bindings.17.channel 9
}

ctl.multi_capture {
    type hw
    card 0
}

pcm.multi_playback {
    type multi
    slaves.a.pcm hw:0
    slaves.a.channels 10

# First 8 channels of first soundcard (playback)
    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 a
    bindings.6.channel 6
    bindings.7.slave a
    bindings.7.channel 7

# S/PDIF section. Uncomment bindings if required.

# S/PDIF first soundcard (playback)
    #bindings.16.slave a
    #bindings.16.channel 8
    #bindings.17.slave a
    #bindings.17.channel 9
}

ctl.multi_playback {
    type hw
    card 0
}

最佳答案

amixer 工具不显示设备名称,而是显示混音器控件。

ICE1712芯片确实只有一个采集设备(恰好有12个 channel )。


要为各个 channel 获取虚拟设备,请尝试将如下内容添加到您的 ~/.asoundrc/etc/asound.conf:

pcm.one_channel {
    @args [ CHANNEL ]
    @args.CHANNEL { type integer }
    type dsnoop
    ipc_key 20130206
    slave {
        pcm "hw:0"
        channels 12
        rate 48000
    }
    bindings [ $CHANNEL ]
}

然后使用设备名称,如 one_channel:0one_channel:1

关于python - ALSA & Python - 捕获多个单声道音频输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14725257/

相关文章:

linux - Linux 内核模块的 LPM 实现

ios - Phonegap 媒体停止系统音乐

python - 通用哈希实现中的整数溢出

python - 我可以记住一个 Python 生成器吗?

c - 如何使用 select 从 stdin 读取输入?

c - recv 调用缓慢的原因

Python、 `let`、 `with`、局部作用域、调试打印和临时变量

python - 数组解释的循环旋转

python - 精确的异步计时

android - 在 Android 应用程序中实现声音