C语言PCM16K采样率转为8K,pcm数据采样率8k转为16k

#include using namespace std;

void Resample16K(short* pInAudioData, int nInAudioLen, short* pOutAudioData, int& nOutAudioLen)

{

short* sSampleIn = pInAudioData;

int nFrequency = 0;

while (sSampleIn - pInAudioData < nInAudioLen)

{

memcpy((char*)(pOutAudioData + nFrequency), (char*)sSampleIn, 2);

nFrequency++;

memcpy((char*)(pOutAudioData + nFrequency), (char*)sSampleIn, 2);

nFrequency++;

sSampleIn++;

}

nOutAudioLen = nFrequency*2;

}

int main()

{

char* filename = "sh.pcm";

FILE* fp = fopen(filename, "ab+");

FILE *fp_down = fopen("out.pcm", "wb+");

fseek(fp, 0, SEEK_END);

int buff_len = ftell(fp);

fseek(fp, 0, SEEK_SET);

unsigned char* pData = (unsigned char*)malloc(buff_len);

memset(pData, 0, buff_len);

fread(pData, sizeof(unsigned char), buff_len, fp);

char* pOutData = new char [buff_len*2];

memset(pOutData, 0, buff_len * 2);

int nLOutLen = 0;

Resample16K((short*)pData ,buff_len/2, (short*)pOutData, nLOutLen);

fwrite(pOutData, 1, nLOutLen, fp_down);

fclose(fp);

fclose(fp_down);

return 0;

}

你可能感兴趣的:(C语言PCM16K采样率转为8K,pcm数据采样率8k转为16k)