我正在编写一个用于编辑 Wav 音频文件的 C 程序。我已将所有文件数据加载到一个无符号整数值数组 (UINT16_T) 中。
现在,我想减少文件的体积。我认为减少单个值的值(一定百分比)就足够了。但如果我这样做,我会得到一个带有噪音的音频文件(我想我理解称为“静态”或“点击噪音”)
为什么?哪个是正确的程序?
谢谢你!
这是受影响的一段代码:
FILE* fp;
FILE* fp2;
/*Size of my file*/
#define BUFFER_SIZE 28242852
/*Array with file data*/
unsigned char *buffer;
/*Array used for converting two bytes in an unsigned int*/
unsigned char uintBytes[2];
/*The unsigned int obtained*/
uint16_t * conv;
/*The new value calculated*/
uint16_t nuovoValore;
/*Array used for the reverse conversion, form UINT to bytes*/
unsigned char* nuovoValArray;
for(i=44; i<BUFFER_SIZE;i++){
if(i%2==0){
/*I read 2 bytes form the array and "convert" it in an unsigned int*/
uintBytes[0]=buffer[i];
uintBytes[1]=buffer[i+1];
conv=(uint16_t *) &uintBytes[0];
/*Calculate the new value (-30%) to write in the new file*/
nuovoValore= *conv - ((float)*conv*30/100);
if(nuovoValore<0) nuovoValore=0;
nuovoValArray=malloc(2);
memset(nuovoValArray,'\0',2);
nuovoValArray=(unsigned char*)&nuovoValore;
/*Write the two bytes of the new file*/
fwrite(&nuovoValArray[0], 1, 1, fp2);
fwrite(&nuovoValArray[1], 1, 1, fp2);
}
}