ImageVerifierCode 换一换
格式:DOCX , 页数:21 ,大小:19.28KB ,
资源ID:10774940      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10774940.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(ADPCM压缩算法.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

ADPCM压缩算法.docx

1、ADPCM压缩算法ADPCM压缩算法ADPCM(Adaptive Differential Pulse Code Modulation),是一种针对 16bits( 或8bits或者更高) 声音波形数据的一种有损压缩算法,它将声音流中每次采样的 16bit 数据以 4bit 存储,所以压缩比 1:4. 而且压缩/解压缩算法非常简单,所以是一种低空间消耗,高质量高效率声音获得的好途径。保存声音的数据文件后缀名为 .AUD 的大多用ADPCM 压缩。ADPCM 主要是针对连续的波形数据的,保存的是波形的变化情况,以达到描述整个波形的目的,由于它的编码和解码的过程却很简洁,列在后面,相信大家能够看懂

2、。8bits采样的声音人耳是可以勉强接受的,而 16bit 采样的声音可以算是高音质了。ADPCM 算法却可以将每次采样得到的 16bit 数据压缩到 4bit 。需要注意的是,如果要压缩/解压缩得是立体声信号,采样时,声音信号是放在一起的,需要将两个声道分别处理。ADPCM 压缩过程 首先我们认为声音信号都是从零开始的,那么需要初始化两个变量 int index=0,prev_sample=0;下面的循环将依次处理声音数据流,注意其中的 getnextsample() 应该得到一个 16bit 的采样数据,而 outputdata() 可以将计算出来的数据保存起来,程序中用到的 step_t

3、able,index_adjust 附在后面:int index=0,prev_sample:=0;while (还有数据要处理)cur_sample=getnextsample();/ 得到当前的采样数据delta=cur_sample-prev_sample;/ 计算出和上一个的增量if (delta7) code=7;/ 它描述了声音强度的变化量index += index_adjustcode ;/ 根据声音强度调整下次取steptable 的序号if (index88) index=88;prev_sample=cur_sample;outputode(code|sb);/ 加上符号

4、位保存起来ADPCM 解压缩过程 接压缩实际是压缩的一个逆过程,同样其中的 getnextcode() 应该得到一个编码,,而 outputsample() 可以将解码出来的声音信号保存起来。这段代码同样使用了同一个的 setp_table 和 index_adjust() 附在后面:int index=0,cur_sample=0;while (还有数据要处理) code=getnextcode();/ 得到下一个数据if (code & 8) != 0) sb=1 else sb=0;code&=7;/ 将 code 分离为数据和符号delta = (step_tableindex*cod

5、e)/4+step_tableindex/8;/ 后面加的一项是为了减少误差if (sb=1) delta=-delta;cur_sample+=delta; / 计算出当前的波形数据if (cur_sample32767) output_sample(32767);else if (cur_sample-32768) output_sample(-32768);else output_sample(cur_sample);index+=index_adjustcode;if (index88) index=88;附表 int index_adjust8 = -1,-1,-1,-1,2,4,6

6、,8;int step_table89 =7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50,55,60,66,73,80,88,97,107,118,130,143,157,173,190,209,230,253,279,307,337,371, 408,449,494,544,598,658,724,796,876,963,1060,1166,1282,1411,1552,1707,1878,2066, 2272,2499,2749,3024,3327,3660,4026,4428,4871,5358,5894,6484,

7、7132,7845,8630,9493,10442,11487,12635,13899,15289,16818,18500,20350,22385,24623,27086,29794,32767TCPMP原代码赏析/* 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 2 of

8、 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 shou

9、ld have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA* $Id: adpcm.h 271 2005-08-09 08:31:35Z picard $* The Core Pocket Media Player* Copyright (c) 2004-2005 Gabor

10、 Kovacs*/#ifndef _ADPCM_H#define _ADPCM_H#define ADPCM_CLASS FOURCC(A,D,P,C)#define ADPCM_MS_ID FOURCC(A,D,M,S)#define ADPCM_IMA_ID FOURCC(A,D,I,M)#define ADPCM_IMA_QT_ID FOURCC(A,D,I,Q)#define ADPCM_G726_ID FOURCC(G,7,2,6)extern void ADPCM_Init();extern void ADPCM_Done();#endif/* This program is fr

11、ee 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 2 of the License, or* (at your option) any later version.* This program is distributed in the hope that it will be useful,* but WITH

12、OUT 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, write to the Free Software* Foundati

