• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie: trying to log samples
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie: trying to log samples


  • Subject: Re: Newbie: trying to log samples
  • From: Michael Thornburgh <email@hidden>
  • Date: Wed, 2 Feb 2005 23:21:58 -0800


hi Michael.

you're being fed 4096 bytes, which is (extremely probably) 1024 Float32 samples, which is furthermore extremely probably 512 interleaved stereo (L-R) frames of audio. the canonical logical format used by CoreAudio in the IO callbacks (AudioDeviceIOProc or MTCoreAudio IOTarget) is 32-bit native-endian floating-point normalized LPCM (that is, linear samples from -1.0 to +1.0), no matter what the physical format of the device is.

the number of frames in an AudioBuffer B (in canonical format) is

B.mDataByteSize / B.mNumberChannels / sizeof(Float32)

all AudioBuffers in an AudioBufferList represent the same amount of time (the same number of frames, which could mean a different number of samples if there are differing numbers of channels in the buffers). each AudioBuffer in an AudioBufferList corresponds to one stream of the audio device. most common audio devices have 0 or 1 streams in each direction.

-mike


On Feb 2, 2005, at 10:55 PM, Michael Hanna wrote:

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:
email@hidden

This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Newbie: trying to log samples
      • From: Michael Hanna <email@hidden>
References: 
 >Newbie: trying to log samples (From: Michael Hanna <email@hidden>)

  • Prev by Date: Newbie: trying to log samples
  • Next by Date: Re: Initializing static C++ class variable in a HAL plugin
  • Previous by thread: Newbie: trying to log samples
  • Next by thread: Re: Newbie: trying to log samples
  • Index(es):
    • Date
    • Thread