2019独角兽企业重金招聘Python工程师标准>>>

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 decodingfor (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 decodingfor (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 samplesfor (sb = 0; sb < bound; sb++)for (ch = 0; ch < nch; ch++){nb = allocation[ch][sb];if(nb == 0)syin[ch][sb] = 0;elsesyin[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);elsefor (ch = 0; ch < nch; ++ch)syin[ch][sb] = 0;//4. Synthesis subband filterfor (ch = 0; ch < nch; ch++)filter.synthesisSubBand(syin[ch], ch);}//5. Ancillary bitsint discard = slots + maindata_begin - bs.getBytePos();bs.skipBytes(discard);}
}

上一篇:(十六)用JAVA编写MP3解码器——解码Layer2

下一篇:(十八)用JAVA编写MP3解码器——迷你播放器

【下载地址】http://jmp123.sourceforge.net/

转载于:https://my.oschina.net/darkness/blog/363528

(十七)用JAVA编写MP3解码器——解码Layer1相关推荐

  1. (十八)用JAVA编写MP3解码器——迷你播放器

    2019独角兽企业重金招聘Python工程师标准>>> 1.定义解码一帧的接口   ILayer123 Layer1.Layer2和Layer3这三个类都实现了ILayer123的d ...

  2. 用JAVA编写MP3解码器

    [内容提要] <用JAVA编写MP3解码器>系列文章将对JAVA实现MP3解码的技术细节作介绍,本着开源的精神,文中给出完整的MPEG 1.0/2.0/2.5 Audio Layer I/ ...

  3. 用JAVA编写MP3解码器——GUI

    以下代码是开源(GPL)程序jmp123的一部分. http://blog.csdn.net/ycb1689/article/details/17393135 (一)简单的GUI 在jmp123.ja ...

  4. (附)用JAVA编写MP3解码器——GUI

    2019独角兽企业重金招聘Python工程师标准>>> 以下代码是开源(GPL)程序jmp123的一部分. (一)简单的GUI 在jmp123.jar所在目录为当前目录启动jmp12 ...

  5. java做mp3_用java编写MP3播放器

    展开全部 作业其实还是自己写的好.要用到JMF包啊,到网上下载一个JMF包,照着说明安装上. 以下是我写e68a84e8a2ad62616964757a686964616f31333332643336 ...

  6. Java播放MP3——JLayer

    目录 1 简介 2 下载 3 事件与监听器 4 播放器 4.1  Player播放器 4.2  jlp极简播放器 4.3  jlap简易播放器 4.4  AdvancedPlayer高级播放器 1 简 ...

  7. 使用Java播放MP3或Wav音频

    JavaSound是一个小巧的低层应用程序接口(API),它支持数字音频和乐器数字接口(MIDI)数据的记录和回放.在JDK 1.3.0之前,JavaSound是一个标准的Java扩展API,但从Ja ...

  8. Java 播放MP3

    Java 播放MP3 的六种方法 1 使用官方的解决方案 2 使用第三方解决方案 (jl1.0.jar) 3 使用第三方解决方案 (jmp123.jar) 4 使用自定义解决方案(推荐) 4.1 依赖 ...

  9. java编写布局文件_鸿蒙OS利用JAVA编写的布局实践练习

    鸿蒙OS利用JAVA编写的布局实践练习 鸿蒙OS利用JAVA编写的布局实践练习 目录 JAVA UI框架 利用JAVA代码实现一个简单的布局 利用xml实现上述布局 JAVA UI框架 ??应用的Ab ...

最新文章

  1. AI 不可以作为专利认证发明人,“因为它不是人”
  2. SLinkList(静态链表)
  3. Quartz框架中的Trigger
  4. mysql和sqlserver分页的区别_关于SQLServer和MySQL 查询分页语句区别
  5. 如何在Windows中打开和使用命令提示符
  6. concat特征融合_MSFNet:多重空间融合网络进行实时语义分割(北航和旷视联合提出)...
  7. oracle awr报告生成_分享AWR报告的生成和简单分析方法
  8. C#窗体间的数据传值(转)
  9. 荣耀20/20 Pro相机规格曝光:DxOMark排名或将再次改变
  10. 图神经网络的可解释性
  11. CSS3 Gradient 渐变
  12. 使用腾讯云服务器搭建自己网站应该怎么做
  13. SD卡、TF卡、MMC卡、emmc、sdio扫盲
  14. java异常以及处理
  15. QML入门教程(12): Item介绍
  16. PostgreSQL命令行常用命令psql
  17. 基于docker实现人人影视CVNT虚拟化多开,基于selinum实现自动化点击程序
  18. PAT乙级——1003
  19. 2020主流室内定位技术对比
  20. 九招使用 Telegram必学,使用Telegram 必看实用功能

热门文章

  1. python调用curl_Python3模拟curl发送post请求操作示例
  2. dataguard如何实现切换_ORACLE dataguard 切换
  3. 计算机考试策略,计算机等级考试应试的策略.doc
  4. easyUi reload 重定向URL
  5. 如何获取一个随机数:10 - 99
  6. python自动化常用模块_Python自动化之常用模块
  7. java编写Linux文件共享,ubuntu下用samba实现windows与linux文件共享
  8. int 为什么是2147483647_「2147483647」当int类型超出了[-2147483648,2147483647]会发生什么? - seo实验室...
  9. php根据图片地址获取图片原始高宽,Js获取图片原始宽高的实现代码
  10. mysql的collate_MYSQL中的COLLATE是什么?