创建MP3解码器

 - 采用Symbian中MAD(MPEG音频解码库)用法

前段时间我在newlc.com写了为Series 60创建MP3播放器的程序。我收到了许多关于MP3解码并运用在Symbian上的邮件。这里采用Symbian中MAD(MPEG音频解码库)用法来解决问题。

[b]概叙[/b]

因为Symbian 7.0中可以通过MMF在smartphones在播放MP3, 但如果你的手机不支持 MP3解码,或如果你想自己接收解码MP3。这里我将演示如何采用Symbian中的MAD(MPEG音频解码,libmad)用法。

为什么使用MAD呢? 因为它是高品质的MPEG音频解码器,并且它已经在ARM下测试通过(也就是说不同的微型电脑和掌上MP3可以使用它)。

[b]将MAD移植到Symbian[/b]

为了得到MAD来源,将需要以下文件:

[code]+inc
   -D.dat
   -imdct_s.dat
   -qc_table.dat
   -rq_table.dat
   -sf_table.dat
   -bit.h
   -config.h
   -decoder.h
   -fixed.h
   -frame.h
   -global.h
   -huffman.h
   -layer12.h
   -layer3.h
   -mad.h
   -stream.h
   -synth.h
   -timer.h
   -version.h
+src
   -bit.c
   -decoder.c
   -fixed.c
   -frame.c
   -huffman.c
   -layer12.c
   -layer3.c
   -stream.c
   -synth.c
   -timer.c
   -version.c
   -imdct_l_arm.S[/code]

固定静态函数/ 变量为非静态.(变量可以被转换为"静态的const")。

编辑mad.h,,为设备对象和FPM_DEFAULT定义FPM_ARM. 如果你的WINS编译器不支持big inline,需要这样做:
[code]# ifndef__WINS__
inline
#endif[/code]

可能在layer3.c III_decode函数中引起堆栈错误,即在字符串:
[code]mad_fixed_t xr[2][576];[/code]
你可以为变量分配存储器或(在简单程序的情况下)为WINS对象使用窍门,置成静态变量.在真机上它会正常运行的.

imdct_l_arm.S是针对ARMI最佳化的,使用它必须添加它的报头(函数 III_imdct_l) .
[code]# ifndef __WINS__
void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36], unsigned int block_type);
# else
static
void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36], unsigned int block_type)
...[/code]
注意! 优化的 imdct_l_arm 不能在THUMB下编译,所以只是ARMI 对象被使用.

[b]创建MP3解码动态链接库[/b]

使用MP3解码器的最好方法是DLL,你可以编译一次或有效的若干次,没有任何的平台特殊事件。所以使用ETTYPE.为libmad把/epoc32/include/libc加入在MM文件中的SYSTEMINCLUDE。如果想使用优化的III_imdct_l函数,加入到MMP:
[code]#if !defined (WINS)
SOURCE  imdct_l_arm.S
#endif[/code]
同样加入到bld.inf:(所以imdct_l_arm对THUMB编译)
[code]PRJ_PLATFORMS
ARMI WINS[/code]

如果在iii_decode函数中为堆栈错误使用窍门并且在WINS库中没有_chkstk,需要自己添加它(empty void _chkstk()):

为了在程序中使用DLL,添加函数。

你可以使用基于madplay的MP3解码器的主循环:
[list=1]
[*]读文件到缓冲器
[*]MP3结构解码
[*]应用滤波器
[*]合成解码到PCM样本
[*]重新取PCM样本
[/list]

[b]过滤[/b]  大多数的Symbian smartphones不支持立体声播放,所以这里你可以实现单一声音合成。并且可以使用平衡器。

[b]频率[/b]  不需要做没必要的计算,如果所需频率大于当前架框流通频率的一半,在申请滤波器后转换架框选项:
[code]Frame.options |= MAD_OPTION_HALFSAMPLERATE;[/code]

[b]编译器[/b]

   推荐使用 GCC 3 编译这一程序。根据我的测试它比普通的GCC 2.95解码器速度快20%。不要忘记MAD在GNU General Public License version 2下是得到许可的。

希望文章对你能有所帮助,同时欢迎写出注释或提出宝贵意见。

