I need to delete pause in wav file (pause - area with amplitudes<16 and length>N samples). Don't really understand how to work with samples, and how to read sample by sample from file. Below is my code:
#include <stdio.h>
#include <stdlib.h>
#define BUFSIZE 4000
typedef struct header {
char chunk_id[4];
int chunk_size;
char format[4];
char subchunk1_id[4];
int subchunk1_size;
short int audio_format;
short int num_channels;
int sample_rate;
int byte_rate;
short int block_align;
short int bits_per_sample;
short int extra_param_size;
char subchunk2_id[4];
int subchunk2_size;
} header;
typedef struct header* header_p;
void change_file(char * input, int N){
FILE * infile = fopen(input, "rb");
FILE * outfile = fopen("outfile.wav", "wb");
short int inbuff16[BUFSIZE];
header_p meta = (header_p)malloc(sizeof(header));
if (infile) {
fread(meta, 1, sizeof(header), infile);
fwrite(meta, 1, sizeof(header), outfile);
while (!feof(infile)) {
fread(inbuff16, 1, BUFSIZE, infile);
//delete pause here
fwrite(inbuff16, 1, BUFSIZE, outfile);
}
}
if (infile) { fclose(infile); }
if (outfile) { fclose(outfile); }
if (meta) { free(meta); }
}
int main (int argc, char const *argv[]){
char infile[] = "track.wav";
change_file(infile, 20);
return 0;
}