MUSIC WOES!!!

My streaming music is getting all screwed up when I change scenes, it starts "stuttering"! I'm testing on iOS 4, using daily build Corona Version 2011.654 (2011.8.2). I did not seem to have this problem when I was using CoronaSDK-2011.591, but I had a different problem on iOS 5 where the streaming music would skip or cut out after 2 seconds, so I read through the forum and saw maybe I should use the latest build. So now the music does not cut out on iOS 5, but I am getting this stuttering problem. HELP! I can't find the answer. Why can't I just stream some simple music here? They are not even big files.

What kind of sound files are you using?

I'm assuming you already did everything described on the Audio Notes page:
http://developer.anscamobile.com/partner/audionotes

Performance tuning is tough. You can help us in two ways.

First, we need a reproducible test case demonstrating the performance problem with a detailed description of what hardware you've tested on and which ones work well and which don't. Also, any specific things that seem to interfere with the audio playback (e.g. OpenFeint) is useful information. (And answer Peach's question about what file formats are you using and did you try changing them to other types, e.g. MP3 to AAC or IMA4 or WAV.)

Second, read this thread, particularly my reply #15:
http://developer.anscamobile.com/forum/2011/04/11/warning-failed-create-audio-sound#comment-60474

Try playing with those values until you get something that works nice. I recommend you start with audio.loadStream(file, {bufferSize=8192, maxQueueBuffers=12, startupBuffers=4, buffersQueuedPerUpdate=2})
because I've been thinking maybe that is the sweet spot.

P.S. Tell me your results because I want the information so I can decide if this change should go into the core.

Hi Guys/Gals thanks for the help!

I may have fixed it, I was playing with it last night and so far today in testing the "stuttering" issue has not appeared today in testing.

The problem was occurring during transition back to the main scene with the menu, after the game was over, I have some intro music there. I was not using the director class or anything, just some transitions and removing display objects.

The music that was getting messed up was an M4A exported from Audacity at a quality of 102, 44100Hz which I read was equivalent to a quality slightly above an MP3 at 128KBS. Anyway, I did the following two things:

1) Re-exported all streaming music as 128KBS MP3, constant bit rate, 44100Hz.
2) Added audioPlayFrequency = 44100 to my config

That was pretty simple and the problem seems to be gone, testing on an iPhone 4 with iOS 4.2.10, haven't tried iOS 5 yet.

But I wonder if I should do those other things as you suggest, with the bufferSize and maxQueueBuffers etc. What do you think?

Thanks again!

If you want to test the parameters I suggested, please do so. But since you cannot reproduce the original problem now, it will be hard to compare.

Please note that we are nearing a release. As the date approaches, the current settings become more permanent and it will be harder to change in the future. So if you do find we need to make changes, the sooner the better.

Guess I am trying those parameters anyway, the problem is BACK! This very well might be related to OpenFeint. I have a button on my main scene that let's a user choose if they want to use OF, I don't just initialize it first go around until the user turns it on. So all day testing today I had not enabled OF, but when I did the problem came back. I'll let you know what I find out with those parameters.

OK, I put in the parameters {bufferSize=8192, maxQueueBuffers=12, startupBuffers=4, buffersQueuedPerUpdate=2} leaving everything else the same (music at 128KBS MP3, constant bit rate, 44100Hz) and it did not solve the problem. So Next step I re-exported the streams at 96KBS, constant bit rate, 22050HZ and I just took out the "audioPlayFrequency=44100Hz" setting in the config, so far the problem is gone even with OF enabled. It seems to me the only way to solve the problem is with the lower quality MP3. Would you have any other suggestions?

Yes, you can try increasing maxQueueBuffers, startupBuffers, or buffersQueuedPerUpdate. (Try changing just one at a time to get a feel at how each changes things.)

maxQueueBuffers is the maximum number of read-ahead buffers (each of size bufferSize). The idea is that when the system is idle, we can read-ahead and fill more buffers in advance. So if a CPU heavy period comes and can't get enough time to read more buffers, we have a reserve pool we can draw from. Be warned, increasing this number eats more memory (each buffer is bufferSize + minor overhead).

startupBuffers is the number of buffers to read ahead before starting play. This must be less than maxQueueBuffers. This is also of the numbers to read-ahead when playback stopped because of starvation (e.g. ran out of read-ahead buffers due to CPU load). Warning, setting this higher means you have more delay between the time you say audio.play() and when you start hearing it play.

buffersQueuedPerUpdate is the number of buffers to read-ahead every update cycle. You can think of an update cycle as once per frame, but it is actually less frequent than that. The update happens on a background thread so the timing is non-deterministic. Increasing this value may mean you spend more time in the audio update pass which means you might have less time to spend doing other things, like drawing or physics.

Wow thanks for that info! That's really good to know! I may play with it a bit using the MP3's that were causing trouble. I might like to use the higher quality encodings, but to be honest I can't really tell the difference using the iPhone speakers definitely, and even on a semi-decent pair of M-Audio desktop monitors. What is your opinion? We're talking background music for a game, I'd like for it to sound good but I don't think it needs to have the fidelity of a performance by the London Symhpony Orchestra. What is a respectable setting for MP3 export in kbps and Hz project rate?

And is a constant bit rate encoding going to be better than a variable bit rate regarding sound or cpu performance?

Thanks for all your help

Have same problem with AAC file (128kB/s). Try all daily builds from 653 to 671. iOS5 and Corona simulator give me the same bad result.

Hey guys,

I am having the exactly same problem with the sound (loadStream)!!

I`ve tried using .mp3 and .aac audio files with 128Kbps encode. But both get me audio stuttering anyway. So I`ll try using .wav right now to see if it change something.

PS: I`ve even tried the @ingemar solution for this on other thread but that did not help solving my problem too.

If someone get news about this subject, please report here as it may be very helpful for all of us at any time.

Regards,
Rodrigo.

If you are running iOS 5, you must use Build 698 or later. There is a bad Apple/OpenAL regression bug in iOS 5.0 we have been struggling to work around.

Rodrigo, if you've found a different bug, we need you to submit a bug report with a simple reproducible test case with all your assets included. You should do this ASAP because we are about to release soon which means we are locking things down now as we speak and will not be able to make any more changes soon.

We also need to know what platforms this is happening on, Mac, Windows, iOS, Android, and which specific devices/hardware and OS versions.

Post the bug number here.

Hi @ewing,

Firstly, thank you very much for the attention.

So I would like to explain you and others that may be having the same audio/sound problems (stuttering) when using the audio.loadStream API.

I`ve been in trouble with that API when trying to play a background sound (37s lenght, .mp3, 128Kbps). So after research the most part of the forum I`ve seen that it was a regression bug of Apple. :\

So after reading so many posts I have tried all the following trying to get the problem solved:

1) Changed the .mp3 file for a .aac file (DID NOT SOLVE);

2) Changed the .aac file for a .wav file (DID NOT SOLVE);

3) Followed all the very helpfull @ingemar member "solution" that he explained on other thread. That speaks about hard-coding the audio.reserveChannels() and declaring which channel to play for each audio file as well. (DID NOT SOLVE);

4) Finally I have followed line-by-line of your beautiful explanation on this thread/post #15 (http://developer.anscamobile.com/forum/2011/04/11/warning-failed-create-audio-sound#comment-60474) and VOILÁ, after setting as you`ve mentioned about the "secret audio API" -> audio.loadStream(file, {bufferSize=8192, maxQueueBuffers=12, startupBuffers=4, buffersQueuedPerUpdate=2}) ALL the audio files using the audio.loadStream API STARTED WORKING BEAUTIFULLY! :-]

So THANK YOU so much for sharing your audio API`s Secret @ewing! It killed the stuttering sound with one right shot! haha

PS.1: I was under daily-build versions (2011.698/699/700) when seeing and resolving this audio`s problem.

PS.2: My tech specs:
Running OS X Lion Version 10.7.2

Model Name: MacBook Pro
Model Identifier: MacBookPro8,1
Processor Name: Intel Core i5
Processor Speed: 2.3 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache (per Core): 256 KB
L3 Cache: 3 MB
Memory: 4 GB

- MacBook Pro (13-inch, Early 2011)

PS.3: @ewing, with your solution I got to be able to use ANY type of audio file as well (I mean .mp3, .aac, .wav).

So I hope it does help other members as well. :)

Cheers,
Rodrigo.

Rodrigo: Would you submit a bug report with us (link at top) with the information you just posted here and the test program with audio files attached? I want to reproduce this problem and then make the parameters you tried the default in Corona if everything continues to work. Please post the bug number here so I can look it up quickly.

By the way, was the stuttering only on Mac, or was it on all devices too?

Hey ewing,

it was stuttering on Mac, xCode Simulator and the iDevices as well.

iDevices tested:

1) iPhone 4 - iOS 5.0.1
2) iPod Touch 4 - iOS 5.0.1
3) iPad - iOS 5.0.1

Regards,
Rodrigo.

Hey ewing,

No Problem! I will.

As soon as I report the BUG I will post here it`s index number.

Cheers,
Rodrigo.

Hi @ewing,

I`ve submitted the BUG info right now.

It has been logged as case #10227

PS: I`ve attached all my assets as audio files as well so it can be easier for you to get into understanding it and I`ve also commented all the code into the menu.lua file as well.

Thank you one more time!

Rodrigo.

views:1875 update:2011/12/3 14:45:35
corona forums © 2003-2011