Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

[BUG] Audio clipped on iOS4.1

Upgrading to iOS4.1 has caused audio played in createSound() to be clipped.

  • occurs whether the app is built with 1.4.1.1 or 1.5
  • occurs on both devices and simulators running 4.1
  • doesn't occur in simulator targeting 3.2, or a device running 4.1
  • use reports that no other apps are suffering from clipped audio after the upgrade

Sample test.js and two small mp3s which reproduce it available at

http://ichi2.net/repro.zip

— asked October 18th 2010 by Damien Elmes
  • audio
  • bug
  • iphone
  • sound
0 Comments

2 Answers

  • Accepted Answer

    The delay is about 135 ms in the simulator for the files you provided. I know it is a clumsy fix but it may be close enough to help.

    
    function queueSound() {
        if (!l.length) {
            return;
        }
        var fname = l.pop();
        var snd = Ti.Media.createSound({url: fname});
    
        listen(snd, "complete", function (e)  {
          setTimeout(function() {
            if (snd) {
                snd.release();
            }
            snd = null;
            queueSound();
          }, 135);
    
    
               });
        listen(snd, "error", function ()  {
                   alert("Error Playing Sound");
                   if (snd) {
                       snd.release();
                   }
                   snd = null;
                   queueSound();
               });
               snd.play();
    }
    
    — answered October 18th 2010 by John McKnight
    permalink
    0 Comments
  • I did some testing with your project and I can duplicate what you are seeing. I looked in the XCode project that was generated and did some debugging there and it looks like the problem may be iOS itself. I know it isn't much of an answer, more of a confirmation of an issue.

    What I did in your test code was use setTimeout to add a time delay before the sound object was released and the next item was queued. I based the pause on the duration of the file that was being played and it isn't necessary at all when the clip is longer than a second or two.

    — answered October 18th 2010 by John McKnight
    permalink
    1 Comment
    • Interesting - I tried commenting out the release, but didn't think to try delaying the next audio. Unfortunately it's not a great solution in this case, as the app is playing a series of successive tones to create Chinese phrases, and it sounds stilted if there's a delay between the different tones.

      — commented October 18th 2010 by Damien Elmes
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.