Re: only on cocoa?
Re: only on cocoa?
- Subject: Re: only on cocoa?
- From: Benjamin Golinvaux <email@hidden>
- Date: Mon, 13 Aug 2001 02:31:04 +0200
You will not avoid at least one C function in your
code which is the audio callback, but you can
make it very short.
Maybe you could pass the id of your object through defptr
and have the C audioCallback function call some method in
your object with the right parameters :
OSStatus audioCallback (AudioDeviceID inDevice, const AudioTimeStamp*
inNow, ..., void *defptr)
{
id obj = (id)defptr; // though I guess id is just a typedef for
void* so this cast should be useless...
[defptr audioCallbackOnDevice:inDevice Now:inNow ...];
}
That implies the C function is compiled by the ObjC compiler, not in a
.c file.
hth
Benjamin Golinvaux
www.arboretum.com
On Monday, August 13, 2001, at 02:07 AM, email@hidden wrote:
Hi, Thanks a lot for the link James. I've been given myself a crash
course/refresher in Obj-C and Cocoa development this weekend, so I've
actually managed to progress a little bit in terms of the point of my
question about Obj-C and the CoreAudio APIs. The thing is that I would
like to write a callback, for instance an AudioDeviceIOProc, in a way
that maintains the object-oriented nature of Obj-C and my classes. It
seems that you can't write it that way. The way James' handled it was by
writing an object oriented class and then writing the AudioDeviceIOProc
method as a C function
OSStatus audioCallback (AudioDeviceID inDevice, const AudioTimeStamp*
inNow, ..., void *defptr) {}
so it can't access any of the object's variables directly but only
through
a struct defined as
typedef struct {
@defs(ClassNameGoesHere);
} classnamegoesheredef;
and passed to the AudioDevice so it passes the struct as the defptr
argument in the class' AudioDeviceIOProc function. So, basically unless
there's some way for me to write an AudioDeviceIOProc as "real" Obj-C
method i.e.
- (OSStatus) audioCallback: (AudioDeviceID) inDevice
inNow: (const AudioTimeStamp*)inNow
inInputData: (const AudioBufferList*)inInputData
etc...
it looks like I have to write struct defs for every object I want to
access in the callback. If anyone knows how to pass an Obj-C instance
method as an AudioDeviceIOProc don't read further and just let me know
(sample code appreciated). I'm fairly certain it can't be done, so
now I have to figure out how to be able to access multiple different
objects (instances) and hopefully make it so I can only modify some
instance variables whereas others I can get the value of the variables
but
cannot change (ie. have accessor methods through this struct I pass in).
I'm really disappointed in the way it seems the interaction with this
API
is going to have to work and restructure my program from being object
oriented to being "kinda' object oriented" and I'll have to relearn all
the arcane ways of advanced C and figure out how to combine that with
object oriented programming as done with Obj-C code. It seems like more
of
a kludge than blending pascal and C as those two had similar, simple
ways
of modelling data and process flow.
Thanks for any advice/flames,
Ben
On Sat, 11 Aug 2001, James McCartney wrote:
on 8/11/01 3:20 AM, email@hidden at email@hidden
wrote:
Obj-C is C and the API is C, so you just make C calls.
For an example see my simple Cocoa demo app :
http://www.audiosynth.com/sinewavedemo.html
--- james mccartney email@hidden
<http://www.audiosynth.com>
SuperCollider - a real time synthesis programming language for the
PowerMac.
<ftp://www.audiosynth.com/pub/updates/SC2.2.10.sea.hqx>
_______________________________________________
coreaudio-api mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/coreaudio-api