iphone - Accessing raw audio data with Audio Queue using AudioFileReadPackets -
i'm attempting access raw audio data sent audio queue callback, after calling audiofilereadpackets, number of bytes (numbytes) 0.
void aqrecorder::myinputbufferhandler(void *inuserdata, audioqueueref inaq, audioqueuebufferref inbuffer, const audiotimestamp * instarttime, uint32 innumpackets, const audiostreampacketdescription* inpacketdesc) { aqrecorder *aqr = (aqrecorder *)inuserdata; try { if (innumpackets > 0) { //read packets uint32 numbytes; osstatus result = audiofilereadpackets(aqr->mrecordfile, // audio file packets of audio data read. false, // set true cache data. otherwise, set false. &numbytes, // on output, pointer number of bytes returned. (__bridge audiostreampacketdescription*)inpacketdesc, // pointer array of packet descriptions have been allocated. aqr->mrecordpacket, // packet index of first packet want returned. &innumpackets, // on input, pointer number of packets read. on output, number of packets read. inbuffer->maudiodata); // pointer user-allocated memory. inbuffer->maudiodatabytesize = numbytes; sint16 *testbuffer = (sint16*)inbuffer->maudiodata; (int i=0; < numbytes; i++) { uint16 currentdata = testbuffer[i]; printf("current data in testbuffer %d", currentdata); } // if we're not stopping, re-enqueue buffe gets filled again if (aqr->isrunning()) xthrowiferror(audioqueueenqueuebuffer(inaq, inbuffer, 0, null), "audioqueueenqueuebuffer failed"); } catch (caxexception e) { char buf[256]; fprintf(stderr, "error: %s (%s)\n", e.moperation, e.formaterror(buf)); } } i able values between 0 , 4294967296 when print out first index of testbuffer, not seem empty. ideas why numbytes 0 after audiofilereadpackets executes?
i'm still unsure why numbytes 0, found workable solution this question.
to size of testbuffer used following code:
int samplecount = inbuffer->maudiodatabytescapacity / sizeof(sint16);
Comments
Post a Comment