[Qt][Embedded][PXA270]
[Audio Codec][ALSA][alsa-lib][OSS][madplay]
支援Audio Codec: 關於Qt 4.8.6的AudioOutput與Creator XScale PXA270的聲音輸出之兩三事
這篇文章原本預計是在Qt 4.8.6上支援Audio輸出,在Qt 4.8.6上的聲音輸出使用的是ALSA(Advanced Linux Sound Architecture)的user-space library: alsa-lib來操作硬體裝置輸出聲音,然而後來因為缺乏alsa.conf的問題,於是改用回舊版Linux Sound System: OSS(Open Sound System)搭配madplay來操作硬體裝置輸出聲音,以下紀錄在Creator XScale PXA270支援Audio Codec到處踩雷的一些過程,歡迎各位多多指教~
Qt與ALSA
Qt的Audio輸出在multimedia模組內的audio部分(src/multimedia/audio),其中qaudiodevicefactory.cpp可以明顯看出在linux平台上,使用的是ALSA:
#ifndef QT_NO_AUDIO_BACKEND #if defined(Q_OS_WIN) #include "qaudiodeviceinfo_win32_p.h" #include "qaudiooutput_win32_p.h" #include "qaudioinput_win32_p.h" #elif defined(Q_OS_MAC) #include "qaudiodeviceinfo_mac_p.h" #include "qaudiooutput_mac_p.h" #include "qaudioinput_mac_p.h" #elif defined(HAS_ALSA) #include "qaudiodeviceinfo_alsa_p.h" #include "qaudiooutput_alsa_p.h" #include "qaudioinput_alsa_p.h" #elif defined(Q_OS_SYMBIAN) #include "qaudiodeviceinfo_symbian_p.h" #include "qaudiooutput_symbian_p.h" #include "qaudioinput_symbian_p.h" #endif #endif
因此我嘗試下載並交叉編譯alsa-lib-1.1.0:
在讀官方文件後發現原來是gcc版本太舊
Detailed changelog between 1.0.27.2 and 1.0.28 releases: 連結
"Using __sync_synchronize as the default fallback for barriers. This has been available since gcc 4.1"
而我的cross-compiler版本是4.0.2 冏
於是繼續嘗試使用alsa-lib-1.0.27.2再來一次:
最後發現應該是缺乏/usr/share/alsa/alsa.conf (PS: alsa.cnf介紹一、介紹二)
所以才造成無法work
小結: Qt與alsa-lib結合成功,但是alsa環境設定搞不太懂
使用的是madplay,google後發現許多文章也在嵌入式開發板上使用此library
madplay是MPEG Audio Decoder的縮寫 官網在: http://www.underbit.com/products/mad/
這是一個open source的MP3解碼撥放器
使用libid3tag處理MP3資訊、zlib解壓縮、libmad播放狀態機
並且可以透過configure的--with-alsa option來決定是否要使用ALSA(需要alsa-lib)
若沒下option會使用OSS 而在新華範例裡原來預設使用的就是OSS
於是我後來就使用madplay的方式啦~
PS1: OSS使用/dev/dsp來播放聲音,對這個裝置寫入就會撥放
PS2: madplay的限制是當有人開啟/dev/dsp寫入時,第二個再來開會造成前者bad file descriptor,沒有mix的功能
PS3: madplay有一madmix.c沒有試過,但是看起來必須兩首音樂同時撥放
OSS對於只播一首音樂,沒有混音需求者夠用
wget ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.1.0.tar.bz2 tar jxvf alsa-lib-1.1.0.tar.bz2 export QT_ROOT=/home/eos/qt-desktop-opensource-src-4.8.6 CC="arm-unknown-linux-gnu-gcc -O3 -march=armv5te -mtune=xscale -Wa,-mcpu=xscale -Uarm -mapcs -mno-sched-prolog -mabi=apcs-gnu -mno-thumb-interwork -fno-omit-frame-pointer" CXX="arm-unknown-linux-gnu-g++ -O3 -march=armv5te -mtune=xscale -Wa,-mcpu=xscale -Uarm -mapcs -mno-sched-prolog -mabi=apcs-gnu -mno-thumb-interwork -fno-omit-frame-pointer" CPP="arm-unknown-linux-gnu-gcc -E" CXXCPP="arm-unknown-linux-gnu-g++ -E" ./configure --host=arm-linux --prefix=$QT_ROOT/build-pxa270/alsa-lib-1.1.0 make -j8結果一開始編譯就遇到include問題,在google過後發現是缺少#include <sys/stat.h>
parser.c:262: error: 'S_IRUSR' undeclared再加上include後,繼續編譯死在__sync_synchronize undefine問題
在讀官方文件後發現原來是gcc版本太舊
Detailed changelog between 1.0.27.2 and 1.0.28 releases: 連結
"Using __sync_synchronize as the default fallback for barriers. This has been available since gcc 4.1"
而我的cross-compiler版本是4.0.2 冏
於是繼續嘗試使用alsa-lib-1.0.27.2再來一次:
make -j8 wget ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.0.27.2.tar.bz2 tar jxvf alsa-lib-1.0.27.2.tar.bz2 cd alsa-lib-1.0.27.2 export QT_ROOT=/home/eos/qt-desktop-opensource-src-4.8.6 CC="arm-unknown-linux-gnu-gcc -O3 -march=armv5te -mtune=xscale -Wa,-mcpu=xscale -Uarm -mapcs -mno-sched-prolog -mabi=apcs-gnu -mno-thumb-interwork -fno-omit-frame-pointer" CXX="arm-unknown-linux-gnu-g++ -O3 -march=armv5te -mtune=xscale -Wa,-mcpu=xscale -Uarm -mapcs -mno-sched-prolog -mabi=apcs-gnu -mno-thumb-interwork -fno-omit-frame-pointer" CPP="arm-unknown-linux-gnu-gcc -E" CXXCPP="arm-unknown-linux-gnu-g++ -E" ./configure --host=arm-linux --prefix=$QT_ROOT/build-pxa270/alsa-lib-1.0.27.2 make -j8 make install ./configure -embedded arm -xplatform qws/linux-arm-pxa270-g++ -prefix build-pxa270 -release -no-opengl -opensource -verbose -no-glib -no-xrender -no-xrandr -no-xfixes -no-xcursor -no-xinerama -no-xsync -no-xvideo -no-xshape -little-endian -confirm-license -no-rpath -qt-mouse-tslib -multimedia -audio-backend注意看configure輸出,Alsa support部分:
Building on: qws/linux-x86_64-g++ Building for: qws/linux-arm-pxa270-g++ Architecture: arm Host architecture: x86_64 qmake vars .......... cat: .qmake.vars: No such file or directory qmake switches ......... Build .................. libs examples demos docs translations Configuration .......... cross_compile release embedded largefile stl precompile_header exceptions_off minimal-config small-config medium-config large-config full-config no-pkg-config qt3support accessibility shared embedded reduce_exports ipv6 clock-gettime clock-monotonic mremap getaddrinfo ipv6ifname getifaddrs png freetype zlib nis alsa concurrent multimedia audio-backend svg script scripttools declarative release Debug .................. no Qt 3 compatibility ..... yes QtDBus module .......... no QtConcurrent code ...... yes QtGui module ........... yes QtScript module ........ yes QtScriptTools module ... yes QtXmlPatterns module ... no Phonon module .......... no Multimedia module ...... yes SVG module ............. yes WebKit module .......... yes JavaScriptCore JIT ..... no Declarative module ..... yes Declarative debugging ...yes Support for S60 ........ no Symbian DEF files ...... no STL support ............ yes PCH support ............ yes MMX/3DNOW/SSE/SSE2/SSE3. no/no/no/no/no SSSE3/SSE4.1/SSE4.2..... no/no/no AVX..................... no iWMMXt support ......... no NEON support ........... no IPv6 support ........... yes IPv6 ifname support .... yes getaddrinfo support .... yes getifaddrs support ..... yes Accessibility .......... yes NIS support ............ yes CUPS support ........... no Iconv support .......... no Glib support ........... no GStreamer support ...... no PulseAudio support ..... no Large File support ..... yes GIF support ............ plugin TIFF support ........... plugin (qt) JPEG support ........... plugin (qt) PNG support ............ yes (qt) MNG support ............ plugin (qt) zlib support ........... yes Session management ..... no Embedded support ....... arm Freetype2 support ...... auto (yes) Graphics (qt) .......... linuxfb multiscreen Graphics (plugin) ...... Decorations (qt) ....... styled windows default Decorations (plugin) ... Keyboard driver (qt) ... tty Keyboard driver (plugin) .. Mouse driver (qt) ...... pc linuxtp tslib Mouse driver (plugin) .. OpenGL support ......... no OpenVG support ......... no SQLite support ......... plugin (qt) OpenSSL support ........ no Alsa support ........... yes ICD support ............ no libICU support ......... no Use system proxies ..... no這次成功編譯與結合Qt,但是在Qt AudioDevice卻都拿到Null
最後發現應該是缺乏/usr/share/alsa/alsa.conf (PS: alsa.cnf介紹一、介紹二)
所以才造成無法work
小結: Qt與alsa-lib結合成功,但是alsa環境設定搞不太懂
Creator XScale PXA270的聲音輸出
在參考新華提供的MP3Player範例使用的是madplay,google後發現許多文章也在嵌入式開發板上使用此library
madplay是MPEG Audio Decoder的縮寫 官網在: http://www.underbit.com/products/mad/
這是一個open source的MP3解碼撥放器
使用libid3tag處理MP3資訊、zlib解壓縮、libmad播放狀態機
並且可以透過configure的--with-alsa option來決定是否要使用ALSA(需要alsa-lib)
若沒下option會使用OSS 而在新華範例裡原來預設使用的就是OSS
於是我後來就使用madplay的方式啦~
PS1: OSS使用/dev/dsp來播放聲音,對這個裝置寫入就會撥放
PS2: madplay的限制是當有人開啟/dev/dsp寫入時,第二個再來開會造成前者bad file descriptor,沒有mix的功能
PS3: madplay有一madmix.c沒有試過,但是看起來必須兩首音樂同時撥放
結論
Qt與alsa-lib可以一起編譯結合,但是要work的前提是alsa要本來就會work~OSS對於只播一首音樂,沒有混音需求者夠用
留言
張貼留言