跳到主要內容

[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:
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對於只播一首音樂,沒有混音需求者夠用

留言

這個網誌中的熱門文章

Run Android VTS with Android R emulator through WSL

Background Android VTS The Android Vendor Test Suite (VTS) provides extensive new functionality for Android testing and promotes a test-driven development process. Android R emulator Run the latest Android R image from Google CI build artifacts WSL WSL is a collection of components that enables native Linux ELF64 binaries to run on Windows . It contains both user mode and kernel mode components. It is primarily comprised of: User mode session manager service that handles the Linux instance life cycle Pico provider drivers (lxss.sys, lxcore.sys) that emulate a Linux kernel by translating Linux syscalls Pico processes that host the unmodified user mode Linux (e.g. /bin/bash) It is the space between the user mode Linux binaries and the Windows kernel components where the magic happens. By placing unmodified Linux binaries in Pico processes we enable Linux system calls to be directed into the Windows kernel. The lxss.sys and lxcore.sys drivers translate the Linux s...

[Qt][Embedded][PXA270]
Porting Qt 4.8.6 for Creator XScale PXA270

這篇文章介紹這學期我在嵌入式作業系統課程,使用Creator XScale PXA270板子的一些學習筆記與製作final project的一些過程,歡迎各位多多指教~ 背景介紹 Creator XScale PXA270開發版是一塊由 新華電腦(microtime) 公司出品的 模組化XScale/ARM/SoC/FPGA/DSP嵌入式行動通訊發展平台 ,在此課程與final project主要使用的是"Create XScale‐PXA270 子板"與"MTLCD‐0708048 LCD Module",在Create XScale‐PXA270子板上的為Intel(現在已出售給Marvell)的 Xscale系列 PXA270 處理器,基於ARMv5TE架構指令集,在旁附有SDRAM Memory 64MB、Flash Memory 32MB、SD Card Connectors、RJ45 10/100 Base‐T Ethernet Interface、USB 1.1 Device/Host Port各一、AC97 Audio Codec(Line_in、Mic_in、Headphone)、ADC Interface*4、PWM Interface、CMOS Camera Interface、TFT-LCD Interface、GPIO Interface...等;在軟體功能部分,由新華科技提供了GNU GCC cross compiler toolchain(arm-unknown-linux-gnu-gcc 4.0.2)、Uboot 1.1.5、Linux Kernel 2.6.15.3與patch(提供支援子板上的Ethernet、USB Host、TFT‐LCD(Frame buffer、Touch Screen)、AC97‐Codec...等與母板LED、7‐Seg LED、Key Pad...等的device driver)、rootfs,相關的實驗環境設定可以參考 User Guide 。 看到以上這麼多的軟硬體介面,別以為這板子有多強,其實這是 2006 年 ASUS P535 手機使用的規格了,不禁讓人感嘆科技進步之快阿~ 在此附上開發版本尊 Qt 是自由且開放原始碼的跨平台C...

[Android][AOSP][ddmlib][Intelij IDEA][Gradle]搭建Android ddmlib編譯環境

Android ddmlib在AOSP的platform/tools/base的repo內 可以使用以下指令將整個repo的master branch抓回: git clone https://android.googlesource.com/platform/tools/base 取其中的annotations、common、ddmlib 建立Intelij IDEA專案 使用Intelij IDEA開一新的Java Project,GroupId、ArtifictedId、Version隨便,並使用graddle wrapper方式建立專案: GroupId 'com.android.tools.ddms' ArtifictedId = 'ddmlib' Version '1.0-SNAPSHOT' 刪除IDE建立的src資料夾,建立base資料夾,將annotations、common、ddmlib複製進來 參考Android Studio建立的專案,修改build.gradle為: // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { mavenCentral() } } allprojects { repositories { mavenCentral() } } task clean(type: Delete) { delete rootProject.buildDir } 修改settings.gradle,加入annotations、common、ddmlib為include rootProject.name = 'ddmlib' include ':base:annotations' include ':base:common' include ':base:ddmlib' 修改annotations、common、ddmlib內的b...