Re: Using AudioConverterFillComplexBuffer to Decompress Audio File Dynamically
Re: Using AudioConverterFillComplexBuffer to Decompress Audio File Dynamically
- Subject: Re: Using AudioConverterFillComplexBuffer to Decompress Audio File Dynamically
- From: Kevin Dixon <email@hidden>
- Date: Tue, 20 Aug 2013 10:48:10 -0700
You might need a higher performance data structure than NSData. I
recommend Michael Tyson's circular buffer
https://github.com/michaeltyson/TPCircularBuffer
On Tue, Aug 20, 2013 at 4:30 AM, Richard Oths <email@hidden> wrote:
> Indeed that worked well and was able to format as mono too. The
> 'incantations' below i modified from a SO posting, however substituting
> NSMutableData object with NSMutableArray seems to hang the process,
> nevertheless a good step in the right direction.
>
> Many thanks ...
>
> CMSampleBufferRef nextBuffer = [assetReaderOutput copyNextSampleBuffer];
> if (nextBuffer) {
> //new
> AudioBufferList audioBufferList;
> NSMutableData *data=[[NSMutableData alloc] init];
> CMBlockBufferRef blockBuffer;
>
> CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(nextBuffer, NULL,
> &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
>
> for( int j=0; j < audioBufferList.mNumberBuffers; j++ )
> {
> AudioBuffer audioBuffer = audioBufferList.mBuffers[j];
> SInt16 *frame = (SInt16*)audioBuffer.mData;
>
>
>
>
>
> [data appendBytes:frame
> length:audioBuffer.mDataByteSize];
> }
>
> On Aug 19, 2013, at 3:58 PM, Kevin Dixon wrote:
>
> Once you have your AVAssetReaderAudioMixOutput, you can simply call
> copyNextSampleBuffer on that object. If you have configured the
> AVAssetReader with the proper client format, then it will be in plain
> 16 bit PCM, or whatever you asked for.
>
> For example
>
> _audioDecodeSettings = [NSDictionary dictionaryWithObjectsAndKeys:
> [NSNumber
> numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
> [NSNumber numberWithFloat:samplingRate],
> AVSampleRateKey,
> [NSNumber numberWithInt: numCh],
> AVNumberOfChannelsKey,
> [NSData dataWithBytes: &layout length:
> sizeof(AudioChannelLayout)], AVChannelLayoutKey,
> [NSNumber numberWithInt:16],
> AVLinearPCMBitDepthKey,
> [NSNumber numberWithBool:NO],
> AVLinearPCMIsNonInterleaved,
> [NSNumber numberWithBool:NO],
> AVLinearPCMIsFloatKey,
> [NSNumber numberWithBool:NO],
> AVLinearPCMIsBigEndianKey,
> nil];
>
> //get audioTracks from the AVAsset tracksWithMediaType:AVMediaTypeAudio
>
> AVAssetReaderAudioMixOutput * newReaderOutput =
> [AVAssetReaderAudioMixOutput
> assetReaderAudioMixOutputWithAudioTracks:audioTracks
>
> audioSettings:
> _audioDecodeSettings];
>
> //add output to AVAssetReader instance
>
> //AVAssetReader startReading
>
> then copyNextSampleBuffer. You must do some CF incantations to get
> this data into the properly "retained" format and all that.
>
> HTH
> -Kevin
>
>
> On Mon, Aug 19, 2013 at 1:46 PM, Richard Oths <email@hidden> wrote:
>
> Hello,
>
>
> Trying to convert compressed audio file dynamically and populating array
>
> with PCM sample integer amplitudes for further evaluation. Following the
>
> steps in http://www.subfurther.com/blog/category/ipod/ - I am good up to the
>
> point of writing to file via assetWriterInput object. But why can't i grab
>
> the decompressed sample data before they are written into file? My hunch is
>
> that there is more going on behind the scenes with the assetWriter in terms
>
> of conversion.
>
>
> Is AudioConverterFillComplexBuffer the correct approach to capture
>
> decompressed audio dynamically? Any examples are greatly appreciated.
>
>
> ~Mickey
>
>
> _______________________________________________
>
> 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
>
>
_______________________________________________
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