Right then, this is taxing my poor brain.....
I've written a simple mp3 player using MAD and JACK in C. This works a treat. I now want to encapsulate this into a class and stick in a Qt application. I've copied the code into a class structure and I'm trying to compile it. JACK uses a callback mechanism to send data to the sound system. Under C i used 4 functions to assign callbacks to functions. I've added these functions into the class. The class definition looks like this:
Code:
class MP3Play : public QWidget
{
public:
MP3Play( QWidget *parent=0, const char *name=0 );
int Load(QString);
private:
const char *ProgName;
int default_driver;
char *buffer;
int buf_size;
int sample;
int iCount;
SNDFILE *sf;
//typedef double sample_t;
typedef jack_default_audio_sample_t sample_t;
struct mad_stream Stream;
struct mad_frame Frame;
struct mad_synth Synth;
mad_timer_t Timer;
unsigned char InputBuffer[INPUT_BUFFER_SIZE+MAD_BUFFER_GUARD], OutputBuffer[OUTPUT_BUFFER_SIZE], *OutputPtr, *GuardPtr;
const unsigned char *OutputBufferEnd;
int Status, i, iSpill, bdecode;
unsigned long FrameCount;
bstdfile_t *BstdFile;
FILE *InputFp;
sample_t spill_l[1152];
sample_t spill_r[1152];
FILE *mp3file;
jack_client_t *client;
const char **ports;
/*Our output port*/
jack_port_t *output_port_l,*output_port_r;
/*The current sample rate*/
jack_nframes_t sr;
int process (jack_nframes_t, void *);
int srate (jack_nframes_t, void *);
void error (const char *);
void jack_shutdown (void *);
};
The JACK specific initalisation code looks this:
Code:
jack_set_error_function (MP3Play::error);
jack_set_process_callback (client, MP3Play::process, 0);
jack_set_sample_rate_callback (client, MP3Play::srate, 0);
jack_on_shutdown (client, MP3Play::jack_shutdown, 0);
The compiler errors look like this:
Code:
mp3playback.cpp: In member function `int MP3Play::Load(QString)':
mp3playback.cpp:118: error: no matches converting function `error' to type `
void (*)(const char*)'
mp3playback.cpp:76: error: candidates are: void MP3Play::error(const char*)
mp3playback.cpp:126: error: no matches converting function `process' to type `
int (*)(unsigned int, void*)'
mp3playback.cpp:74: error: candidates are: int MP3Play::process(unsigned int,
void*)
mp3playback.cpp:127: error: no matches converting function `srate' to type `int
(*)(unsigned int, void*)'
mp3playback.cpp:75: error: candidates are: int MP3Play::srate(unsigned int,
void*)
mp3playback.cpp:128: error: no matches converting function `jack_shutdown' to
type `void (*)(void*)'
mp3playback.cpp:77: error: candidates are: void MP3Play::jack_shutdown(void*)
All I want is to completely encapsulate the code into a class, so I can initialise as many players I need.
Any pointers? (Pardon the pun)