Re: Playing AudioBuffers from Memory
Re: Playing AudioBuffers from Memory
- Subject: Re: Playing AudioBuffers from Memory
- From: Jens Bauer <email@hidden>
- Date: Tue, 10 Feb 2004 06:01:36 +0100
Hi Craig,
I am having a brain freeze on how to unwrap the Ptr.
To establish communication between the callbacks, the best approach,
would be to pass a pointer in the refCon (aka. userData).
When you install your callback, you give CoreAudio a callback pointer
along with a data pointer. The data pointer is your own; it *could*
even be just a longword of flags, but in most cases, it'd be much more
useful to pass a structure pointer.
You should usually not pass exactly the same userData to both the
recordCallback and the playbackCallback.
Eg.
typedef struct MyChannel MyChannel;
struct MyChannel
{
float left;
float right;
};
typedef struct MyUserData MyUserData;
struct MyUserData
{
MyWindowController *wc; /* eh... sorry about that name. =) */
double sampleRate; /* Used by both kinds of callbacks */
MyUserData *otherUserData; /* The playbackCallback's otherUserData
points to the recordCallback's userData and vice versa */
UInt32 head; /* current write index in buffer */
UInt32 tail; /* current read index in buffer */
UInt32 size; /* size of buffer */
MyChannel *buffer; /* some data buffer */
...
/* other info */
...
};
Then allocate one buffer for the playback and one for the record
functions.
Your callback shouldn't really need to know the window controller, all
the data your callbacks need should be stored in your UserData
structure, so you can split your sources better, otherwise your
callback would be wired to the window controller, and couldn't be used
from another kind of controller.
Now, when both buffers are created, do this:
playbackUserInfo->otherUserData = recordUserInfo;
recordUserInfo->otherUserData = playbackUserInfo;
...Then you can access the other callback's data from the active
callback. Ofcourse, there are many ways to do it. =)
-The worst way, would be to have a static variable holding a buffer.
Worst, because you can't have more than one document then. ;)
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.