
??想了解更多關于開源的內容,請訪問:??
??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??