Core Audio

88 views
Skip to first unread message

John McKerrell

unread,
Mar 16, 2011, 12:45:32 PM3/16/11
to nsmanc...@googlegroups.com
Hi All

I've been having an issue getting something working with Core Audio. I've tried the mailing list and the forum to no avail so wondering if anyone here can help. Rather than paste the whole email in I'll link to the forum posting and Gist and hopefully someone will be able to help. Basically I'm trying to play some packets of encoded PCM data but it's not working.


Thanks

John

Linan Wang

unread,
Mar 16, 2011, 4:14:46 PM3/16/11
to nsmanc...@googlegroups.com
hi john,
i worked on core audio about two years ago and don't remember all the details, but where is your aq_callback? seems you forgot to paste it in the gist. it appears to me you put what should be in the aq_callback into the body: AudioQueueEnqueueBuffer should be called in the aq_callback function, which is only called on demand by the core audio framework.

--
You received this message because you are subscribed to the Google Groups "NSManchester - Cocoa Developers Meetup" group.
To post to this group, send email to nsmanc...@googlegroups.com.
To unsubscribe from this group, send email to nsmanchester...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nsmanchester?hl=en.



--
Best regards

Linan Wang

John McKerrell

unread,
Mar 17, 2011, 6:55:31 AM3/17/11
to nsmanc...@googlegroups.com
Hi

I thought you were able to queue stuff up outside of aq_callback and then if the queue ran out aq_callback would then be called? I do have an aq_callback but currently it's just logging a message to say it has been called, which is never occurring. Does this sound right or have I missed something?

(Thanks for being the first person on the internet to actually respond though!)

John

Linan Wang

unread,
Mar 17, 2011, 7:21:31 AM3/17/11
to nsmanc...@googlegroups.com
hi, 
to validate your thought, you could just check the result of ln 25:
s = AudioQueueEnqueueBuffer(self.aq, aq_buffer, 0, NULL);
i guess s would be <-6000 because AudioQueueStart is actually an async call involving hardware setup, 
the audioqueue is not really ready immediately after the AudioQueueStart call.
hope my memory doesn't fail me :)

John McKerrell

unread,
Mar 17, 2011, 9:32:26 AM3/17/11
to nsmanc...@googlegroups.com
Hm... it seems to be giving me 0. Though a bit odd is the fact that I commented out the code that does the queuing and my aq_callback still didn't get called, which I guess suggest something's not right? I did notice that I wasn't starting an AVSession so I've now done that but it's still not working. My code has ended up in rather a mess after trying various different options.

Linan Wang

unread,
Mar 17, 2011, 9:46:59 AM3/17/11
to nsmanc...@googlegroups.com
just re-checked your codes. why you gave mBytesPerPacket, mFramesPerPacket, mBytesPerFrame, etc. to 0? in my memory these needs to be setup according to your data and audio format. you fed core audio these 0s, and core audio believes no buffer needed and thus never call aq_callback to request data. make sense?

John McKerrell

unread,
Mar 17, 2011, 10:00:24 AM3/17/11
to nsmanc...@googlegroups.com
Hm.. that's a good point, yeah I may have to revisit that. If you have any suggestions for what values should go in there going by the description that I'm getting for the audio that would be appreciated but I'll probably need to leave it for a bit before I can really start tweaking it.

John McKerrell

unread,
Mar 18, 2011, 4:46:08 PM3/18/11
to nsmanc...@googlegroups.com
Hmm... I had a look and I'm trying to come up with the right values. Going by the numbers of 4 bits per channel and 1 channel I'm expecting half a byte per sample, but I don't see how I would actually specify that. I've gone with 656 bytes per packet as that's what I seem to be getting....

So then I remembered that I read that IMA4 gives 4:1 compression, and also that on this web page it mentioned 2 bytes per packet:


So I just tried the following but it's failing, as far as I can see this should at least "compute", but it's giving me a fmt? error:

        AudioStreamBasicDescription asbd;

        asbd.mSampleRate = 8000;

        asbd.mFormatID = kAudioFormatAppleIMA4;

        asbd.mFormatFlags = 0;//kLinearPCMFormatFlagIsSignedInteger; 

        asbd.mBytesPerPacket = 656;

        asbd.mFramesPerPacket = 328

        asbd.mBytesPerFrame = 2;

        asbd.mChannelsPerFrame = 1;

        asbd.mBitsPerChannel = 16;

        asbd.mReserved = 0;


The numbers appear correct to me but then I don't really know what I'm doing, any suggestions appreciated :-)


John

Linan Wang

unread,
Mar 18, 2011, 5:16:10 PM3/18/11
to nsmanc...@googlegroups.com
i don't know where you get these numbers. they don't look right to me.
you probably also need to read this to know the definition of sample rate, sample/frame, packet, channel, etc: http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/CoreAudioGlossary/Glossary/core_audio_glossary.html#//apple_ref/doc/uid/TP40004453-CH210-SW1

John McKerrell

unread,
Mar 19, 2011, 6:19:50 AM3/19/11
to nsmanc...@googlegroups.com
Ok, had a bit more of a play this morning, realised that I may be using the wrong mFormatID as I came across the following in the documentation: 

kAudioFormatDVIIntelIMA
DVI/Intel IMA ADPCM - ACM code 17 (17 matches the ASF "Audio Media Type")

I'm a little bit confused by the fact that the ASF "Audio Media Type" gives bitsPerSample of 4. By my understanding of frame from the glossary a frame contains one sample per-channel, so in this a frame should contain one 4 bit sample, bytesPerFrame can't be half a byte. I guessed that this needed to be post-decompression which would come out to 2 bytes (if IMA is 4:1). So my current description is:

        AudioStreamBasicDescription asbd;

        asbd.mSampleRate = 8000;

        asbd.mFormatID = kAudioFormatDVIIntelIMA;

        asbd.mFormatFlags = 0;//kLinearPCMFormatFlagIsSignedInteger; 

        asbd.mBytesPerPacket = 2;

        asbd.mFramesPerPacket = 1

        asbd.mBytesPerFrame = 2;

        asbd.mChannelsPerFrame = 1;

        asbd.mBitsPerChannel = 16;

        asbd.mReserved = 0;


If I try that it's not giving an error and is giving me audio but it's clearly wrong, just noise. Any further suggestions? If not I may submit a TSI to Apple, might as well use them as they're there.

John

John McKerrell

unread,
Mar 22, 2011, 7:17:34 AM3/22/11
to nsmanc...@googlegroups.com
Actually it looks like I might have got this working, I'm still experimenting with bytes per packet and frames per packet but I'm getting audio out using values such as these:

        AudioStreamBasicDescription asbd;

        asbd.mSampleRate = 8000;

        asbd.mFormatID = kAudioFormatDVIIntelIMA;

        asbd.mFormatFlags = 0;//kLinearPCMFormatFlagIsSignedInteger; 

        asbd.mBytesPerPacket = 656;

        asbd.mFramesPerPacket = 328

        asbd.mBytesPerFrame = 2;

        asbd.mChannelsPerFrame = 1;

        asbd.mBitsPerChannel = 16;

        asbd.mReserved = 0;


It's still not quite there but I've got other work I need to get done now so will have to put this down for a bit.


John

Reply all
Reply to author
Forward
0 new messages