Re: Daisy and captureCurrentPtr
Re: Daisy and captureCurrentPtr
- Subject: Re: Daisy and captureCurrentPtr
- From: Jens Bauer <email@hidden>
- Date: Thu, 5 Feb 2004 22:59:47 +0100
Hi Craig,
I only noticed that you can max. record almost 6MB of audio data, which
stays in memory.
Uhm, and one other thing:
Your -recordBuffers: method is a toggle-method, but it's not changing
the title of the sender.
You would probably either want it to act as a sticky button, and then
remove the toggle-code (so that if people click it multiple times, it
just stays recording), so you can have a separate stop button, or you
could get some inspiration from this:
- (IBAction)toggleRecord:(id)sender
{
OSStatus err;
if(1 == [toggleRecordButton state]) // this could be [sender state],
depends on your implementation
{
NSLog(@"record (1)");
err = AudioDeviceStart(inputDevice, recordCallback);
if(kAudioHardwareNoError == err)
{
[toggleRecordButton setTitle:@"Stop"]; // see comment above.
}
}
else
{
NSLog(@"record (!1)");
err = AudioDeviceStop(inputDevice, recordCallback);
if(kAudioHardwareNoError == err)
{
[toggleRecordButton setTitle:@"Start"];
}
}
}
I also noticed that in your record: method, you don't stop, but you
keep 'starting'; I recommend that you balance the starts & stops
equally. =)
On Thursday, Feb 5, 2004, at 22:04 Europe/Copenhagen, Craig Bakalian
wrote:
Hi Jens,
Enclosed is the code I have modified from Daisy. I think it is
working. I gotta save the captureStorage to disk to see if it is
actually storing Audio data, or play it back somehow. Shesh, this is
a journey!
Please read thru, and tell me if I am sewing invisible fabric :)).
There was an odd thing is the IOProc, I had to make sure that the
ioData->mBuffers[0].mData was not 0x0. I didn't see this in Daisy.
OSStatus myInputCallback(void *inRefCon,
AudioUnitRenderActionFlags inActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumFrames,
AudioBufferList *ioData)
{
MyWindowController *con = (MyWindowController *)inRefCon;
if((ioData != NULL) && (ioData->mNumberBuffers > 0))
{
if(con->captureInput)
{
if(con->captureCurrentPtr + ioData->mBuffers[0].mDataByteSize <
con->captureStorage + kSizeOfCaptureBuffer)
{
// will only be able to capture 17 seconds of audio using 44k1Hz
stereo/32bit, as the audio-buffer doesn't grow.
// I'll try coming up with an example on making a harddisk-recorder...
I got a simple idea for one now. =)
if(ioData->mBuffers[0].mData)
{
BlockMove(ioData->mBuffers[0].mData, con->captureCurrentPtr,
ioData->mBuffers[0].mDataByteSize);
con->captureCurrentPtr += ioData->mBuffers[0].mDataByteSize;
con->captureTotalBytesCaptured +=
ioData->mBuffers[0].mDataByteSize;
}
}
}
}
return 0;
// Uhm, for cosmetic reasons and good habits:
return(kAudioHardwareNoError); here. =)
}
-(IBAction)recordBuffers: (id)sender
{
[self buildGraph];
captureCurrentPtr = NULL;
if(captureInput == NO)
{
if (captureStorage == NULL)
{
// buffer is only allocated once, so it has a fixed size, and will not
grow:
captureStorage = malloc(kSizeOfCaptureBuffer);
if (captureStorage != NULL)
captureInput = YES;
}
else
captureInput = YES;
if (captureInput)
{
captureCurrentPtr = captureStorage;
captureTotalBytesCaptured = 0;
AudioUnitAddRenderNotify(reverbUnit,(AURenderCallback)myInputCallback,s
elf);
// You add a callback here. If the user clicks the record button
multiple times, you will keep adding callbacks. I don't know whether or
not CoreAudio will detect this, and only leave one callback there, but
I strongly suggest that you turn off the callback after
'captureInput=NO;' below...
}
}
else
{
captureInput=NO;
// old callback is still running here. You should turn it off.
}
}
-(IBAction)stopRecordingBuffers: (id)sender
{
// I suggest you remove only the callback if it isn't already removed
above; eg. you could use 'captureInput' as a flag, and only remove it,
if this flag isn't NO.
AudioUnitRemoveRenderNotify(reverbUnit,(AURenderCallback)myInputCallbac
k,self);
// you only remove the callback once.
AUGraphStop(mainGraph);
AUGraphUninitialize(mainGraph);
AUGraphClose(mainGraph);
}
My suggestion for a GUI would be something like a tape..
Have a...
* record button that toggles record on/off, but doesn't rewind. Eg. a
record/pause/record/pause.
* rewind button that goes to the beginning of the recorded buffer
* play/pause button that replays the buffer
* 'go to end' button, so the recording can be continued from where it
left off. (depends on how the application will be used, though).
-It's always good to "emulate" a tape-recorder; the UI will be very
easy to learn for new users that way. =)
I've probably gone way too detailed, but it's probably better than
skipping a few things that could be of interest to you. ;)
Love,
Jens
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.