Hello,
I was coding a simple audio clock when I found a strange bug on my iPad Mini.
After calling the “sound” function a certain number of times the system plays all the samples together every subsequent call.
@maurky I tried to load your code and run it, but no luck. The audiodata is causing problems, probably because it’s so big. Can you recreate the problem with a smaller music version or with Codea’s build in music.
If I have understand correctly, you are saying the bug is that multiple sounds play at once? This is normal.
P.S. you are using classes wrong! You need to make an instance of a class, not just call the class. See below my changes:
Say = class()
function Say:init()
self.stime=0
self.ary={}
end
function Say:play(id)
if audiodata[id] ~= nil then
print("Playing ",id)
sound (soundbuffer( audiodata[id].data, FORMAT_MONO16, 22050))
end
end
function Say:update()
if #self.ary == 0 then
return
end
self.stime = self.stime - DeltaTime
if self.stime <= 0 then
local id = table.remove(self.ary, 1)
if audiodata[id] ~= nil then
self:play(id)
self.stime = audiodata[id].len
end
end
end
function Say:talk(ary)
if type(ary) == "table" then
for _, data in pairs(ary) do
table.insert(self.ary, data)
end
else
table.insert(self.ary, ary)
end
end
function setup()
say1 = Say()
say1:talk({'n4','n3','n2','n1','8bit_stab_1'})
end
function draw()
background(40, 40, 50)
say1:update()
end
function touched ()
local id = math.random(4)
say1:play("n"..id)
end