Re: Newbie problems Cocoa, objective-C using CoreAudio C libraries
Re: Newbie problems Cocoa, objective-C using CoreAudio C libraries
- Subject: Re: Newbie problems Cocoa, objective-C using CoreAudio C libraries
- From: "Craig Lewiston" <email@hidden>
- Date: Thu, 23 Oct 2008 19:09:40 -0400
Can you tell me where to grab the SpeakHere code? I'm developing for
desktop, not iPhone, so I don't have access to the SpeakHere example
code on http://developer.apple.com/iphone/ without registering and
having to pay $ (or at least that's what it appears).
On Thu, Oct 23, 2008 at 6:52 PM, Craig Hopson <email@hidden> wrote:
> John,
>
> I haven't taken more than a couple of seconds to look over what you have
> submitted but nothing strikes me as being amiss, so, in the words of one of
> my CS professors long ago... If the problem isn't where you are looking,
> look somewhere else. You should grab a copy of the SpeakHere sample code
> and compare with what you are doing. It is a Cocoa project which plays and
> records audio. It could be that you have not retained the object you are
> trying to access and it has been collected out from under you.
>
> -Craig
>
>
> On Oct 23, 2008, at 4:31 PM, Craig Lewiston wrote:
>
>> It looks like the problem is due to pAqData being an invalid object.
>> I was able to isolate the error by calling
>> AudioFileID testaudiofile = [pAqData mAudioFile];
>> right after declaring pAqData:
>> AQRecorderState *pAqData = (AQRecorderState *) aqData;
>> which returned the same error from before.
>>
>> So, it's clear to me that I have a problem linking the incoming aqData
>> pointer to pAqData. Could someone help me understand what is
>> happening in that line of code? Here is the full header again to the
>> callback function and the first line of its code:
>>
>> ##########
>> static void HandleInputBuffer(
>> void *aqData,
>> AudioQueueRef inAQ,
>> AudioQueueBufferRef inBuffer,
>> const AudioTimeStamp *inStartTime,
>> UInt32 inNumPackets,
>> const AudioStreamPacketDescription *inPacketDesc
>> ) {
>>
>> AQRecorderState *pAqData = (AQRecorderState *) aqData; //
>> 1
>> ##########
>>
>> It seems that my problem stems from not being able to access the
>> AQRecorderState object from within the callback function. If someone
>> could help me figure out how to access that object from within the
>> callback function, I'd greatly appreciate.
>>
>> Thanks again,
>> Craig
>>
>>
>> On Thu, Oct 23, 2008 at 5:16 PM, Craig Lewiston <email@hidden>
>> wrote:
>>>
>>> Thanks John. After playing around some more, I found that my code
>>> executes, and that the callback gets called the first time, but that
>>> it then fails at:
>>>
>>> AudioFileWritePackets (
>>> [pAqData mAudioFile],
>>> false,
>>> inBuffer->mAudioDataByteSize,
>>> inPacketDesc,
>>> [pAqData mCurrentPacket],
>>> &inNumPackets,
>>> inBuffer->mAudioData)
>>>
>>> When I load it into gdb manually, I get the following error msg in gdb:
>>>
>>> Program received signal EXC_BAD_ACCESS, Could not access memory.
>>> Reason: KERN_PROTECTION_FAILURE at address: 0x00000002
>>> [Switching to process 22761 thread 0x4403]
>>> 0xfffeff20 in objc_msgSend_rtp ()
>>>
>>>
>>> I'm guessing that this error is due to the way that I am referencing
>>> one or more of the variables in the AudioFileWritePackets() call. The
>>> complete callback function is posted below. As you can see, I am
>>> using the accessor methods I created, such as [pAqData mAudioFile] and
>>> [pAqData mCurrentPacket]. However, I am still using the following
>>> conventions: inBuffer->mAudioDataByteSize, inBuffer->mAudioData to
>>> access the buffer being passed into the callback function. Is this
>>> the source of my problem? Is this the correct way to address those
>>> buffers?
>>>
>>> Thanks again in advance,
>>> Craig.
>>>
>>>
>>> ###########
>>> static void HandleInputBuffer(
>>> void *aqData,
>>> AudioQueueRef inAQ,
>>> AudioQueueBufferRef inBuffer,
>>> const AudioTimeStamp *inStartTime,
>>> UInt32 inNumPackets,
>>> const AudioStreamPacketDescription *inPacketDesc
>>> ) {
>>>
>>> AQRecorderState *pAqData = (AQRecorderState *) aqData; //
>>> 1
>>>
>>> if (inNumPackets == 0 && ([pAqData DataFormatmBytesPerPacket] != 0)) {
>>> inNumPackets = inBuffer->mAudioDataByteSize / [pAqData
>>> DataFormatmBytesPerPacket];
>>> }
>>> NSLog(@"CALLBACK");
>>> if (AudioFileWritePackets (
>>> [pAqData mAudioFile],
>>> false,
>>> inBuffer->mAudioDataByteSize,
>>> inPacketDesc,
>>> [pAqData mCurrentPacket],
>>> &inNumPackets,
>>> inBuffer->mAudioData) == noErr) {
>>> [pAqData addToCurrentPacket:inNumPackets]; // 4
>>> }
>>> if ([pAqData mIsRunning] == 0) {
>>> return;
>>> }
>>>
>>> AudioQueueEnqueueBuffer ([pAqData mQueue], inBuffer, 0, NULL);
>>> }
>>>
>>> On Thu, Oct 23, 2008 at 4:50 PM, John Zorko <email@hidden> wrote:
>>>>
>>>> Craig,
>>>> I'm a n00b as well, but i've got code working -- streaming / playing,
>>>> not
>>>> recording, though. Anyway, I used an ObjC class successfully instead of
>>>> the
>>>> struct. If you post some code where the problem happens, maybe I can
>>>> help?
>>>>
>>>> On Oct 23, 2008, at 12:41 PM, Craig Lewiston wrote:
>>>>
>>>> I'm a newbie to Cocoa and CoreAudio, and have been trying to get the
>>>> AudioQueue Record Audio example working in a Cocoa app for a few days:
>>>>
>>>> http://developer.apple.com/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/AQRecord/chapter_3_section_1.html
>>>>
>>>> I have been somewhat successful, but not completely, and I think the
>>>> reason is due to my lack of understanding of how to use C libraries
>>>> within an Cocoa/Objective-C application. I have a few basic questions
>>>> I was hoping to get answered:
>>>>
>>>>
>>>> 1. In the tutorial, the first step calls for creating a custom
>>>> structure to manage the state of the audio queue. This is done in C
>>>> with:
>>>> struct AQRecorderState {}
>>>>
>>>> I initially approached this by creating a class,
>>>> @interface AQRecorderState : NSObject {}
>>>>
>>>> I then wrote all the accessor methods necessary to implement the the
>>>> class within the rest of the tutorial code. I was able to get my code
>>>> to compile, but my program kept crashing while inside the callback
>>>> function HandleInputBuffer(){}, specifically when executing
>>>> AudioFileWritePackets (). I am now wondering if it is necessary to
>>>> define a class like I did, or if it's possible to just define the
>>>> structure in C, and use C commands to refer to the structure within my
>>>> Obj-C code. For those of you that have used Audio Queue and
>>>> Cocoa/Obj-C, how do you implement this -- as a C structure or an Obj-C
>>>> class?
>>>>
>>>>
>>>> 2. Trouble with callback functions. I have been declaring my callback
>>>> function, static void HandleInputBuffer(){}, in the header file for my
>>>> application, after the @end interface declarative. Is there a proper
>>>> place/way to declare C callback functions in Objective-C files?
>>>>
>>>>
>>>> 3. Finally, are there any working Cocoa examples implementing
>>>> AudioQueue? I am really only looking to see how these details I
>>>> mentioned above (structs, callbacks) are handled in Objective-C.
>>>>
>>>>
>>>> Thanks in advance,
>>>> Craig
>>>> _______________________________________________
>>>> Do not post admin requests to the list. They will be ignored.
>>>> Coreaudio-api mailing list (email@hidden)
>>>> Help/Unsubscribe/Update your Subscription:
>>>>
>>>> This email sent to email@hidden
>>>>
>>>>
>>>> Regards,
>>>> John
>>>> Falling You - exploring the beauty of voice and sound
>>>> http://www.fallingyou.com
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Coreaudio-api mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>>
>> This email sent to email@hidden
>>
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden