Decoding stereo channels with audio extraction API
Decoding stereo channels with audio extraction API
- Subject: Decoding stereo channels with audio extraction API
- From: Joseph Ayers <email@hidden>
- Date: Wed, 03 Sep 2008 18:22:42 -0400
- Organization: Northeastern University
I'm trying to separate the audio buffer extracted from a QuickTime movie
using the QT audio Extraction API.
http://developer.apple.com/quicktime/audioextraction.html
First of all, Is there a Reference Document that describes the API?
During the extraction,
error = MovieAudioExtractionGetProperty(extractionSessionRef,
kQTPropertyClass_MovieAudioExtraction_Audio,
kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
sizeof (asbd), &asbd, nil);
NSLog(@" format flags = %d",asbd.mFormatFlags);
NSLog(@" sample rate = %f",asbd.mSampleRate);
NSLog(@" bytes/packet = %d",asbd.mBytesPerPacket);
NSLog(@" frames/packet = %d",asbd.mFramesPerPacket);
NSLog(@" bytes/frame = %d",asbd.mBytesPerFrame);
NSLog(@" channels/frame = %d",asbd.mChannelsPerFrame);
NSLog(@" bits/channel = %d",asbd.mBitsPerChannel);
returns
2008-09-03 18:01:56.900 Roboplasm[38339:813] format flags = 41
2008-09-03 18:01:56.900 Roboplasm[38339:813] sample rate =
48000.000000
2008-09-03 18:01:56.902 Roboplasm[38339:813] bytes/packet = 4
2008-09-03 18:01:56.909 Roboplasm[38339:813] frames/packet = 1
2008-09-03 18:01:56.915 Roboplasm[38339:813] bytes/frame = 4
2008-09-03 18:01:56.915 Roboplasm[38339:813] channels/frame = 2
2008-09-03 18:01:56.915 Roboplasm[38339:813] bits/channel = 32
A sample buffer defined as:
Byte * samples;
int sampleCount;
Is loaded using:
float numFramesF = asbd.mSampleRate * ((float)
GetMovieDuration(soundToPlay) / (float) GetMovieTimeScale(soundToPlay));
UInt32 numFrames = (UInt32) numFramesF;
NSLog(@"numFrames is %d",numFrames);
UInt32 extractionFlags = 0;
AudioBufferList* buffer =
calloc(sizeof(AudioBufferList), 1);
buffer->mNumberBuffers = 1;
buffer->mBuffers[0].mNumberChannels = asbd.mChannelsPerFrame;
buffer->mBuffers[0].mDataByteSize = sizeof(UInt16) *
buffer->mBuffers[0].mNumberChannels * numFrames;
[self setSamples:calloc(buffer->mBuffers[0].mDataByteSize, 1)];
buffer->mBuffers[0].mData = samples;
[self setSampleCount: numFrames * buffer->mBuffers[0].mNumberChannels];
error = MovieAudioExtractionFillBuffer(extractionSessionRef,
&numFrames, buffer, &extractionFlags);
NSLog(@"Ending extraction session...");
error = MovieAudioExtractionEnd(extractionSessionRef);
NSLog(@" %d",error);
NSLog(@"ExitMovies...");
ExitMovies();
NSLog(@"Loaded %d samples",sampleCount);
My question is that I want to fill two mutable arrays
NSMutableArray * ipbuf;
NSMutableArray * idbuf;
with the left and right channel samples. The code below generates a
monotonically increasing array of numbers which increase
by four from sample to sample. What am I doing wrong?
Joseph Ayers
- (void)deinterlaceBuffer
{
int i = 0;
if (ipbuf == NULL) {
//ipbuf = (UInt16 *)calloc(1, sizeof(samples));
[self setIpbuf:[[NSMutableArray alloc] init]];
NSLog(@"ipbuf Allocated");
}
if (idbuf == NULL) {
[self setIdbuf:[[NSMutableArray alloc] init]];
//idbuf = (UInt16 *)calloc(1, sizeof(samples));
NSLog(@"idbuf Allocated");
}
UInt16 ipval,idval;
while (i < sampleCount){
ipval = (UInt16)(*samples + ((i-1)*4));
NSNumber* ipsample = [[NSNumber alloc] initWithInt:(int)ipval];
[ipbuf addObject:(NSNumber*) ipsample];
idval = (UInt16)(*samples + ((i-1)*4)+2);
NSNumber* idsample = [[NSNumber alloc] initWithInt:(int)idval];
[idbuf addObject:(NSNumber*) idsample];
i = i++;
if (i<100){
NSLog(@" Sample %d %d %d",i, ipval, idval);
}
[ipsample release];
[idsample release];
}
--
Joseph Ayers, Professor
Department of Biology and
Marine Science Center
Northeastern University
East Point, Nahant, MA 01908
Phone (781) 581-7370 x309(office), x335(lab)
Cellular (617) 755-7523, FAX: (781) 581-6076
Boston Office 444RI, (617) 373-4044
eMail: email@hidden
http://www.neurotechnology.neu.edu/
_______________________________________________
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