資源簡介
IMA ADPCM PCM 編碼和解碼 C語言程序
代碼片段和文件信息
#include?“adpcm.h“
/*?Intel?ADPCM?step?variation?table?*/
static?int?indexTable[16]={
????-1-1-1-12468
????-1-1-1-12468
};
static?int?stepsizeTable[89]={
????78910111213141617
????19212325283134374145
????5055606673808897107118
????130143157173190209230253279307
????337371408449494544598658724796
????87696310601166128214111552170718782066
????2272249927493024332736604026442848715358
????58946484713278458630949310442114871263513899
????152891681818500203502238524623270862979432767
};
void?adpcm_decoder(char*inbuff?char*outbuff?int?len_of_in?struct?adpcm_state?*state?)
{
?int??i=0j=0;
????char?tmp_data;
????struct?adpcm_state?*tmp_state?=state;
????long?step;/*?Quantizer?step?size?*/
????signed?long?predsample;/*?Output?of?ADPCM?predictor?*/
????signed?long?diffq;/*?Dequantized?predicted?difference?*/
????int?index;/*?Index?into?step?size?table?*/
????int?Samp;
????unsigned?char?SampHSampL;
????unsigned?char?inCode;
?
????/*?Restore?previous?values?of?predicted?sample?and?quantizer?step
????size?index
????*/
????predsample?=state->valprev;
????index?=state->index;
?
????for(i=0;i ?{
??tmp_data=inbuff[i/2];??
??if(i%2)
???inCode=(tmp_data&0xf0)>>4;
??else
???inCode=tmp_data?&0x0f;
????
??step?=stepsizeTable[index];
???/*?Inverse?quantize?the?ADPCM?code?into?a?predicted?difference
????using?the?quantizer?step?size
???*/
????
??diffq?=step?>>3;
??if(inCode?&4)
???diffq?+=step;
??if(inCode?&2)
???diffq?+=step?>>1;
??if(inCode?&1)
???diffq?+=step?>>2;
????/*?Fixed?predictor?computes?new?predicted?sample?by?adding?the
????old?predicted?sample?to?predicted?difference
????*/
??if(inCode?&8)
???predsample?-=diffq;
??else
???predsample?+=diffq;
????/*?Check?for?overflow?of?the?new?predicted?sample
????*/
???if(predsample?>32767)
???predsample?=32767;
???else?if(predsample?<-32768)
???predsample?=-32768;
????/*?Find?new?quantizer?stepsize?index?by?adding?the?old?index
????to?a?table?lookup?using?the?ADPCM?code
????*/
???index?+=indexTable[inCode];
????/*?Check?for?overflow?of?the?new?quantizer?step?size?index
????*/
??if(index?<0)
???index?=0;
??if(index?>88)
???index?=88;
????/*?Return?the?new?ADPCM?code?*/
??Samp=predsample;
??if(Samp>=0)
??{
???SampH=Samp/256;
???SampL=Samp-256*SampH;
??}
??else
??{
???Samp=32768+Samp;
???SampH=Samp/256;
???SampL=Samp-256*SampH;
???SampH+=0x80;
??}
??outbuff[j++]=SampL;
??outbuff[j++]=SampH;???
?}
?
?/*?Save?the?predicted?sample?and?quantizer?step?size?index?for
?next?iteration
?*/
?state->valprev?=(short)predsample;
?state->index?=(char)index;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-09-04?12:31??test1\
?????目錄???????????0??2014-09-04?12:24??test1\Debug\
?????文件????????1799??2014-09-04?12:16??test1\Debug\StdAfx.obj
?????文件????????3399??2014-09-04?12:16??test1\Debug\adpcm.obj
?????文件??????163886??2014-09-04?12:24??test1\Debug\test1.exe
?????文件??????182932??2014-09-04?12:24??test1\Debug\test1.ilk
?????文件????????7051??2014-09-04?12:24??test1\Debug\test1.obj
?????文件??????203728??2014-09-04?12:16??test1\Debug\test1.pch
?????文件??????435200??2014-09-04?12:24??test1\Debug\test1.pdb
?????文件???????41984??2014-09-04?12:24??test1\Debug\vc60.idb
?????文件???????53248??2014-09-04?12:24??test1\Debug\vc60.pdb
?????文件????????1202??2014-09-04?12:06??test1\ReadMe.txt
?????文件?????????292??2014-09-04?12:06??test1\StdAfx.cpp
?????文件?????????769??2014-09-04?12:06??test1\StdAfx.h
?????文件????????2756??2014-09-04?12:16??test1\adpcm.c
?????文件?????????366??2014-09-04?12:01??test1\adpcm.h
?????文件????????4175??2014-09-04?12:01??test1\main.c
?????文件????????4019??2014-09-04?12:24??test1\test1.cpp
?????文件????????4658??2014-09-04?12:18??test1\test1.dsp
?????文件?????????533??2014-09-04?12:06??test1\test1.dsw
?????文件???????41984??2014-09-04?12:31??test1\test1.ncb
?????文件???????48640??2014-09-04?12:31??test1\test1.opt
?????文件????????1246??2014-09-04?12:24??test1\test1.plg
評論
共有 條評論