package wav import "core:fmt" import "core:math" import "core:strings" import "core:os" Wav :: struct { path : string, handle : os.Handle, buf : []u8, reported_size : u32, bext : string, ixml : string, format : Audio_Format, channels : int, channel_names : []string, sample_rate : int, bit_depth : int, } Audio_Format :: enum { PCM = 1, FLOAT = 3, } BUFFER_SIZE :: 1<<15 main :: proc() { sweden, sweden_ok := read_wav("test/sweden.wav", context.temp_allocator) fmt.printf("\n\nsweden = %#v\n\n", sweden) enok, enok_ok := read_wav("test/ENOKS-BIRHTDAYT02.WAV", context.temp_allocator) fmt.printf("\n\nenok = %#v\n\n", enok) } read_wav :: proc(path : string, allocator:=context.allocator) -> (Wav, bool) { file : Wav file_ok : os.Error file.handle, file_ok = os.open(path) defer os.close(file.handle) assert(file_ok == os.General_Error.None) file.buf = new([BUFFER_SIZE]u8)[:] defer delete(file.buf) os.read(file.handle, file.buf) head : int = 0 // RIFF header fmt.println(string(file.buf[0:4])) if string(file.buf[0:4]) != "RIFF" do return {}, false head += 4 // Size file.reported_size = read_little_endian_u32(file.buf[head:head+4]) fmt.println("Reported size:", file.reported_size) head += 4 // Confirming again that this is a wave file fmt.println(string(file.buf[head:head+4])) if string(file.buf[head:head+4]) != "WAVE" do return {}, false head += 4 fmt.println("\nChunks:\n") // Looping through chunks for _ in 0..