hi - I built a music theory app. One of the modules plays audio of different musical scales, one octave up and one octave back down. I’m wondering if my code is the best way to do this. I find the playback is quite uneven. Specifially it sort of ‘limps’, with alternate notes sounding slightly longer. Here’s the gist of my code. This code is triggered when a user taps a button (the “hearButton”) to play the scale.
hearButtonListener = function(event)
--code omitted ...
local up = true
local i = 1
local channelCounter = 1
local iterations = (#scaleData.soundArray * 2) - 1
local areWeDone = function(event)
--Listener on the play button is removed during playback. This code puts it back when the scale is over
end -- end of inner function areWeDone
local playSounds = function(event)
if up == true then
audio.play(scaleData.soundArray[i],{channel = channelCounter,
onComplete = areWeDone})
i = i + 1
if i == #scaleData.soundArray then up = false end
elseif up == false then
audio.play(scaleData.soundArray[i],{channel = channelCounter,
onComplete = areWeDone} )
i = i - 1
end
channelCounter = channelCounter + 1
end -- end of inner function playSounds
scaleData.theTimer = timer.performWithDelay(250,playSounds,iterations)
scaleData.timerTable[scaleData.timerIndex] = scaleData.theTimer
scaleData.timerIndex = scaleData.timerIndex + 1
end
end