ALSA子系统(二)------PCM (digital audio) plugins

你好!这里是风筝的博客,
欢迎和我一起交流。

PCM插件(plugins)扩展了PCM设备的功能。插件负责各种采样转换,通道之间的采样复制,命名设备、写入文件、为多个输入/输出连接声卡/设备(不同步采样)、使用多通道声卡/设备等工作。

Slave definition

Slave 插件可以使用字符串直接指定从属插件,也可以在复合配置节点内输入定义。还可以指定一些限制(例如静态速率或通道数)。

pcm_slave.NAME {
    pcm STR     # PCM name
    # or
    pcm { }     # PCM definition
    format STR  # Format or "unchanged"
    channels INT    # Count of channels or "unchanged" string
    rate INT    # Rate in Hz or "unchanged" string
    period_time INT # Period time in us or "unchanged" string
    buffer_time INT # Buffer time in us or "unchanged" string
}

例如:

pcm_slave.slave_rate44100Hz {
    pcm "hw:0,0"
    rate 44100
}
pcm.rate44100Hz {
    type plug
    slave slave_rate44100Hz
}

等效配置如下:

pcm.rate44100Hz {
    type plug
    slave {
        pcm "hw:0,0"
        rate 44100
    }
}

译者注:这配置会使得音频以固定的44.1K频率输出。

Plugin: hw

该插件直接与ALSA内核驱动程序通信。这是未经任何转换的原始通信。模仿mmap访问可以被启用,但是在这种情况下,预计会有更糟的延迟。
nonblock选项指定设备是否以非阻塞方式打开。请注意,此选项不会更改读/写访问的阻止行为。这仅影响打开设备时的阻塞行为。如果您想保持与旧版ALSA的兼容性,请关闭此选项。

pcm.name {
    type hw         # Kernel PCM
    card INT/STR        # Card name (string) or number (integer)
    [device INT]        # Device number (default 0)
    [subdevice INT]     # Subdevice number (default -1: first available)
    [sync_ptr_ioctl BOOL]   # Use SYNC_PTR ioctl rather than the direct mmap access for control structures
    [nonblock BOOL]     # Force non-blocking open mode
    [format STR]        # Restrict only to the given format
    [channels INT]      # Restrict only to the given channels
    [rate INT]      # Restrict only to the given rate
    [chmap MAP]     # Override channel maps; MAP is a string array
}
Function reference

Plugin: mmap_emul

pcm.name {
    type mmap_emul
    slave PCM
}

Plugin: shm

该插件通过共享内存与服务器通信。这是未经任何转换的原始通信,但是可以预期会出现较差的性能。

pcm.name {
        type shm                # Shared memory PCM
    server STR      # Server name
    pcm STR         # PCM name
}
Function reference

Plugin: Null

此插件丢弃PCM流的内容或创建零采样填充的流。
注意:此实现使用设备/ dev / null(播放,必须可写)和/ dev / full(录音,必须可读)。

pcm.name {
        type null               # Null PCM
    [chmap MAP]     # Provide channel maps; MAP is a string array
}
Function reference
  • snd_pcm_null_open()
  • _snd_pcm_null_open()

Plugin: copy

该插件将样本从主PCM复制到给定的从PCM。两者的通道数,格式和速率必须匹配。

pcm.name {
    type copy       # Copy PCM
    slave STR       # Slave name
    # or
    slave {         # Slave definition
        pcm STR     # Slave PCM name
        # or
        pcm { }     # Slave PCM definition
    }
}
Function reference
  • snd_pcm_copy_open()
  • _snd_pcm_copy_open()

译者注:配置一个音频流copy到到声卡1的小例子:
aplay -D copy spring_48K_2ch_16bit.wav

pcm.copy {
   type copy       # Copy PCM
   slave {         # Slave definition
       pcm "hw:1,0"
   }
}

Plugin: linear

此插件将线性采样从主线性PCM转换为给定的从PCM。两者的通道数,格式和速率必须匹配。

pcm.name {
        type linear             # Linear conversion PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
                format STR      # Slave format
        }
}
Function reference
  • snd_pcm_linear_open()
  • _snd_pcm_linear_open()

