开发者

wav file handling in C

开发者 https://www.devze.com 2023-03-06 08:37 出处:网络
I want to read a wav file & change its bit per sample rate(from 16 to 32). But my program is not copying entire file. Source file is 175KB where as destination file is only 2KB.

I want to read a wav file & change its bit per sample rate(from 16 to 32). But my program is not copying entire file. Source file is 175KB where as destination file is only 2KB. Bits per sample is at 34 bytes from beginning.

My code is:-

#include<stdio.h>
void main()
{
 FILE *fp,*fo;
 char ch,ch1;
 int j=0,s=0,arr[4],k=0;
 long int i=0;
 fp=fopen("msoft.wav","rb");
 fo=fopen("dest.wav","wb");
 while(1)
 {
 i=i+1;
 ch=fgetc(fp);
 if(ch==EOF)break;
 else
  {
    if(i==34)
    {
    while(i<=35)
    {
     ch=f开发者_StackOverflow社区getc(fp);
        arr[j]=ch;
        i++;
        j++;
    }
    for(k=0;k<2;k++)
    printf("\n%d",arr[k]);
     s=arr[1];
     s=(s<<8)+arr[0];
     printf("\n\nS=%d",s);
     s=s*2;
     printf("\n new s=%d",s);
     ch1=s & 255;
     fputc(ch1,fo);
     ch1=s & (255<<8);
     fputc(ch1,fo);
    }
    else
        fputc(ch,fo);
 }
 }
 printf("\nOk");
 getch();
}

Please help.


fgetc returns an int, not a char. You absolutely need to save its return value into an int otherwise there will be no difference between an plain 0 in the file and EOF.

See related question: fgetc does not identify EOF

0

精彩评论

暂无评论...
验证码 换一张
取 消