嵌入式linux开发板使用pulseaudio连接蓝牙耳机播放音频文件

pulseaudio基于a2dp音频架构,其使用流程如下:
首先需要一直bluez5及pulseaudio,此处关于一直pulseaudio详见其他博客。
配置使用流程:
1.开启蓝牙设备

//此处与后续的bluetoothctl命令中的power on相对应,没有开启的话,bluetoothctl会报错.
root@imx6qsabresd:~#rfkill unblock bluetooth

2.启动蓝牙

root@imx6qsabresd:~#hciconfig hci0 up

3.通过bluetoothctl连接蓝牙耳机

//必须先启动bluetoothd,否则bluetoothctl无法工作
root@imx6qsabresd:~#bluetoothd&
root@imx6qsabresd:~#bluetoothctl
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent 
Default agent request successful
[bluetooth]# scan on
Discovery started
[CHG] Controller A4:17:31:C7:9B:B6 Discovering: yes
[NEW] Device 74:7D:04:2F:F1:BA 74-7D-04-2F-F1-BA
[NEW] Device 88:0F:10:87:22:CE 88-0F-10-87-22-CE
[CHG] Device 88:0F:10:87:22:CE Name: MI_SCALE
[CHG] Device 88:0F:10:87:22:CE Alias: MI_SCALE
[NEW] Device 35:BD:7B:5D:CC:AE 35-BD-7B-5D-CC-AE
[NEW] Device 38:BC:1A:B2:9B:5D 38-BC-1A-B2-9B-5D
[CHG] Device 35:BD:7B:5D:CC:AE LegacyPairing: no
[CHG] Device 35:BD:7B:5D:CC:AE Name: J2-USB Bluetooth
[CHG] Device 35:BD:7B:5D:CC:AE Alias: J2-USB Bluetooth
[CHG] Device 38:BC:1A:B2:9B:5D Name: MEIZU MX4
[CHG] Device 38:BC:1A:B2:9B:5D Alias: MEIZU MX4
[NEW] Device 00:1A:7D:DA:71:13 00-1A-7D-DA-71-13
[CHG] Device 00:1A:7D:DA:71:13 RSSI: -76
[CHG] Device 00:1A:7D:DA:71:13 Name: JavieWong-PC
[CHG] Device 00:1A:7D:DA:71:13 Alias: JavieWong-PC
[CHG] Device 35:BD:7B:5D:CC:AE LegacyPairing: yes
[CHG] Device 35:BD:7B:5D:CC:AE RSSI: -48
[CHG] Device 38:BC:1A:B2:9B:5D UUIDs:
        00001112-0000-1000-8000-00805f9b34fb
        00001203-0000-1000-8000-00805f9b34fb
        0000111f-0000-1000-8000-00805f9b34fb
        00001116-0000-1000-8000-00805f9b34fb
        00001115-0000-1000-8000-00805f9b34fb
        0000110c-0000-1000-8000-00805f9b34fb
        0000110f-0000-1000-8000-00805f9b34fb
        0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device 88:0F:10:87:22:CE RSSI: -92
[bluetooth]# pair 35:BD:7B:5D:CC:AE
Attempting to pair with 35:BD:7B:5D:CC:AE
[CHG] Device 35:BD:7B:5D:CC:AE Connected: yes
[CHG] Device 35:BD:7B:5D:CC:AE UUIDs:
        0000110b-0000-1000-8000-00805f9b34fb
        0000110e-0000-1000-8000-00805f9b34fb
        0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 35:BD:7B:5D:CC:AE Paired: yes
Pairing successful
[bluetooth]# connect 35:BD:7B:5D:CC:AE
Attempting to connect to 35:BD:7B:5D:CC:AE
[CHG] Device 35:BD:7B:5D:CC:AE Connected: yes
[bluetooth]# info 35:BD:7B:5D:CC:AE
Device 35:BD:7B:5D:CC:AE
        Name: J2-USB Bluetooth
        Alias: J2-USB Bluetooth
        Class: 0x240404
        Icon: audio-card
        Paired: yes
        Trusted: no
        Blocked: no
        Connected: yes
        LegacyPairing: yes
        UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
        UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
