Voice Lab
check_wav
int check_wav(FILE *in_file_ptr, int *data_length, int *sample_rate)
{
int header_length;
int size;
char header[MAX_HEADER_LENGTH];
(*sample_rate) = -1;
/* check if the file has a WAVe header */
/* go to beginning of file */
fseek(in_file_ptr,0,SEEK_SET);
fread(&header, sizeof(char), 4, in_file_ptr);
if(strncmp(header, "RIFF", strlen("RIFF")) != 0) {
/* not wave header */
fseek(in_file_ptr,0,0);
return(0);
}
fread(&size, sizeof(char), 4, in_file_ptr);
fread(header, sizeof(char), 4, in_file_ptr);
if(strncmp(header, "WAVE", strlen("WAVE")) != 0) {
/* not wave header */
fseek(in_file_ptr,0,0);
return(0);
}
fread(header, sizeof(char), 4, in_file_ptr);
if(strncmp(header, "fmt ", strlen("fmt ")) != 0) {
/* not wave header */
fseek(in_file_ptr,0,0);
return(0);
}
fread(&size, sizeof(char), 4, in_file_ptr); /* size of wave section chunk (usually 16) */
fread(header, sizeof(char), 2, in_file_ptr); /* Type of WAVE format. */
fread(header, sizeof(char), 2, in_file_ptr); /* mono (0x01) or stereo (0x02). */
fread(&(*sample_rate), sizeof(char), 4, in_file_ptr); /* Sample rate. */
fread(&size, sizeof(char), 4, in_file_ptr); /* Bytes/Second. */
fread(header, sizeof(char), 2, in_file_ptr); /* Block alignment. */
(*data_length) = header[0];
fread(header, sizeof(char), 2, in_file_ptr); /* Bits/Sample. */
printf("Bits per sample: %d\n", header[0]);
fread(header, sizeof(char), 4, in_file_ptr);
if(strncmp(header, "data", strlen("data")) != 0) {
/* not valid wave header */
fseek(in_file_ptr,0,0);
(*sample_rate) = -1;
return(0);
}
fread(&size, sizeof(char), 4, in_file_ptr);
/* wave file found */
header_length = ftell(in_file_ptr);
return(header_length);
}
No comments:
Post a Comment