[url=http://newlc.com/IMG/zip/MP3DecodeDLL.zip]下载源码[/url]
16-3-2007 17:01 admin
Creating MP3 Decoder

Adopt MAD (MPEG audio decoder library) to usage with Symbian

Sometime ago I wrote at newlc.com forum that create MP3 player for Series 60 by myself. I receiving a lot of mail with many questions about MP3 decoding and playing on Symbian.

Here you can read about one solution for decoding MP3 with usage of MAD library (it is licensed under GPL).

[b]Introduction[/b]

Since Symbian 7.0s you can play MP3 on some smartphones via MMF, but what if your phone does not support MP3 decoder? Or if you want to receive decoded MP3 by yourself?

I will show you how to adopt MAD (MPEG audio decoder, libmad) for usage with Symbian.

Why MAD? Because it is high-quality MPEG audio decoder, which is already tested under ARM CPU (i.e. different Pocket PC and Palm MP3 players use it).

[b]Porting MAD to Symbian[/b]

Get last MAD sources, you will need next files:
[code]+inc
   -D.dat
   -imdct_s.dat
   -qc_table.dat
   -rq_table.dat
   -sf_table.dat
   -bit.h
   -config.h
   -decoder.h
   -fixed.h
   -frame.h
   -global.h
   -huffman.h
   -layer12.h
   -layer3.h
   -mad.h
   -stream.h
   -synth.h
   -timer.h
   -version.h
+src
   -bit.c
   -decoder.c
   -fixed.c
   -frame.c
   -huffman.c
   -layer12.c
   -layer3.c
   -stream.c
   -synth.c
   -timer.c
   -version.c
   -imdct_l_arm.S[/code]
Fix static functions/variables to non-static (variables can be changed to "static const").

Edit mad.h - change it to define FPM_ARM for device targets and FPM_DEFAULT otherwise.

If your WINS compiler does not support big inline functions just do so:
[code]#ifndef __WINS__
inline
#endif[/code]

There can stack error occures at layer3.c III_decode function - due to string:
[code]mad_fixed_t xr[2][576];[/code]

You can alloc memory for this variable by yourself or (in case of simple application) just use trick for WINS target - make this variable static. On real device it will work correct.

imdct_l_arm.S is optimized for ARMI - to use it you must add its header (function III_imdct_l).
[code]# ifndef __WINS__
void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36], unsigned int block_type);
# else
static
void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36], unsigned int block_type)
...[/code]

Attention! Optimized imdct_l_arm can not be compiled under THUMB, so just ARMI target can be used.

[b]Creating MP3 Decode DLL[/b]

The best way to use MP3 Decoder is DLL - you can compile it once and useful multiple times, there is no any platform specific things. So - use TARGETTYPE dll. Add /epoc32/include/libc to SYSTEMINCLUDE at MMP file - for libmad. If you want to use optimized III_imdct_l function, add to MMP:
[code]#if !defined (WINS)
SOURCE  imdct_l_arm.S
#endif[/code]

Also add to bld.inf (so imdct_l_arm can not be compiled for THUMB):
[code]PRJ_PLATFORMS
ARMI WINS[/code]

If you use trick for stack fault at iii_decode function and you have no _chkstk function at your WINS libraries - add it by yourself (empty void _chkstk()).

To use DLL from your application, add there functions etc.

You can use main cycle of MP3 decoding based on madplay sources:
[list=1]
[*]read file to buffer
[*] decode MP3 frame
[*] apply filter
[*] synthesize decoded frame to PCM samples
[*] resample PCM samples
[/list]

Filter. Most of Symbian smartphones do not allow to play stereo sound, so you can merge sound to mono here. And you can implement equalizer here.

Frequency. Do not make not required calculations - if required frequency is more than half of current frame currency, change frame options after applying filter:
[code]Frame.options |= MAD_OPTION_HALFSAMPLERATE;[/code]
[b]Compilation[/b]

I recommend you use GCC 3 to compile this library. By my tests it is up to 20% faster than usual GCC 2.95 with MP3 decoding.

Do not forget that MAD is licensed under GNU General Public License version 2.

It is created just for test of MAD speed on Series 60 about 1 year ago, so if you want to use it in your software - add additional checks etc.

[b]Conclusion[/b]

I hope, this article help you.

If you have any comments/suggestion - you are welcomed.

【[url=http://newlc.com/Creating-MP3-Decoder.html]原文地址[/url]】

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值