Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21476
Modified Files: Tag: desiredata s_audio_oss.c s_audio_portaudio.c s_main.c Log Message: switch audio and midi to C++
Index: s_audio_oss.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_audio_oss.c,v retrieving revision 1.6.4.2.2.2.2.3 retrieving revision 1.6.4.2.2.2.2.4 diff -C2 -d -r1.6.4.2.2.2.2.3 -r1.6.4.2.2.2.2.4 *** s_audio_oss.c 30 Jun 2007 20:30:18 -0000 1.6.4.2.2.2.2.3 --- s_audio_oss.c 9 Jul 2007 17:51:14 -0000 1.6.4.2.2.2.2.4 *************** *** 66,70 **** static int oss_blockmode = 0; /* flag to use "blockmode" */ static int oss_32bit = 0; /* allow 23 bit transfers in OSS */ - static char ossdsp[] = "/dev/dsp%d";
/* don't assume we can turn all 31 bits when doing float-to-fix; --- 66,69 ---- *************** *** 88,93 **** for (i = 0; i < 10; i++) { char devname[100]; ! if (i == 0) strcpy(devname, "/dev/dsp"); ! else sprintf(devname, "/dev/dsp%d", i); if ((fd = open(devname, O_WRONLY|O_NONBLOCK)) != -1) { oss_ndev++; --- 87,91 ---- for (i = 0; i < 10; i++) { char devname[100]; ! if (i == 0) strcpy(devname, "/dev/dsp"); else sprintf(devname, "/dev/dsp%d", i); if ((fd = open(devname, O_WRONLY|O_NONBLOCK)) != -1) { oss_ndev++; *************** *** 162,166 **** } /* post("adv_samples %d", sys_advance_samples); */ ! nfragment = (sys_schedadvance * (44100. * 1.e-6)) / linux_fragsize; fragbytes = linux_fragsize * (dev->d_bytespersamp * nchannels); logfragsize = ilog2(fragbytes); --- 160,164 ---- } /* post("adv_samples %d", sys_advance_samples); */ ! nfragment = int(sys_schedadvance * 44100.e-6 / linux_fragsize); fragbytes = linux_fragsize * (dev->d_bytespersamp * nchannels); logfragsize = ilog2(fragbytes); *************** *** 222,226 ****
int oss_open_audio(int nindev, int *indev, int nchin, int *chin, ! int noutdev, int *outdev, int nchout, int *chout, int rate) { /* IOhannes */ int capabilities = 0; --- 220,224 ----
int oss_open_audio(int nindev, int *indev, int nchin, int *chin, ! int noutdev, int *outdev, int nchout, int *chout, int rate, int bogus) { /* IOhannes */ int capabilities = 0; *************** *** 249,255 **** goto end_out_loop;
! if (thisdevice > 0) ! sprintf(devname, "/dev/dsp%d", thisdevice); ! else sprintf(devname, "/dev/dsp"); /* search for input request for same device. Succeed only if the number of channels matches. */ --- 247,251 ---- goto end_out_loop;
! if (thisdevice > 0) sprintf(devname, "/dev/dsp%d", thisdevice); else sprintf(devname, "/dev/dsp"); /* search for input request for same device. Succeed only if the number of channels matches. */ *************** *** 332,371 **** int wantchannels = (nchin>n)?chin[n]:wantmore; int alreadyopened = 0; ! if (!wantchannels) ! goto end_in_loop; ! ! if (thisdevice > 0) ! sprintf(devname, "/dev/dsp%d", thisdevice); ! else sprintf(devname, "/dev/dsp"); ! sys_setalarm(1000000); ! ! /* perhaps it's already open from the above? */ if (linux_dacs[n].d_fd >= 0) { fd = linux_adcs[n].d_fd; alreadyopened = 1; } else { ! /* otherwise try to open it here. */ if ((fd = open(devname, O_RDONLY | O_AUDIOFLAG)) == -1) { post("%s (readonly): %s", devname, strerror(errno)); goto end_in_loop; } ! if (fcntl(fd, F_SETFD, 1) < 0) ! post("couldn't set close-on-exec flag on audio"); ! if ((flags = fcntl(fd, F_GETFL)) < 0) ! post("couldn't get audio device flags"); ! else if (fcntl(fd, F_SETFL, flags & (!O_NDELAY)) < 0) ! post("couldn't set audio device flags"); ! if (sys_verbose) ! post("opened %s for reading only\n", devname); } linux_adcs[linux_nindevs].d_fd = fd;
! gotchans = oss_setchannels(fd, ! (wantchannels>OSS_MAXCHPERDEV)?OSS_MAXCHPERDEV:wantchannels, ! devname); ! if (sys_verbose) ! post("opened audio input device %s; got %d channels", ! devname, gotchans);
if (gotchans < 1) { --- 328,353 ---- int wantchannels = (nchin>n)?chin[n]:wantmore; int alreadyopened = 0; ! if (!wantchannels) goto end_in_loop; ! if (thisdevice > 0) sprintf(devname, "/dev/dsp%d", thisdevice); else sprintf(devname, "/dev/dsp"); sys_setalarm(1000000); ! /* perhaps it's already open from the above? */ if (linux_dacs[n].d_fd >= 0) { fd = linux_adcs[n].d_fd; alreadyopened = 1; } else { ! /* otherwise try to open it here. */ if ((fd = open(devname, O_RDONLY | O_AUDIOFLAG)) == -1) { post("%s (readonly): %s", devname, strerror(errno)); goto end_in_loop; } ! if (fcntl(fd, F_SETFD, 1) < 0) post("couldn't set close-on-exec flag on audio"); ! if ((flags = fcntl(fd, F_GETFL)) < 0) post("couldn't get audio device flags"); ! else if (fcntl(fd, F_SETFL, flags & (!O_NDELAY)) < 0) post("couldn't set audio device flags"); ! if (sys_verbose) post("opened %s for reading only\n", devname); } linux_adcs[linux_nindevs].d_fd = fd;
! gotchans = oss_setchannels(fd, (wantchannels>OSS_MAXCHPERDEV)?OSS_MAXCHPERDEV:wantchannels, devname); ! if (sys_verbose) post("opened audio input device %s; got %d channels", devname, gotchans);
if (gotchans < 1) { *************** *** 376,386 **** linux_adcs[linux_nindevs].d_nchannels = gotchans; oss_configure(linux_adcs+linux_nindevs, rate, 0, alreadyopened); - inchannels += gotchans; linux_nindevs++; - wantmore = wantchannels-gotchans; ! /* LATER think about spreading large numbers of channels over ! various dsp's and vice-versa */ end_in_loop: ; } --- 358,365 ---- linux_adcs[linux_nindevs].d_nchannels = gotchans; oss_configure(linux_adcs+linux_nindevs, rate, 0, alreadyopened); inchannels += gotchans; linux_nindevs++; wantmore = wantchannels-gotchans; ! /* LATER think about spreading large numbers of channels over various dsp's and vice-versa */ end_in_loop: ; } *************** *** 611,615 **** lp = (t_oss_int32 *)buf; i--; fp1++, lp++) { float f = *fp1 * 2147483648.; ! *lp = (f >= 2147483647. ? 2147483647. : (f < -2147483648. ? -2147483648. : f)); } } else { --- 590,594 ---- lp = (t_oss_int32 *)buf; i--; fp1++, lp++) { float f = *fp1 * 2147483648.; ! *lp = int(f >= 2147483647. ? 2147483647. : (f < -2147483648. ? -2147483648. : f)); } } else { *************** *** 619,623 **** { for (j=0, fp2 = fp1; j<nchannels; j++, fp2 += sys_dacblocksize) { ! int s = *fp2 * 32767.; if (s > 32767) s = 32767; else if (s < -32767) s = -32767; --- 598,602 ---- { for (j=0, fp2 = fp1; j<nchannels; j++, fp2 += sys_dacblocksize) { ! int s = int(*fp2 * 32767.); if (s > 32767) s = 32767; else if (s < -32767) s = -32767;
Index: s_main.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_main.c,v retrieving revision 1.7.4.17.2.22.2.20 retrieving revision 1.7.4.17.2.22.2.21 diff -C2 -d -r1.7.4.17.2.22.2.20 -r1.7.4.17.2.22.2.21 *** s_main.c 29 Jun 2007 22:17:36 -0000 1.7.4.17.2.22.2.20 --- s_main.c 9 Jul 2007 17:51:14 -0000 1.7.4.17.2.22.2.21 *************** *** 40,44 **** extern int m_scheduler(); void sys_addhelppath(char *p); ! extern "C" void alsa_adddev(char *name); extern "C" int sys_parsercfile(char*filename);
--- 40,44 ---- extern int m_scheduler(); void sys_addhelppath(char *p); ! void alsa_adddev(char *name); extern "C" int sys_parsercfile(char*filename);
*************** *** 47,51 **** #endif /* THREDED_SF */
! char pd_version[] = "DesireData 2007.07.07"; char pd_compiletime[] = __TIME__; char pd_compiledate[] = __DATE__; --- 47,51 ---- #endif /* THREDED_SF */
! char pd_version[] = "DesireData 2007.06.30"; char pd_compiletime[] = __TIME__; char pd_compiledate[] = __DATE__; *************** *** 134,138 **** pd_init(); /* start the message system */ sys_findprogdir(argv[0]); /* set sys_progname, guipath */ - /* tb: command line flag to defeat preset loading */ for (i = 0; i != argc; ++i) if (!strcmp(argv[i],"-noprefs") || !strcmp(argv[i],"-rcfile")) noprefs = 1; --- 134,137 ---- *************** *** 143,148 **** if (sys_argparse(argc-1, argv+1)) return 1; /* parse cmd line */ sys_afterargparse(); /* post-argparse settings */ ! if (sys_verbose || sys_version) fprintf(stderr, "%scompiled %s %s\n", ! pd_version, pd_compiletime, pd_compiledate); if (sys_version) return 0; /* if we were just asked our version, exit here. */ if (sys_startgui()) return 1; /* start the gui */ --- 142,146 ---- if (sys_argparse(argc-1, argv+1)) return 1; /* parse cmd line */ sys_afterargparse(); /* post-argparse settings */ ! if (sys_verbose || sys_version) fprintf(stderr, "%s, compiled %s %s\n", pd_version, pd_compiletime, pd_compiledate); if (sys_version) return 0; /* if we were just asked our version, exit here. */ if (sys_startgui()) return 1; /* start the gui */ *************** *** 164,168 **** HINSTANCE ntdll; char filename[MAXPDSTRING]; - sprintf(filename, "%s.dll", sys_externalschedlibname); sys_bashfilename(filename, filename); --- 162,165 ---- *************** *** 172,177 **** return 0; } ! externalmainfunc = (t_externalschedlibmain)GetProcAddress(ntdll, ! "main"); return((*externalmainfunc)(sys_extraflagsstring)); #else --- 169,173 ---- return 0; } ! externalmainfunc = (t_externalschedlibmain)GetProcAddress(ntdll,"main"); return((*externalmainfunc)(sys_extraflagsstring)); #else
Index: s_audio_portaudio.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/s_audio_portaudio.c,v retrieving revision 1.1.2.21.2.2 retrieving revision 1.1.2.21.2.3 diff -C2 -d -r1.1.2.21.2.2 -r1.1.2.21.2.3 *** s_audio_portaudio.c 30 Jun 2007 20:28:14 -0000 1.1.2.21.2.2 --- s_audio_portaudio.c 9 Jul 2007 17:51:14 -0000 1.1.2.21.2.3 *************** *** 163,187 **** /* set block size */ blocksize=64; ! ! while ((float)blocksize / (float)rate * 1000 * 2 <advance) ! { ! if (blocksize == 1024) ! break; ! else ! blocksize *= 2; ! } pa_blocksize = blocksize;
/* initialize io buffer */ ! for (j=0; j != MAX_PA_CHANS;++j) ! { ! if (pa_inbuffer[j]) ! freealignedbytes(pa_inbuffer[j], 0); ! ! if (pa_outbuffer[j]) ! freealignedbytes(pa_outbuffer[j], 0); ! ! pa_inbuffer[j] = getalignedbytes((blocksize + sys_dacblocksize) * sizeof (float)); ! pa_outbuffer[j] = getalignedbytes((blocksize + sys_dacblocksize) * sizeof (float)); } pa_bufferpos = 0; --- 163,175 ---- /* set block size */ blocksize=64; ! while ((float)blocksize/(float)rate*1000*2 < advance && blocksize==1024) blocksize *= 2; pa_blocksize = blocksize;
/* initialize io buffer */ ! for (j=0; j != MAX_PA_CHANS;++j) { ! if (pa_inbuffer[j]) freealignedbytes(pa_inbuffer[j], 0); ! if (pa_outbuffer[j]) freealignedbytes(pa_outbuffer[j], 0); ! pa_inbuffer[j] = (float *)getalignedbytes((blocksize + sys_dacblocksize)*sizeof(float)); ! pa_outbuffer[j] = (float *)getalignedbytes((blocksize + sys_dacblocksize)*sizeof(float)); } pa_bufferpos = 0; *************** *** 197,211 **** /* patestCallback */, NULL);
! if (err == paNoError) ! { ! const PaStreamInfo * streaminfo = Pa_GetStreamInfo (pa_stream); ! t_atom atoms[4];
! t_symbol * pd = gensym("pd"); ! t_symbol * selector1 = gensym("audiocurrentininfo"); ! t_symbol * selector2 = gensym("audiocurrentoutinfo"); ! ! sys_schedadvance = 1e-6 * streaminfo->outputLatency;
SETFLOAT(atoms, (float)indeviceno); --- 185,196 ---- /* patestCallback */, NULL);
! if (err == paNoError) { ! const PaStreamInfo *streaminfo = Pa_GetStreamInfo(pa_stream); t_atom atoms[4]; + t_symbol *pd = gensym("pd"); + t_symbol *selector1 = gensym("audiocurrentininfo"); + t_symbol *selector2 = gensym("audiocurrentoutinfo");
! sys_schedadvance = int(1e-6 * streaminfo->outputLatency);
SETFLOAT(atoms, (float)indeviceno); *************** *** 221,240 **** typedmess(pd->s_thing, selector2, 4, atoms); } ! } ! else ! err = 0;
! if ( err != paNoError ) ! { post("Error number %d occured opening portaudio stream\n", err); post("Error message: %s\n", Pa_GetErrorText( err ) ); sys_inchannels = sys_outchannels = 0; ! pa_indev = pa_outdev = -1.f; pa_inchans = pa_outchans = 0; ! return (1); ! } ! else if (sys_verbose) ! post("... opened OK."); pa_inchans = inchans; pa_outchans = outchans; --- 206,220 ---- typedmess(pd->s_thing, selector2, 4, atoms); } ! } else err = 0;
! if (err != paNoError) { post("Error number %d occured opening portaudio stream\n", err); post("Error message: %s\n", Pa_GetErrorText( err ) ); sys_inchannels = sys_outchannels = 0; ! pa_indev = int(pa_outdev = -1.f); pa_inchans = pa_outchans = 0; ! return 1; ! } else if (sys_verbose) post("... opened OK."); pa_inchans = inchans; pa_outchans = outchans; *************** *** 251,255 **** post("Error message: %s\n", Pa_GetErrorText(err)); sys_inchannels = sys_outchannels = 0; ! return (1); }
--- 231,235 ---- post("Error message: %s\n", Pa_GetErrorText(err)); sys_inchannels = sys_outchannels = 0; ! return 1; }
*************** *** 259,263 **** post("successfully started");
! return (0); }
--- 239,243 ---- post("successfully started");
! return 0; }
*************** *** 301,369 **** void sys_lock_timeout_notification(void);
! int process (const void *input, void *output, unsigned long frameCount, ! const PaStreamCallbackTimeInfo* timeInfo, ! PaStreamCallbackFlags statusFlags, void *userData) ! { int i; ! int timeout = (float)frameCount / (float) sys_dacsr * 1e6; ! ! if (statusFlags) ! sys_xrun_notification(); ! ! if (sys_timedlock(timeout) == ETIMEDOUT) ! /* we're late */ ! { sys_lock_timeout_notification(); return 0; } ! ! for (i = 0; (unsigned)i < frameCount / sys_dacblocksize; ++i) ! { int j; ! for (j = 0; j < sys_inchannels; j++) ! { t_sample * in = ((t_sample**)input)[j] + i * sys_dacblocksize; ! copyvec(sys_soundin + j * sys_dacblocksize, ! in, sys_dacblocksize); } - sched_tick(sys_time + sys_time_per_dsp_tick); ! ! for (j = 0; j < sys_outchannels; j++) ! { t_sample * out = ((t_sample**)output)[j] + i * sys_dacblocksize; ! copyvec(out, sys_soundout + j * sys_dacblocksize, ! sys_dacblocksize); } ! /* update peak meters */ ! if (sys_meters) ! sys_peakmeters(); ! ! /* clear the output buffer */ zerovec(sys_soundout, pa_outchans * sys_dacblocksize); } - run_all_idle_callbacks(); sys_unlock(); - return 0; }
! void pa_close_audio( void) ! { #ifndef DEBUG if(sys_verbose) #endif post("closing portaudio"); ! ! if (pa_inchans || pa_outchans) ! { ! if (pa_stream) ! { int status = Pa_StopStream(pa_stream); ! ! if (status) ! post("error closing audio: %d", status); ! Pa_CloseStream(pa_stream); pa_stream = NULL; --- 281,321 ---- void sys_lock_timeout_notification(void);
! int process (const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo* timeInfo, ! PaStreamCallbackFlags statusFlags, void *userData) { int i; ! int timeout = int((float)frameCount / (float) sys_dacsr * 1e6); ! if (statusFlags) sys_xrun_notification(); ! if (sys_timedlock(timeout) == ETIMEDOUT) /* we're late */ { sys_lock_timeout_notification(); return 0; } ! for (i = 0; (unsigned)i < frameCount / sys_dacblocksize; ++i) { int j; ! for (j = 0; j < sys_inchannels; j++) { t_sample * in = ((t_sample**)input)[j] + i * sys_dacblocksize; ! copyvec(sys_soundin + j * sys_dacblocksize, in, sys_dacblocksize); } sched_tick(sys_time + sys_time_per_dsp_tick); ! for (j = 0; j < sys_outchannels; j++) { t_sample * out = ((t_sample**)output)[j] + i * sys_dacblocksize; ! copyvec(out, sys_soundout + j * sys_dacblocksize, sys_dacblocksize); } ! if (sys_meters) sys_peakmeters(); zerovec(sys_soundout, pa_outchans * sys_dacblocksize); } run_all_idle_callbacks(); sys_unlock(); return 0; }
! void pa_close_audio(void) { #ifndef DEBUG if(sys_verbose) #endif post("closing portaudio"); ! if (pa_inchans || pa_outchans) { ! if (pa_stream) { int status = Pa_StopStream(pa_stream); ! if (status) post("error closing audio: %d", status); Pa_CloseStream(pa_stream); pa_stream = NULL; *************** *** 371,395 **** } sys_setscheduler(0); - #ifndef DEBUG if(sys_verbose) #endif post("portaudio closed"); - pa_inchans = pa_outchans = 0; pa_indev = pa_outdev = -1; }
- - /* for blocked IO */ ! int pa_send_dacs(void) ! { /* we don't support blocking i/o */ return SENDDACS_NO; }
- - void pa_listdevs(void) /* lifted from pa_devs.c in portaudio */ { --- 323,340 ---- } sys_setscheduler(0); #ifndef DEBUG if(sys_verbose) #endif post("portaudio closed"); pa_inchans = pa_outchans = 0; pa_indev = pa_outdev = -1; }
/* for blocked IO */ ! int pa_send_dacs(void) { /* we don't support blocking i/o */ return SENDDACS_NO; }
void pa_listdevs(void) /* lifted from pa_devs.c in portaudio */ { *************** *** 517,522 **** }
! void pa_getcurrent_devices(void) ! { t_symbol * pd = gensym("pd"); t_symbol * selector = gensym("audiodevice"); --- 462,466 ---- }
! void pa_getcurrent_devices(void) { t_symbol * pd = gensym("pd"); t_symbol * selector = gensym("audiodevice"); *************** *** 527,549 **** }
! void pa_test_setting (int ac, t_atom *av) ! { ! int indev = atom_getfloatarg(0, ac, av); ! int outdev = atom_getfloatarg(1, ac, av); ! int samplerate = atom_getfloatarg(2, ac, av); ! int inchans = atom_getfloatarg(3, ac, av); ! int outchans = atom_getfloatarg(4, ac, av); ! int advance = atom_getfloatarg(5, ac, av); ! t_symbol * pd = gensym("pd"); ! t_symbol * selector = gensym("testaudiosettingresult"); t_atom argv[1]; - pa_initialize(); - indev = pddev2padev(indev,1); outdev = pddev2padev(outdev,0); ! ! if ((pa_indev == -1) && (pa_outdev == -1)) ! { int ret; PaStreamParameters inputParameters, outputParameters; --- 471,488 ---- }
! void pa_test_setting (int ac, t_atom *av) { ! int indev = atom_getintarg(0, ac, av); ! int outdev = atom_getintarg(1, ac, av); ! int samplerate = atom_getintarg(2, ac, av); ! int inchans = atom_getintarg(3, ac, av); ! int outchans = atom_getintarg(4, ac, av); ! int advance = atom_getintarg(5, ac, av); ! t_symbol *pd = gensym("pd"); ! t_symbol *selector = gensym("testaudiosettingresult"); t_atom argv[1]; pa_initialize(); indev = pddev2padev(indev,1); outdev = pddev2padev(outdev,0); ! if (pa_indev==-1 && pa_outdev==-1) { int ret; PaStreamParameters inputParameters, outputParameters; *************** *** 568,591 **** }
! static int pddev2padev(int pddev,int input) ! { int j; int devno; pa_initialize(); ! ! for (j = 0, devno = 0; j < Pa_GetDeviceCount(); j++) ! { const PaDeviceInfo *info = Pa_GetDeviceInfo(j); int maxchans = input?info->maxInputChannels:info->maxOutputChannels; ! if (maxchans > 0) ! { ! if (devno == pddev) ! { ! return j; ! } devno++; } } - return -1; } --- 507,522 ---- }
! static int pddev2padev(int pddev,int input) { int j; int devno; pa_initialize(); ! for (j = 0, devno = 0; j < Pa_GetDeviceCount(); j++) { const PaDeviceInfo *info = Pa_GetDeviceInfo(j); int maxchans = input?info->maxInputChannels:info->maxOutputChannels; ! if (maxchans > 0) { ! if (devno == pddev) return j; devno++; } } return -1; }