Cocoa and PortAudio!
Cocoa and PortAudio!
- Subject: Cocoa and PortAudio!
- From: email@hidden
- Date: Wed, 16 Oct 2002 22:01:00 +0200
Hi all!
I'm an audio engineering student from sweden with a great interest in
audio programming. I've been programming Cocoa for a while now (I've
read Cocoa Programming for Mac OS X, by Hillegass, Learning Cocoa by
Apple and Building Cocoa Applications along with some Carbon
literature) but I still have quite a lot to learn.
Last week I found out about Port Audio, a crossplatform API for
audio-development. I've come as far as to understand the very first
tutorial which produce a sawtooth - tonegenerator.
As I had figured out how the tutorial worked I wanted to make a
graphical interface to it. I succeeded and made a very simple graphical
interface with a start and a stop button. But it wasn't very exciting!
As I tried to improve it with a Cocoa interface I ran into some
problems that the PortAudio-people suggested I should ask you guys.
So, here's the problem. I wanted to implement an NSSlider to change to
pitch of the tone. That wouldn't be much of a problem if it weren't for
the fact that the function that writes the audio buffer is declared as
a normal C++-function and I didn't know but to put it outside of the
implementation of my "MyDocument"-file. It looks something like this in
my Cocoa-App.
static int jontesCallback(void* inputBuffer, void* outputBuffer,
unsigned long framesPerBuffer, PATimestamp outTime, void*
userData)
{
/.../
for( i=0; i<framesPerBuffer; i++ )
{
*out++ = data->left_phase; /* left */
*out++ = data->right_phase; /* right */
/* Generate simple sawtooth phaser that ranges between -1.0 and
1.0. */
data->left_phase += 0.01f;
/* When signal reaches top, drop back down. */
if( data->left_phase >= 1.0f ) data->left_phase -= 2.0f;
/* higher pitch so we can distinguish left and right. */
data->right_phase += 0.03f;
if( data->right_phase >= 1.0f ) data->right_phase -= 2.0f;
}
return 0;
}
@implementation MyDocument
{
...
}
Now, if I wanted to alter the pitch I figured that the only thing I had
to do was to multiply 0.01f (in data->left_phase += 0.01f) with a float
of some kind. My excellent idea was to modify the nib-fil to add an
NSSlider called pitchSlide and then do the following method-call:
data -> left_phase += [pitchSlide floatValue] * 0.01f;
The compiler hates me though. It complains about the function
pitchSlide not beeing defined and so on.
I am aware that it probably has something to do with this function
beeing implemented as a C++-function. I don't know though how to change
it. I tried to make a sawtooth-class, but I don't know how to implement
a class like the one above in Cocoa and in such a way that PortAudio
will understand it.
If this is an understandable problem, and you know how to help me,
please do!
/Jont Olof
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.