OpenHarmony支持USB接口声卡适配说明

系统 OpenHarmony
本文介绍了OpenHarmony系统适配USB声卡的指导说明希望对大家有所帮助。

想了解更多关于开源的内容,请访问:

​51CTO 开源基础软件社区​

​https://ost.51cto.com​

前言

USB声卡是一种外置声卡,不受主机硬件约束可以实现更好的声音品质和更多的功能。使用USB接口支持热插拔,方便易用,在生活中被广泛使用。

1、功能描述

OpenHarmony ADM(Audio Driver Model)框架支持USB声卡的插拔识别,支持USB声卡的播放、录音、音量控制和静音功能。

2、构建开关

CONFIG_DRIVERS_HDF_AUDIO_USB
OpenHarmony系统ADM(Audio Driver Model)框架要支持USB声卡首先要打开构建开关:CONFIG_DRIVERS_HDF_AUDIO_USB=y

3、功能配置

(1)配置文件:device_info.hcs 添加USB声卡节点

文件路径:
vendor/isoftstone/yangfan-j/hdf_config/khdf/device_info/。

hostName = "audio_host";
priority = 110;...
device_audio :: device {...
device_usb :: deviceNode {
policy = 2;
priority = 60;
preload = 2;
permission = 0666;
moduleName = "HDF_AUDIO";
}
}...
}

(2)配置文件:audio_config.hcs 添加USB声卡服务信息

...
controller_0x120c1002 :: card_controller {
match_attr = "hdf_audio_driver";
serviceName = "hdf_audio_codec_usb_dev";
}
}
}

4、应用样例

audio_sample_render是用来测试录音功能的工具,audio_sample_capture是用来测试播放功能的工具,audio_sample_event是用来检测USB插拔事件上报的工具。这两个工具可以通过编译得到,编译命令如下:
./build.sh --product-name *** -T audio_sample_render -T audio_sample_capture -T audio_sample_event。

cd /data/
./audio_sample_render YoungForYou.wav
./audio_sample_capture 123.wav

5、功能验证

使用hdc工具推送audio_sample_render和audio_sample_event和wav音频文件到开发板data目录下。

hdc file send E:\audio_sample_render /data
hdc file send E:\audio_sample_event /data
hdc file send E:\xxx.wav /data

(1)USB声卡类设备插拔检测

进入shell端口进行一次USB设备插入、拔出流程。

cd /data/
chmod +x audio_sample_event
./audio_sample_event

(2)USB声卡类设备放音

进入shell端口进行一次完整的播放、停止、退出流程。

cd /data/
chmod +x audio_sample_render
./audio_sample_render YoungForYou.wav
==================== Loading Mode ===================
| 1. Passthrough Loading |
| 2. IPC Loading |
======================================================
Please enter your choice:
2
================= Select Audio Card ==================
1. primary
2. primary1
3. hdmi
4. usb
5. a2dp
======================================================
Please enter your choice:
4
================== Play Render Menu ==================
| 1. Render Start |
| 2. Render Stop |
| 3. Render Resume |
| 4. Render Pause |
| 5. Render SetVolume |
| 6. Render GetGain |
| 7. Render SetMute |
| 8. Render SetAttributes |
| 9. Render SelectScene |
| 10. Render getEXtParams |
| 11. Render getMmapPosition |
| 12.Exit |
======================================================
your choice is:
1
Music channels = 2
Music Rate = 44100 Hz
Music Bit = 16 bit
============= Play Render Mode ==========
| 1. Render non-mmap |
| 2. Render mmap |
========================================
Please enter your choice:
1
Start Successful,Music is playing
================== Play Render Menu ==================
| 1. Render Start |
| 2. Render Stop |
| 3. Render Resume |
| 4. Render Pause |
| 5. Render SetVolume |
| 6. Render GetGain |
| 7. Render SetMute |
| 8. Render SetAttributes |
| 9. Render SelectScene |
| 10. Render getEXtParams |
| 11. Render getMmapPosition |
| 12.Exit |
======================================================
your choice is:
2
Stop Successful
================== Play Render Menu ==================
| 1. Render Start |
| 2. Render Stop |
| 3. Render Resume |
| 4. Render Pause |
| 5. Render SetVolume |
| 6. Render GetGain |
| 7. Render SetMute |
| 8. Render SetAttributes |
| 9. Render SelectScene |
| 10. Render getEXtParams |
| 11. Render getMmapPosition |
| 12.Exit |
======================================================
your choice is:
12

