Re: Data Types for Extracting samples from Audio Buffer
Re: Data Types for Extracting samples from Audio Buffer
- Subject: Re: Data Types for Extracting samples from Audio Buffer
- From: Jacob Lukas <email@hidden>
- Date: Sun, 5 Oct 2008 11:32:05 -0700
On Oct 5, 2008, at 09:47, Joseph Ayers wrote:
I'm trying to extract the audio samples from an audio buffer
returned from the QuickTime Audio extraction API into a
NSMutableArray of NSNumbers.
<snip>
The code I am using is:
AudioBufferList* abl;
NSMutableArray * ipbuf;
NSMutableArray * idbuf;
NSNumber* ipsamp;
NSNumber* idsamp;
unsigned short *ippointer = (unsigned short *)abl-
>mBuffers[0].mData;
unsigned short *idpointer = (unsigned short *)abl-
>mBuffers[1].mData;
for (isamp = 1; abl->mBuffers[0].mDataByteSize;isamp++){
[ipsamp initWithUnsignedShort:(unsigned short)ippointer[isamp]];
[ipbuf insertObject:ipsamp atIndex:isamp];
[idsamp initWithUnsignedShort:(unsigned short)idpointer[isamp]];
[idbuf insertObject:idsamp atIndex:isamp];
}
The program crashes on the line
[ipsamp initWithUnsignedShort:(unsigned short)ippointer[isamp]];
with
Program received signal: “EXC_BAD_ACCESS”.
Try this on for size:
// Edited in Mail -- not guaranteed to even compile
// Completely untested
AudioBufferList* abl = /* fetch valid AudioBufferList */;
NSMutableArray * ipbuf = [NSMutableArray array];
NSMutableArray * idbuf = [NSMutableArray array];
NSNumber* ipsamp = nil; // not strictly necessary
NSNumber* idsamp = nil;
unsigned short *ippointer = (unsigned short *)abl->mBuffers[0].mData;
unsigned short *idpointer = (unsigned short *)abl->mBuffers[1].mData;
// Skipping first sample
// where is isamp declared?
for (isamp = 1; isamp < abl->mBuffers[0].mDataByteSize; isamp++){
ipsamp = [NSNumber numberWithUnsignedShort:(unsigned
short)ippointer[isamp]];
[ipbuf addObject:ipsamp];
idsamp = [NSNumber numberWithUnsignedShort:(unsigned
short)idpointer[isamp]];
[idbuf addObject:idsamp];
}
-Jacob_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden