Soundbuffer problem on iPad mini

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.

This simple program can reproduce the problem:

It plays a sample for every ‘touch’ event, if you swipe two fingers for few seconds the bug will be reproduced.

I also tryed to play with the “soundBufferSize” function with no success, same results.

I think there is something wrong with the audio buffer wrapper function in codea, is the “sound” function related to OpenAL library ?

Thank you in advice

@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()




function Say:play(id) 

    if audiodata[id] ~= nil then

        print("Playing ",id)

        sound (soundbuffer( audiodata[id].data, FORMAT_MONO16, 22050))


function Say:update() 
    if #self.ary == 0 then


    self.stime = self.stime - DeltaTime

    if self.stime <= 0 then     

        local id = table.remove(self.ary, 1)

        if audiodata[id] ~= nil then


            self.stime = audiodata[id].len




function Say:talk(ary) 
    if type(ary) == "table" then
        for _, data in pairs(ary) do
            table.insert(self.ary, data)
        table.insert(self.ary, ary)

function setup()

    say1 = Say()



function draw()

    background(40, 40, 50)



function touched ()

    local id = math.random(4)



The bug is: when I touch the screen (with one finger, without moving) I hear all the numbers samples playing together.

This bug happen on iPad Mini only, i tested it on iPad 1, 2 also and it is not reproducible.

The faster way to reproduce the bug is lauching the project on Air Code, swipe on screen for one second and press ?R or Ctrl+R to restart.

Another way to reproduce is:

  1. launch program
  2. put 3 fingers on screen
  3. swipe the fingers fast for 3/5 seconds and release

Now, if you are on iPad Mini and touch the screen you can hear all the numbers playing together with a single call (sound call)

Any ideas?

ps.: Thank you for code fix!

this is normal behavior (I believe) the reason it isn’t happening at the beginning is your talk function plays them in order.

We finally got a clue.
I’ve tested the program inside the xcode, and I found this error repeated:

2014-09-05 12:10:38.441 AClock[2626:60b] OAL Error: +[ALWrapper deleteBuffers:numBuffers:]: Invalid Operation (error code 0x0000a004)
2014-09-05 12:10:38.442 AClock[2626:60b] OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification. Resetting audio session.
2014-09-05 12:10:38.534 AClock[2626:60b] OAL Error: -[OALAudioSession setAudioSessionActive:]: Could not deactivate audio session: Error Domain=NSOSStatusErrorDomain Code=560030580 "The operation couldn??t be completed. (OSStatus error 560030580.)"

It looks like is OpenAL error, tested on my iPad mini (iPad4,4)

Do you think i should open ticket on issue traker?

Sure, if you find an issue, put it on the tracker so Simeon can see it and fix it.

@wrmichael: It seems I reach your same bug on the xcode console, I’ve put it on the tracker, I hope it can help you too:

@zoyt: Sorry for bumping old threads.

Haha. I’m not that picky. It’s just that, in the moderators and my opinions, we prefer threads older than a month not to be bumped.

@zoyt: Lol, I know, but was fun :slight_smile: