資源描述:
《視音頻處理技術(shù)二》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、《視音頻處理技術(shù)》實驗報吿學(xué)院班級姓名學(xué)號任課教師《視音頻處理技術(shù)》實驗報告學(xué)號:姓名:班級:實驗2音頻數(shù)據(jù)的處理要求:1、給定一個16KHz的音頻數(shù)據(jù)(一維整數(shù)數(shù)組)A,時間長度為1秒。請對音頻數(shù)據(jù)A進行8KHz的采樣,用量化值q二12進行量化,并進行PCM編碼,并打印輸出前100個采樣的PCM編碼。其中A的定義如下:IntA[160()0];Floatpi=3.1415926535;For(inti=0;i<16000;i++)A[i]=(int)(sin(i/pi)*256)+256;2、以題1中得到的8KHz重采樣
2、的音頻數(shù)據(jù)為基礎(chǔ),進行DPCM編碼,量化閾值q=12,并打印輸出前100個采樣的DPCM編碼。3、以題1中得到的8KHz重采樣的音頻數(shù)據(jù)為基礎(chǔ),使用以下簡化規(guī)則進行的ADPCM編碼,并打印輸出前100個釆樣的ADPCM編碼。ADPCM簡化規(guī)則為:1)當(dāng)前音頻樣本的采值的預(yù)測值S(町等與上一個樣本值的量化編碼值S(n-l).2)如果當(dāng)前值S(n)與預(yù)測值S(n),的差e(n)<5時,量化閾值q=2;3)如果當(dāng)前值S(n)與預(yù)測值S(“的差5<=e(n)<20時,量化閾值q=6;3)如果當(dāng)前值S(n)與預(yù)測值S(Q的差e(n)
3、>二20吋,量化閾值q=12;源代碼:#includc#includevoidcaiyang(){inti,bufl16000];FILE*fout,*fin;if(!(fin=fopen("b.txt,,,V)))printfC'error!can'topentheinfile!");if(!(fout=fopen("c.txt,,,,'wH)))printf("crror!can'topentheoutfilc!");fread(buf,sizeof(int),16000,fi
4、n);for(i=l;i<16000;i+=2){fwritc(&buf[i],sizeof(int),1,fbut);)fclose(fin);fclose(foul);voidpcm_codc()inti,buf[8OOOJ;FILE*fin,*fout;fin=fopen("c.txt","r");fread(buf,sizeof(int),8000,fin);fclose(fin);fout=fopen(',d.txt,,,"w");printf("pcm_code:");for(i=0;i5、){buf[i]=buf[i]/12;printfC'%d”,buf[i]);}printf("");fwritc(buf5sizcof(int),8000,fin);fclose(fout);}voidpcm_code(){inti,temp,pre,buf[8000];FILE*fout,*fin;if(!(fin=fopen(,,c.txt,,,,,r")))printfC'error!can'topentheinfile!");if(!(fout=fopen("dpcm.txt",,,w")))printf
6、("crror!can'topentheoutfilc!");fread(buf,sizeof(int),8000,fin);buf[0]=(buf[0])/12;fwrite(&buf[0],sizeof(int),1,fout);pre=buf[0]*12;for(i=l;i<8000;i++){teinp=buf(i
7、;buf[i]=(buf[i]-pre)/12;pre=(temp/l2)*12;fwrite(&buf[i],sizeof(int),1,fout);}fclose(fin);fclosc(fou
8、t);printf(Hdpcm_code:n);for(i=0;i<100;i++)printf(M%d”,buffi]);}printfC'");}voidadpcm_codc(){inti,temp.pre,buf[8000J;FILEif(!(fin=fopen("c.txt";,r")))printf("error!can'topentheinfilc!");if(!(fout=fopen("dpcm.txt","w")))printfC'error!can'topentheoutfile!")
9、;fread(buf,sizeof(int),8000,fin);if(buf[0]/12<5)buf[0]/=2;elseif(buf[0)/12<20)buf[0)/=6;elsebuf[0]/=12;pre=buf[0]/12;fwrite(&buf[0],sizeof(int),1,fout);