Last active
March 9, 2026 03:23
-
-
Save lee2sman/e18b9bfd7e8c2eeb279ceca76e74a3b5 to your computer and use it in GitHub Desktop.
Native love2d implementation of a sine wave
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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