]> _ Git - colon3wavtool.git/commitdiff
wave header
authorparking_turkeys <roya1060wien@gmail.com>
Fri, 7 Aug 2026 21:34:37 +0000 (17:34 -0400)
committerparking_turkeys <roya1060wien@gmail.com>
Fri, 7 Aug 2026 21:34:37 +0000 (17:34 -0400)
readwave.c
wavtool.h

index 0c6d2cd..691a1d2 100644 (file)
@@ -32,6 +32,72 @@ int readWave(char *filename, int16_t buffer[]) //if buffer is NULL it only retur
                error_msg = "input wave file not good :<";
                goto error;
        };
+       uint32_t riff_length = 0; //length of the rest of the file
+       ReadFile(fp, &riff_length, 4, &bytes_read, NULL);
+       if (bytes_read != 4) {
+               error_msg = "file ended before the 8th byte?? wha";
+               goto error;
+       };
+       //now the WAVE chunk id
+       ReadFile(fp, chunk_id, 4, &bytes_read, NULL);
+       if (strcmp("WAVE", chunk_id)) {
+               error_msg = "not a WAVE file :<";
+               goto error;
+       };
+       //now the 'fmt ' chunk id
+       ReadFile(fp, chunk_id, 4, &bytes_read, NULL);
+       if (strcmp("fmt ", chunk_id)) {
+               error_msg = "fmt chunk not first chunk :(";
+               goto error;
+       };
+       //length
+       uint32_t fmt_length = 0;
+       ReadFile(fp, &fmt_length, 4, &bytes_read, NULL);
+       if (bytes_read != 4) {
+               error_msg = "couldn't read length of 'fmt ' chunk in input wave file";
+               goto error;
+       };
+       //now the format tag
+       uint16_t format_tag = 0;
+       ReadFile(fp, &format_tag, 2, &bytes_read, NULL);
+       if (format_tag != 1) {
+               error_msg = "not the format i like...";
+               goto error;
+       };
+       uint16_t channel_count = 0;
+       ReadFile(fp, &channel_count, 2, &bytes_read, NULL);
+       if (channel_count != 1) {
+               error_msg = "input wave file not mono";
+               goto error;
+       };
+       uint32_t sampling_rate = 0;
+       ReadFile(fp, &sampling_rate, 4, &bytes_read, NULL);
+       if (sampling_rate != SAMPLING_RATE) {
+               error_msg = "incorrect sampling rate (should be 44100)";
+               goto error;
+       };
+       uint8_t boring[6] = {0};
+       ReadFile(fp, boring, 6, &bytes_read, NULL);
+       if (bytes_read != 6) {
+               error_msg = "input file ended unexpectedly in 'fmt ' chunk";
+               goto error;
+       };
+       uint16_t bitsPerSample = 0;
+       ReadFile(fp, &bitsPerSample, 2, &bytes_read, NULL);
+       if (bitsPerSample != 16) {
+               error_msg = "input file has non-16-bit samples";
+               goto error;
+       };
+       ReadFile(fp, &chunk_id, 4, &bytes_read, NULL);
+       if (strcmp(chunk_id, "data")) {
+               error_msg = "input file does not have data chunk right after fmt  chunk";
+               goto error;
+       };
+
+
+
+       
+
 
 
        return 0;
index ab7a293..a56c134 100644 (file)
--- a/wavtool.h
+++ b/wavtool.h
@@ -9,6 +9,8 @@
 #include <stdio.h>
 #include <stdint.h>
 
+#define SAMPLING_RATE 44100
+
 struct riff_chunk {
        char ckID[4];//NOT ZERO TERMINATED
        uint32_t ckSize;