Created
November 29, 2016 15:59
-
-
Save Jon-Schneider/8b7c53d27a7a13346a643dac9c19d34f to your computer and use it in GitHub Desktop.
C Wav Header Struct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// WAV header spec information: | |
//https://web.archive.org/web/20140327141505/https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ | |
//http://www.topherlee.com/software/pcm-tut-wavformat.html | |
typedef struct wav_header { | |
// RIFF Header | |
char riff_header[4]; // Contains "RIFF" | |
int wav_size; // Size of the wav portion of the file, which follows the first 8 bytes. File size - 8 | |
char wave_header[4]; // Contains "WAVE" | |
// Format Header | |
char fmt_header[4]; // Contains "fmt " (includes trailing space) | |
int fmt_chunk_size; // Should be 16 for PCM | |
short audio_format; // Should be 1 for PCM. 3 for IEEE Float | |
short num_channels; | |
int sample_rate; | |
int byte_rate; // Number of bytes per second. sample_rate * num_channels * Bytes Per Sample | |
short sample_alignment; // num_channels * Bytes Per Sample | |
short bit_depth; // Number of bits per sample | |
// Data | |
char data_header[4]; // Contains "data" | |
int data_bytes; // Number of bytes in data. Number of samples * num_channels * sample byte size | |
// uint8_t bytes[]; // Remainder of wave file is bytes | |
} wav_header; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Kasslim You're spot on. I've come a long way since I wrote this. This was written for OSX/iOS where ints are guaranteed to be 32 bit and wouldn't necessarily work with other platforms or compilers.