| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
hi, I'm trying to log the samples coming from the microphone. This code is from the net that uses the MTCoreAudio. buffer->mDataByteSize %u gives me 4096 bytes, so I'm assuming that I'm being fed 4096 bytes, or 2048 samples per cycle(each sample being 2 bytes long, or 16-bit).
I added the unsigned char aSample[2] (want to see if I can get the first sample out of the buffer as a starting point). Then once the data is read-in, I memcpy the first sample to the aSample array. Then I log it to the console as an unsigned 16-bit. However my output is the same over and over:
2005-02-03 01:44:45.577 Recordotron[4074] aSample 5392
2005-02-03 01:44:45.588 Recordotron[4074] aSample 5392
2005-02-03 01:44:45.600 Recordotron[4074] aSample 5392
Clearly I'm not doing something right, but I'm not sure what! :)
Any help at all would be appreciated.
Michael
- (OSStatus) readCycleForDevice: (MTCoreAudioDevice *) theDevice
timeStamp: (const AudioTimeStamp *) now
inputData: (const AudioBufferList *) inputData
inputTime: (const AudioTimeStamp *) inputTime
outputData: (AudioBufferList *) outputData
outputTime: (const AudioTimeStamp *) outputTime
clientData: (void *) clientData
{
unsigned char aSample[2];
// peer into the data
const AudioBuffer *buffer;
buffer = &inputData->mBuffers[0];
//NSLog(@"buffer->mDataByteSize %u", buffer->mDataByteSize);
// will this sample put us over the line? If so, dump the data
// and tell the UI to stop the recording and disable the Stop
// button. We don't stop the actual reading from here
// because it seems to leave some stale locks in the MTCoreAudio
// guts.
if (g_lastIndex + buffer->mDataByteSize > SOUND_BUFFER_SIZE) {
[self performSelectorOnMainThread: @selector(stopRecording:)
withObject: self
waitUntilDone: NO];
} else {
memcpy (aSample + 2, buffer->mData, 2); // grab 2 bytes(one sample)
NSLog(@"aSample %hi", aSample); // output as an unsigned 16-bit integer
// append the data to the end of our buffer
memcpy (g_soundBuffer + g_lastIndex,
buffer->mData, buffer->mDataByteSize);
g_lastIndex += buffer->mDataByteSize;
}
return (noErr);
} // readCycleForDevice
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/coreaudio-api/ email@hidden
This email sent to email@hidden
| References: | |
| >Newbie: trying to log samples (From: Michael Hanna <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.