Skip to content

Instantly share code, notes, and snippets.

@mebens
Created October 17, 2012 06:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mebens/3904043 to your computer and use it in GitHub Desktop.
Save mebens/3904043 to your computer and use it in GitHub Desktop.
Generate sine wave tones in Love2D
local samples = 100000
local data = love.sound.newSoundData(samples)
local noteChange = 10000
local note = 200
local change = 50
local minimum = 100
for i = 0, samples * 2 - 1 do
if i % noteChange == 0 then
local factor = -2 + math.random(0, 4)
if note <= minimum then factor = 1 end
note = note + change * factor
end
data:setSample(i, math.sin(i % note / note / (math.pi * 2)))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment