I converted CAF to AAC format using TPAACAudioConverter, but the converted file duration is 0

I am using AVAudioRecorder. I record sound in caf format. After that, I convert the caf file to aac format using TPAACAudioConverter . It works fine, but the converted file lasts 00:00. Is there a way to get the duration of the aac audio file.

+6
source share
2 answers

AAC format does not support any simulator. You can check it on your device. It will work fine and you can get the AAC sound file.

+2
source

Can you play the file in a cafe?

If you want to record the sound from the microphone to aac file, you can use the audio queue services (I can post some code)

Edit: this is an implementation from the Apple dev tutorial, there might be some errors since I changed them to fit your question

//AudioQ.mm @implementation AudioQ static const int nBuffer = 3; struct AQRecorderState{ AudioStreamBasicDescription mDataFormat; AudioQueueRef mQueue; AudioQueueBufferRef mBuffers[nBuffer]; AudioFileID mAudioFile; UInt32 bufferByteSize; SInt64 mCurrentPacket; bool mIsRunning; }; AQRecorderState aqData; CFURLRef url; static OSStatus BufferFilledHandler( void * inUserData, SInt64 inPosition, UInt32 requestCount, const void * buffer, UInt32 * actualCount ){ // callback when you write to the file // you can handle audio packet and send them for broadcasting return 0; } static void HandleInputBuffer( void *aqData, AudioQueueRef inAq, AudioQueueBufferRef inBuffer, const AudioTimeStamp *inStartTime, UInt32 inNumPackets, const AudioStreamPacketDescription *inPacketDesc ) { AQRecorderState *pAqData = (AQRecorderState*) aqData; if (AudioFileWritePackets ( pAqData->mAudioFile, false, inBuffer->mAudioDataByteSize, inPacketDesc, pAqData->mCurrentPacket, &inNumPackets, inBuffer->mAudioData ) == noErr) { pAqData->mCurrentPacket += inNumPackets; } else { NSLog(@"err writing packet"); } if (pAqData->mIsRunning == 0) return; AudioQueueEnqueueBuffer(pAqData->mQueue,inBuffer,0,NULL); } -(OSStatus) initializeAQ{ //--- set the output format ---// aqData.mDataFormat.mSampleRate = 22050; aqData.mDataFormat.mFormatID = kAudioFormatMPEG4AAC; aqData.mDataFormat.mFormatFlags = kMPEG4Object_AAC_Main; aqData.mDataFormat.mBytesPerPacket = 0; aqData.mDataFormat.mFramesPerPacket = 1024; aqData.mDataFormat.mBytesPerFrame = 0; aqData.mDataFormat.mChannelsPerFrame = 1; aqData.mDataFormat.mBitsPerChannel = 0; AudioFileTypeID fileType = kAudioFileAAC_ADTSType; aqData.bufferByteSize = 0x5000; // ?? AudioQueueNewInput(&aqData.mDataFormat, HandleInputBuffer, &aqData, CFRunLoopGetMain(), kCFRunLoopCommonModes, 0, &aqData.mQueue); aqData.mCurrentPacket = 0; aqData.mIsRunning = true; //--- record in a file get the callback when writing ---// AQRecorderState *pAqData = &aqData; AudioFileInitializeWithCallbacks((void*)&pAqData, nil, BufferFilledHandler, nil, nil, fileType, &aqData.mDataFormat, kAudioFileFlags_EraseFile, &aqData.mAudioFile); //--- prepare set of audio queue buffers ---// for(int i = 0 ; i < nBuffer ; i++){ AudioQueueAllocateBuffer(aqData.mQueue, aqData.bufferByteSize, &aqData.mBuffers[i]); AudioQueueEnqueueBuffer(aqData.mQueue, aqData.mBuffers[i], 0, NULL); } return 0; } -(void) start{ AudioQueueStart(aqData.mQueue, NULL); } -(void) stop{ NSLog(@"stoping"); AudioQueueStop(aqData.mQueue, true); aqData.mIsRunning = false; AudioQueueDispose (aqData.mQueue,true); AudioFileClose (aqData.mAudioFile); } @end 

AudioQ.h

 static void HandleInputBuffer( void *aqData, AudioQueueRef inAq, AudioQueueBufferRef inBuffer, const AudioTimeStamp *inStartTime, UInt32 inNumPackets, const AudioStreamPacketDescription *inPacketDesc ); static OSStatus BufferFilledHandler( void * inUserData, SInt64 inPosition, UInt32 requestCount, const void * buffer, UInt32 * actualCount ); -(OSStatus)initializeAQ; -(void)stop; -(void)start; 
0
source

Source: https://habr.com/ru/post/950272/


All Articles