Re: Cocoa and PortAudio
Re: Cocoa and PortAudio
- Subject: Re: Cocoa and PortAudio
- From: David Remahl <email@hidden>
- Date: Thu, 17 Oct 2002 14:46:09 +0200
I already replied to Jont Olof privately (in Swedish), but with this
additional information I can give a better structured response.
The key is to use the userData pointer which is passed to the callback to
get an entrypoint back into the object in question. Since the callback is
not a member of the class MyDocument, it has no access to the slider outlet.
Instead, you should hook up the slider to an action in the document object
and from there store the float pitch value away. When creating the audio
stream, you should make sure that you pass (void*)self as the userData
parameter.
Also create an accessor for the pitch float in your document subclass:
- (float)pitchValue
{
return pitchValue
}
Then you do something like this in the callback (I am not quite sure what
the userData structure is, but you should add a pointer to the Document
somewhere in that structure):
static int jontesCallback(void *inputBuffer, void *outputBuffer,
>
unsigned long framesPerBuffer,
>
PaTimestamp outTime, void *userData)
>
{
>
// TypeCasting av userData och outPutBuffer
>
>
jontesTestData *data = (jontesTestData*)userData;
>
float *out = (float*)outputBuffer;
// cut
>
for( i = 0; i < framesPerBuffer; i++ )
>
{
>
*out++ = data -> left_phase;
>
*out++ = data -> right_phase;
>
>
data -> left_phase += [data->docObj pitchValue] * 0.01f;
>
if( data -> left_phase >= 1.0f )
>
{
>
data -> left_phase -= 2.0f;
>
}
>
>
data -> right_phase += [data->docObj pitchValue] * 0.01f;
>
if ( data -> right_phase >= 1.0f )
>
{
>
data -> right_phase -= 2.0f;
>
}
>
}
>
return 0;
>
}
I hope this makes some sense!
/ Rgds, David Remahl
>
> I think you need to give us more details. Please show us the whole of
>
> the
>
> callback code and please copy & paste the error message instead of
>
> paraphrasing it. It still doesn't look like a C++ versus Obj-C issue -
>
> it
>
> seems simpler than that.
>
>
Okay. Here's the Document-files for the app. In the project of course
>
I've also included all the PortAudio-files required to use the API, but
>
these are the only files I've been messing around with. Are the
>
portAudio-files of importance as well? In that case they can be found at
>
http://www.portaudio.com.
>
>
the JontesCallbackfunction looks like this (modified for
>
pitch-modification via an NSSlider named pitchSlide, comments excluded:
>
>
#import "MyDocument.h"
>
>
static int jontesCallback(void *inputBuffer, void *outputBuffer,
>
unsigned long framesPerBuffer,
>
PaTimestamp outTime, void *userData)
>
{
>
// TypeCasting av userData och outPutBuffer
>
>
jontesTestData *data = (jontesTestData*)userData;
>
float *out = (float*)outputBuffer;
>
>
unsigned int i;
>
>
>
(void) outTime; // to prevent unused variable warnings.
>
(void) inputBuffer;
>
>
>
>
for( i = 0; i < framesPerBuffer; i++ )
>
{
>
*out++ = data -> left_phase;
>
*out++ = data -> right_phase;
>
>
data -> left_phase += [pitchSlider floatValue] * 0.01f;
>
if( data -> left_phase >= 1.0f )
>
{
>
data -> left_phase -= 2.0f;
>
}
>
>
data -> right_phase += [pitchSlider floatValue] * 0.01f;
>
if ( data -> right_phase >= 1.0f )
>
{
>
data -> right_phase -= 2.0f;
>
}
>
}
>
return 0;
>
}
>
>
>
@implementation MyDocument { .. }
>
>
>
The error message I get is:
>
>
Compiling MyDocument.mm (1 error)
>
"pitchSlider" undeclared (first use this function) (Each undeclared
>
identifier is reported only once for each function is appears in.)
>
>
>
Thanx in advance
>
>
/Jont Olof
>
/* MyDocument */
>
>
#import <Cocoa/Cocoa.h>
>
#import <iostream.h>
>
#import <math.h>
>
#import "portaudio.h"
>
#define NUM_SECONDS (4)
>
#define SAMPLE_RATE (44100)
>
>
typedef struct
>
{
>
float left_phase;
>
float right_phase;
>
}
>
jontesTestData;
>
>
>
static jontesTestData data;
>
>
>
@interface MyDocument : NSDocument
>
{
>
PortAudioStream *stream;
>
PaError err;
>
IBOutlet NSSlider *pitchSlider;
>
}
>
- (IBAction)audioStart:(id)sender;
>
- (IBAction)audioStop:(id)sender;
>
@end
_______________________________________________
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.