Skip to main content
Douglas McCarroll
Inspiring
August 4, 2013
Question

Erratic sound clipping on iOS - first part of sound isn't played

  • August 4, 2013
  • 1 reply
  • 2013 views

Hi All,

On my iPhone I'm seeing (actually, hearing) a problem where the beginnings of sounds aren't being played. These are MP3 files that the app has downloaded and saved on the device. They are being loaded and played like this:

        var file:File = new File(url);
        var request:URLRequest = new URLRequest(file.url);
        var context:SoundLoaderContext = new SoundLoaderContext(500, true);
        var sound:Sound = new Sound(request, context);
        sound.addEventListener(IOErrorEvent.IO_ERROR, onSoundLoadError);
        sound.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSoundLoadError);
        var transform:SoundTransform = new SoundTransform(soundVolumeAdjustmentFactor);
        _soundChannel = _sound.play(0, 1, transform);
        _soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);

This is happening in a Flex mobile app. I'm not seeing it on Android, on the desktop AIR simulator, or on my 5th generation iPod Touch - only on my iPhone 4.

The problem is somewhat random/erratic - as to when / which audios / degree of clipping - but is easy to reproduce in my app. I haven't tried creating a sample, bare bones app that demonstrates the problem yet - I'm hoping that one of you will have dealt with this and can provide an easy solution.     I've already put several days into trying to solve this at this point, and have done a lot of googling.

I'm seeing clipping of anything from a fraction of a second up to cases where the first 10 seconds of an audio isn't played. Typically my files range from as short as a fraction of a second to several seconds, but I'm using a longer (12 second) file for testing purposes, which is what allows me to see cases where a full 10 seconds of audio is ignored. This 10-second case only happens in the first file that's played after I start up the app.

The only thing that I've found that helps is to a) create the Sound and SoundTransform, b) play the sound in a loop at zero volume (new SoundTransform(0)), c) wait a while (1 second) using Timer, then d) play the sound again with volume turned up. This improves the situation but doesn't solve it.

  • The problem becomes much more predictable - i.e. less random and erratic. It happens to the same degree to the same files in the sequence of files that I'm playing.
  • The problem decreases, e.g. the maximum clipping that I'm seeing is 3-4 seconds, and it happens in a smaller percentage of the files that I play.

Once I do this, the problem seems to affect specific files more than others. In other words, it consistently impacts certain files but not others, regardless of their position in the sequence of play. The problem-prone and problem-free files look similar to me when I open them in Audacity. Mystery upon mystery.

Any ideas on what is causing this, or how to prevent it? Is this a known bug? Is there an error in my code?

Thanks,

Douglas

This topic has been closed for replies.

1 reply

Douglas McCarroll
Inspiring
August 7, 2013

I've discovered that this 'sound clipping' problem only occurs after I use Microphone.

All I have to do is set a class property to an instance of the mic, like this:

_microphone = Microphone.getMicrophone()

then enable it like this:

_microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, onNewRecordingSampleData)

From then on, even after I remove the event listener, the app mangles audios played as described in the previous post.

Is there something else that I should be doing to disable the mic?

Adobe Employee
August 9, 2013

Hi Douglas,

I am trying to create a sample application using above information  provided on iPhone4(v6.1.3) with AIR SDK availabe at http://www.adobe.com/devnet/air/air-sdk-download.html and unfortunately it could not be reproduce yet. I have attached the zip file at https://www.dropbox.com/s/q41l58vin6h4foh/MicrophoneSound.zip , please have a look on the .as file and let me know if this is not the same case or I have missed something.

Regards,

Nimit

Douglas McCarroll
Inspiring
August 12, 2013

Hi Nimit,

Thanks for responding on this thread. You hadn't added an event listener to the mic, and I only have the problem when the mic is activated by adding an event listener. But I've done a bit of work and 'enhanced' your example a bit, and I'm still not seeing the problem.

At this point we have two options. One is for me to work on creating a minimal case of an app with this problem. This will probably take a few (more) days of my time, but I'm willing to do it.

The other would be for you to download my app. It's open source and publicly available at http://code.google.com/p/languagementor/. It's not a trivial app (10K+ lines of code). I don't know if this would work for you on a practical level - but I'm guessing that you have ways to see what's happening 'under the hood' and you might be able to quickly diagnose why audios aren't playing.

What do you think? If the second option would work for you, you'll find a ReadMe file with setup instructions at the root of the /trunk/languagementor folder, and I can provide you with very specific 'bug repro' steps that you can follow once you have the app on an iPhone 4.

Thanks,

Douglas