Last active
November 5, 2015 19:49
-
-
Save josefnpat/a019501522eb76d82607 to your computer and use it in GitHub Desktop.
SourceFromTone function from kyle__
This file contains 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 SourceFromTone(tone_in_hz) | |
local rate = 44100 | |
local samples = math.floor((rate / tone_in_hz) + 0.5) | |
tone_in_hz = rate / samples | |
local data = love.sound.newSoundData(samples, rate) | |
--print(samples, rate, tone_in_hz) | |
for i = 0, samples do | |
local value = (i * math.pi * tone_in_hz) / (rate / 2) | |
--print(value, math.sin(value)) | |
data:setSample(i, math.sin(value)) | |
end | |
local src = love.audio.newSource(data) | |
src:setLooping(true) | |
return src | |
end | |
function love.load() | |
SourceFromTone(440):play() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment