//Time:2016/08/04
#include <stdio.h>
#include <stdlib.h>
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;
}
#include <stdio.h>
#include <stdlib.h>
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;
}