13、on, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA* $Id: adpcm.c 565 2006-01-12 14:11:44Z picard $* The Core Pocket Media Player* Copyright (c) 2004-2005 Gabor Kovacs*/#include ./common/common.h#include adpcm.h#include g726/g72x.htypedef struct state int Predictor; int StepIndex; int St

14、ep; int Sample1; int Sample2; int CoEff1; int CoEff2; int IDelta; state;typedef struct adpcmcodec Codec;buffer Data;int Channel; /IMA_QTint16_t* Buffer;state State2;g726_state G7262; adpcm;static const int IndexTable16 = -1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8,;static const int StepTa

15、ble89 = 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 274

16、9, 3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767;/ AdaptationTable, AdaptCoeff1, and AdaptCoeff2 are from libsndfilestatic const int AdaptationTable = 230, 230, 230, 230, 307, 40

17、9, 512, 614,768, 614, 512, 409, 307, 230, 230, 230;static const int AdaptCoeff1 = 256, 512, 0, 192, 240, 460, 392;static const int AdaptCoeff2 = 0, -256, 0, 64, 0, -208, -232;static _INLINE int IMA_Calc(state* s, int v) int StepIndex; int Predictor; int Diff,Step; Step = StepTables-StepIndex; StepIn

18、dex = s-StepIndex + IndexTablev; if (StepIndex 88) StepIndex = 88; Diff = (2 * (v & 7) + 1) * Step) 3; Predictor = s-Predictor; if (v & 8) Predictor -= Diff; else Predictor += Diff;if (Predictor 32767) Predictor = 32767;else if (Predictor Predictor = Predictor; s-StepIndex = StepIndex; return Predic

19、tor;static _INLINE int MS_Calc(state* s, int v) int Predictor; Predictor = (s-Sample1 * s-CoEff1) + (s-Sample2 * s-CoEff2) 8; Predictor += (v & 0x08) ? v-0x10:v) * s-IDelta;if (Predictor 32767) Predictor = 32767;else if (Predictor Sample2 = s-Sample1; s-Sample1 = Predictor; s-IDelta = (AdaptationTab

20、lev * s-IDelta) 8; if (s-IDelta IDelta = 16; return Predictor;static int Process(adpcm* p, const packet* Packet, const flowstate* State)int i;int Predictor;const uint8_t* In;const uint8_t* InEnd;int16_t* Out = p-Buffer;if (Packet) if (Packet-RefTime = 0) p-Codec.Packet.RefTime = Packet-RefTime; Buff

21、erPack(&p-Data,0); BufferWrite(&p-Data,Packet-Data0,Packet-Length,1024);else p-Codec.Packet.RefTime = TIME_UNKNOWN;if (!BufferRead(&p-Data,&In,p-Codec.In.Format.Format.Audio.BlockAlign) return ERR_NEED_MORE_DATA;InEnd = In + p-Codec.In.Format.Format.Audio.BlockAlign;switch (p-Codec.Node.Class)case A

22、DPCM_G726_ID: g726_state *g1,*g2; g1 = g2 = &p-G7260; if (p-Codec.In.Format.Format.Audio.Channels=2) +g2; switch (p-Codec.In.Format.Format.Audio.Bits) case 2: for (;In 6,g1); Out1 = (int16_t)g726_16_decoder(In0 4,g2); Out2 = (int16_t)g726_16_decoder(In0 2,g1); Out3 = (int16_t)g726_16_decoder(In0,g2)

23、; break; case 3: InEnd -= 2; for (;In 5,g1); Out1 = (int16_t)g726_24_decoder(In0 2,g2); Out2 = (int16_t)g726_24_decoder(In0 7),g1); Out3 = (int16_t)g726_24_decoder(In1 4,g2); Out4 = (int16_t)g726_24_decoder(In1 1,g1); Out5 = (int16_t)g726_24_decoder(In1 6),g2); Out6 = (int16_t)g726_24_decoder(In2 3,

24、g1); Out7 = (int16_t)g726_24_decoder(In2 0,g2); break; case 4: for (;In 4,g1); Out1 = (int16_t)g726_32_decoder(In0,g2); break; case 5: InEnd -= 4; for (;In 3,g1); Out1 = (int16_t)g726_40_decoder(In0 6),g2); Out2 = (int16_t)g726_40_decoder(In1 1,g1); Out3 = (int16_t)g726_40_decoder(In1 4),g2); Out4 = (int16_t)g726_40_decoder(In2 7),g1); Out5 = (int16_t)g726_40_decoder(In3 2,g2); Out6 = (int16_t)g726_40_decoder(In3 5),g1); Out7 = (int16_t)g726_40_decoder(In4 0,g2); break; break;case ADPCM_IMA_QT

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1