On 6 Oct 2008, at 10:27 pm, Joseph Ayers wrote:

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];

The above two lines just leak two NSNumber objects, otherwise contributing nothing useful. This isn't the problem you're having though, so let's move on...


        nsamples = abl->mBuffers[0].mDataByteSize;

        for (isamp = 1; nsamples; isamp++){

What terminates this loop? Nothing that I can see - 'nsamples' isn't a statement that does anything, since its value isn't changed within the loop nor compared to anything.


ipsamp = [NSNumber numberWithUnsignedShort:(unsigned short)ippointer[isamp]];
                     [ipbufaddObject:ipsamp];
idsamp = [NSNumber numberWithUnsignedShort:(unsigned short)idpointer[isamp]];
                     [idbufaddObject:idsamp];

Are you *really* sure you want to allocate an entire object per sample? While not directly a cause of the problem, this could place heavy demands on your memory usage requirements. But OK, optimize later, moving on...


                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


You are logging NSNumber object references using %d, which is for an integer. Thus it's taking the address of the object and attempting to display it as an integer. Hence the value logged is not the contents of the number but its address.

See:

http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#/ /apple_ref/doc/uid/TP40004265-SW1

You need to use %@ which will log the result of the object's - description method, which for an NSNumber includes its contained value.

2008-10-06 07:22:45.770 Roboplasm[29177:813] isamp 108540 ipsamp 4255904 idsamp 4255904
Program received signal:  “EXC_BAD_ACCESS”.

I suspect this is occurring because isamp is being incremented beyond the last sample value in the input array, because you have no loop termination condition.

hth,

Graham_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to