文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

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

2024-11-30 17:28

关注

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

​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​

来源:51CTO 开源基础软件社区内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