Plugin: linear<->float

该插件从主PCM将线性采样转换为浮点采样和将浮点采样转换为线性采样,给定的从动PCM。两者的通道数,格式和速率必须匹配。

pcm.name {
        type lfloat             # Linear<->Float conversion PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
                format STR      # Slave format
        }
}
Function reference
  • snd_pcm_lfloat_open()
  • _snd_pcm_lfloat_open()

Plugin: Mu-Law

此插件可从主PCM将Mu-Law样本转换为线性或将线性转换为Mu-Law样本给定的从PCM。两者的通道数,格式和速率必须匹配。

pcm.name {
        type mulaw              # Mu-Law conversion PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
                format STR      # Slave format
        }
}
Function reference
  • snd_pcm_mulaw_open()
  • _snd_pcm_mulaw_open()

Plugin: A-Law

此插件可从主PCM将A-Law样本转换为线性或将线性转换为A-Law样本给定的从PCM。两者的通道数,格式和速率必须匹配。

pcm.name {
        type alaw               # A-Law conversion PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
                format STR      # Slave format
        }
}
Function reference
  • snd_pcm_alaw_open()
  • _snd_pcm_alaw_open()

Plugin: Ima-ADPCM

此插件可从主PCM将Ima-ADPCM样本转换为线性或将线性转换为Ima-ADPCM样本给定的从PCM。两者的通道数,格式和速率必须匹配。

pcm.name {
        type adpcm              # Ima-ADPCM conversion PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
                format STR      # Slave format
        }
}
Function reference
  • snd_pcm_adpcm_open()
  • _snd_pcm_adpcm_open()

Plugin: Route & Volume

该插件转换通道并在转换过程中设置音量,两者的格式和速率必须匹配。
SCHANNEL可以用通道名称代替编号(例如FL,LFE),如果这样,将从从设备选择匹配的通道映射。

pcm.name {
        type route              # Route & Volume conversion PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
                [format STR]    # Slave format
                [channels INT]  # Slave channels
        }
        ttable {                # Transfer table (bi-dimensional compound of cchannels * schannels numbers)
                CCHANNEL {
                        SCHANNEL REAL   # route value (0.0 - 1.0)
                }
        }
        [chmap MAP]             # Override channel maps; MAP is a string array
}
Function reference
  • snd_pcm_route_open()
  • _snd_pcm_route_open()

译者注:配置声卡1双通道配置为单通道
将输入的两声道数据分别作1倍衰减,然后合成单声道数据:
ttable 第一个值表示输入的通道序号
ttable 第二个值表示输出的通道序号
ttable 第三个值表示衰减值

pcm.makemono {
   type route
   slave.pcm "hw:1,0"
   ttable {
      0.0 1    # in-channel 0, out-channel 0, 100% volume
      1.0 1    # in-channel 1, out-channel 0, 100% volume
   }
}

Plugin: Rate

该插件转换速率。输入和输出格式必须是线性的。

pcm.name {
    type rate               # Rate PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
                rate INT        # Slave rate
                [format STR]    # Slave format
        }
    converter STR           # optional
    # or
    converter [ STR1 STR2 ... ] # optional
                # Converter type, default is taken from
                # defaults.pcm.rate_converter
    # or
    converter {     # optional
        name STR    # Convertor type
        xxx yyy     # optional convertor-specific configuration
    }
}

译者注:转换为48khz

pcm.rate_convert {
       type rate
       slave {
               pcm "hw:1,0"
              rate 48000
       }
}
Function reference
  • snd_pcm_rate_open()
  • _snd_pcm_rate_open()

Plugin: conversion plugin

该插件可根据要求转换通道,速率和格式。