[bluetooth]# 
imx-hdmi-audio imx-hdmi-audio: HDMI Video is not ready!
imx-hdmi-audio imx-hdmi-audio: ASoC: can't open platform imx-hdmi-audio: -22
imx-hdmi-audio imx-hdmi-audio: HDMI Video is not ready!
imx-hdmi-audio imx-hdmi-audio: ASoC: can't open platform imx-hdmi-audio: -22
imx-hdmi-audio imx-hdmi-audio: HDMI Video is not ready!
imx-hdmi-audio imx-hdmi-audio: ASoC: can't open platform imx-hdmi-audio: -22
imx-hdmi-audio imx-hdmi-audio: HDMI Video is not ready!
imx-hdmi-audio imx-hdmi-audio: ASoC: can't open platform imx-hdmi-audio: -22
imx-hdmi-audio imx-hdmi-audio: HDMI Video is not ready!
imx-hdmi-audio imx-hdmi-audio: ASoC: can't open platform imx-hdmi-audio: -22
imx-hdmi-audio imx-hdmi-audio: HDMI Video is not ready!
imx-hdmi-audio imx-hdmi-audio: ASoC: can't open platform imx-hdmi-audio: -22
imx-hdmi-audio imx-hdmi-audio: HDMI Video is not ready!
imx-hdmi-audio imx-hdmi-audio: ASoC: can't open platform imx-hdmi-audio: -22
imx-hdmi-audio imx-hdmi-audio: HDMI Video is not ready!
imx-hdmi-audio imx-hdmi-audio: ASoC: can't open platform imx-hdmi-audio: -22

4.在另外一个控制终端中启动pulseaudio

//
root@imx6qsabresd:~# pulseaudio --system
W: [pulseaudio] main.c: Running in system mode, but --disallow-exit not set!
W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set!
N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode!
W: [pulseaudio] main.c: OK, so you are running PA in system mode. Please note that you most likely shouldn't be doing that.
W: [pulseaudio] main.c: If you do it nonetheless then it's your own fault if things don't work as expected.
W: [pulseaudio] main.c: Please read http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/ for an explanation why system mode is usually a bad idea.
E: [pulseaudio] module-alsa-card.c: Failed to find a working profile.
E: [pulseaudio] module.c: Failed to load module "module-alsa-card" (argument: "device_id="0" name="platform-sound-hdmi.21" card_name="alsa_card.platform-sound-hdmi.21" namereg_fail=false tsched=yes fixed_latency_range=no ignore_dB=no deferred_volume=yes use_ucm=yes card_properties="module-udev-detect.discovered=1""): initialization failed.
W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.config/pulse/cookie': No such file or directory
W: [pulseaudio] authkey.c: Failed to load authentication key '/var/run/pulse/.config/pulse/cookie': No such file or directory
W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.pulse-cookie': No such file or directory
W: [pulseaudio] authkey.c: Failed to load authentication key '/var/run/pulse/.pulse-cookie': No such file or directory

5、配置默认音频输出设备

root@imx6qsabresd:~#pacmd help
Available commands:
    help                      Show this help
    list-modules              List loaded modules
    list-cards                List cards
    list-sinks                List loaded sinks
    list-sources              List loaded sources
    list-clients              List loaded clients
    list-sink-inputs          List sink inputs
    list-source-outputs       List source outputs
    stat                      Show memory block statistics
    info                      Show comprehensive status
    load-module               Load a module (args: name, arguments)
    unload-module             Unload a module (args: index|name)
    describe-module           Describe a module (arg: name)
    set-sink-volume           Set the volume of a sink (args: index|name, volume)
    set-source-volume         Set the volume of a source (args: index|name, volume)
    set-sink-mute             Set the mute switch of a sink (args: index|name, bool)
    set-source-mute           Set the mute switch of a source (args: index|name, bool)
    set-sink-input-volume     Set the volume of a sink input (args: index, volume)
    set-source-output-volume  Set the volume of a source output (args: index, volume)
    set-sink-input-mute       Set the mute switch of a sink input (args: index, bool)
    set-source-output-mute    Set the mute switch of a source output (args: index, bool)
    set-default-sink          Set the default sink (args: index|name)
    set-default-source        Set the default source (args: index|name)
    set-card-profile          Change the profile of a card (args: index|name, profile-name)
    set-sink-port             Change the port of a sink (args: index|name, port-name)
    set-source-port           Change the port of a source (args: index|name, port-name)
    set-port-latency-offset   Change the latency of a port (args: card-index|card-name, port-name, latency-offset)
    suspend-sink              Suspend sink (args: index|name, bool)
    suspend-source            Suspend source (args: index|name, bool)
    suspend                   Suspend all sinks and all sources (args: bool)
    move-sink-input           Move sink input to another sink (args: index, sink)
    move-source-output        Move source output to another source (args: index, source)
    update-sink-proplist      Update the properties of a sink (args: index|name, properties)
    update-source-proplist    Update the properties of a source (args: index|name, properties)
    update-sink-input-proplist Update the properties of a sink input (args: index, properties)
    update-source-output-proplist Update the properties of a source output (args: index, properties)
    list-samples              List all entries in the sample cache
    play-sample               Play a sample from the sample cache (args: name, sink|index)
    remove-sample             Remove a sample from the sample cache (args: name)
    load-sample               Load a sound file into the sample cache (args: name, filename)
    load-sample-lazy          Lazily load a sound file into the sample cache (args: name, filename)
    load-sample-dir-lazy      Lazily load all files in a directory into the sample cache (args: pathname)
    kill-client               Kill a client (args: index)
    kill-sink-input           Kill a sink input (args: index)
    kill-source-output        Kill a source output (args: index)
    set-log-target            Change the log target (args: null|auto|syslog|stderr|file:PATH|newfile:PATH)
    set-log-level             Change the log level (args: numeric level)
    set-log-meta              Show source code location in log messages (args: bool)
    set-log-time              Show timestamps in log messages (args: bool)
    set-log-backtrace         Show backtrace in log messages (args: frames)
    play-file                 Play a sound file (args: filename, sink|index)
    dump                      Dump daemon configuration
    dump-volumes              Debug: Show the state of all volumes
    shared                    Debug: Show shared properties
    exit                      Terminate the daemon
