Godot Version
4.3
Question
I’m trying to make a simple little program that’ll convert .wav files into the SNES format .brr files making use of OS.execute to run a prewritten command prompt program.
The program is supposed to automatically detect loop points within imported wav files for the purposes of determining whether the loop points are divisible by 16. I tried implementing the loop point reader today, but it kept falsely returning that the audio source does not loop. Can someone tell me how to fix this code?
extends TextureRect
Function to process the dropped file
func _on_file_dropped(paths: PackedStringArray) → void:
var file_path = paths[0]
if file_path.ends_with(“.wav”):
# Load the WAV file as an AudioStreamWAV
var file = FileAccess.open(file_path, FileAccess.READ)
var audio_stream = AudioStreamWAV.new()
audio_stream.data = file.get_buffer(file.get_length())
if audio_stream == null:
print("Failed to load file: ", file_path)
return
# Access loop points (properties of AudioStreamWAV)
var loop_start = audio_stream.loop_begin
var loop_end = audio_stream.loop_end
# Check if the loop points exist
if loop_start == loop_end:
print("doesn't loop")
else:
# Check if the loop points are divisible by 16
if loop_start % 16 == 0 and loop_end % 16 == 0:
print("loopable")
else:
print("incompatible")
else:
print("Not a WAV file: ", file_path)
This function is automatically called when a file is dropped on the TextureRect
func _ready() → void:
# Enable drag-and-drop for the node
get_viewport().files_dropped.connect(_on_file_dropped)