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