root@imx6qsabresd:~#pactl list cards
Card #0
        Name: alsa_card.platform-sound.20
        Driver: module-alsa-card.c
        Owner Module: 7
        Properties:
                alsa.card = "0"
                alsa.card_name = "wm8962-audio"
                alsa.long_card_name = "wm8962-audio"
                device.bus_path = "platform-sound.20"
                sysfs.path = "/devices/soc0/sound.20/sound/card0"
                device.string = "0"
                device.description = "wm8962-audio"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card"
        Profiles:
                input:analog-mono: Analog Mono Input (sinks: 0, sources: 1, priority: 2, available: yes)
                input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
                output:analog-mono: Analog Mono Output (sinks: 1, sources: 0, priority: 200, available: yes)
                output:analog-mono+input:analog-mono: Analog Mono Duplex (sinks: 1, sources: 1, priority: 202, available: yes)
                output:analog-stereo: Analog Stereo Output (sinks: 1, sources: 0, priority: 6000, available: yes)
                output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (sinks: 1, sources: 1, priority: 6060, available: yes)
                off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
        Active Profile: output:analog-stereo+input:analog-stereo
        Ports:
                analog-input: Analog Input (priority: 10000, latency offset: 0 usec)
                        Part of profile(s): input:analog-mono, input:analog-stereo, output:analog-mono+input:analog-mono, output:analog-stereo+input:analog-stereo
                analog-output-speaker: Speakers (priority: 10000, latency offset: 0 usec, not available)
                        Properties:
                                device.icon_name = "audio-speakers"
                        Part of profile(s): output:analog-mono, output:analog-mono+input:analog-mono, output:analog-stereo, output:analog-stereo+input:analog-stereo
                analog-output-headphones: Headphones (priority: 9000, latency offset: 0 usec, available)
                        Properties:
                                device.icon_name = "audio-headphones"
                        Part of profile(s): output:analog-mono, output:analog-mono+input:analog-mono, output:analog-stereo, output:analog-stereo+input:analog-stereo
如果发现板子上有单个声卡设备,则按照步骤5.1配置既可以,如果有多个声卡设备按照5.2步骤配置
5.1 单声音配置
Card #1
        Name: bluez_card.35_BD_7B_5D_CC_AE
        Driver: module-bluez5-device.c
        Owner Module: 24
        Properties:
                device.description = "J2-USB Bluetooth"
                device.string = "35:BD:7B:5D:CC:AE"
                device.api = "bluez"
                device.class = "sound"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/hci0/dev_35_BD_7B_5D_CC_AE"
                bluez.class = "0x240404"
                bluez.alias = "J2-USB Bluetooth"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
        Profiles:
                a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
                headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: no)
                off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
        Active Profile: a2dp_sink
        Ports:
                headset-output: Headset (priority: 0, latency offset: 0 usec)
                        Part of profile(s): a2dp_sink, headset_head_unit
                headset-input: Headset (priority: 0, latency offset: 0 usec, not available)
                        Part of profile(s): headset_head_unit
root@imx6qsabresd:~#pacmd list-sinks
1 sink(s) available.
  * index: 1
        name: <bluez_sink.35_BD_7B_5D_CC_AE>
        driver: <module-bluez5-device.c>
        flags: HARDWARE DECIBEL_VOLUME LATENCY 
        state: SUSPENDED
        suspend cause: IDLE 
        priority: 9030
        volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        base volume: 65536 / 100% / 0.00 dB
        volume steps: 65537
        muted: no
        current latency: 0.00 ms
        max request: 2 KiB
        max rewind: 0 KiB
        monitor source: 1
        sample spec: s16le 2ch 44100Hz
        channel map: front-left,front-right
                     Stereo
        used by: 0
        linked by: 0
        fixed latency: 39.51 ms
        card: 0 <bluez_card.35_BD_7B_5D_CC_AE>
        module: 24
        properties:
                bluetooth.protocol = "a2dp_sink"
                device.description = "J2-USB Bluetooth"
                device.string = "35:BD:7B:5D:CC:AE"
                device.api = "bluez"
                device.class = "sound"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/hci0/dev_35_BD_7B_5D_CC_AE"
                bluez.class = "0x240404"
                bluez.alias = "J2-USB Bluetooth"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
        ports:
                headset-output: Headset (priority 0, latency offset 0 usec, available: unknown)
                        properties:

        active port: <headset-output>
