#创作者激励#OpenHarmony支持USB接口声卡适配说明 原创 精华

软通动力HOS
发布于 2023-3-17 09:29
浏览
1收藏

【本文正在参加2023年第一期优质创作者激励计划】

前言

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.功能配置

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";
}
}...
}

3.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

5.1 USB声卡类设备插拔检测

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

cd /data/
chmod +x audio_sample_event
./audio_sample_event

5.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

5.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声卡的指导说明希望对大家有所帮助。

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
4
收藏 1
回复
举报
1条回复
按时间正序
/
按时间倒序
红叶亦知秋
红叶亦知秋

很完整的使用说明

回复
2023-3-17 17:48:44
回复
    相关推荐