Skip to content

Instantly share code, notes, and snippets.

@josefnpat
Last active November 5, 2015 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josefnpat/a019501522eb76d82607 to your computer and use it in GitHub Desktop.
Save josefnpat/a019501522eb76d82607 to your computer and use it in GitHub Desktop.
SourceFromTone function from kyle__
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