root@imx6qsabresd:~#pacmd list-cards
1 card(s) available.
    index: 0
        name: <bluez_card.35_BD_7B_5D_CC_AE>
        driver: <module-bluez5-device.c>
        owner module: 24
        properties:
                device.description = "J2-USB Bluetooth"
                device.string = "35:BD:7B:5D:CC:AE"
                device.api = "bluez"
                device.class = "sound"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/hci0/dev_35_BD_7B_5D_CC_AE"
                bluez.class = "0x240404"
                bluez.alias = "J2-USB Bluetooth"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
        profiles:
                a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 10, available: unknown)
                headset_head_unit: Headset Head Unit (HSP/HFP) (priority 20, available: no)
                off: Off (priority 0, available: yes)
        active profile: <a2dp_sink>
        sinks:
                bluez_sink.35_BD_7B_5D_CC_AE/#1: J2-USB Bluetooth
        sources:
                bluez_sink.35_BD_7B_5D_CC_AE.monitor/#1: Monitor of J2-USB Bluetooth
        ports:
                headset-output: Headset (priority 0, latency offset 0 usec, available: unknown)
                        properties:

                headset-input: Headset (priority 0, latency offset 0 usec, available: no)
                        properties:

root@imx6qsabresd:~#pacmd set-default-sink 1
root@imx6qsabresd:~#pacmd set-card-profile 0 a2dp_sink
root@imx6qsabresd:~#pacmd info
Memory blocks currently allocated: 1, size: 64.0 KiB.
Memory blocks allocated during the whole lifetime: 53616, size: 67.8 MiB.
Memory blocks imported from other processes: 0, size: 0 B.
Memory blocks exported to other processes: 0, size: 0 B.
Total sample cache size: 0 B.
Default sample spec: s16le 2ch 44100Hz
Default channel map: front-left,front-right
Default sink name: bluez_sink.35_BD_7B_5D_CC_AE
Default source name: bluez_sink.35_BD_7B_5D_CC_AE.monitor
Memory blocks of type POOL: 1 allocated/39706 accumulated.
Memory blocks of type POOL_EXTERNAL: 0 allocated/0 accumulated.
Memory blocks of type APPENDED: 0 allocated/0 accumulated.
Memory blocks of type USER: 0 allocated/0 accumulated.
Memory blocks of type FIXED: 0 allocated/0 accumulated.
Memory blocks of type IMPORTED: 0 allocated/13910 accumulated.
24 module(s) loaded.
    index: 0
        name: <module-device-restore>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "Automatically restore the volume/mute state of devices"
                module.version = "6.0"
    index: 1
        name: <module-stream-restore>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "Automatically restore the volume/mute/device state of streams"
                module.version = "6.0"
    index: 2
        name: <module-card-restore>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "Automatically restore profile of cards"
                module.version = "6.0"
    index: 3
        name: <module-augment-properties>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "Augment the property sets of streams with additional static information"
                module.version = "6.0"
    index: 4
        name: <module-switch-on-port-available>
        argument: <>
        used: -1
        load once: no
        properties:

    index: 5
        name: <module-udev-detect>
        argument: <tsched=0>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "Detect available audio hardware and load matching drivers"
                module.version = "6.0"
    index: 7
        name: <module-bluetooth-policy>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Fr茅d茅ric Dalleau"
                module.description = "When a bluetooth sink or source is added, load module-loopback"
                module.version = "6.0"
    index: 8
        name: <module-bluetooth-discover>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Jo茫o Paulo Rechi Vita"
                module.description = "Detect available Bluetooth daemon and load the corresponding discovery module"
                module.version = "6.0"
    index: 9
        name: <module-bluez5-discover>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Jo茫o Paulo Rechi Vita"
                module.description = "Detect available BlueZ 5 Bluetooth audio devices and load BlueZ 5 Bluetooth audio drivers"
                module.version = "6.0"
    index: 10
        name: <module-native-protocol-unix>
        argument: <>
        used: -1
        load once: no
        properties:
                module.author = "Lennart Poettering"
                module.description = "Native protocol (UNIX sockets)"
                module.version = "6.0"
    index: 11
        name: <module-default-device-restore>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "Automatically restore the default sink and source"
                module.version = "6.0"
    index: 12
        name: <module-rescue-streams>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "When a sink/source is removed, try to move its streams to the default sink/source"
                module.version = "6.0"
    index: 13
        name: <module-always-sink>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Colin Guthrie"
                module.description = "Always keeps at least one sink loaded even if it's a null one"
                module.version = "6.0"
    index: 15
        name: <module-intended-roles>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "Automatically set device of streams based on intended roles of devices"
                module.version = "6.0"
    index: 16
        name: <module-suspend-on-idle>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "When a sink/source is idle for too long, suspend it"
                module.version = "6.0"
    index: 17
        name: <module-console-kit>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "Create a client for each ConsoleKit session of this user"
                module.version = "6.0"
    index: 18
        name: <module-position-event-sounds>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "Position event sounds between L and R depending on the position on screen of the widget triggering them."
                module.version = "6.0"
    index: 19
        name: <module-role-cork>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Lennart Poettering"
                module.description = "Mute & cork streams with certain roles while others exist"
                module.version = "6.0"
    index: 20
        name: <module-filter-heuristics>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Colin Guthrie"
                module.description = "Detect when various filters are desirable"
                module.version = "6.0"
    index: 21
        name: <module-filter-apply>
        argument: <>
        used: -1
        load once: yes
        properties:
                module.author = "Colin Guthrie"
                module.description = "Load filter sinks automatically when needed"
                module.version = "6.0"
    index: 22
        name: <module-x11-publish>
        argument: <display=:0>
        used: -1
        load once: no
        properties:
                module.author = "Lennart Poettering"
                module.description = "X11 credential publisher"
                module.version = "6.0"
    index: 23
        name: <module-x11-cork-request>
        argument: <display=:0>
        used: -1
        load once: no
        properties:
                module.author = "Lennart Poettering"
                module.description = "Synthesize X11 media key events when cork/uncork is requested"
                module.version = "6.0"
    index: 24
        name: <module-bluez5-device>
        argument: <path=/org/bluez/hci0/dev_35_BD_7B_5D_CC_AE>
        used: 0
        load once: no
        properties:
                module.author = "Jo茫o Paulo Rechi Vita"
                module.description = "BlueZ 5 Bluetooth audio sink and source"
                module.version = "6.0"
    index: 25
        name: <module-cli-protocol-unix>
        argument: <>
        used: -1
        load once: no
        properties:
                module.author = "Lennart Poettering"
                module.description = "Command line interface protocol (UNIX sockets)"
                module.version = "6.0"
1 sink(s) available.
  * index: 1
        name: <bluez_sink.35_BD_7B_5D_CC_AE>
        driver: <module-bluez5-device.c>
        flags: HARDWARE DECIBEL_VOLUME LATENCY 
        state: SUSPENDED
        suspend cause: IDLE 
        priority: 9030
        volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        base volume: 65536 / 100% / 0.00 dB
        volume steps: 65537
        muted: no
        current latency: 0.00 ms
        max request: 2 KiB
        max rewind: 0 KiB
        monitor source: 1
        sample spec: s16le 2ch 44100Hz
        channel map: front-left,front-right
                     Stereo
        used by: 0
        linked by: 0
        fixed latency: 39.51 ms
        card: 0 <bluez_card.35_BD_7B_5D_CC_AE>
        module: 24
        properties:
                bluetooth.protocol = "a2dp_sink"
                device.description = "J2-USB Bluetooth"
                device.string = "35:BD:7B:5D:CC:AE"
                device.api = "bluez"
                device.class = "sound"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/hci0/dev_35_BD_7B_5D_CC_AE"
                bluez.class = "0x240404"
                bluez.alias = "J2-USB Bluetooth"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
        ports:
                headset-output: Headset (priority 0, latency offset 0 usec, available: unknown)
                        properties:

        active port: <headset-output>
1 source(s) available.
  * index: 1
        name: <bluez_sink.35_BD_7B_5D_CC_AE.monitor>
        driver: <module-bluez5-device.c>
        flags: DECIBEL_VOLUME LATENCY 
        state: SUSPENDED
        suspend cause: IDLE 
        priority: 1030
        volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        base volume: 65536 / 100% / 0.00 dB
        volume steps: 65537
        muted: no
        current latency: 0.00 ms
        max rewind: 0 KiB
        sample spec: s16le 2ch 44100Hz
        channel map: front-left,front-right
                     Stereo
        used by: 0
        linked by: 0
        fixed latency: 39.51 ms
        monitor_of: 1
        card: 0 <bluez_card.35_BD_7B_5D_CC_AE>
        module: 24
        properties:
                device.description = "Monitor of J2-USB Bluetooth"
                device.class = "monitor"
                device.string = "35:BD:7B:5D:CC:AE"
                device.api = "bluez"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/hci0/dev_35_BD_7B_5D_CC_AE"
                bluez.class = "0x240404"
                bluez.alias = "J2-USB Bluetooth"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
1 client(s) logged in.
    index: 26
        driver: <cli.c>
        owner module: 25
        properties:
                application.name = "UNIX socket client"
1 card(s) available.
    index: 0
        name: <bluez_card.35_BD_7B_5D_CC_AE>
        driver: <module-bluez5-device.c>
        owner module: 24
        properties:
                device.description = "J2-USB Bluetooth"
                device.string = "35:BD:7B:5D:CC:AE"
                device.api = "bluez"
                device.class = "sound"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/hci0/dev_35_BD_7B_5D_CC_AE"
                bluez.class = "0x240404"
                bluez.alias = "J2-USB Bluetooth"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
        profiles:
                a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 10, available: unknown)
                headset_head_unit: Headset Head Unit (HSP/HFP) (priority 20, available: no)
                off: Off (priority 0, available: yes)
        active profile: <a2dp_sink>
        sinks:
                bluez_sink.35_BD_7B_5D_CC_AE/#1: J2-USB Bluetooth
        sources:
                bluez_sink.35_BD_7B_5D_CC_AE.monitor/#1: Monitor of J2-USB Bluetooth
        ports:
                headset-output: Headset (priority 0, latency offset 0 usec, available: unknown)
                        properties:

                headset-input: Headset (priority 0, latency offset 0 usec, available: no)
                        properties:

0 sink input(s) available.
0 source output(s) available.
0 cache entrie(s) available.
root@imx6qsabresd:~#pacmd stat
Memory blocks currently allocated: 1, size: 64.0 KiB.
Memory blocks allocated during the whole lifetime: 53616, size: 67.8 MiB.
Memory blocks imported from other processes: 0, size: 0 B.
Memory blocks exported to other processes: 0, size: 0 B.
Total sample cache size: 0 B.
Default sample spec: s16le 2ch 44100Hz
Default channel map: front-left,front-right
Default sink name: bluez_sink.35_BD_7B_5D_CC_AE
Default source name: bluez_sink.35_BD_7B_5D_CC_AE.monitor
Memory blocks of type POOL: 1 allocated/39706 accumulated.
Memory blocks of type POOL_EXTERNAL: 0 allocated/0 accumulated.
Memory blocks of type APPENDED: 0 allocated/0 accumulated.
Memory blocks of type USER: 0 allocated/0 accumulated.
Memory blocks of type FIXED: 0 allocated/0 accumulated.
Memory blocks of type IMPORTED: 0 allocated/13910 accumulated.
5.2 多声卡设备配置
root@imx6qsabresd:~# pacmd set-card-profile 1 a2dp_sink
root@imx6qsabresd:~# pactl list sinks
Sink #0
        State: SUSPENDED
        Name: alsa_output.platform-sound.20.analog-stereo
        Description: wm8962-audio Analog Stereo
        Driver: module-alsa-card.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 7
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Base Volume: 65536 / 100% / 0.00 dB
        Monitor Source: alsa_output.platform-sound.20.analog-stereo.monitor
        Latency: 0 usec, configured 0 usec
        Flags: HARDWARE DECIBEL_VOLUME LATENCY 
        Properties:
                alsa.resolution_bits = "16"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = ""
                alsa.id = "HiFi wm8962-0"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "0"
                alsa.card = "0"
                alsa.card_name = "wm8962-audio"
                alsa.long_card_name = "wm8962-audio"
                device.bus_path = "platform-sound.20"
                sysfs.path = "/devices/soc0/sound.20/sound/card0"
                device.string = "hw:0"
                device.buffering.buffer_size = "17632"
                device.buffering.fragment_size = "4408"
                device.access_mode = "mmap"
                device.profile.name = "analog-stereo"
                device.profile.description = "Analog Stereo"
                device.description = "wm8962-audio Analog Stereo"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card"
        Ports:
                analog-output-speaker: Speakers (priority: 10000, not available)
                analog-output-headphones: Headphones (priority: 9000, available)
        Active Port: analog-output-headphones
        Formats:
                pcm

Sink #1
        State: SUSPENDED
        Name: bluez_sink.35_BD_7B_5D_CC_AE
        Description: J2-USB Bluetooth
        Driver: module-bluez5-device.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 24
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Base Volume: 65536 / 100% / 0.00 dB
        Monitor Source: bluez_sink.35_BD_7B_5D_CC_AE.monitor
        Latency: 0 usec, configured 0 usec
        Flags: HARDWARE DECIBEL_VOLUME LATENCY 
        Properties:
                bluetooth.protocol = "a2dp_sink"
                device.description = "J2-USB Bluetooth"
                device.string = "35:BD:7B:5D:CC:AE"
                device.api = "bluez"
                device.class = "sound"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/hci0/dev_35_BD_7B_5D_CC_AE"
                bluez.class = "0x240404"
                bluez.alias = "J2-USB Bluetooth"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
        Ports:
                headset-output: Headset (priority: 0)
        Active Port: headset-output
        Formats:
                pcm
root@imx6qsabresd:~# pacmd set-default-sink 1
root@imx6qsabresd:~# pactl list sources
Source #0
        State: SUSPENDED
        Name: alsa_output.platform-sound.20.analog-stereo.monitor
        Description: Monitor of wm8962-audio Analog Stereo
        Driver: module-alsa-card.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 7
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Base Volume: 65536 / 100% / 0.00 dB
        Monitor of Sink: alsa_output.platform-sound.20.analog-stereo
        Latency: 0 usec, configured 0 usec
        Flags: DECIBEL_VOLUME LATENCY 
        Properties:
                device.description = "Monitor of wm8962-audio Analog Stereo"
                device.class = "monitor"
                alsa.card = "0"
                alsa.card_name = "wm8962-audio"
                alsa.long_card_name = "wm8962-audio"
                device.bus_path = "platform-sound.20"
                sysfs.path = "/devices/soc0/sound.20/sound/card0"
                device.string = "0"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card"
        Formats:
                pcm

