/*
 * libsndfile_lite.h -- a minimal interface to Erik de Castro Lopo's libsndfile
 *
 * Made for use with Visualworks Smalltalk DLLCC
 * Stephen Pope -- stp@create.ucsb.edu -- 2003.07.16
 */

/******* Function Prototypes ********/

/* open/close sound files */

int openSndFile(char * name, unsigned mode);
int createSndFile(char * name, unsigned mode, unsigned format, 
			unsigned rate, unsigned channels);
int closeSndFile(unsigned which);

/* get sound file header data */

int getSndFileFormat(unsigned which);
int getSndFileRate(unsigned which);
int getSndFileChannels(unsigned which);
int getSndFileFrames(unsigned which);

/* seek within a sound file */

int seekSndFile(unsigned which, unsigned pos, unsigned key);

/* read/write float samples */

int readSndFileFSamples(unsigned which, float * where, unsigned count);
int writeSndFileFSamples(unsigned which, float * where, unsigned count);

/* read/wrote short samples */

int readSndFileISamples(unsigned which, short * where, unsigned count);
int writeSndFileISamples(unsigned which, short * where, unsigned count);

/******************************************************************************************
 * portaudio_lite.h -- minimal interface to the portaudio library
 *
 * Made for use with Visualworks Smalltalk DLLCC
 * Stephen Pope -- stp@create.ucsb.edu -- 2003.07.16
 *
 * Notes:
 *	Most of these return 0 on success.
 *	They return other values (like -1) on non-fatal errors and use oeFail on fatal errors.
 *	I currently use the default device for the stream, ignoring the first arg to the open call.
 */

/******* Function Prototypes ********/

/* initialize/terminate portaudio */

int pa_initialize(void);
int pa_terminate(void);

/* open the stream */

int pa_open(int device, unsigned in_ch, unsigned out_ch, 
		unsigned long format, unsigned rate, unsigned blockSize,
		_oop in_sem, _oop out_sem,
		short * in_buffer, short * out_buffer);

/* start/stop/close the default PA stream */

int pa_start(void);
int pa_stop(void);
int pa_close(void);

/* send up a sample buffer */

void pa_input(short * where, int count);

/* request the next output buffer */

void pa_output(short * where, int count);

/******************************************************************************************
 * portmidi_lite.h -- minimal interface to the portmidi library
 *
 * Made for use with Visualworks Smalltalk DLLCC
 * Stephen Pope -- stp@create.ucsb.edu -- 2003.07.18
 *
 * ToDo: 
 *	controller cacheing
 *	blocking read
 *
 */

/******* Function Prototypes ********/

/* initialize/terminate portmidi */

int pm_initialize(void);
int pm_terminate(void);

/* open/close the I/O stream */

int pm_open(int device, unsigned in, unsigned out);
int pm_close(void);

/* devices */

int pm_count_devices(void);
int pm_default_input_device(void);
int pm_default_output_device(void);

/* I/O */

int pm_poll(void);			/* return 1 if data available */
long pm_read(void);		/* blocking read (will be run in a separate thread) */

int pm_write_short(long msg);	/* 3 bytes encoded into a long */
int pm_write_data3(unsigned char d1, unsigned char d2, unsigned char d3);
int pm_write_data2(unsigned char d1, unsigned char d2);
int pm_write_long(long * msg, unsigned length);

/* test -- play a note*/

void pm_test(void);

/******************************************************************************************
 * fftw_lite.h -- a minimal interface to the FFTW FFT library
 *
 * Made for use with Visualworks Smalltalk DLLCC
 * Stephen Pope -- stp@create.ucsb.edu -- 2003.07.17
 */

/******** Complex data type ********/

/* typedef fftwf_complex float[2]; */

/******* Function Prototypes ********/

/* initialize FFTW data structures and plans */

int fftw_initialize(unsigned size, float * samples, float /* fftwf_complex */ * spectrum);

/* perform forward/reverse FFT */

void fftw_forward_transform(void);
void fftw_reverse_transform(void);

/* int/float block copy to/from float sample buffer */

void fftw_short_to_float(short * data);
void fftw_int_to_float(int * data);

void fftw_float_to_short(short * data);
void fftw_float_to_int(int * data);

/* block copy of spectrum to magnitude buffer */

void fftw_mag_spectrum(float * data);
