I'm trying to make a program/game able to open any audio file located in the filesystem and playing it in loop. I've had some issues so I simplified the code in order to save the buffer to a new file and compare them
Here is my code (placed inside a function triggered by a button):
var audio = "/filepath/filename.wav"
var file = File.new()
var buffer = file.get_buffer(file.get_len())
var stream = AudioStreamSample.new()
stream.data = buffer
stream.format = 1 # 16 bit
stream.mix_rate = 44100
stream.stereo = true
stream.loop_end = buffer.size()
stream.loop_mode = 1
I'm having these problems:
-Somehow, the new audio file is 44 bytes bigger than the original, and opening it in Audacity reveals a "click" at the beginning that wasn't in the original file, and it's also longer.
-When loading the original file into an audio stream via
$AudioStreamPlayer.stream = stream and playing it, the click sounds, and it doesn't loop.
I need to keep the exact same file size because I'll be working with an audio file that need to be synced, and also the loop has to be clean and stay in time.
I've tried loading the files with the editor import settings and it works perfectly, but I need my program to be able to load external files (also files generated from mic input, etc) during runtime.