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: Joseph Ayers <email@hidden>
- Date: Mon, 06 Oct 2008 07:27:00 -0400
I got the code for extracting samples from an Audio Buffer to compile
and run without errors as:
unsigned short *ippointer = (unsigned short *)abl->mBuffers[0].mData;
unsigned short *idpointer = (unsigned short *)abl->mBuffers[1].mData;
ipbuf = [[NSMutableArray alloc] init];
idbuf = [[NSMutableArray alloc] init];
NSNumber* ipsamp = [[NSNumber alloc] init];
NSNumber* idsamp = [[NSNumber alloc] init];
nsamples = abl->mBuffers[0].mDataByteSize;
for (isamp = 1; nsamples; isamp++){
ipsamp = [NSNumber numberWithUnsignedShort:(unsigned
short)ippointer[isamp]];
[ipbufaddObject:ipsamp];
idsamp = [NSNumber numberWithUnsignedShort:(unsigned
short)idpointer[isamp]];
[idbufaddObject:idsamp];
NSLog(@" isamp %d ipsamp %d idsamp %d",isamp,ipsamp,idsamp);
}
2008-10-06 07:22:45.768 Roboplasm[29177:813] isamp 108534 ipsamp
4255904 idsamp 4255904
2008-10-06 07:22:45.768 Roboplasm[29177:813] isamp 108535 ipsamp
4255904 idsamp 4255904
2008-10-06 07:22:45.768 Roboplasm[29177:813] isamp 108536 ipsamp
4255904 idsamp 4255904
2008-10-06 07:22:45.769 Roboplasm[29177:813] isamp 108537 ipsamp
4255904 idsamp 4255904
2008-10-06 07:22:45.769 Roboplasm[29177:813] isamp 108538 ipsamp
4255904 idsamp 4255904
2008-10-06 07:22:45.769 Roboplasm[29177:813] isamp 108539 ipsamp
4255904 idsamp 4255904
2008-10-06 07:22:45.770 Roboplasm[29177:813] isamp 108540 ipsamp
4255904 idsamp 4255904
Program received signal: “EXC_BAD_ACCESS”.
2008-10-06 07:22:45.770 Roboplasm[29177:813] isamp 108541 ipsamp
4255904 idsamp 4255904
2008-10-06 07:22:45.770 Roboplasm[29177:813] isamp 108542 ipsamp
4255904 idsamp 4255904
2008-10-06 07:22:45.771 Roboplasm[29177:813] isamp 108543 ipsamp
4255904 idsamp 4255904
on Line:
ipsamp = [NSNumber numberWithUnsignedShort:(unsigned
short)ippointer[isamp]];
nsamples is 213120 so the loop bombed before reaching the end of the
buffers
I'm suspicious that values like 4255904 are inappropriate for 16 bit
audio samples.
How can I determine what is going wrong here.
Thanks,
Joseph
On Oct 5, 2008, at 2:32 PM, Jacob Lukas wrote:
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
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)
Boston: 444 Richards Hall (617) 373-4044
Cellular (617) 755-7523, FAX: (781) 581-6076
eMail: email@hidden
http://www.neurotechnology.neu.edu/
_______________________________________________
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