iphone remote io: bad access in recording callback
iphone remote io: bad access in recording callback
- Subject: iphone remote io: bad access in recording callback
- From: Joel Reymont <email@hidden>
- Date: Wed, 11 Feb 2009 13:50:02 +0000
I know this has been reported as a simulator bug but I have a nagging
suspicion that there's something that I'm doing wrong.
My code crashes _every_ time in the simulator and on the second or
third invocation of the callback on the device.
I don't do anything with the data in the callback so I was hoping that
the buffer will be written over and over again. Alas, the code
crashes. Why?
In case it matters, the audio unit and buffer properties are defined
like this:
@property (nonatomic) AudioUnit audioUnit;
@property (nonatomic) AudioBufferList* inputBuffer;
The buffer in this case is 1024 bytes long (512 frames x 16 bits),
inBusNumber is 1, inNumberFrames is indeed 512 and ioData is NULL.
static OSStatus recordingCallback(void *inRefCon,
AudioUnitRenderActionFlags
*ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
AudioServer *server = (AudioServer*)inRefCon;
OSStatus status;
status = AudioUnitRender([server audioUnit],
ioActionFlags,
inTimeStamp,
kInputBus,
inNumberFrames,
[server inputBuffer]);
if (status != noErr)
return status;
return noErr;
}
I set up the audio format like this:
AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate = 44100.00;
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger |
kAudioFormatFlagIsPacked;
audioFormat.mFramesPerPacket = 1;
audioFormat.mChannelsPerFrame = kChannelsPerFrame;
audioFormat.mBitsPerChannel = 16;
audioFormat.mBytesPerPacket = 2;
audioFormat.mBytesPerFrame = 2;
I set the callback like this:
status = AudioUnitSetProperty(_audioUnit,
kAudioOutputUnitProperty_SetInputCallback,
kAudioUnitScope_Global, kInputBus,
&callbackStruct,
sizeof(callbackStruct));
Finally, I tell the audio unit no to allocate buffers:
flag = 0;
status = AudioUnitSetProperty(_audioUnit,
kAudioUnitProperty_ShouldAllocateBuffer,
kAudioUnitScope_Output, kInputBus,
&flag, sizeof(flag));
and allocate the buffers themselves:
// Calculate number of buffers from channels
UInt32 propsize = offsetof(AudioBufferList, mBuffers[0]) +
(sizeof(AudioBuffer) * kChannelsPerFrame);
// Allocate buffer lists
_inputBuffer = (AudioBufferList *)malloc(propsize);
_inputBuffer->mNumberBuffers = kChannelsPerFrame;
//Pre-allocate buffers for AudioBufferLists
for (UInt32 i = 0; i < _inputBuffer->mNumberBuffers; i++) {
_inputBuffer->mBuffers[i].mNumberChannels = 1;
_inputBuffer->mBuffers[i].mDataByteSize = kBufferSizeBytes;
_inputBuffer->mBuffers[i].mData = malloc(kBufferSizeBytes);
}
---
http://tinyco.de
--- Mac & iPhone
_______________________________________________
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