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 08:45:37 -0400
Wow. Many thanks,
That certainly helped. With:
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)/2;
for (isamp = 0; isamp<nsamples; ++isamp){
ipsamp = [NSNumber numberWithUnsignedShort:(unsigned
short)ippointer[isamp]];
[ipbufaddObject:ipsamp];
idsamp = [NSNumber numberWithUnsignedShort:(unsigned
short)idpointer[isamp]];
[idbufaddObject:idsamp];
if (isamp < 100) {
NSLog(@" isamp %d ipsamp %@ idsamp %@",isamp,ipsamp,idsamp);
}
}
I get
2008-10-06 08:39:05.177 Roboplasm[32065:813] isamp 0 ipsamp 0 idsamp 0
2008-10-06 08:39:05.178 Roboplasm[32065:813] isamp 1 ipsamp 15196
idsamp 15214
2008-10-06 08:39:05.178 Roboplasm[32065:813] isamp 2 ipsamp 0 idsamp 0
2008-10-06 08:39:05.178 Roboplasm[32065:813] isamp 3 ipsamp 15218
idsamp 15241
2008-10-06 08:39:05.179 Roboplasm[32065:813] isamp 4 ipsamp 0 idsamp 0
2008-10-06 08:39:05.179 Roboplasm[32065:813] isamp 5 ipsamp 15250
idsamp 15273
2008-10-06 08:39:05.179 Roboplasm[32065:813] isamp 6 ipsamp 0 idsamp 0
2008-10-06 08:39:05.180 Roboplasm[32065:813] isamp 7 ipsamp 15248
idsamp 15327
2008-10-06 08:39:05.180 Roboplasm[32065:813] isamp 8 ipsamp 0 idsamp 0
2008-10-06 08:39:05.180 Roboplasm[32065:813] isamp 9 ipsamp 15192
idsamp 15356
2008-10-06 08:39:05.180 Roboplasm[32065:813] isamp 10 ipsamp 0 idsamp 0
2008-10-06 08:39:05.181 Roboplasm[32065:813] isamp 11 ipsamp 15128
idsamp 15344
2008-10-06 08:39:05.181 Roboplasm[32065:813] isamp 12 ipsamp 0 idsamp 0
2008-10-06 08:39:05.181 Roboplasm[32065:813] isamp 13 ipsamp 15122
idsamp 15341
2008-10-06 08:39:05.182 Roboplasm[32065:813] isamp 14 ipsamp 0 idsamp 0
2008-10-06 08:39:05.182 Roboplasm[32065:813] isamp 15 ipsamp 15140
idsamp 15370
2008-10-06 08:39:05.182 Roboplasm[32065:813] isamp 16 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.183 Roboplasm[32065:813] isamp 17 ipsamp 15164
idsamp 15387
2008-10-06 08:39:05.183 Roboplasm[32065:813] isamp 18 ipsamp 0 idsamp 0
2008-10-06 08:39:05.183 Roboplasm[32065:813] isamp 19 ipsamp 15214
idsamp 15375
2008-10-06 08:39:05.185 Roboplasm[32065:813] isamp 20 ipsamp 0 idsamp 0
2008-10-06 08:39:05.185 Roboplasm[32065:813] isamp 21 ipsamp 15244
idsamp 15334
2008-10-06 08:39:05.186 Roboplasm[32065:813] isamp 22 ipsamp 0 idsamp 0
2008-10-06 08:39:05.201 Roboplasm[32065:813] isamp 23 ipsamp 15237
idsamp 15316
2008-10-06 08:39:05.203 Roboplasm[32065:813] isamp 24 ipsamp 0 idsamp 0
2008-10-06 08:39:05.210 Roboplasm[32065:813] isamp 25 ipsamp 15180
idsamp 15346
2008-10-06 08:39:05.211 Roboplasm[32065:813] isamp 26 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.211 Roboplasm[32065:813] isamp 27 ipsamp 15128
idsamp 15370
2008-10-06 08:39:05.212 Roboplasm[32065:813] isamp 28 ipsamp 0 idsamp 0
2008-10-06 08:39:05.214 Roboplasm[32065:813] isamp 29 ipsamp 15130
idsamp 15382
2008-10-06 08:39:05.214 Roboplasm[32065:813] isamp 30 ipsamp 0 idsamp 0
2008-10-06 08:39:05.215 Roboplasm[32065:813] isamp 31 ipsamp 15192
idsamp 15390
2008-10-06 08:39:05.218 Roboplasm[32065:813] isamp 32 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.219 Roboplasm[32065:813] isamp 33 ipsamp 15258
idsamp 15389
2008-10-06 08:39:05.221 Roboplasm[32065:813] isamp 34 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.222 Roboplasm[32065:813] isamp 35 ipsamp 15292
idsamp 15381
2008-10-06 08:39:05.223 Roboplasm[32065:813] isamp 36 ipsamp 0 idsamp 0
2008-10-06 08:39:05.224 Roboplasm[32065:813] isamp 37 ipsamp 15304
idsamp 15380
2008-10-06 08:39:05.224 Roboplasm[32065:813] isamp 38 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.228 Roboplasm[32065:813] isamp 39 ipsamp 15300
idsamp 15383
2008-10-06 08:39:05.229 Roboplasm[32065:813] isamp 40 ipsamp 0 idsamp 0
2008-10-06 08:39:05.229 Roboplasm[32065:813] isamp 41 ipsamp 15293
idsamp 15375
2008-10-06 08:39:05.230 Roboplasm[32065:813] isamp 42 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.231 Roboplasm[32065:813] isamp 43 ipsamp 15301
idsamp 15361
2008-10-06 08:39:05.231 Roboplasm[32065:813] isamp 44 ipsamp 0 idsamp 0
2008-10-06 08:39:05.232 Roboplasm[32065:813] isamp 45 ipsamp 15339
idsamp 15362
2008-10-06 08:39:05.238 Roboplasm[32065:813] isamp 46 ipsamp 32768
idsamp 0
2008-10-06 08:39:05.239 Roboplasm[32065:813] isamp 47 ipsamp 15373
idsamp 15368
2008-10-06 08:39:05.240 Roboplasm[32065:813] isamp 48 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.240 Roboplasm[32065:813] isamp 49 ipsamp 15383
idsamp 15366
2008-10-06 08:39:05.241 Roboplasm[32065:813] isamp 50 ipsamp 32768
idsamp 32768
2008-10-06 08:39:05.242 Roboplasm[32065:813] isamp 51 ipsamp 15377
idsamp 15370
2008-10-06 08:39:05.242 Roboplasm[32065:813] isamp 52 ipsamp 32768
idsamp 32768
2008-10-06 08:39:05.243 Roboplasm[32065:813] isamp 53 ipsamp 15377
idsamp 15388
2008-10-06 08:39:05.244 Roboplasm[32065:813] isamp 54 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.244 Roboplasm[32065:813] isamp 55 ipsamp 15393
idsamp 15394
2008-10-06 08:39:05.245 Roboplasm[32065:813] isamp 56 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.246 Roboplasm[32065:813] isamp 57 ipsamp 15402
idsamp 15377
2008-10-06 08:39:05.247 Roboplasm[32065:813] isamp 58 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.247 Roboplasm[32065:813] isamp 59 ipsamp 15387
idsamp 15360
2008-10-06 08:39:05.248 Roboplasm[32065:813] isamp 60 ipsamp 32768
idsamp 0
2008-10-06 08:39:05.248 Roboplasm[32065:813] isamp 61 ipsamp 15365
idsamp 15359
2008-10-06 08:39:05.249 Roboplasm[32065:813] isamp 62 ipsamp 32768
idsamp 32768
2008-10-06 08:39:05.249 Roboplasm[32065:813] isamp 63 ipsamp 15363
idsamp 15362
2008-10-06 08:39:05.249 Roboplasm[32065:813] isamp 64 ipsamp 32768
idsamp 32768
2008-10-06 08:39:05.250 Roboplasm[32065:813] isamp 65 ipsamp 15374
idsamp 15362
2008-10-06 08:39:05.250 Roboplasm[32065:813] isamp 66 ipsamp 32768
idsamp 32768
2008-10-06 08:39:05.251 Roboplasm[32065:813] isamp 67 ipsamp 15381
idsamp 15369
2008-10-06 08:39:05.251 Roboplasm[32065:813] isamp 68 ipsamp 32768
idsamp 0
2008-10-06 08:39:05.252 Roboplasm[32065:813] isamp 69 ipsamp 15382
idsamp 15386
2008-10-06 08:39:05.253 Roboplasm[32065:813] isamp 70 ipsamp 32768
idsamp 0
2008-10-06 08:39:05.253 Roboplasm[32065:813] isamp 71 ipsamp 15374
idsamp 15403
2008-10-06 08:39:05.254 Roboplasm[32065:813] isamp 72 ipsamp 0 idsamp 0
2008-10-06 08:39:05.254 Roboplasm[32065:813] isamp 73 ipsamp 15360
idsamp 15413
2008-10-06 08:39:05.255 Roboplasm[32065:813] isamp 74 ipsamp 0 idsamp 0
2008-10-06 08:39:05.256 Roboplasm[32065:813] isamp 75 ipsamp 15360
idsamp 15410
2008-10-06 08:39:05.256 Roboplasm[32065:813] isamp 76 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.260 Roboplasm[32065:813] isamp 77 ipsamp 15384
idsamp 15394
2008-10-06 08:39:05.262 Roboplasm[32065:813] isamp 78 ipsamp 0 idsamp 0
2008-10-06 08:39:05.263 Roboplasm[32065:813] isamp 79 ipsamp 15406
idsamp 15378
2008-10-06 08:39:05.263 Roboplasm[32065:813] isamp 80 ipsamp 0 idsamp
32768
2008-10-06 08:39:05.264 Roboplasm[32065:813] isamp 81 ipsamp 15405
idsamp 15370
2008-10-06 08:39:05.264 Roboplasm[32065:813] isamp 82 ipsamp 0 idsamp 0
2008-10-06 08:39:05.265 Roboplasm[32065:813] isamp 83 ipsamp 15405
idsamp 15365
2008-10-06 08:39:05.266 Roboplasm[32065:813] isamp 84 ipsamp 0 idsamp 0
2008-10-06 08:39:05.267 Roboplasm[32065:813] isamp 85 ipsamp 15425
idsamp 15349
2008-10-06 08:39:05.269 Roboplasm[32065:813] isamp 86 ipsamp 32768
idsamp 0
2008-10-06 08:39:05.270 Roboplasm[32065:813] isamp 87 ipsamp 15440
idsamp 15339
2008-10-06 08:39:05.271 Roboplasm[32065:813] isamp 88 ipsamp 0 idsamp 0
2008-10-06 08:39:05.271 Roboplasm[32065:813] isamp 89 ipsamp 15431
idsamp 15358
2008-10-06 08:39:05.272 Roboplasm[32065:813] isamp 90 ipsamp 32768
idsamp 32768
2008-10-06 08:39:05.272 Roboplasm[32065:813] isamp 91 ipsamp 15415
idsamp 15368
2008-10-06 08:39:05.273 Roboplasm[32065:813] isamp 92 ipsamp 32768
idsamp 0
2008-10-06 08:39:05.274 Roboplasm[32065:813] isamp 93 ipsamp 15413
idsamp 15361
2008-10-06 08:39:05.274 Roboplasm[32065:813] isamp 94 ipsamp 0 idsamp 0
2008-10-06 08:39:05.275 Roboplasm[32065:813] isamp 95 ipsamp 15411
idsamp 15337
2008-10-06 08:39:05.275 Roboplasm[32065:813] isamp 96 ipsamp 0 idsamp 0
2008-10-06 08:39:05.276 Roboplasm[32065:813] isamp 97 ipsamp 15396
idsamp 15348
2008-10-06 08:39:05.276 Roboplasm[32065:813] isamp 98 ipsamp 0 idsamp 0
2008-10-06 08:39:05.277 Roboplasm[32065:813] isamp 99 ipsamp 15385
idsamp 15373 etc...
Note the occurrence of samples with the value of 0 alternating with
samples that are reasonable. However,
this alternation is not rigid as the 0's can be substituted with
reasonable numbers.
Any idea what's going on here?
Thanks again,
Joseph
On Oct 6, 2008, at 7:53 AM, Graham Cox wrote:
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
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