(3)USB声卡类设备录音

进入shell端口进行一次完整的录音、停止、退出流程。

==================== Loading Mode ===================
| 1. Passthrough Loading |
| 2. IPC Loading |
======================================================
Please enter your choice:
2
================= Select Audio Card ==================
1. primary
2. usb
======================================================
Please enter your choice:
2
============== Play Capture select ===========
| 1. Capture Poll |
| 2. Capture Interrupt |
==============================================
Please enter your choice:
1
================== Play Capture Menu ==================
| 1. Capture Start |
| 2. Capture Stop |
| 3. Capture Resume |
| 4. Capture Pause |
| 5. Capture SetVolume |
| 6. Capture SetGain |
| 7. Capture SetMute |
| 8. Capture SetAttributes |
| 9. Capture SelectScene |
| 10. Capture GetExtParams |
| 11. Capture getMmapPosition |
| 12.Exit |
=======================================================
your choice is:
1
============= Play Capture Mode ==========
| 1. Capture non-mmap |
| 2. Capture mmap |
=========================================
Please enter your choice:
1
Start Successful
================== Play Capture Menu ==================
| 1. Capture Start |
| 2. Capture Stop |
| 3. Capture Resume |
| 4. Capture Pause |
| 5. Capture SetVolume |
| 6. Capture SetGain |
| 7. Capture SetMute |
| 8. Capture SetAttributes |
| 9. Capture SelectScene |
| 10. Capture GetExtParams |
| 11. Capture getMmapPosition |
| 12.Exit |
=======================================================
your choice is:
Recording,the audio file size is 512Kb
Recording,the audio file size is 1024Kb
2
Stop Successful
================== Play Capture Menu ==================
| 1. Capture Start |
| 2. Capture Stop |
| 3. Capture Resume |
| 4. Capture Pause |
| 5. Capture SetVolume |
| 6. Capture SetGain |
| 7. Capture SetMute |
| 8. Capture SetAttributes |
| 9. Capture SelectScene |
| 10. Capture GetExtParams |
| 11. Capture getMmapPosition |
| 12.Exit |
=======================================================
your choice is:
12
Record file path:123.wav

总结:

支持USB声卡可以大幅丰富设备的使用场景,可以提高用户体验,本文介绍了OpenHarmony系统适配USB声卡的指导说明希望对大家有所帮助。

想了解更多关于开源的内容,请访问:

​51CTO 开源基础软件社区​

​https://ost.51cto.com​

责任编辑:jianghua 来源: 51CTO 开源基础软件社区
相关推荐

2023-02-07 15:43:13

三方库适配鸿蒙

2022-01-13 10:11:59

鸿蒙HarmonyOS应用

2022-08-17 16:38:46

WLAN接口组件功能

2022-04-18 10:47:55

UI框架鸿蒙操作系统

2023-03-03 21:42:18

鸿蒙

2022-02-08 23:59:12

USB接口串行

2023-04-06 09:10:13

设备移植鸿蒙

2009-06-12 09:07:24

LinuxUSB3.0

2023-08-14 16:24:30

Linux

2010-02-01 18:06:48

Python Edit

2014-08-15 09:41:52

Ubuntu

2011-04-11 13:26:25

Linux驱动

2014-09-16 09:57:56

INotifyProp

2023-09-19 07:27:53

英特尔Wi-Fi 7PCIe

2023-05-22 16:03:14

刷机包鸿蒙

2023-03-10 09:47:45

OpenGL渲染设备移植

2015-02-12 17:23:33

微信SDK

2023-10-26 14:35:04

苹果iOS

2015-01-26 13:16:30

NFCAndroid
点赞
收藏

51CTO技术栈公众号