Source #1
        State: SUSPENDED
        Name: alsa_input.platform-sound.20.analog-stereo
        Description: wm8962-audio Analog Stereo
        Driver: module-alsa-card.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 7
        Mute: no
        Volume: front-left: 33804 /  52% / -17.25 dB,   front-right: 33804 /  52% / -17.25 dB
                balance 0.00
        Base Volume: 26090 /  40% / -24.00 dB
        Monitor of Sink: n/a
        Latency: 0 usec, configured 0 usec
        Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
        Properties:
                alsa.resolution_bits = "16"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = ""
                alsa.id = "HiFi wm8962-0"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "0"
                alsa.card = "0"
                alsa.card_name = "wm8962-audio"
                alsa.long_card_name = "wm8962-audio"
                device.bus_path = "platform-sound.20"
                sysfs.path = "/devices/soc0/sound.20/sound/card0"
                device.string = "hw:0"
                device.buffering.buffer_size = "17632"
                device.buffering.fragment_size = "4408"
                device.access_mode = "mmap"
                device.profile.name = "analog-stereo"
                device.profile.description = "Analog Stereo"
                device.description = "wm8962-audio Analog Stereo"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card"
        Ports:
                analog-input: Analog Input (priority: 10000)
        Active Port: analog-input
        Formats:
                pcm

Source #2
        State: SUSPENDED
        Name: bluez_sink.35_BD_7B_5D_CC_AE.monitor
        Description: Monitor of J2-USB Bluetooth
        Driver: module-bluez5-device.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 24
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Base Volume: 65536 / 100% / 0.00 dB
        Monitor of Sink: bluez_sink.35_BD_7B_5D_CC_AE
        Latency: 0 usec, configured 0 usec
        Flags: DECIBEL_VOLUME LATENCY 
        Properties:
                device.description = "Monitor of J2-USB Bluetooth"
                device.class = "monitor"
                device.string = "35:BD:7B:5D:CC:AE"
                device.api = "bluez"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/hci0/dev_35_BD_7B_5D_CC_AE"
                bluez.class = "0x240404"
                bluez.alias = "J2-USB Bluetooth"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
        Formats:
                pcm
root@imx6qsabresd:~# pacmd set-default-source 2
5.3 测试蓝牙耳机
//在终端中使用pactl list命令查看此时的配置已经OK
root@imx6qsabresd:~# pactl list sinks
Sink #1
        State: SUSPENDED
        Name: bluez_sink.35_BD_7B_5D_CC_AE
        Description: J2-USB Bluetooth
        Driver: module-bluez5-device.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 24
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Base Volume: 65536 / 100% / 0.00 dB
        Monitor Source: bluez_sink.35_BD_7B_5D_CC_AE.monitor
        Latency: 0 usec, configured 0 usec
        Flags: HARDWARE DECIBEL_VOLUME LATENCY 
        Properties:
                bluetooth.protocol = "a2dp_sink"
                device.description = "J2-USB Bluetooth"
                device.string = "35:BD:7B:5D:CC:AE"
                device.api = "bluez"
                device.class = "sound"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/hci0/dev_35_BD_7B_5D_CC_AE"
                bluez.class = "0x240404"
                bluez.alias = "J2-USB Bluetooth"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
        Ports:
                headset-output: Headset (priority: 0)
        Active Port: headset-output
        Formats:
                pcm
root@imx6qsabresd:~# pactl list cards
Card #0
        Name: bluez_card.35_BD_7B_5D_CC_AE
        Driver: module-bluez5-device.c
        Owner Module: 24
        Properties:
                device.description = "J2-USB Bluetooth"
                device.string = "35:BD:7B:5D:CC:AE"
                device.api = "bluez"
                device.class = "sound"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/hci0/dev_35_BD_7B_5D_CC_AE"
                bluez.class = "0x240404"
                bluez.alias = "J2-USB Bluetooth"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
        Profiles:
                a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
                headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: no)
                off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
        Active Profile: a2dp_sink
        Ports:
                headset-output: Headset (priority: 0, latency offset: 0 usec)
                        Part of profile(s): a2dp_sink, headset_head_unit
                headset-input: Headset (priority: 0, latency offset: 0 usec, not available)
                        Part of profile(s): headset_head_unit

6.使用aplay软件播放音乐

