I have a program that manipulates .wav file to be 8bit 8000hz mono. After that I need to strip the headers and do various stuff to the samples.
I'm having trouble with stripping the .wav headers, though. I thought it would just read the file in character by character then resave without the header bytes. Unfortunately the code doesn't do what I expected. I've been working on this for a while, so I'm probably just missing something stupidly simple, but some help would be great.
Given a .wav file:
Code:
RIFF˜WAVEfmt @@data”ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÅÇÇÇÇÉÉÉÑÑÑÑÑÉÇÄ}{zyxwwwxyz{{||}~ÄÅÇÇÑÖÖÖÖÑÑÑÉÇÇÅÄÄÄÄÅÇÇÑÖÜÜáááààààáÜÑÉÇÅ}|{yxwwwwxz{|~ÄÅÇÉÑÑÖÖÖÖÖÜÜÜÜÖÑÇÅÄ~~~}|{zyyxwvuttsrrrrssttuvwxyz}ÅÑáâåéèëëëëëëëêèééééééçåäâàÜÖÑÇÅÄ~}|{yyxwvuutttuvxyz|}ÅÇÉÑÖÖÜÜÖÑÑÑÉÉÅÄ~|{yxwvvuuuvvwwxyz{{zzzz{{|~ÄÅÅÇÇÉÑÜáâäåçéèéééçåãäâââââääãääâàáÜÖÖÑÉÇÅÄ~|{yxwvvuuuuvvwwwxyyzz{{{{{{{||}}~~}||{{{zzyyzz{{|}}}}||{{{|}~ÄÇÉÉÉÑÑÖÖÜàäåéèêëííëêèéçåãääääããããäâàáÜÖÑÉÇÅ~|zyxwvutttssssttuvvwxxyyzyyyz|}~}}{xvsqonnoqsuwy{}ÄÇÉÑÜáááÜÜÜÜÜÖÑÑÖÜÜáàäçëìïóôöõõöóìêåàÖÇ~}~~ÄÉÜàãéèêêêêééçãàÖÅ|yvsqolheca_]ZYWVVVWWXY[^aflszÇâêïöúûü††üûûûûùõôñîêçäáÑÅ|zxwutsrrsuwz~ÇÜâçêìïñïîìëéäáÉÄ}~
into this code:
Code:
void kedit(char *file)
{
int MAX_SAMPLE = 1000000;
int slen;
int i;
char sample[MAX_SAMPLE];
char nsample[MAX_SAMPLE];
char tempfile[175];
FILE *wav;
FILE *outwav;
snprintf(tempfile, 175, "temp%s", file);
wav = fopen(tempfile, "r");
outwav = fopen(file, "w");
slen = 0;
while( (sample[slen] = getc(wav)) != EOF)
{
slen++;
printf("sample%d: %s\n", slen, sample);
}
fclose(wav);
for(i = 12; i < slen; i++)
{
nsample[i-12] = sample[i];
printf("nsample: %s", nsample);
printf(" sample: %s\n", sample);
}
fprintf(outwav, nsample);
fclose(outwav);
return;
}
I get this output:
Code:
sample1: R
sample2: RI
sample3: RIF
sample4: RIFF
sample5: RIFF?
sample6: RIFF?
sample7: RIFF?
sample8: RIFF?
sample9: RIFF?
sample10: RIFF?
~~~~~~all the way to: sample767
nsample: f sample: RIFF?
nsample: fm sample: RIFF?
nsample: fmt sample: RIFF?
nsample: fmt sample: RIFF?
nsample: fmt sample: RIFF?
nsample: fmt sample: RIFF?
nsample: fmt sample: RIFF?
~~~~~~Repeats to 767...
The output should be the .wav file minus the first 12 bytes. What am I doing wrong?