mattgallagher / AudioStreamer

A streaming audio player class (AudioStreamer) for Mac OS X and iPhone.
http://cocoawithlove.com
1.93k stars 553 forks source link

wav playback broken? #15

Open isalkind opened 14 years ago

isalkind commented 14 years ago

With the latest iteration (Mac or iPhone), wav playback terminates with EXC_BAD_ACCESS. The following appears in the debugger console preceding the termination: "Queueing of audio buffer failed. err: ˇˇˇŒ -50"

I have an older version with an AudioStreamer.m dated March 10, 2010 that plays back wav just fine.

I'll search for a resolution as time permits, but streaming audio is not my forte.

isalkind commented 14 years ago

Broke between the Nov 24, 2009 checkpoint and the Mar 29, 2010 checkpoint.

ghassett commented 13 years ago

I am having this exact same problem -- MP3's play, but WAV's cause the app to crash.

I am working through the code in the debugger but cannot yet figure out why AudioQueueEnqueueBuffer returns -50 as an error on line 1372 of AudioStreamer.m.

Anyone have any suggestions? Here's where err comes back as -50:


if (packetsFilled)
{
    err = AudioQueueEnqueueBuffer(audioQueue, fillBuf, packetsFilled, packetDescs);
}
else
{
    err = AudioQueueEnqueueBuffer(audioQueue, fillBuf, 0, NULL);
}

if (err)
{
    [self failWithErrorCode:AS_AUDIO_QUEUE_ENQUEUE_FAILED];
    return;
}
isalkind commented 13 years ago

I did come up with a fix for this problem. If I recall correctly it had something to do with how VBR vs non-VBR streams are handled. Give me a chance to look at my changes and I will post later in the day.

ghassett commented 13 years ago

Wow, thank you so much for your speedy response. Looking forward to the fix. I found a version of AudioStreamer that DOES in fact play WAV files (it's an older version of your code, without your other improvements). I stepped through the code for both and am completely baffled why one works and the other doesn't, because they both appear to be calling into the audio framework in exactly the same way. I really appreciate your help and your work -- thank you.

isalkind commented 13 years ago

I forked the repository and committed my changes. You can find them in the 'isalkind' branch. Only touched the AudioStreamer.h & AudioStreamer.m files. Certain calculations assumed VBR. These changes try to detect when something is non-VBR (CBR) and make calculations appropriately.

Although the changes should work for other non-VBR streams, I have only tested them specifically with wav streams. Your millage may vary.

ghassett commented 13 years ago

Great fix, life is good. Thank you very, very much.

bhavinb commented 13 years ago

Faced the same issue and used fixed version of the streamer provided by isalkind. Wav streaming works great now. Thanks isalkind!!