pcm.name {
        type plug               # Automatic conversion PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
        [format STR]    # Slave format (default nearest) or "unchanged"
        [channels INT]  # Slave channels (default nearest) or "unchanged"
        [rate INT]  # Slave rate (default nearest) or "unchanged"
        }
    route_policy STR    # route policy for automatic ttable generation
                # STR can be 'default', 'average', 'copy', 'duplicate'
                # average: result is average of input channels
                # copy: only first channels are copied to destination
                # duplicate: duplicate first set of channels
                # default: copy policy, except for mono capture - sum
    ttable {        # Transfer table (bi-dimensional compound of cchannels * schannels numbers)
        CCHANNEL {
            SCHANNEL REAL   # route value (0.0 - 1.0)
        }
    }
    rate_converter STR  # type of rate converter
    # or
    rate_converter [ STR1 STR2 ... ]
                # type of rate converter
                # default value is taken from defaults.pcm.rate_converter
}
Function reference
  • snd_pcm_plug_open()
  • _snd_pcm_plug_open()

译者注:像是rate插件的升级版…

pcm_slave.sl3 {
	pcm "hw:1,0"
	format S16_LE
	channels 2
	rate 16000
}
pcm.complex_convert {
	type plug
	slave sl3
}

Plugin: File

此插件将PCM流的内容存储到文件中或将其通过管道传输到命令,并可选地使用现有文件作为输入数据源(即“虚拟麦克风”)

pcm.name {
        type file               # File PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
        }
    file STR        # Output filename (or shell command the stream
                # will be piped to if STR starts with the pipe
                # char).
                # STR can contain format keys, replaced by
                # real values corresponding to the stream:
                # %r    rate (replaced with: 48000)
                # %c    channels (replaced with: 2)
                # %b    bits per sample (replaced with: 16)
                # %f    sample format string
                #           (replaced with: S16_LE)
                # %%    replaced with %
    or
    file INT        # Output file descriptor number
    infile STR      # Input filename - only raw format
    or
    infile INT      # Input file descriptor number
    [format STR]        # File format ("raw" or "wav")
    [perm INT]      # Output file permission (octal, def. 0600)
}

译者注:播放/录音时保存raw数据到/tmp目录下:
aplay -D copy spring_48K_2ch_16bit.wav

pcm.copy {
   type copy       # Copy PCM
   slave {         # Slave definition
       pcm "hw:1,0"
   }
}
Function reference
  • snd_pcm_file_open()
  • _snd_pcm_file_open()

Plugin: Multiple streams to One

该插件将多个流转换为一个。

pcm.name {
        type multi              # Multiple streams conversion PCM
        slaves {        # Slaves definition
        ID STR      # Slave PCM name
        # or
        ID {
            pcm STR     # Slave PCM name
            # or
            pcm { }     # Slave PCM definition
            channels INT    # Slave channels
        }
        }
    bindings {      # Bindings table
        N {
            slave STR   # Slave key
            channel INT # Slave channel
        }
    }
    [master INT]        # Define the master slave
}

例如,要将具有两声道立体声(hw:0,0和hw:0,1)的两个PCM流绑定为一个4声道立体声PCM流,请定义如下:

pcm.quad {
    type multi
    slaves.a.pcm "hw:0,0"
    slaves.a.channels 2
    slaves.b.pcm "hw:0,1"
    slaves.b.channels 2
    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
}

请注意,所得的pcm“quad”不是交错格式,而是“ complex”格式。因此,只能处理交错(或非交错)格式的应用程序无法访问它。在这种情况下,请使用route 或 plug插件包装此PCM 。

译者注:上面的demo表示:
配置声卡"hw:0,0"别名为a,最大声道为2,声卡"hw:0,1"别名为b,最大声卡为2.
bindings指定多个声卡声道数排列,
上述表明a声卡的0 1 为multi的声道0声道1输出,b声卡的0 1 为multi的声道2声道3输出

pcm.quad2 {
    type route
    slave.pcm "quad"
    ttable.0.0 1
    ttable.1.1 1
    ttable.2.2 1
    ttable.3.3 1
}
Function reference
  • snd_pcm_multi_open()
  • _snd_pcm_multi_open()

Plugin: Share

此插件允许与更多客户端共享多个渠道。对每个通道的访问是专有的(样本不混合在一起)。这意味着,如果第一个客户端使用通道零,则第二个客户端不能使用此通道。如果您正在寻找混合插件,请使用dmix插件。
与dshare插件的区别在于,Share插件需要服务器程序“ aserver”,而dshare插件不需要显式服务器,但需要访问共享缓冲区。

