Program works with .wave file.
The code below is a part of program that finds "data" subchunk. It writes all necessary chunks to the output file and then finds "data"
(copyes next 4 bytes into char comp_dataID[4];
and compares it with const char dataID[4] = "data";
):
while(1) /* finding "data"*/ {
fread(comp_dataID, 4, 1, input);
if ( memcmp(comp_dataID, dataID, 4) == 0 ) {
printf(">>> \"data\" found!\n");
fwrite(&comp_dataID, 1, 4, output);
break;
}
else {
fseek(input, -3, SEEK_CUR);
}
}
There can be many extentional subchunks before the "data", so I want to optimize the program:
- If the next 4 bytes contain "...." then copy next 4 bytes. (skips 3 unnecessary operations)
- If "...d" then
fseek(input, -1, SEEK_CUR);
/* set pionter before "d" */ and then copy the next 4 bytes. - If "..da" then
fseek(input, -2, SEEK_CUR);
/* set pionter before "d" */ and then copy the next 4 bytes. - If ".dat" then
fseek(input, -3, SEEK_CUR);
/* set pionter before "d" */ and then copy the next 4 bytes.
The problem is that I don't understand how to compare "...d" and "data". I.e. how to find out if char comp_dataID[4];
containd "...d" or "..da" or ".dat".
The question: Is there any function that does this (that returns number of characters that were matched: 0 in case of "....", 1 in case of "...d" and so on.)?
...or I shall use for()
cycle ti find "d", then to find "a" and then "t". And according to the rezults, set pionter before "d" in order to copy the next 4 bytes ("data").
PS After this char[4] the next 4 bytes are the size of all samples (it is used in program)