Change WAV File In C

317 views Asked by At

I'm trying to change WAV File factor with C. i need to multiple all bytes with the factor i'm getting from the user. i wrote a function that read 2 bytes and return a short int type. but i can get the OUTPUT file be as the OUT file from the Example program i have. Please help ** Attaching Code

void modify_data(unsigned char*buffer, char *name, long filelen, float factor){
short  temp=0;
char byte[2]={0};
FILE *fp=NULL;
int i,big=0;
unsigned int check=0;
char *str=strtok(name,".");

sprintf(name,"%s‫‪_modified‬‬.wav",name);
fp=fopen(name,"wb");
fwrite(buffer,1,44,fp);
for (i=44;i<filelen;i+=2){
    check=0;
    temp= (short)read_short(i,buffer);

    printf("%hu\n",temp);
    /*check=(int)(temp | check);
    check=check*factor;
    printf("%d\n",check);

    //getchar();
*/
    if ((roundf(temp*factor))>= MAX16BIT){
     temp=MAX16BIT;
    printf("True\n");
    } 
    else {  
        if  ((roundf(temp*factor)) <= -1*MAX16BIT) temp=-1*MAX16BIT;
        else temp=(short)round((double)(temp*factor));
    }
    byte[0] = (temp & 0xFF);
        byte[1] = ((temp & 0xFF00)>>8);
    fwrite(byte,1,2,fp);
    temp=0;
    }
fclose(fp);
}
0

There are 0 answers