210703
Hi, a while ago I expressed interest in writing tools to help with .spc music. Well, the first step on that journey is a little program I'm working on called "FlarfBrr".
FlarfBrr is essentially going to be a graphical version of Optiroc's Brr encoder program. The user would drag and drop a wav file into the window, have its loop points automatically read, and then have a straight conversion to Brr based on the loop points.
I've added the drag and drop functionality, and now I'm working on a script to test detecting the loop points. After researching the .wav filetype here's what I've come up with in godot
extends Node
# Function to extract and check loop points
func get_loop_points(wav_path: String):
var file = FileAccess.open(wav_path, FileAccess.READ)
if file == null:
print("Error: Could not open file")
return
var buffer = file.get_buffer(file.get_length()) # Read full file
var smpl_bytes = "smpl".to_utf8_buffer() # Convert string to PackedByteArray
var smpl_index = -1
# Manually search for the 'smpl' bytes in the buffer
for i in range(buffer.size() - smpl_bytes.size()):
if buffer.slice(i, i + smpl_bytes.size()) == smpl_bytes:
smpl_index = i
break
if smpl_index == -1:
print("doesn't loop")
return
# Extract loop start and loop end values (little-endian format)
var loop_start_bytes = buffer.slice(smpl_index + 28, smpl_index + 32)
var loop_end_bytes = buffer.slice(smpl_index + 32, smpl_index + 36)
# Reverse manually and decode to uint32
loop_start_bytes.reverse()
loop_end_bytes.reverse()
var loop_start = loop_start_bytes.decode_u32(0) # Decode from the beginning of the slice
var loop_end = loop_end_bytes.decode_u32(0) # Decode from the beginning of the slice
# If loop start and loop end are the same, there's no loop
if loop_start == loop_end:
print("doesn't loop")
return
# If loop points are divisible by 16, it's compatible
if loop_start % 16 == 0 and loop_end % 16 == 0:
print("loopable")
else:
print("incompatible")
# Usage example
func _ready():
get_loop_points("res://OverdriveGuitar.wav") # Change the path to your WAV file
For some reason, samples that loop are incorrectly labeled as non-looping. Can someone help me rewrite this script to properly get the loop points? (I tried posting this on stack overflow but they didn't like it for some reason. jerks)
FlarfBrr is essentially going to be a graphical version of Optiroc's Brr encoder program. The user would drag and drop a wav file into the window, have its loop points automatically read, and then have a straight conversion to Brr based on the loop points.
I've added the drag and drop functionality, and now I'm working on a script to test detecting the loop points. After researching the .wav filetype here's what I've come up with in godot
extends Node
# Function to extract and check loop points
func get_loop_points(wav_path: String):
var file = FileAccess.open(wav_path, FileAccess.READ)
if file == null:
print("Error: Could not open file")
return
var buffer = file.get_buffer(file.get_length()) # Read full file
var smpl_bytes = "smpl".to_utf8_buffer() # Convert string to PackedByteArray
var smpl_index = -1
# Manually search for the 'smpl' bytes in the buffer
for i in range(buffer.size() - smpl_bytes.size()):
if buffer.slice(i, i + smpl_bytes.size()) == smpl_bytes:
smpl_index = i
break
if smpl_index == -1:
print("doesn't loop")
return
# Extract loop start and loop end values (little-endian format)
var loop_start_bytes = buffer.slice(smpl_index + 28, smpl_index + 32)
var loop_end_bytes = buffer.slice(smpl_index + 32, smpl_index + 36)
# Reverse manually and decode to uint32
loop_start_bytes.reverse()
loop_end_bytes.reverse()
var loop_start = loop_start_bytes.decode_u32(0) # Decode from the beginning of the slice
var loop_end = loop_end_bytes.decode_u32(0) # Decode from the beginning of the slice
# If loop start and loop end are the same, there's no loop
if loop_start == loop_end:
print("doesn't loop")
return
# If loop points are divisible by 16, it's compatible
if loop_start % 16 == 0 and loop_end % 16 == 0:
print("loopable")
else:
print("incompatible")
# Usage example
func _ready():
get_loop_points("res://OverdriveGuitar.wav") # Change the path to your WAV file
For some reason, samples that loop are incorrectly labeled as non-looping. Can someone help me rewrite this script to properly get the loop points? (I tried posting this on stack overflow but they didn't like it for some reason. jerks)