
??想了解更多關(guān)于開源的內(nèi)容,請(qǐng)?jiān)L問:??
??51CTO 開源基礎(chǔ)軟件社區(qū)??
??https://ost.51cto.com??
前言
USB聲卡是一種外置聲卡,不受主機(jī)硬件約束可以實(shí)現(xiàn)更好的聲音品質(zhì)和更多的功能。使用USB接口支持熱插拔,方便易用,在生活中被廣泛使用。
1、功能描述
OpenHarmony ADM(Audio Driver Model)框架支持USB聲卡的插拔識(shí)別,支持USB聲卡的播放、錄音、音量控制和靜音功能。
2、構(gòu)建開關(guān)
CONFIG_DRIVERS_HDF_AUDIO_USB
OpenHarmony系統(tǒng)ADM(Audio Driver Model)框架要支持USB聲卡首先要打開構(gòu)建開關(guān):CONFIG_DRIVERS_HDF_AUDIO_USB=y
3、功能配置
(1)配置文件:device_info.hcs 添加USB聲卡節(jié)點(diǎn)
文件路徑:
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聲卡服務(wù)信息
...
controller_0x120c1002 :: card_controller {
match_attr = "hdf_audio_driver";
serviceName = "hdf_audio_codec_usb_dev";
}
}
}
4、應(yīng)用樣例
audio_sample_render是用來測(cè)試錄音功能的工具,audio_sample_capture是用來測(cè)試播放功能的工具,audio_sample_event是用來檢測(cè)USB插拔事件上報(bào)的工具。這兩個(gè)工具可以通過編譯得到,編譯命令如下:
./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、功能驗(yàn)證
使用hdc工具推送audio_sample_render和audio_sample_event和wav音頻文件到開發(fā)板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聲卡類設(shè)備插拔檢測(cè)
進(jìn)入shell端口進(jìn)行一次USB設(shè)備插入、拔出流程。
cd /data/
chmod +x audio_sample_event
./audio_sample_event
(2)USB聲卡類設(shè)備放音
進(jìn)入shell端口進(jìn)行一次完整的播放、停止、退出流程。
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聲卡類設(shè)備錄音
進(jìn)入shell端口進(jìn)行一次完整的錄音、停止、退出流程。
==================== 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
總結(jié):
支持USB聲卡可以大幅豐富設(shè)備的使用場(chǎng)景,可以提高用戶體驗(yàn),本文介紹了OpenHarmony系統(tǒng)適配USB聲卡的指導(dǎo)說明希望對(duì)大家有所幫助。
??想了解更多關(guān)于開源的內(nèi)容,請(qǐng)?jiān)L問:??
??51CTO 開源基礎(chǔ)軟件社區(qū)??
??https://ost.51cto.com??