|
From: Johnny P. <ele...@us...> - 2004-04-23 14:39:55
|
Update of /cvsroot/xpanda/Panda/Drivers/Portaudio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21900/Portaudio Added Files: main.cpp compile-mingw.sh Log Message: Portaudio driver --- NEW FILE: main.cpp --- /* Portaudio - Portaudio Panda driver. written by Giovanni Petrantoni. Copyright (c) 2003, Giovanni Petrantoni. http://xpanda.sf.net/ main.cpp - main file. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA elementicaotici - by Johnny (Giovanni) Petrantoni, ITALY - Rome. e-mail: jo...@la... */ #include <Panda/panda.h> #include "portaudio.h" struct __myObjData { DriverParamList list; int inCh; int outCh; bool isConfigured; float sampleRate; long bufferSize; char driverName[60]; PortAudioStream* stream; float **inBuffer,**outBuffer; }; static int paCallback(void *inputBuffer, void *outputBuffer,unsigned long framesPerBuffer,PaTimestamp outTime, void *userData) { MyData *x = (MyData*)userData; float *in,*out; in = (float*)inputBuffer; out = (float*)outputBuffer; for(int chn=0;chn<x->inCh;chn++) { for (unsigned long i = 0; i< framesPerBuffer; i++) x->inBuffer[chn][i] = in[chn+(i*x->inCh)]; } doPandaRender(framesPerBuffer); for(int chn=0;chn<x->outCh;chn++) { for (unsigned long i = 0; i< framesPerBuffer; i++) out[chn+(i*x->outCh)] = x->outBuffer[chn][i]; } return 0; } MyData * HelloPandaDriver(void) { MyData *x; x = (MyData*)malloc(sizeof(MyData)); x->list.manyParameters = 5; x->list.parameterDesc = (char**)malloc(sizeof(char*)*x->list.manyParameters); x->list.parameterType = (int*)malloc(sizeof(int)*x->list.manyParameters); x->list.parameterID = (int*)malloc(sizeof(int)*x->list.manyParameters); for(int i=0;i<x->list.manyParameters;i++) { x->list.parameterDesc[i] = (char*)malloc(sizeof(char)*60); } strcpy(x->list.parameterDesc[0],"Input Channels"); x->list.parameterType[0] = INT_T; x->list.parameterID[0] = 'inch'; strcpy(x->list.parameterDesc[1],"Output Channels"); x->list.parameterType[1] = INT_T; x->list.parameterID[1] = 'ouch'; strcpy(x->list.parameterDesc[2],"Device Name"); x->list.parameterType[2] = CHAR_T; x->list.parameterID[2] = 'devn'; strcpy(x->list.parameterDesc[3],"Sample Rate"); x->list.parameterType[3] = CHAR_T; x->list.parameterID[3] = 'sr '; strcpy(x->list.parameterDesc[4],"Buffer Size"); x->list.parameterType[4] = CHAR_T; x->list.parameterID[4] = 'bsiz'; x->inCh = 0; x->outCh = 2; x->sampleRate = 44100.0f; x->bufferSize = 512L; strcpy(&x->driverName[0],"DEFAULT"); x->isConfigured = false; return x; } void FlushDriver(MyData *x) { for(int i=0;i<x->list.manyParameters;i++) { free(x->list.parameterDesc[i]); } free(x->list.parameterDesc); free(x->list.parameterType); free(x->list.parameterID); if(x->isConfigured) { Pa_CloseStream(x->stream); Pa_Terminate(); } } extern "C" int portaudio_load_default (MyData *driver, int numDevices, int capturing, int playing, int* inputDeviceID, int* outputDeviceID) { const PaDeviceInfo *pdi; int i,j; int found = 0; printf("Look for default driver\n"); *inputDeviceID = Pa_GetDefaultInputDeviceID(); *outputDeviceID = Pa_GetDefaultOutputDeviceID(); for(i=0; i<numDevices; i++) { pdi = Pa_GetDeviceInfo(i); printf("---------------------------------------------- #%d\n", i); if (i == Pa_GetDefaultInputDeviceID()) { driver->inCh = (capturing) ? pdi->maxInputChannels : 0; strcpy (&driver->driverName[0],pdi->name); found = 1; } if (i == Pa_GetDefaultOutputDeviceID()){ driver->outCh = (playing) ? pdi->maxOutputChannels : 0; strcpy (&driver->driverName[0],pdi->name); found = 1; } printf("\nName = %s\n", pdi->name); printf("Max Inputs = %d ", pdi->maxInputChannels); printf("Max Outputs = %d\n", pdi->maxOutputChannels); if( pdi->numSampleRates == -1 ){ printf("Sample Rate Range = %f to %f\n", pdi->sampleRates[0], pdi->sampleRates[1]); }else{ printf("Sample Rates ="); for(j=0; j<pdi->numSampleRates; j++){ printf(" %8.2f,", pdi->sampleRates[j]); } printf("\n"); } printf("Native Sample Formats = "); if( pdi->nativeSampleFormats & paInt8 ) printf("paInt8, "); if( pdi->nativeSampleFormats & paUInt8 ) printf("paUInt8, "); if( pdi->nativeSampleFormats & paInt16 ) printf("paInt16, "); if( pdi->nativeSampleFormats & paInt32 ) printf("paInt32, "); if( pdi->nativeSampleFormats & paFloat32 ) printf("paFloat32, "); if( pdi->nativeSampleFormats & paInt24 ) printf("paInt24, "); if( pdi->nativeSampleFormats & paPackedInt24 ) printf("paPackedInt24, "); printf("\n"); } return found; } extern "C" int portaudio_load_driver (MyData *driver, int numDevices, int capturing, int playing, int* inputDeviceID, int* outputDeviceID, char* driver_name) { const PaDeviceInfo *pdi; int found = 0; int i,j; printf("Look for %s driver\n",driver_name); for(i=0; i<numDevices; i++) { pdi = Pa_GetDeviceInfo(i); printf("---------------------------------------------- #%d\n", i); if (strcmp(driver_name,pdi->name) == 0) { // compare the JACK_DRIVER_PARAM_STRING_MAX first character if (pdi->maxInputChannels > 0) { *inputDeviceID = i; driver->inCh = (capturing) ? pdi->maxInputChannels : 0; strcpy(&driver->driverName[0],pdi->name); printf("Found input driver = %s\n", driver_name); found = 1; }else if (pdi->maxOutputChannels > 0) { *outputDeviceID = i; driver->outCh = (playing) ? pdi->maxOutputChannels : 0; strcpy (&driver->driverName[0],pdi->name); printf("Found output driver = %s\n", driver_name); found = 1; }else { printf("Found driver without input or ouput = %s\n", driver_name); } } printf("\nName = %s\n", pdi->name); printf("Max Inputs = %d ", pdi->maxInputChannels); printf("Max Outputs = %d\n", pdi->maxOutputChannels); if( pdi->numSampleRates == -1 ){ printf("Sample Rate Range = %f to %f\n", pdi->sampleRates[0], pdi->sampleRates[1]); }else{ printf("Sample Rates ="); for(j=0; j<pdi->numSampleRates; j++){ printf(" %8.2f,", pdi->sampleRates[j]); } printf("\n"); } printf("Native Sample Formats = "); if( pdi->nativeSampleFormats & paInt8 ) printf("paInt8, "); if( pdi->nativeSampleFormats & paUInt8 ) printf("paUInt8, "); if( pdi->nativeSampleFormats & paInt16 ) printf("paInt16, "); if( pdi->nativeSampleFormats & paInt32 ) printf("paInt32, "); if( pdi->nativeSampleFormats & paFloat32 ) printf("paFloat32, "); if( pdi->nativeSampleFormats & paInt24 ) printf("paInt24, "); if( pdi->nativeSampleFormats & paPackedInt24 ) printf("paPackedInt24, "); printf("\n"); } return found; } int CreateAudioEngine(MyData *x) { if(Pa_Initialize()!=paNoError) return FALSE; int inputDeviceID,outputDeviceID; int numDevices = Pa_CountDevices(); int found = -1; if (strcmp(&x->driverName[0],"DEFAULT") == 0) { found = portaudio_load_default(x,numDevices,TRUE,TRUE,&inputDeviceID,&outputDeviceID); if (!found) { printf("ERROR : default driver has not been found\n"); return FALSE; } }else{ found = portaudio_load_driver(x,numDevices,TRUE,TRUE,&inputDeviceID,&outputDeviceID,&x->driverName[0]); if (!found) { printf("ERROR : driver %s has not been found \n",&x->driverName[0]); return FALSE; } } int err = Pa_OpenStream(&x->stream, x->inCh > 0 ? inputDeviceID : paNoDevice, x->inCh, paFloat32, // 32 bit floating point input NULL, x->outCh > 0 ? outputDeviceID : paNoDevice, x->outCh, paFloat32, // 32 bit floating point output NULL, x->sampleRate, x->bufferSize, // frames per buffer 0, // number of buffers, if zero then use default minimum paClipOff, // we won't output out of range samples so don't bother clipping them paCallback, x); if(err!=paNoError) return FALSE; if(x->inCh>0) { x->inBuffer = (float**)malloc(sizeof(float*)*x->inCh); for(int i=0;i<x->inCh;i++) { x->inBuffer[i] = (float*)malloc(sizeof(float)*x->bufferSize); } } if(x->outCh>0) { x->outBuffer = (float**)malloc(sizeof(float*)*x->outCh); for(int i=0;i<x->outCh;i++) { x->outBuffer[i] = (float*)malloc(sizeof(float)*x->bufferSize); } } setDAC(x->outBuffer); setADC(x->inBuffer); SetPandaBufferSize(x->bufferSize); SetPandaSampleRate(x->sampleRate); SetPandaInChannels(x->inCh); SetPandaOutChannels(x->outCh); x->isConfigured = TRUE; return TRUE; } int StartAudio(MyData *x) { if(!x->isConfigured) return FALSE; PaError err = Pa_StartStream(x->stream); return err == paNoError ? TRUE : FALSE; } int StopAudio(MyData *x) { if(!x->isConfigured) return FALSE; PaError err = Pa_StopStream(x->stream); return err == paNoError ? TRUE : FALSE; } int SetParameter(MyData *x,int parameter,Var *inValues) { if(!inValues) return FALSE; switch(parameter) { case 'inch': if(inValues->varType==INT_T) x->inCh = *(int*)inValues->var_t; else return FALSE; break; case 'ouch': if(inValues->varType==INT_T) x->outCh = *(int*)inValues->var_t; else return FALSE; break; case 'devn': if(inValues->varType==CHAR_T) strcpy(&x->driverName[0],(char*)inValues->var_t); else return FALSE; break; case 'sr ': if(inValues->varType==FLOAT_T) x->sampleRate = *(float*)inValues->var_t; else return FALSE; break; case 'bsiz': if(inValues->varType==LONG_T) x->bufferSize = *(long*)inValues->var_t; else return FALSE; break; default: return FALSE; } return TRUE; } int GetParameter(MyData *x,int parameter,Var *outValues) { if(!outValues) return FALSE; switch(parameter) { case 'inch': if(outValues->varType==INT_T) *(int*)outValues->var_t = x->inCh; else return FALSE; break; case 'ouch': if(outValues->varType==INT_T) *(int*)outValues->var_t = x->outCh; else return FALSE; break; case 'devn': if(outValues->varType==CHAR_T) strcpy((char*)outValues->var_t,&x->driverName[0]); else return FALSE; break; case 'sr ': if(outValues->varType==FLOAT_T) *(float*)outValues->var_t = x->sampleRate; else return FALSE; break; case 'bsiz': if(outValues->varType==LONG_T) *(long*)outValues->var_t = x->bufferSize; else return FALSE; break; default: return FALSE; } return TRUE; } DriverParamList GetParametersList(MyData *x) { return x->list; } --- NEW FILE: compile-mingw.sh --- gcc -c -Iportaudio_v18_1/pa_common -I. -o pablio.o portaudio_v18_1/pablio/pablio.c gcc -c -Iportaudio_v18_1/pa_common -I. -o ringbuffer.o portaudio_v18_1/pablio/ringbuffer.c gcc -c -Iportaudio_v18_1/pa_common -I. -o pa_convert.o portaudio_v18_1/pa_common/pa_convert.c gcc -c -Iportaudio_v18_1/pa_common -I. -o pa_lib.o portaudio_v18_1/pa_common/pa_lib.c gcc -c -Iportaudio_v18_1/pa_common -I. -o pa_trace.o portaudio_v18_1/pa_common/pa_trace.c gcc -c -Iportaudio_v18_1/pa_common -I. -o pa_win.o portaudio_v18_1/pa_win_wmme/pa_win_wmme.c gcc -c -Iportaudio_v18_1/pa_common -I. -o main.o main.cpp gcc -shared -fPIC -D__WIN32__=1 Panda/panda.dll -lstdc++ -o portaudio.dll *.o /mingw/lib/libwinmm.a |