Layer1的编码更简单,解码端的代码也就比Layer2还简单不少。网络上还有部分老歌是采用Layer2压缩的,但Layer1编码方式的就很难找到了,手头的编码器没有Layer1编码方式,所以这些代码没有经过测试,不详细讲解解码过程了。作为一个完整的MPEG Audio解码器,我还是加入了这部分代码。解码Layer1的源码:
/* * Layer1.java -- MPEG 1.0 Audio Layer I Decoder * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * If you would like to negotiate alternate licensing terms, you may do * so by contacting the author: <http://jmp123.sourceforge.net/> */ package decoder; public final class Layer1 implements ILayer123 { Header header; BitStream bs; Synthesis filter; float[] factor; byte[][] allocation; //[2][32] byte[][] scalefactor; //[2][32] float[][] syin; //[2][32] public Layer1(BitStream bitstream,Header h, Synthesis filter, int wch) { header = h; bs = bitstream; this.filter = filter; allocation = new byte[2][32]; scalefactor = new byte[2][32]; syin = new float[2][32]; factor = Layer2.factor; // ISO/IEC 11172-3 Table 3-B.1. } /* * 逆量化公式: * s'' = (2^nb / (2^nb - 1)) * (s''' + 2^(-nb + 1)) * s' = factor * s'' */ float requantization(int ch, int sb, int nb) { int samplecode = bs.getBits17(nb); int nlevels = (1 << nb); float requ = 2.0f * samplecode / nlevels - 1.0f; //s''' requ += (float)Math.pow(2, 1-nb); requ *= nlevels / (nlevels - 1); //s'' requ *= factor[scalefactor[ch][sb]]; //s' return requ; } public void decodeFrame() throws Exception { int sb, gr, ch, nb; int nch = header.getChannels(); int bound = (header.getMode() == 1) ? ((header.getModeExtension() + 1) * 4) : 32; int slots = header.getMainDataSlots(); bs.append(slots); int maindata_begin = bs.getBytePos(); //1. Bit allocation decoding for (sb = 0; sb < bound; sb++) for (ch = 0; ch < nch; ++ch) { nb = bs.getBits9(4); if (nb == 15) throw new Exception("decodeFrame()->nb=15"); allocation[ch][sb] = (byte)((nb != 0) ? (nb + 1) : 0); } for (sb = bound; sb < 32; sb++) { nb = bs.getBits9(4); if (nb == 15) throw new Exception("decodeFrame()->nb=15"); allocation[0][sb] = (byte)((nb != 0) ? (nb + 1) : 0); } //2. Scalefactor decoding for (sb = 0; sb < 32; sb++) for (ch = 0; ch < nch; ch++) if (allocation[ch][sb] != 0) scalefactor[ch][sb] = (byte)bs.getBits9(6); for (gr = 0; gr < 12; gr++) { //3. Requantization of subband samples for (sb = 0; sb < bound; sb++) for (ch = 0; ch < nch; ch++){ nb = allocation[ch][sb]; if(nb == 0) syin[ch][sb] = 0; else syin[ch][sb] = requantization(ch, sb, nb); } //mode=1(Joint Stereo) for (sb = bound; sb < 32; ++sb) if ((nb = allocation[0][sb]) != 0) for (ch = 0; ch < nch; ++ch) syin[ch][sb] = requantization(ch, sb, nb); else for (ch = 0; ch < nch; ++ch) syin[ch][sb] = 0; //4. Synthesis subband filter for (ch = 0; ch < nch; ch++) filter.synthesisSubBand(syin[ch], ch); } //5. Ancillary bits int discard = slots + maindata_begin - bs.getBytePos(); bs.skipBytes(discard); } }
上一篇:(十六)用JAVA编写MP3解码器——解码Layer2
相关推荐
纯java实现的MP3解码器,装逼使用,面试使用,很好的实现。
java的mp3解码器(非JMF、控制台播放音乐) 用于在你自己的程序中引入,播放MP3文件 运行前先编译---build.bat/build.sh
基于通用可编程GPU的视频编解码器——架构、算法与实现
纯java写的解码器 不含任何jar包
jmp123是一个解码速度很快的纯JAVA的开源的MP3解码器。在2核2.9G CPU上跑,解码速度达到每秒15000帧以上;在4核 CPU上会跑得更快。
C++实现的Mp3解码器
MP3是 ISO/MPEG标准的一部分,ISO/MPEG标准描述了使用高性能感知编码方案的音频压缩,此标准一直在不断更新以满足“质高量小”的追求,现已形成 MPEG Layer 1、Layer 2、Layer 3三个音频编码解码方案。MPEG Layer 3...
好不容易找到的,虽然使用matlab实现,但对理解MP3格式很有帮助!
1、好用的mp3播放器,可以试试 2、mp3解码器
H.264的三大编解码器之一JM最新版,为VC下C工程源码,可直接使用或二次开发。 文件中包含说明文档
许多刚接触mina的朋友,对于mina的编解码器的编写很迷惑.希望这个文档可以帮助朋友们少走弯路。 资源中是一个比较典型的编解码器写法。生成了可执行文件。并对编解码器的代码有详细注释。
Huffman编解码问题——讲解.docx
专用 asf /avi/ai/wpf 解码器 专用 asf /avi/ai/wpf 解码器 专用 asf /avi/ai/wpf 解码器 专用 asf /avi/ai/wpf 解码器 专用 asf /avi/ai/wpf 解码器 专用 asf /avi/ai/wpf 解码器 专用 asf /avi/ai/wpf 解码器 专用...
mp3解码库,千千静听,kugou等mp3播放器使用的解码库
用vc6.0编写的MP3播放器和MP3解码器。 单独将MP3解码器编译成静态链接库lib文件, 然后MP3播放器中再调用lib。 很有参考价值。。。
jmp123 JAVA MP3解码,jmp123 JAVA MP3解码
接轨生活,解码术语——初中语文文学术语的生活化理解方法探究 (1).pdf
该程序是一个非常好的学习MP3 解码器的说明文档,并且他还介绍了MP3编码的原理对于我们理解MP3解码有很好的帮助,是一个不可多得的好文档
Netty 框架学习 —— 编解码器框架(csdn)————程序