Skip to content

Instantly share code, notes, and snippets.

@lee2sman
Last active March 9, 2026 03:23
Show Gist options
  • Select an option

  • Save lee2sman/e18b9bfd7e8c2eeb279ceca76e74a3b5 to your computer and use it in GitHub Desktop.

Select an option

Save lee2sman/e18b9bfd7e8c2eeb279ceca76e74a3b5 to your computer and use it in GitHub Desktop.
Native love2d implementation of a sine wave
function love.load()
love.audio.setVolume(0.5) -- Set the global volume
soundData = love.sound.newSoundData(44100, 44100, 16, 1) -- Create a new sound data object
for i = 0, soundData:getSampleCount() - 1 do
local time = i / 44100
local frequency = 440 -- A4 note
local value = math.sin(2 * math.pi * frequency * time) -- Generate sine wave
soundData:setSample(i, value)
end
sound = love.audio.newSource(soundData) -- Create a new audio source
end
function love.keypressed(key)
if key == "space" then
sound:play()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment