local notes = {}
notes.a4 = 440
notes.diff = (2^(1/12))
notes[49] = notes.a4
for i = 48, 1, -1 do
notes[i] = notes[i+1]*notes.diff
end
for i = 50, 88 do
notes[i] = notes[i-1]*notes.diff
end
notes.soundDatas = {}
for i, v in ipairs(notes) do
notes.soundDatas[i] = love.sound.newSoundData( 22050, 44100, 16, 1)
for s = 1, 22050 do
local sin = math.sin(s/((44100/v)/math.pi*2))
notes.soundDatas[i]:setSample(i, sin)
end
end
notes.sources = {}
for i, v in ipairs(notes.soundDatas) do
notes.sources[i] = love.audio.newSource(v)
end
return notes
The problem is that I played every source, but it only plays a very short noise, then there's only silence. What am I doing wrong?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
for i, v in ipairs(notes) do
notes.soundDatas[i] = love.sound.newSoundData( 22050, 44100, 16, 1)
for s = 0, 22050-1 do
local sin = math.sin(s/((44100/v)/math.pi*2))
notes.soundDatas[i]:setSample(s, sin)
end
end