c語言pcm編碼
『壹』 PCM編碼的DSP實現
這是編碼子程序,大概思路是這樣的,還需要自己微調。
#include<stdio.h>
#include<math.h>
int main()
{int dataleft=0X0000;
scanf("%d",&dataleft);
int b=0 ,lj=0,dl=0,dn=0,pcm=0 ;
if(dataleft<=0)
{dataleft=abs(dataleft);
b=1;
};
dataleft>>4;
if(dataleft<=15&&dataleft>=0)
{ lj=1;
dl=000;
dn=(dataleft-0)/lj;}
if(dataleft<=31&dataleft>=16)
{ lj=1;
dl=001;
dn=(dataleft-16)/lj;}
if(dataleft<=63&dataleft>=32)
{lj=2;
dl=010;
dn=(dataleft-32)/lj;}
if(dataleft<=127&dataleft>=64)
{ lj=4;
dl=011;
dn=(dataleft-64)/lj;}
if(dataleft<=255&dataleft>=128)
{ lj=8;
dl=100;
dn=(dataleft-128)/lj;}
if(dataleft<=511&dataleft>=256)
{ lj=16;
dl=101;
dn=(dataleft-256)/lj;}
if(dataleft<=1023&dataleft>=512)
{ lj=32;
dl=110;
dn=(dataleft-512)/lj;}
if(dataleft<=2047&dataleft>=1024)
{lj=64;
dl=111;
dn=(dataleft-1024)/lj;}
b=b<<7;
dl=dl<<3;
pcm=b+dl+dn;
printf("%d",pcm);
}
『貳』 a律pcm編碼用c語言怎麼實現(急!!!!)
http://www.yzmcc.com/soft/sort014/sort016/sort0224/down-184389.html
『叄』 使用C語言實現G.723.1語音編解碼的操作
不太明白你說的啥意思,但是以我的理解,想要實現音視頻編解碼只要可以知道你想要編解碼的文件的數據結構應該一切就可以搞定,通俗點講就是,你怎麼存的,你就怎麼給讀就行
『肆』 題:基於單片機的pcm編碼設計與實現!求論文/資料
其實這個一點都不難。和我們機械的畢業設計簡直不能比。
我的經驗是:集中優勢兵力,各個擊破!
STC89C54 AT89C51
AD:MAX1166 AD7705 LTC1864 ADC0808 ADC0809
存儲用 I2C 24C02之類
很簡單的哇!!!!
至於程序 ,框架搭好後,還不如魚得水?想咋整就咋整。
『伍』 pcm語音編碼和參數編碼相比,哪個的語音質量較好
波形編碼是最簡單也是應用最早的語音編碼方法。最基本的一種就是PCM編碼,如G.711 建議中的A 律或μ 律。APCM、DPCM和ADPCM也屬於波形編碼的范疇,使用這些技術的標准有G.721、G.726、G.727 等。波形編碼具有實施簡單、性能優良的特點,不足是編碼帶寬往往很難再進一步下降。
『陸』 正弦波形用A律PCM間接編碼,用C語言實現
呵呵這個我剛編完,經過老師驗收。給你了,用C++寫的,你稍做修改就行。
#include <iostream>
using namespace std;
int main()
{
const int sect = 8; //number of segement.
const int startingVol[sect+1] = {0,16,32,64,128,256,512,1024,2048};
// the starting value of every segement.
const int quanIntvl[sect] = {1,1,2,4,8,16,32,64};
//quantity interval of every Segments, 1 equeal to 1/2048.
int pcmInd = 0; //pcm code's index.
int pcmCode[sect] = {0,0,0,0,0,0,0,0}; // 8 bit of pcm codes.
int sampleValue = 1270;
int startPoint; //starting point of the segement starting piont
//such as startingVol[startPoint] = 16 or 128 etc.
int finePoint; //the starting point of inner segement code.
int quanValue; // it's used to store the final quantity value.
int quanError; //error caused by quantity.
//the following four variables is used in geting the segmentCode
int low = 0;
int high = sect;
int mid;
int loopInd1 = 0; //loop index to get segment code
int loopInd2 = 0; //loop index to get inner segment codes
//get the first_digit code of polarity
(sampleValue > 0) ? (pcmCode[pcmInd++] = 1) : (pcmCode[pcmInd] = 0);
sampleValue = abs(sampleValue); //make sure the voltage is positive
//get the segment code using modified halve search
while(loopInd1 < 3) //only need 3 loops the segmentCode can be got
{
mid = (low + high)/2;
//after 3 loops, sampeValue falls in startingVol[mid] - startingVol[mid] or
//in startingVol[mid-1] - startingVol[mid]
if(sampleValue < startingVol[mid])
{
pcmCode[pcmInd++] = 0;
high = mid;
startPoint = mid - 1 ;
}
else
{
pcmCode[pcmInd++] = 1;
low = mid;
startPoint = mid;
}
loopInd1++;
}//end while
//get the last four bits codes of pcm
low = 0;
high = 16; //every segment is split into 16 small segments of the same size
while(loopInd2 < 4)
{
mid = (low + high)/2;
//make the compare progress clear using the following two setences.
quanValue = startingVol[startPoint] + mid * quanIntvl[startPoint];
cout<<startingVol[startPoint]<<" + "<<quanIntvl[startPoint]<<" * "<<mid<<" = "
<<quanValue <<" ? "<<sampleValue<<endl;
//make the compare progress clear using the above two setences.
if(sampleValue < startingVol[startPoint] + mid * quanIntvl[startPoint])
{
pcmCode[pcmInd++] = 0;
high = mid;
finePoint = mid -1;
}
else
{
pcmCode[pcmInd++] = 1;
low = mid;
finePoint = mid;
}
loopInd2++;
}//end while
quanValue = startingVol[startPoint] + finePoint * quanIntvl[startPoint];
quanValue += quanIntvl[startPoint] / 2; //final quantity value.
quanError = abs( sampleValue - quanValue); // error of quantity.
cout<<"Final quantity value is: "<<quanValue<<endl;
cout<<"Error of quantity is: "<<quanError<<endl;
cout<<"PCM codes are: ";
for(int i = 0; i < 8; i++)
{
cout<<pcmCode[i]<<" ";
}//end for
cout<<endl;
return 0;
}
還有解碼你要不要?
『柒』 如何用C語言實現PCM編碼
PCM 脈沖編碼調制是Pulse Code Molation的縮寫。脈沖編碼調制是數字通信的編碼方式之一。主要過程是將話音、圖像等模擬信號每隔一定時間進行取樣,使其離散化,同時將抽樣值按分層單位四捨五入取整量化,同時將抽樣值按一組二進制碼來表示抽樣脈沖的幅值。
模擬信號數字化必須經過三個過程,即抽樣、量化和編碼,以實現話音數字化的脈沖編碼調制(PCM,Pulse Coding Molation)技術。
抽樣(Sampling)
抽樣是把模擬信號以其信號帶寬2倍以上的頻率提取樣值,變為在時間軸上離散的抽樣信號的過程。例如,話音信號帶寬被限制在0.3~3.4kHz內,用 8kHz的抽樣頻率(fs),就可獲得能取代原來連續話音信號的抽樣信號。對一個正弦信號進行抽樣獲得的抽樣信號是一個脈沖幅度調制(PAM)信號,如下圖對模擬正弦信號的抽樣所示。對抽樣信號進行檢波和平滑濾波,即可還原出原來的模擬信號。
量化(quantizing)
抽樣信號雖然是時間軸上離散的信號,但仍然是模擬信號,其樣值在一定的取值范圍內,可有無限多個值。顯然,對無限個樣值一一給出數字碼組來對應是不可能的。為了實現以數字碼表示樣值,必須採用「四捨五入」的方法把樣值分級「取整」,使一定取值范圍內的樣值由無限多個值變為有限個值。這一過程稱為量化。
量化後的抽樣信號與量化前的抽樣信號相比較,當然有所失真,且不再是模擬信號。這種量化失真在接收端還原模擬信號時表現為雜訊,並稱為量化雜訊。量化雜訊的大小取決於把樣值分級「取整」的方式,分的級數越多,即量化級差或間隔越小,量化雜訊也越小。
編碼(Coding)
量化後的抽樣信號在一定的取值范圍內僅有有限個可取的樣值,且信號正、負幅度分布的對稱性使正、負樣值的個數相等,正、負向的量化級對稱分布。若將有限個 量化樣值的絕對值從小到大依次排列,並對應地依次賦予一個十進制數字代碼(例如,賦予樣值0的十進制數字代碼為0),在碼前以「+」、「-」號為前綴,來 區分樣值的正、負,則量化後的抽樣信號就轉化為按抽樣時序排列的一串十進制數字碼流,即十進制數字信號。簡單高效的數據系統是二進制碼系統,因此,應將十 進制數字代碼變換成二進制編碼。根據十進制數字代碼的總個數,可以確定所需二進制編碼的位數,即字長。這種把量化的抽樣信號變換成給定字長的二進制碼流的 過程稱為編碼。常式:
#include<iostream>
usingnamespacestd;
intmain()
{
constintsect=8;//numberofsegement.
constintstartingVol[sect+1]={0,16,32,64,128,256,512,1024,2048};
//.
constintquanIntvl[sect]={1,1,2,4,8,16,32,64};
//,1equealto1/2048.
intpcmInd=0;//pcmcode'sindex.
intpcmCode[sect]={0,0,0,0,0,0,0,0};//8bitofpcmcodes.
intsampleValue=1270;
intstartPoint;//
//suchasstartingVol[startPoint]=16or128etc.
intfinePoint;//.
intquanValue;//it'.
intquanError;//errorcausedbyquantity.
//
intlow=0;
inthigh=sect;
intmid;
intloopInd1=0;//loopindextogetsegmentcode
intloopInd2=0;//
//getthefirst_digitcodeofpolarity
(sampleValue>0)?(pcmCode[pcmInd++]=1):(pcmCode[pcmInd]=0);
sampleValue=abs(sampleValue);//makesurethevoltageispositive
//
while(loopInd1<3)//
{
mid=(low+high)/2;
//after3loops,sampeValuefallsinstartingVol[mid]-startingVol[mid]or
//instartingVol[mid-1]-startingVol[mid]
if(sampleValue<startingVol[mid])
{
pcmCode[pcmInd++]=0;
high=mid;
startPoint=mid-1;
}
else
{
pcmCode[pcmInd++]=1;
low=mid;
startPoint=mid;
}
loopInd1++;
}//endwhile
//getthelastfourbitscodesofpcm
low=0;
high=16;//
while(loopInd2<4)
{
mid=(low+high)/2;
//.
quanValue=startingVol[startPoint]+mid*quanIntvl[startPoint];
cout<<startingVol[startPoint]<<"+"<<quanIntvl[startPoint]<<"*"<<mid<<"="
<<quanValue<<"?"<<sampleValue<<endl;
//.
if(sampleValue<startingVol[startPoint]+mid*quanIntvl[startPoint])
{
pcmCode[pcmInd++]=0;
high=mid;
finePoint=mid-1;
}
else
{
pcmCode[pcmInd++]=1;
low=mid;
finePoint=mid;
}
loopInd2++;
}//endwhile
quanValue=startingVol[startPoint]+finePoint*quanIntvl[startPoint];
quanValue+=quanIntvl[startPoint]/2;//finalquantityvalue.
quanError=abs(sampleValue-quanValue);//errorofquantity.
cout<<"Finalquantityvalueis:"<<quanValue<<endl;
cout<<"Errorofquantityis:"<<quanError<<endl;
cout<<"PCMcodesare:";
for(inti=0;i<8;i++)
{
cout<<pcmCode[i]<<"";
}//endfor
cout<<endl;
return0;
}
『捌』 怎麼樣用c語言實現amr解碼為pcm數據
您好,很高興為您解答: 如果你搜一下Nokia或NewLC論壇,會有很多問關於如何錄制amr聲音文件的帖子。首先讓我們了解一下Nokia手機上常用的聲音文件格式,一般的Nokia手機都會支持wav,midi,pcm,amr這幾種文件格式。