pcm.name {
        type share              # Share PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                [format STR]    # Slave format
                [channels INT]  # Slave channels
                [rate INT]      # Slave rate
                [period_time INT] # Slave period time in us
                [buffer_time INT] # Slave buffer time in us
        }
    bindings {
        N INT       # Slave channel INT for client channel N
    }
}
Function reference
  • snd_pcm_share_open()
  • _snd_pcm_share_open()

Plugin: hooks

当打开,修改或关闭此插件时,该插件用于调用某些“hooks”功能。通常,它用于更改特定状态下特定于PCM的控制值(请参见下面的示例)。

# Hook arguments definition
hook_args.NAME {
    ...         # Arbitrary arguments
}
# PCM hook type
pcm_hook_type.NAME {
    [lib STR]       # Library file (default libasound.so)
    [install STR]       # Install function (default _snd_pcm_hook_NAME_install)
}
# PCM hook definition
pcm_hook.NAME {
    type STR        # PCM Hook type (see pcm_hook_type)
    [args STR]      # Arguments for install function (see hook_args)
    # or
    [args { }]      # Arguments for install function
}
# PCM hook plugin
pcm.NAME {
    type hooks      # PCM with hooks
    slave STR       # Slave name
    # or
    slave {         # Slave definition
        pcm STR     # Slave PCM name
        # or
        pcm { }     # Slave PCM definition
    }
    hooks {
        ID STR      # Hook name (see pcm_hook)
        # or
        ID { }      # Hook definition (see pcm_hook)
    }
}

例:

hooks.0 {
    type ctl_elems
    hook_args [
        {
            name "Wave Surround Playback Volume"
            preserve true
            lock true
            optional true
            value [ 0 0 ]
        }
        {
            name "EMU10K1 PCM Send Volume"
            index { @func private_pcm_subdevice }
            lock true
            value [ 0 0 0 0 0 0 255 0 0 0 0 255 ]
        }
    ]
}

在访问此pcm时,此处的控件“ Wave Surround Playback Volume”和“ EMU10K1 PCM Send Volume”被设置为给定值。由于这些控件采用多维值,因此该value字段被写入数组。如果preserve为true,则在pcm关闭时将保存并恢复旧值。这lock意味着控件在此pcm打开期间被锁定,并且不能被其他人更改。当optional被设置,返回却忽略了任何错误,即使指定的控件不存在。

Function reference
  • The function ctl_elems -_snd_pcm_hook_ctl_elems_install() -安装由给定配置描述的CTL设置。
  • snd_pcm_hooks_open()
  • _snd_pcm_hooks_open()

Plugin: dmix

该插件可直接混合多个流。32位混合为24位。低有效字节用零填充。多余的8位用于饱和。

pcm.name {
    type dmix       # Direct mix
    ipc_key INT     # unique IPC key
    ipc_key_add_uid BOOL    # add current uid to unique IPC key
    ipc_perm INT        # IPC permissions (octal, default 0600)
    hw_ptr_alignment STR    # Slave application and hw pointer alignment type
                # STR can be one of the below strings :
                # no
                # roundup
                # rounddown
                # auto (default)
    tstamp_type STR     # timestamp type
                # STR can be one of the below strings :
                # default, gettimeofday, monotonic, monotonic_raw
    slave STR
    # or
    slave {         # Slave definition
        pcm STR     # slave PCM name
        # or
        pcm { }     # slave PCM definition
        format STR  # format definition
        rate INT    # rate definition
        channels INT
        period_time INT # in usec
        # or
        period_size INT # in frames
        buffer_time INT # in usec
        # or
        buffer_size INT # in frames
        periods INT # when buffer_size or buffer_time is not specified
    }
    bindings {      # note: this is client independent!!!
        N INT       # maps slave channel to client channel N
    }
    slowptr BOOL        # slow but more precise pointer updates
}

