Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27719
Modified Files: Tag: desiredata s_audio_mmio.c Log Message: cleanup and remove fprintf
Index: s_audio_mmio.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_audio_mmio.c,v retrieving revision 1.4.4.1.4.2 retrieving revision 1.4.4.1.4.3 diff -C2 -d -r1.4.4.1.4.2 -r1.4.4.1.4.3 *** s_audio_mmio.c 10 Jul 2007 05:47:28 -0000 1.4.4.1.4.2 --- s_audio_mmio.c 30 Jul 2007 23:26:40 -0000 1.4.4.1.4.3 *************** *** 53,66 **** static int ntsnd_inphase[NAPORTS]; /* index of next buffer to read */
! static void nt_waveinerror(char *s, int err) { char t[256]; waveInGetErrorText(err, t, 256); ! fprintf(stderr, s, t); }
! static void nt_waveouterror(char *s, int err) { char t[256]; waveOutGetErrorText(err, t, 256); ! fprintf(stderr, s, t); }
--- 53,66 ---- static int ntsnd_inphase[NAPORTS]; /* index of next buffer to read */
! static void nt_waveinerror(const char *s, int err) { char t[256]; waveInGetErrorText(err, t, 256); ! error(s,t); }
! static void nt_waveouterror(const char *s, int err) { char t[256]; waveOutGetErrorText(err, t, 256); ! error(s,t); }
*************** *** 147,153 **** /* Open a waveform device for output in sucessiv device numbering*/ mmresult = waveOutOpen(&ntsnd_outdev[nda], nt_whichdac + nda, (WAVEFORMATEX *)(&form), 0L, 0L, CALLBACK_NULL); ! if (sys_verbose) fprintf(stderr,"opened dac device %d, with return %d\n", nt_whichdac +nda, mmresult); if (mmresult != MMSYSERR_NOERROR) { ! fprintf(stderr,"Wave out open device %d + %d\n",nt_whichdac,nda); nt_waveouterror("waveOutOpen device: %s\n", mmresult); nt_nwaveout = nda; --- 147,153 ---- /* Open a waveform device for output in sucessiv device numbering*/ mmresult = waveOutOpen(&ntsnd_outdev[nda], nt_whichdac + nda, (WAVEFORMATEX *)(&form), 0L, 0L, CALLBACK_NULL); ! if (sys_verbose) post("opened dac device %d, with return %d", nt_whichdac +nda, mmresult); if (mmresult != MMSYSERR_NOERROR) { ! post("Wave out open device %d + %d",nt_whichdac,nda); nt_waveouterror("waveOutOpen device: %s\n", mmresult); nt_nwaveout = nda; *************** *** 246,251 **** phase3 = WRAPFWD(phase2 + 1); } ! post("nad %d phase %d busy %d done %d", nad, phase, firstphasebusy, ! firstphasedone); continue; multipleadc: --- 246,250 ---- phase3 = WRAPFWD(phase2 + 1); } ! post("nad %d phase %d busy %d done %d", nad, phase, firstphasebusy, firstphasedone); continue; multipleadc: *************** *** 276,283 **** phase3 = WRAPFWD(phase2 + 1); } ! if (firstphasebusy < 0) post("nda %d phase %d all %d", ! nda, phase, (ntsnd_outvec[nad][0].lpWaveHdr->dwFlags & WHDR_DONE)); ! else post("nda %d phase %d busy %d done %d", nda, phase, firstphasebusy, ! firstphasedone); continue; multipledac: --- 275,280 ---- phase3 = WRAPFWD(phase2 + 1); } ! if (firstphasebusy < 0) post("nda %d phase %d all %d", nda, phase, (ntsnd_outvec[nad][0].lpWaveHdr->dwFlags & WHDR_DONE)); ! else post("nda %d phase %d busy %d done %d", nda, phase, firstphasebusy, firstphasedone); continue; multipledac: *************** *** 313,324 **** WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr; if (!(inwavehdr->dwFlags & WHDR_DONE)) break; ! if (inwavehdr->dwFlags & WHDR_PREPARED) ! waveInUnprepareHeader(ntsnd_indev[nad], ! inwavehdr, sizeof(WAVEHDR)); inwavehdr->dwFlags = 0L; waveInPrepareHeader(ntsnd_indev[nad], inwavehdr, sizeof(WAVEHDR)); mmresult = waveInAddBuffer(ntsnd_indev[nad], inwavehdr, sizeof(WAVEHDR)); ! if (mmresult != MMSYSERR_NOERROR) ! nt_waveinerror("waveInAddBuffer: %s\n", mmresult); ntsnd_inphase[nad] = phase = WRAPFWD(phase + 1); } --- 310,318 ---- WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr; if (!(inwavehdr->dwFlags & WHDR_DONE)) break; ! if (inwavehdr->dwFlags & WHDR_PREPARED) waveInUnprepareHeader(ntsnd_indev[nad], inwavehdr, sizeof(WAVEHDR)); inwavehdr->dwFlags = 0L; waveInPrepareHeader(ntsnd_indev[nad], inwavehdr, sizeof(WAVEHDR)); mmresult = waveInAddBuffer(ntsnd_indev[nad], inwavehdr, sizeof(WAVEHDR)); ! if (mmresult != MMSYSERR_NOERROR) nt_waveinerror("waveInAddBuffer: %s\n", mmresult); ntsnd_inphase[nad] = phase = WRAPFWD(phase + 1); } *************** *** 331,345 **** WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr; if (!(outwavehdr->dwFlags & WHDR_DONE)) break; ! if (outwavehdr->dwFlags & WHDR_PREPARED) ! waveOutUnprepareHeader(ntsnd_outdev[nda], outwavehdr, sizeof(WAVEHDR)); outwavehdr->dwFlags = 0L; ! memset((char *)(ntsnd_outvec[nda][phase].lpData), ! 0, (CHANNELS_PER_DEVICE * SAMPSIZE * nt_realdacblksize)); ! waveOutPrepareHeader(ntsnd_outdev[nda], outwavehdr, ! sizeof(WAVEHDR)); ! mmresult = waveOutWrite(ntsnd_outdev[nda], outwavehdr, ! sizeof(WAVEHDR)); ! if (mmresult != MMSYSERR_NOERROR) ! nt_waveouterror("waveOutAddBuffer: %s\n", mmresult); ntsnd_outphase[nda] = phase = WRAPFWD(phase + 1); } --- 325,334 ---- WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr; if (!(outwavehdr->dwFlags & WHDR_DONE)) break; ! if (outwavehdr->dwFlags & WHDR_PREPARED) waveOutUnprepareHeader(ntsnd_outdev[nda], outwavehdr, sizeof(WAVEHDR)); outwavehdr->dwFlags = 0L; ! memset((char *)(ntsnd_outvec[nda][phase].lpData), 0, (CHANNELS_PER_DEVICE * SAMPSIZE * nt_realdacblksize)); ! waveOutPrepareHeader( ntsnd_outdev[nda], outwavehdr, sizeof(WAVEHDR)); ! mmresult = waveOutWrite(ntsnd_outdev[nda], outwavehdr, sizeof(WAVEHDR)); ! if (mmresult != MMSYSERR_NOERROR) nt_waveouterror("waveOutAddBuffer: %s\n", mmresult); ntsnd_outphase[nda] = phase = WRAPFWD(phase + 1); } *************** *** 385,389 **** float *fp1, *fp2; int nextfill, doxfer = 0; - int nda, nad; if (!nt_nwavein && !nt_nwaveout) return 0; if (nt_meters) { --- 374,377 ---- *************** *** 406,434 **** first check whether the buffers are marked "done". */ if (!nt_fill) { ! for (nad = 0; nad < nt_nwavein; nad++) { int phase = ntsnd_inphase[nad]; WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr; if (!(inwavehdr->dwFlags & WHDR_DONE)) goto idle; } ! for (nda = 0; nda < nt_nwaveout; nda++) { int phase = ntsnd_outphase[nda]; WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr; if (!(outwavehdr->dwFlags & WHDR_DONE)) goto idle; } ! for (nad = 0; nad < nt_nwavein; nad++) { int phase = ntsnd_inphase[nad]; WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr; ! if (inwavehdr->dwFlags & WHDR_PREPARED) ! waveInUnprepareHeader(ntsnd_indev[nad], inwavehdr, sizeof(WAVEHDR)); } ! for (nda = 0; nda < nt_nwaveout; nda++) { int phase = ntsnd_outphase[nda]; WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr; ! if (outwavehdr->dwFlags & WHDR_PREPARED) ! waveOutUnprepareHeader(ntsnd_outdev[nda], outwavehdr, sizeof(WAVEHDR)); } } /* Convert audio output to fixed-point and put it in the output buffer. */ ! for (nda = 0, fp1 = sys_soundout; nda < nt_nwaveout; nda++) { int phase = ntsnd_outphase[nda]; for (i=0, sp1=(short *)(ntsnd_outvec[nda][phase].lpData)+CHANNELS_PER_DEVICE*nt_fill; i<2; i++, fp1 += sys_dacblocksize, sp1++) { --- 394,421 ---- first check whether the buffers are marked "done". */ if (!nt_fill) { ! for (int nad=0; nad<nt_nwavein; nad++) { int phase = ntsnd_inphase[nad]; WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr; if (!(inwavehdr->dwFlags & WHDR_DONE)) goto idle; } ! for (int nda=0; nda<nt_nwaveout; nda++) { int phase = ntsnd_outphase[nda]; WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr; if (!(outwavehdr->dwFlags & WHDR_DONE)) goto idle; } ! for (int nad=0; nad<nt_nwavein; nad++) { int phase = ntsnd_inphase[nad]; WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr; ! if (inwavehdr->dwFlags & WHDR_PREPARED) waveInUnprepareHeader(ntsnd_indev[nad], inwavehdr, sizeof(WAVEHDR)); } ! for (int nda=0; nda<nt_nwaveout; nda++) { int phase = ntsnd_outphase[nda]; WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr; ! if (outwavehdr->dwFlags & WHDR_PREPARED) waveOutUnprepareHeader(ntsnd_outdev[nda], outwavehdr, sizeof(WAVEHDR)); } } /* Convert audio output to fixed-point and put it in the output buffer. */ ! fp1 = sys_soundout; ! for (int nda=0; nda<nt_nwaveout; nda++) { int phase = ntsnd_outphase[nda]; for (i=0, sp1=(short *)(ntsnd_outvec[nda][phase].lpData)+CHANNELS_PER_DEVICE*nt_fill; i<2; i++, fp1 += sys_dacblocksize, sp1++) { *************** *** 443,447 **** memset(sys_soundout, 0, (sys_dacblocksize *sizeof(t_sample)*CHANNELS_PER_DEVICE)*nt_nwaveout); /* vice versa for the input buffer */ ! for (nad = 0, fp1 = sys_soundin; nad < nt_nwavein; nad++) { int phase = ntsnd_inphase[nad]; for (i=0, sp1=(short *)(ntsnd_invec[nad][phase].lpData)+CHANNELS_PER_DEVICE*nt_fill; i < 2; i++, fp1 += sys_dacblocksize, sp1++) { --- 430,435 ---- memset(sys_soundout, 0, (sys_dacblocksize *sizeof(t_sample)*CHANNELS_PER_DEVICE)*nt_nwaveout); /* vice versa for the input buffer */ ! fp1 = sys_soundin; ! for (int nad=0; nad<nt_nwavein; nad++) { int phase = ntsnd_inphase[nad]; for (i=0, sp1=(short *)(ntsnd_invec[nad][phase].lpData)+CHANNELS_PER_DEVICE*nt_fill; i < 2; i++, fp1 += sys_dacblocksize, sp1++) { *************** *** 454,458 **** if (nt_fill == nt_realdacblksize) { nt_fill = 0; ! for (nad = 0; nad < nt_nwavein; nad++) { int phase = ntsnd_inphase[nad]; HWAVEIN device = ntsnd_indev[nad]; --- 442,446 ---- if (nt_fill == nt_realdacblksize) { nt_fill = 0; ! for (int nad=0; nad<nt_nwavein; nad++) { int phase = ntsnd_inphase[nad]; HWAVEIN device = ntsnd_indev[nad]; *************** *** 460,468 **** waveInPrepareHeader(device, inwavehdr, sizeof(WAVEHDR)); mmresult = waveInAddBuffer(device, inwavehdr, sizeof(WAVEHDR)); ! if (mmresult != MMSYSERR_NOERROR) ! nt_waveinerror("waveInAddBuffer: %s\n", mmresult); ntsnd_inphase[nad] = WRAPFWD(phase + 1); } ! for (nda = 0; nda < nt_nwaveout; nda++) { int phase = ntsnd_outphase[nda]; HWAVEOUT device = ntsnd_outdev[nda]; --- 448,455 ---- waveInPrepareHeader(device, inwavehdr, sizeof(WAVEHDR)); mmresult = waveInAddBuffer(device, inwavehdr, sizeof(WAVEHDR)); ! if (mmresult != MMSYSERR_NOERROR) nt_waveinerror("waveInAddBuffer: %s\n", mmresult); ntsnd_inphase[nad] = WRAPFWD(phase + 1); } ! for (int nda=0; nda<nt_nwaveout; nda++) { int phase = ntsnd_outphase[nda]; HWAVEOUT device = ntsnd_outdev[nda]; *************** *** 470,484 **** waveOutPrepareHeader(device, outwavehdr, sizeof(WAVEHDR)); mmresult = waveOutWrite(device, outwavehdr, sizeof(WAVEHDR)); ! if (mmresult != MMSYSERR_NOERROR) ! nt_waveouterror("waveOutWrite: %s\n", mmresult); ntsnd_outphase[nda] = WRAPFWD(phase + 1); } /* check for DAC underflow or ADC overflow. */ ! for (nad = 0; nad < nt_nwavein; nad++) { int phase = WRAPBACK(ntsnd_inphase[nad] - 2); WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr; if (inwavehdr->dwFlags & WHDR_DONE) goto late; } ! for (nda = 0; nda < nt_nwaveout; nda++) { int phase = WRAPBACK(ntsnd_outphase[nda] - 2); WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr; --- 457,470 ---- waveOutPrepareHeader(device, outwavehdr, sizeof(WAVEHDR)); mmresult = waveOutWrite(device, outwavehdr, sizeof(WAVEHDR)); ! if (mmresult != MMSYSERR_NOERROR) nt_waveouterror("waveOutWrite: %s\n", mmresult); ntsnd_outphase[nda] = WRAPFWD(phase + 1); } /* check for DAC underflow or ADC overflow. */ ! for (int nad=0; nad<nt_nwavein; nad++) { int phase = WRAPBACK(ntsnd_inphase[nad] - 2); WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr; if (inwavehdr->dwFlags & WHDR_DONE) goto late; } ! for (int nda=0; nda<nt_nwaveout; nda++) { int phase = WRAPBACK(ntsnd_outphase[nda] - 2); WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr; *************** *** 493,514 **** idle: /* If more than nt_adcjitterbufsallowed ADC buffers are ready on any input device, resynchronize */ ! for (nad = 0; nad < nt_nwavein; nad++) { int phase = ntsnd_inphase[nad]; WAVEHDR *inwavehdr = ntsnd_invec[nad][WRAPFWD(phase + nt_adcjitterbufsallowed)].lpWaveHdr; ! if (inwavehdr->dwFlags & WHDR_DONE) { ! nt_resyncaudio(); ! return 0; ! } } /* test dac sync the same way */ ! for (nda = 0; nda < nt_nwaveout; nda++) { int phase = ntsnd_outphase[nda]; ! WAVEHDR *outwavehdr = ! ntsnd_outvec[nda] ! [WRAPFWD(phase + nt_dacjitterbufsallowed)].lpWaveHdr; ! if (outwavehdr->dwFlags & WHDR_DONE) { ! nt_resyncaudio(); ! return 0; ! } } #ifdef MIDI_TIMESTAMP --- 479,492 ---- idle: /* If more than nt_adcjitterbufsallowed ADC buffers are ready on any input device, resynchronize */ ! for (int nad=0; nad<nt_nwavein; nad++) { int phase = ntsnd_inphase[nad]; WAVEHDR *inwavehdr = ntsnd_invec[nad][WRAPFWD(phase + nt_adcjitterbufsallowed)].lpWaveHdr; ! if ( inwavehdr->dwFlags & WHDR_DONE) {nt_resyncaudio(); return 0;} } /* test dac sync the same way */ ! for (int nda=0; nda<nt_nwaveout; nda++) { int phase = ntsnd_outphase[nda]; ! WAVEHDR *outwavehdr = ntsnd_outvec[nda][WRAPFWD(phase + nt_dacjitterbufsallowed)].lpWaveHdr; ! if (outwavehdr->dwFlags & WHDR_DONE) {nt_resyncaudio(); return 0;} } #ifdef MIDI_TIMESTAMP *************** *** 527,536 **** nbuf = sys_advance_samples/nt_realdacblksize; if (nbuf >= MAXBUFFER) { ! fprintf(stderr, "pd: audio buffering maxed out to %d\n", ! (int)(MAXBUFFER * ((nt_realdacblksize * 1000.)/44100.))); nbuf = MAXBUFFER; } else if (nbuf < 4) nbuf = 4; ! fprintf(stderr, "%d audio buffers\n", nbuf); nt_naudiobuffer = nbuf; if (nt_adcjitterbufsallowed > nbuf - 2) nt_adcjitterbufsallowed = nbuf - 2; --- 505,513 ---- nbuf = sys_advance_samples/nt_realdacblksize; if (nbuf >= MAXBUFFER) { ! post("pd: audio buffering maxed out to %d", (int)(MAXBUFFER * ((nt_realdacblksize * 1000.)/44100.))); nbuf = MAXBUFFER; } else if (nbuf < 4) nbuf = 4; ! post("%d audio buffers", nbuf); nt_naudiobuffer = nbuf; if (nt_adcjitterbufsallowed > nbuf - 2) nt_adcjitterbufsallowed = nbuf - 2; *************** *** 554,558 **** wRtn = waveInGetDevCaps(i, (LPWAVEINCAPS) &wicap, sizeof(wicap)); if (wRtn) nt_waveinerror("waveInGetDevCaps: %s\n", wRtn); ! else fprintf(stderr, "audio input device #%d: %s\n", i+1, wicap.szPname); } ndevices = waveOutGetNumDevs(); --- 531,535 ---- wRtn = waveInGetDevCaps(i, (LPWAVEINCAPS) &wicap, sizeof(wicap)); if (wRtn) nt_waveinerror("waveInGetDevCaps: %s\n", wRtn); ! else post("audio input device #%d: %s", i+1, wicap.szPname); } ndevices = waveOutGetNumDevs(); *************** *** 561,565 **** wRtn = waveOutGetDevCaps(i, (LPWAVEOUTCAPS) &wocap, sizeof(wocap)); if (wRtn) nt_waveouterror("waveOutGetDevCaps: %s\n", wRtn); ! else fprintf(stderr, "audio output device #%d: %s\n", i+1, wocap.szPname); } } --- 538,542 ---- wRtn = waveOutGetDevCaps(i, (LPWAVEOUTCAPS) &wocap, sizeof(wocap)); if (wRtn) nt_waveouterror("waveOutGetDevCaps: %s\n", wRtn); ! else post("audio output device #%d: %s", i+1, wocap.szPname); } }