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: Graham Cox <email@hidden>
- Date: Mon, 6 Oct 2008 22:53:57 +1100
On 6 Oct 2008, at 10:27 pm, Joseph Ayers wrote:
unsigned short *ippointer = (unsigned short *)abl-
>mBuffers[0].mData;
unsigned short *idpointer = (unsigned short *)abl-
>mBuffers[1].mData;
[]
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];
Another problem I just noticed after posting my first reply.
You cast your buffers to unsigned short*. That's OK, presumably each
sample is 16 bits. But to me, the field mDataByteSize implies that the
buffer size is specified in bytes, not 16-bit words, so the number of
samples is this value / 2.
If your loop were correct, it would look something like:
for( sample = 0; sample < nSamples; ++sample )
{
sampleValue = ipPointer[sample];
}
Because ipPointer is already declared as a pointer unsigned short, the
array subscript will access each sample (2 bytes) at a time, even when
incremented by only one. That's a Good Thing™, but makes the proper
calculation of the number of *samples* critical. By forgetting to do
that, you've overrun the end of your array at about the half-way mark,
as you would expect. That's why you're getting the bad access error.
Graham_______________________________________________
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