ipc_key用整数指定唯一的IPC密钥。该数字对于每个不同的dmix定义必须是唯一的,因为共享内存是使用此键号创建的。当ipc_key_add_uid设置为true时,会将uid值添加到中设置的值中ipc_key。这样可以避免同一IPC密钥同时与不同用户发生冲突。

hw_ptr_alignment指定从属应用程序和硬件指针对齐类型。默认情况下hw_ptr_alignment是自动的。以下是可能的配置:

  • no:启动时丢弃最少帧的最小延迟。但是唤醒应用程序(从snd_pcm_wait()或poll()返回)最多可能需要2 *时间。
  • roundup:确保在启动时播放所有帧。但是延迟将增加到周期1帧。
  • rounddown:保证每个周期都会发生唤醒,并且可以从应用程序写入帧。但是在启动时,周期1之前的帧将被丢弃。
  • auto:根据使用的时间段和缓冲区大小选择最佳方法。如果应用程序缓冲区大小小于2 *应用程序周期,将选择“roundup”以避免运行不足。如果slave_period <10ms,我们可以期望有较低的延迟要求。因此,将选择“rounddown”以避免长时间的唤醒时间。如果依赖于另一个声音设备(例如,将麦克风转发到扬声器),则此类唤醒延迟可能最终以Xruns结束。否则将选择“no”。

请注意,dmix插件本身仅支持单个配置。也就是说,它仅支持固定速率(默认为48000),格式(S16),通道(2)和period_time(125000)。要使用其他配置,必须在从PCM定义中显式设置该值。速率,格式和通道可以通过其他插件来覆盖,但是无论如何只有一种基本配置。

用于将44100 Hz S32_LE格式设置为“ hw:0”的从PCM 的示例配置如下:

pcm.dmix_44 {
    type dmix
    ipc_key 321456  # any unique value
    ipc_key_add_uid true
    slave {
        pcm "hw:0"
        format S32_LE
        rate 44100
    }
}

你可以通过使用 dmix pcm via plug插件听到48000 Hz样本,如下配置:

% aplay -D plug:dmix_44 foo_48k.wav

为了将dmix插件用于OSS仿真设备,必须将周期和缓冲区大小设置为2的幂。例如,

pcm.dmixoss {
    type dmix
    ipc_key 321456  # any unique value
    ipc_key_add_uid true
    slave {
        pcm "hw:0"
        period_time 0
        period_size 1024  # must be power of 2
        buffer_size 8192  # ditto
    }
}

period_time 0必须被设置,为了重置默认值。对于具有多通道IO的声卡,添加绑定会有所帮助

pcm.dmixoss {
    ...
    bindings {
        0 0   # map from 0 to 0
        1 1   # map from 1 to 1
    }
}

因此dmix仅使用前两个通道。另外,请注意,ICE1712的缓冲区大小有限,为5513帧(相当于640 kB)。在这种情况下,请将buffer_size减小为4096。

Function reference
  • The function ctl_elems -_snd_pcm_hook_ctl_elems_install() -安装由给定配置描述的CTL设置。
  • snd_pcm_dmic_open()
  • _snd_pcm_dmic_open()

Plugin: dshare

该插件提供共享渠道。与share插件不同,此插件不需要显式的服务器程序,但可以从每个客户端同时访问共享缓冲区,而dmix和dsnoop插件也可以。以下参数与这些插件几乎相同。

pcm.name {
    type dshare     # Direct sharing
    ipc_key INT     # unique IPC key
    ipc_key_add_uid BOOL    # add current uid to unique IPC key
    ipc_perm INT        # IPC permissions (octal, default 0600)
    hw_ptr_alignment STR    # Slave application and hw pointer alignment type
        # STR can be one of the below strings :
        # no
        # roundup
        # rounddown
        # auto (default)
    tstamp_type STR     # timestamp type
                # STR can be one of the below strings :
                # default, gettimeofday, monotonic, monotonic_raw
    slave STR
    # or
    slave {         # Slave definition
        pcm STR     # slave PCM name
        # or
        pcm { }     # slave PCM definition
        format STR  # format definition
        rate INT    # rate definition
        channels INT
        period_time INT # in usec
        # or
        period_size INT # in frames
        buffer_time INT # in usec
        # or
        buffer_size INT # in frames
        periods INT # when buffer_size or buffer_time is not specified
    }
    bindings {      # note: this is client independent!!!
        N INT       # maps slave channel to client channel N
    }
    slowptr BOOL        # slow but more precise pointer updates

hw_ptr_alignment指定从属应用程序和硬件指针对齐类型。默认情况下,hw_ptr_alignment是自动的。以下是可能的配置:

  • no:启动时丢弃最少帧的最小延迟。但是唤醒应用程序(从snd_pcm_wait()或poll()返回)最多可能需要2 *时间。
  • roundup:确保在启动时播放所有帧。但是延迟将增加到周期1帧。
  • rounddown:保证每个周期都会发生唤醒,并且可以从应用程序写入帧。但是在启动时,周期1之前的帧将被丢弃。
  • auto:根据使用的时间段和缓冲区大小选择最佳方法。如果应用程序缓冲区大小小于2 *应用程序周期,将选择“roundup”以避免运行不足。如果slave_period <10ms,我们可以期望有较低的延迟要求。因此,将选择“rounddown”以避免长时间的唤醒时间。如果依赖于另一个声音设备(例如,将麦克风转发到扬声器),则此类唤醒延迟可能最终以Xruns结束。否则将选择“no”。
Function reference
  • The function ctl_elems -_snd_pcm_hook_ctl_elems_install() -安装由给定配置描述的CTL设置。
  • snd_pcm_dshare_open()
  • _snd_pcm_dshare_open()

Plugin: dsnoop

此插件将一个捕获流拆分为更多。它的工作方式与dmix插件相反,可以同时从许多客户端读取共享捕获缓冲区。以下参数的含义与dmix插件几乎相同。

pcm.name {
    type dsnoop     # Direct snoop
    ipc_key INT     # unique IPC key
    ipc_key_add_uid BOOL    # add current uid to unique IPC key
    ipc_perm INT        # IPC permissions (octal, default 0600)
    hw_ptr_alignment STR    # Slave application and hw pointer alignment type
        # STR can be one of the below strings :
        # no
        # roundup
        # rounddown
        # auto (default)
    tstamp_type STR     # timestamp type
                # STR can be one of the below strings :
                # default, gettimeofday, monotonic, monotonic_raw
    slave STR
    # or
    slave {         # Slave definition
        pcm STR     # slave PCM name
        # or
        pcm { }     # slave PCM definition
        format STR  # format definition
        rate INT    # rate definition
        channels INT
        period_time INT # in usec
        # or
        period_size INT # in frames
        buffer_time INT # in usec
        # or
        buffer_size INT # in frames
        periods INT # when buffer_size or buffer_time is not specified
    }
    bindings {      # note: this is client independent!!!
        N INT       # maps slave channel to client channel N
    }
    slowptr BOOL        # slow but more precise pointer updates
}

hw_ptr_alignment指定从属应用程序和硬件指针对齐类型。默认情况下,hw_ptr_alignment是自动的。以下是可能的配置:

  • no:启动时丢弃最少帧的最小延迟。但是唤醒应用程序(从snd_pcm_wait()或poll()返回)最多可能需要2 *时间。
  • roundup:确保在启动时播放所有帧。但是延迟将增加到周期1帧。
  • rounddown:保证每个周期都会发生唤醒,并且可以从应用程序写入帧。但是在启动时,周期1之前的帧将被丢弃。
  • auto:根据使用的时间段和缓冲区大小选择最佳方法。如果应用程序缓冲区大小小于2 *应用程序周期,则将选择“roundup”以避免溢出。如果slave_period <10ms,我们可以期望有较低的延迟要求。因此,将选择“rounddown”以避免长时间的唤醒时间。否则将选择“no”。
Function reference
  • The function ctl_elems -_snd_pcm_hook_ctl_elems_install() -安装由给定配置描述的CTL设置。
  • snd_pcm_dsnoop_open()
  • _snd_pcm_dsnoop_open()

Plugin: LADSPA <-> ALSA

此插件允许应用一组LADPSA插件。输入和输出格式始终为SND_PCM_FORMAT_FLOAT(请注意:根据体系结构,此类型可以为小端或大端)。

策略重复意味着通道0只能有一个绑定定义。该定义会自动复制到所有通道。如果LADSPA插件具有多个音频输入或输出,则策略重复项将自动切换为策略无。

插件序列化按预期工作。您最终可以在LADPSA插件链中使用的通道(输入/输出)多于ALSA插件链中处理的通道。如果给定的LADSPA输入音频端口不存在ALSA通道,则对该LADSPA端口提供零样本。在输出端(ALSA下一个插件输入),也检查有效通道。如果特定的ALSA通道不存在,则LADSPA输出端口将连接到虚拟样本区域。

LADSPA插件的实例是动态创建的。

pcm.name {
        type ladspa             # ALSA<->LADSPA PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
        }
        [channels INT]      # count input channels (input to LADSPA plugin chain)
    [path STR]      # Path (directory) with LADSPA plugins
    plugins |       # Definition for both directions
        playback_plugins |  # Definition for playback direction
    capture_plugins {   # Definition for capture direction
        N {     # Configuration for LADPSA plugin N
            [id INT]    # LADSPA plugin ID (for example 1043)
            [label STR] # LADSPA plugin label (for example 'delay_5s')
            [filename STR]  # Full filename of .so library with LADSPA plugin code
            [policy STR]    # Policy can be 'none' or 'duplicate'
            input | output {
                bindings {
                    C INT or STR    # C - channel, INT - audio port index, STR - audio port name
                }
                controls {
                        # valid only in the input block
                    I INT or REAL   # I - control port index, INT or REAL - control value
                    # or
                    STR INT or REAL # STR - control port name, INT or REAL - control value
                }
            }
        }
    }
}
Function reference
  • The function ctl_elems -_snd_pcm_hook_ctl_elems_install() -安装由给定配置描述的CTL设置。
  • snd_pcm_ladspa_open()
  • _snd_pcm_ladspa_open()

