Use this lightweight library with LÖVE framework to generate WAV file data from love.SoundData.
Below is an example with Lua:
-- main.lua
-- this file will generate a 1 second sine wave and save it to save folder
local lovewav = require("lovewav")
local sample_rate = 44100
local freq = 440
local sound_data = love.sound.newSoundData(sample_rate, sample_rate, 16, 1)
for i = 0, sample_rate - 1 do
local sample = math.sin(math.pi * 2 * freq * i / sample_rate)
sound_data:setSample(i, sample)
end
local wav_data = lovewav(sound_data)
love.filesystem.write("output.wav", wav_data)You can also use the libary with YueScript:
-- main.yue (to be transpiled to main.lua)
-- this file will generate a 1 second sine wave and save it to save folder
import "lovewav"
sample_rate = 44100
freq = 440
sound_data = love.sound.newSoundData sample_rate, sample_rate, 16, 1
for i = 0, sample_rate - 1
sample = math.sin math.pi * 2 * freq * i / sample_rate
sound_data\setSample i, sample
wav_data = lovewav sound_data
love.filesystem.write "output.wav", wav_data