6.1 aplay有时候可以正常播放,有时候不行,不清楚原因
root@imx6qsabresd:~#aplay test.wav
6.2 使用gstream播放器
//噪声测试
root@imx6qsabresd:~# gst-launch-1.0 audiotestsrc ! pulsesink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstPulseSinkClock
imx-hdmi-audio imx-hdmi-audio: HDMI Video is not ready!
imx-hdmi-audio imx-hdmi-audio: ASoC: can't open platform imx-hdmi-audio: -22
//播放wav文件
root@imx6qsabresd:~# gst-launch-1.0 filesrc location=audio8k16S.wav ! wavparse ! 
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstPulseSinkClock
Got EOS from element "pipeline0".
Execution ended after 0:00:05.090986334
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
autoaudiosinkesd
6.3 使用paplay测试
paplay  audio8k16S.wav 

遇到的问题:
1.

W: [pulseaudio] main.c: This program is not intended to be run as root (unless –system is specified).
E: [pulseaudio] core-util.c: Home directory not accessible: Permission denied
解决办法:启动时加上pulseaudio --system
W: [pulseaudio] main.c: Running in system mode, but –disallow-exit not set!
W: [pulseaudio] main.c: Running in system mode, but –disallow-module-loading not set!
N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode!
N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time!
E: [pulseaudio] main.c: Failed to find user ‘pulse’.
解决办法:新建用户pulse
root@imx6qsabresd:~#useradd pulse
启动bluetoothctl时提示No default controller available
解决办法:没有启动bluetoothd
root@imx6qsabresd:~#bluetoothd&
  • 8
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 38
    评论
### 回答1: 嵌入式 Linux 开发板是一种微型计算机,它可以在物理设备中嵌入,并通过 Linux 操作系统与其他设备进行通信。这些设备通常是非常小巧,可以在各种应用场景中使用,如工业控制、家庭自动化、智能家居等。 嵌入式 Linux 开发板通常具有以下特点: 1. 小巧:它们通常很小,可以方便地安装在物理设备中。 2. 可编程:它们可以通过编程语言(如 C、Python 等)进行开发。 3. 多功能:它们可以支持多种功能,如网络通信、存储数据、显示图像等。 4. 可扩展:它们可以通过外部设备扩展功能,如接入传感器、摄像头等。 如果您对嵌入式 Linux 开发板感兴趣,可以考虑使用 Raspberry Pi、BeagleBone Black 等流行的开发板。 ### 回答2: 嵌入式Linux开发板是指搭载嵌入式Linux操作系统的开发板,通常采用ARM架构的处理器。它可以为嵌入式系统提供完整的Linux环境,包括Linux内核、文件系统以及常用的Linux工具,方便开发人员进行应用程序的开发。 嵌入式Linux开发板具有以下特点: 一、低功耗和高性能:嵌入式Linux开发板使用ARM架构的处理器,具有低功耗和高性能的特点,满足低功耗和高性能的应用需求。 二、丰富的接口和扩展性:嵌入式Linux开发板具有丰富的接口和扩展性,可通过外置扩展板或接口扩展模块满足不同应用场景下的需求。 三、可裁剪性:嵌入式Linux开发板可以根据实际需求进行裁剪,去除不必要的组件和功能,从而减少系统资源的占用,提高系统运行效率。 四、稳定可靠:由于使用Linux操作系统,嵌入式Linux开发板具有非常稳定可靠的特点,可保证系统长时间稳定运行。 嵌入式Linux开发板广泛应用于智能家居、智能医疗、智慧交通、物联 网等领域,成为嵌入式系统开发的主流选择。但是,嵌入式Linux开发板也具有一定的开发门槛,需要开发人员掌握一定的Linux操作系统和嵌入式系统开发经验,才能更好地发挥其功能和优势。 ### 回答3: 嵌入式Linux开发板是一种集成了Linux操作系统和硬件平台的开发板。这种开发板通常是由嵌入式系统厂商或者开发者自行设计的,其主要用途是针对特定的应用场景进行开发和调试,比如智能家居、工业控制、医疗设备等。嵌入式Linux开发板具有以下特点: 1. 硬件平台:嵌入式Linux开发板通常是采用一款微处理器为核心,搭配一些外设如存储器、网络、输入输出接口等组成的系统。硬件平台的选择通常需要根据应用场景的需求、想要实现的功能以及成本等因素进行权衡。 2. Linux系统:嵌入式Linux开发板搭载的是简化版本的Linux操作系统,由于资源受限,会使用一些轻量级的系统,如busybox等。这些系统通常会定制化,去掉一些不必要的部分,从而减小系统运行所需的资源开销,并且加快系统启动、响应等速度。 3. 开发环境:嵌入式Linux开发板的开发环境也是非常重要的一部分。通常有两种方式,一种是通过交叉编译的方式,在主机上编译运行嵌入式系统程序;另一种是通过板载编译方式,直接在开发板上编译运行程序。一般来说,板载编译的方式速度较慢,但对于嵌入式开发板的测试和调试非常方便。 总之,嵌入式Linux开发板嵌入式系统开发的一种重要方式,通过这种方式可以快速构建出自己所需的某种特定应用系统。当然,开发过程中也要考虑到硬件和系统控制等相关方面的问题,以使用更加安全稳定的系统运行设备。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值