Plugin: asym

此插件是播放和录音PCM流的组合。可以为两个方向非对称地定义从PCM。

pcm.name {
        type asym               # Asym PCM
        playback STR            # Playback slave name
        # or
        playback {              # Playback slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
        }
        capture STR             # Capture slave name
        # or
        capture {               # Capture slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
        }
}

例如,您可以将dmix插件和dsnoop插件组合为单个PCM,分别用于播放和录音。

pcm.duplex {
    type asym
    playback.pcm "dmix"
    capture.pcm "dsnoop"
}

通过仅定义一个方向,导致PCM变为半双工。

Function reference
  • _snd_pcm_asym_open()

Plugin: IEC958

此插件将32位IEC958子帧样本转换为线性,或将线性转换为32bit IEC958子帧样本。

pcm.name {
        type iec958             # IEC958 subframe conversion PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
        }
    [status status-bytes]   # IEC958 status bits (given in byte array)
    # IEC958 preamble bits definitions
    # B/M/W or Z/X/Y, B = block start, M = even subframe, W = odd subframe
    # As default, Z = 0x08, Y = 0x04, X = 0x02
    [preamble.z or preamble.b val]
    [preamble.x or preamble.m val]
    [preamble.y or preamble.w val]
}
Function reference
  • snd_pcm_iec958_open()
  • _snd_pcm_iec958_open()

Plugin: Soft Volume

此插件应用软件音量衰减。格式,速率和通道必须与来源和目的都匹配。
当控件为立体声(count = 2)时,假定声道为单声道,2.0、2.1、4.0、4.1、5.1或7.1。
如果该控件已经存在并且是系统控件(即没有用户定义的控件),则该插件将简单地传递其从属,而无需进行任何更改。

