every time callback function of the audio unit is being called, i get another number of samples which is strange because NSLog(@"%ld",inNumberFrames); gives me always 512.
when i do this :
NSLog(@"%li",strlen((const char *)(&bufferList)->mBuffers[0].mData));
i get numbers such as: 50 20 19 160 200 1 …
which is strange.
each call back, i have to get the full buffer 512 samples no ?
i know i dont get all needed samples because if i input a sin 2khz , i get zero crossing of about 600, and if i put nothing, i g et the same.
to retrieve data i do :
static OSStatus recordingCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData)
{
AudioBuffer buffer;
buffer.mNumberChannels = 1;
buffer.mDataByteSize = inNumberFrames * 2;
//NSLog(@"%ld",inNumberFrames);
buffer.mData = malloc( inNumberFrames * 2 );
// Put buffer in a AudioBufferList
AudioBufferList bufferList;
bufferList.mNumberBuffers = 1;
bufferList.mBuffers[0] = buffer;
OSStatus status;
status = AudioUnitRender(audioUnit,
ioActionFlags,
inTimeStamp,
inBusNumber,
inNumberFrames,
&bufferList);
//checkStatus(status);
NSLog(@"%li",strlen((const char *)(&bufferList)->mBuffers[0].mData));
int16_t *q = (int16_t *)(&bufferList)->mBuffers[0].mData;
for(int i=0; i < strlen((const char *)(&bufferList)->mBuffers[0].mData); i++)
{
....
any help with this will save me days !
thanks .
A strlen() of the audio sample buffer is not related to the number of samples. Instead, look at the number of frames given as the callback function’s parameter.