使用C语言实现采样位16bit到8bit的转换

使用C语言实现采样位16bit到8bit的转换_第1张图片//Time:2016/08/04
#include
#include


int main(void)
{
unsigned char* psTest = (unsigned char*)malloc(4);
int tmp = 0;


FILE* fp = fopen("16bit_music.pcm","rb+");
FILE* fp_out = fopen("8bit_music.pcm","wb+");


while(!feof(fp))
{
short* date16 = NULL; //16位的采样数据
char date8 = 0; //8位的采样数据
unsigned char m_date8 = 0;


fread(psTest,1,4,fp);
date16 = (short*)psTest;
date8 = (*date16) >> 8;
m_date8 = date8 + 128;


fwrite(&m_date8,1,1,fp_out);
date16 = (short*)(psTest + 2);
date8 = (*date16) >> 8;
m_date8 = date8 + 128;


fwrite(&m_date8,1,1,fp_out);
tmp++;
}


free(psTest);
fclose(fp);
fclose(fp_out);
return 0;
}

你可能感兴趣的:(音频的基本处理)