pcm.name {
        type softvol            # Soft Volume conversion PCM
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
                [format STR]    # Slave format
        }
        control {
            name STR        # control element id string
        [card STR]      # control card index
        [iface STR]     # interface of the element
        [index INT]     # index of the element
        [device INT]    # device number of the element
        [subdevice INT] # subdevice number of the element
        [count INT]     # control channels 1 or 2 (default: 2)
    }
    [min_dB REAL]           # minimal dB value (default: -51.0)
    [max_dB REAL]           # maximal dB value (default:   0.0)
    [resolution INT]        # resolution (default: 256)
                # resolution = 2 means a mute switch
}

译者注:在第一次使用 softvol 插件进行播放时才会生成对应的控件

Function reference
  • snd_pcm_softvol_open()
  • _snd_pcm_softvol_open()

Plugin: Null

此插件丢弃PCM流的内容,或创建具有零样本的流。
注意:此实现使用设备/ dev / null(播放,必须可写)和/ dev / full(录音,必须可读)。

pcm.name {
        type null               # Null PCM
}
Function reference
  • _snd_pcm_empty_open()

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

更多例子参考:
A close look at ALSA
【ALSA】 asound.conf 插件讲解
asoundrc配置文件简单介绍

  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: alsa-plugins-1.1.5.tar.bz2是一个压缩文件,用于安装和更新ALSA(Advanced Linux Sound Architecture)插件。ALSA是一种在Linux操作系统上提供音频支持的软件架构。 这个压缩文件包含了ALSA插件的源代码,可以在Linux系统上进行编译和安装。通过安装这些插件,用户可以获得更多的音频功能和选项。这些插件包括不同类型的音频效果、数据转换和输入/输出设备支持。 为了安装alsa-plugins-1.1.5.tar.bz2,首先需要解压缩该文件。在终端中使用以下命令可以完成解压缩操作: tar -xvf alsa-plugins-1.1.5.tar.bz2 然后,在解压后的文件夹中执行以下命令来编译和安装插件: ./configure make sudo make install 这将会在系统中安装ALSA插件,并使其可用于音频应用程序。安装完成后,用户可以根据自己的需要配置和使用这些插件。 总而言之,alsa-plugins-1.1.5.tar.bz2是一个用于安装和更新ALSA插件的压缩文件,用户可以通过编译和安装这些插件来增强Linux系统的音频功能。安装过程中需要解压缩文件并执行编译和安装命令。 ### 回答2: alsa-plugins-1.1.5.tar.bz2是一种软件压缩包,其中包含了alsa-plugins软件的版本1.1.5的安装文件。alsa-plugins是一个用于Advanced Linux Sound Architecture (ALSA)的插件集合,它提供了许多音频处理的功能和特性。 该软件包的.tar.bz2后缀表示它使用了tar和bzip2两种压缩算法。tar是一种文件归档工具,可以将多个文件和目录打包成一个文件。而bzip2是一种压缩工具,可以将文件压缩成较小的尺寸以节省存储空间。因此,alsa-plugins-1.1.5.tar.bz2可以解压缩成一个目录,其中包含了alsa-plugins软件的所有源代码和相关文件。 要安装alsa-plugins-1.1.5.tar.bz2,首先需要解压缩该文件。可以使用以下命令在终端中解压缩该文件: tar -xjf alsa-plugins-1.1.5.tar.bz2 解压缩后将得到一个名为alsa-plugins-1.1.5的目录。在该目录中,可能会包含一些安装说明或配置文件,可以阅读这些文档以了解如何编译和安装alsa-plugins。 一般来说,编译和安装软件需要在终端中使用一系列命令。通常的步骤包括配置软件、编译软件和安装软件。具体步骤可能因软件的不同而有所不同,所以建议参考安装说明或官方文档以获得详细指导。 安装成功后,alsa-plugins将被安装在系统中,并且可以在相关的应用程序或设置中使用。alsa-plugins提供了丰富的音频处理插件,可以用于音频播放、录制和处理等多种场景。通过这些插件,用户可以增强音频性能、改善音质、添加音效等。 总之,alsa-plugins-1.1.5.tar.bz2是alsa-plugins软件版本1.1.5的压缩包,解压缩后即可获取该软件的源代码和文件。安装该软件可以提供丰富的音频处理插件,以改善Linux操作系统中的音频功能和体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值