| void die(const char *format, ...) __attribute__ ((format (printf, 1, 2))); | void die(const char *format, ...) __attribute__ ((format (printf, 1, 2))); | ||||
| // WAV file format: | // WAV file format: | ||||
| // https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ | |||||
| // http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html | |||||
| const char *filename=""; | const char *filename=""; | ||||
| char samplename[64]; | char samplename[64]; | ||||
| int16_t format, channels, bits; | int16_t format, channels, bits; | ||||
| uint32_t rate; | uint32_t rate; | ||||
| uint32_t i, length, padlength=0, arraylen; | uint32_t i, length, padlength=0, arraylen; | ||||
| uint32_t chunkSize; | |||||
| int32_t audio=0; | int32_t audio=0; | ||||
| // read the WAV file's header | // read the WAV file's header | ||||
| for (i=0; i<5; i++) { | for (i=0; i<5; i++) { | ||||
| header[i] = read_uint32(in); | header[i] = read_uint32(in); | ||||
| } | } | ||||
| chunkSize = header[4]; | |||||
| if (header[0] != 0x46464952 || header[2] != 0x45564157 | if (header[0] != 0x46464952 || header[2] != 0x45564157 | ||||
| || header[3] != 0x20746D66 || header[4] != 0x00000010) { | |||||
| || header[3] != 0x20746D66 || !(chunkSize == 16 || chunkSize == 18 || chunkSize == 40)) { | |||||
| die("error in format of file %s", filename); | die("error in format of file %s", filename); | ||||
| } | } | ||||
| if (bits != 16) | if (bits != 16) | ||||
| die("file %s has %d bit format, but only 16 is supported", filename, bits); | die("file %s has %d bit format, but only 16 is supported", filename, bits); | ||||
| // skip past any extra data on the WAVE header (hopefully it doesn't matter?) | |||||
| for (chunkSize -= 16; chunkSize > 0; chunkSize--) { | |||||
| read_uint8(in); | |||||
| } | |||||
| // read the data header, skip non-audio data | // read the data header, skip non-audio data | ||||
| while (1) { | while (1) { | ||||
| header[0] = read_uint32(in); | header[0] = read_uint32(in); |