From e192100ea735fb4f3105468862a978cfbf51938a Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Fri, 12 Dec 2025 04:52:35 +0100 Subject: I'm so happy with this update that it's version 1.4 --- build.bat | 2 +- src/main.odin | 11 ++++----- src/wav/wav.odin | 74 ++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/build.bat b/build.bat index 9bf709e..219d828 100755 --- a/build.bat +++ b/build.bat @@ -1,4 +1,4 @@ @echo off odin build src/ -debug -pdb-name:bin/better-report.pdb -out:bin/better-report.exe && bin\better-report.exe test\ -odin build src/ -o:speed -out:C:/tools/better-report.exe +rem odin build src/ -o:speed -out:C:/tools/better-report.exe rem odin run src/wav \ No newline at end of file diff --git a/src/main.odin b/src/main.odin index 7255dd6..20969c1 100644 --- a/src/main.odin +++ b/src/main.odin @@ -172,6 +172,7 @@ parse_folder :: proc(paths : Directory) -> (Report, bool) { append(&header_build, "File Name") append(&header_build, "Scene") append(&header_build, "Take") + append(&header_build, "Duration") append(&header_build, "Timecode") append(&header_build, "TC FPS") append(&header_build, "User Bits") @@ -244,12 +245,10 @@ parse_folder :: proc(paths : Directory) -> (Report, bool) { row[i] = w.scene case "Take": row[i] = fmt.tprintf("T%03d", w.take) + case "Duration": + row[i] = wav.tprint_duration(w) case "Timecode": - row[i] = fmt.tprintf("%02d:%02d:%02d:%02d", // Timecode - w.timecode.hour, - w.timecode.minute, - w.timecode.second, - int(math.round(w.timecode.frame))) + row[i] = wav.tprint_timecode(w) case "TC FPS": if w.tc_dropframe { // TC FPS row[i] = fmt.tprintf("%.03f DF", w.tc_framerate) @@ -258,7 +257,7 @@ parse_folder :: proc(paths : Directory) -> (Report, bool) { } case "User Bits": if w.ubits != {0,0,0,0,0,0,0,0,} { - row[i] = fmt.tprintf("%d%d%d%d%d%d%d%d", expand_values(w.ubits)) + row[i] = fmt.tprint(expand_values(w.ubits), sep="") } case "Tape": row[i] = w.tape diff --git a/src/wav/wav.odin b/src/wav/wav.odin index 41667b5..af11604 100644 --- a/src/wav/wav.odin +++ b/src/wav/wav.odin @@ -9,12 +9,13 @@ import "xml" Wav :: struct { // Basic data - path : string, - format : Audio_Format, - channels : int, - sample_rate : int, - bit_depth : int, - reported_size : u32, + path : string, + format : Audio_Format, + channels : int, + sample_rate : int, + bit_depth : int, + reported_size : int, + data_size : int, // Internals handle : os.Handle, @@ -22,8 +23,7 @@ Wav :: struct { // Metadata date : Date, channel_names : []string, - samples_since_midnight: u64, - timecode : Timecode, // Derived from samples_since_midnight + samples_since_midnight : int, // Source of timecode tc_framerate : f32, tc_dropframe : bool, ubits : [8]u8, @@ -38,18 +38,12 @@ Audio_Format :: enum { INT = 1, FLOAT = 3, } -Timecode :: struct { - hour : u8, - minute : u8, - second : u8, - frame : f32, -} Date :: struct { year, month, day : int, } VERBOSE :: false -BUFFER_SIZE :: 1<<15 +BUFFER_SIZE :: 1<<18 main :: proc() { // Test @@ -93,7 +87,7 @@ read :: proc(path : string, allocator:=context.allocator) -> (Wav, bool) #option head += 4 // Size - file.reported_size = read_little_endian_u32(temp_buf[head:head+4]) + file.reported_size = int(read_little_endian_u32(temp_buf[head:head+4])) when VERBOSE do fmt.println("Reported size:", file.reported_size) head += 4 @@ -113,10 +107,14 @@ read :: proc(path : string, allocator:=context.allocator) -> (Wav, bool) #option chunk_size := int(read_little_endian_u32(temp_buf[head:head+4])) head += 4 when VERBOSE do fmt.println(chunk_id, chunk_size,"\n-------------------------------------") - data_reached := false next_chunk_start := head + chunk_size - if head+chunk_size < BUFFER_SIZE { + data_reached := false + if chunk_id == "data" { + file.data_size = chunk_size + data_reached = true + } + if next_chunk_start < BUFFER_SIZE && !data_reached { print_data : string data_end := head+chunk_size read_end := min(head+15000, data_end) @@ -150,11 +148,9 @@ read :: proc(path : string, allocator:=context.allocator) -> (Wav, bool) #option head += 2 head = data_end null_chunks = 0 - case "data": - data_reached = true case "\x00\x00\x00\x00": if chunk_size == 0 { - null_chunks += 1 + //null_chunks += 1 } } when VERBOSE do fmt.println(print_data, "\n") @@ -408,15 +404,8 @@ read :: proc(path : string, allocator:=context.allocator) -> (Wav, bool) #option when VERBOSE do fmt.printf("Origination Time: %v\n", string(temp_bext[head:head+8])) head += 8 - file.samples_since_midnight = read_little_endian_u64(temp_bext[head:head+8]) - - seconds_since_midnight := file.samples_since_midnight / u64(file.sample_rate) - file.timecode.hour = u8( seconds_since_midnight / 3600) - file.timecode.minute = u8((seconds_since_midnight % 3600) / 60) - file.timecode.second = u8( seconds_since_midnight % 60) - file.timecode.frame = f32( f64(file.samples_since_midnight % u64(file.sample_rate) ) * f64(file.tc_framerate) / f64(file.sample_rate)) + file.samples_since_midnight = int(read_little_endian_u64(temp_bext[head:head+8])) when VERBOSE do fmt.printf("Time Reference: %v (Samples since midnight, source of timecode)\n", file.samples_since_midnight) - when VERBOSE do fmt.printf(" %v seconds + %v samples\n", seconds_since_midnight, file.samples_since_midnight % u64(file.sample_rate)) head += 8 when VERBOSE do fmt.printf("Version: %v\n", read_little_endian_u16(temp_bext[head:head+2])) @@ -436,6 +425,33 @@ read :: proc(path : string, allocator:=context.allocator) -> (Wav, bool) #option return file, true } +tprint_timecode :: proc(file : Wav) -> string { + return print_timecode(file, allocator=context.temp_allocator) +} +print_timecode :: proc(file : Wav, allocator := context.allocator) -> string { + seconds_since_midnight := file.samples_since_midnight / file.sample_rate + hour := int( seconds_since_midnight / 3600) + minute := int((seconds_since_midnight % 3600) / 60) + second := int( seconds_since_midnight % 60) + frame := int( math.round(f64(file.samples_since_midnight % file.sample_rate ) * f64(file.tc_framerate) / f64(file.sample_rate))) + + return fmt.aprintf("%02d:%02d:%02d:%02d",hour,minute,second,frame, + allocator=allocator) +} + +tprint_duration :: proc(file : Wav) -> string { + return print_duration(file, allocator=context.temp_allocator) +} +print_duration :: proc(file : Wav, allocator := context.allocator) -> string { + samples := file.data_size/file.channels/(file.bit_depth/8) + total_seconds := samples/file.sample_rate + + hours := int( total_seconds / 3600) + minutes := int((total_seconds % 3600) / 60) + seconds := int( total_seconds % 60) + + return fmt.aprintf("%02d:%02d:%02d", hours, minutes, seconds, allocator=allocator) +} read_little_endian_u64 :: proc(x : []u8) -> u64 { -- cgit v1.2.1