[PD-cvs] pd/src s_audio_pa.c,1.4.4.7.2.5.2.2,1.4.4.7.2.5.2.3
Mathieu Bouchard
matju at users.sourceforge.net
Tue Jul 31 01:36:22 CEST 2007
Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31408
Modified Files:
Tag: desiredata
s_audio_pa.c
Log Message:
cleanup
Index: s_audio_pa.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_audio_pa.c,v
retrieving revision 1.4.4.7.2.5.2.2
retrieving revision 1.4.4.7.2.5.2.3
diff -C2 -d -r1.4.4.7.2.5.2.2 -r1.4.4.7.2.5.2.3
*** s_audio_pa.c 30 Jun 2007 20:28:14 -0000 1.4.4.7.2.5.2.2
--- s_audio_pa.c 30 Jul 2007 23:36:20 -0000 1.4.4.7.2.5.2.3
***************
*** 17,21 ****
#include <errno.h>
-
#ifdef MSW
/* jmz thinks that we have to include:
--- 17,20 ----
***************
*** 23,32 ****
* on linux: <alloca.h> (might be true for osX too, no way to check right now...)
*/
! # include <malloc.h>
#else
# include <alloca.h>
#endif
-
#ifdef MSW
#include "pthread.h" /* for ETIMEDOUT */
--- 22,30 ----
* on linux: <alloca.h> (might be true for osX too, no way to check right now...)
*/
! #zinclude <malloc.h>
#else
# include <alloca.h>
#endif
#ifdef MSW
#include "pthread.h" /* for ETIMEDOUT */
***************
*** 36,40 ****
/* portaudio's blocking api is not working, yet: */
! /* #define PABLOCKING */
//#ifndef PABLOCKING
--- 34,38 ----
/* portaudio's blocking api is not working, yet: */
! /* #define PABLOCKING */
//#ifndef PABLOCKING
***************
*** 48,103 ****
static PaStreamCallback *pa_callback = NULL;
! int process (const void *input, void *output, unsigned long frameCount,
! const PaStreamCallbackTimeInfo* timeInfo,
! PaStreamCallbackFlags statusFlags, void *userData);
! int pa_open_audio(int inchans, int outchans, int rate, int advance,
! int indeviceno, int outdeviceno, int schedmode)
! {
PaError err;
int j, devno, pa_indev = -1, pa_outdev = -1;
!
! if (schedmode == 1)
! pa_callback = process;
! else
! pa_callback = NULL;
!
! sys_setscheduler(schedmode);
!
! /* Initialize PortAudio */
! err = Pa_Initialize();
! if ( err != paNoError )
! {
! fprintf( stderr,
! "Error number %d occured initializing portaudio\n",
! err);
! fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
! return (1);
! }
!
! /* post("in %d out %d rate %d device %d", inchans, outchans, rate, deviceno); */
! if (inchans > MAX_PA_CHANS)
! {
! post("input channels reduced to maximum %d", MAX_PA_CHANS);
! inchans = MAX_PA_CHANS;
! }
! if (outchans > MAX_PA_CHANS)
! {
! post("output channels reduced to maximum %d", MAX_PA_CHANS);
! outchans = MAX_PA_CHANS;
}
!
! if (inchans > 0)
! {
! for (j = 0, devno = 0; j < Pa_GetDeviceCount(); j++)
! {
const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
! int maxchans = info->maxInputChannels;
! if (maxchans > 0)
! {
! if (devno == indeviceno)
! {
! if (maxchans < inchans)
! inchans = maxchans;
pa_indev = j;
break;
--- 46,74 ----
static PaStreamCallback *pa_callback = NULL;
! int process (const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo* timeInfo,
! PaStreamCallbackFlags statusFlags, void *userData);
! int pa_open_audio(int inchans, int outchans, int rate, int advance, int indeviceno, int outdeviceno, int schedmode) {
PaError err;
int j, devno, pa_indev = -1, pa_outdev = -1;
! pa_callback = schedmode==1 ? process : NULL;
! sys_setscheduler(schedmode);
! /* Initialize PortAudio */
! err = Pa_Initialize();
! if (err != paNoError) {
! fprintf(stderr, "Error number %d occured initializing portaudio\n", err);
! fprintf(stderr, "Error message: %s\n", Pa_GetErrorText(err));
! return 1;
}
! /* post("in %d out %d rate %d device %d", inchans, outchans, rate, deviceno); */
! if ( inchans > MAX_PA_CHANS) {post( "input channels reduced to maximum %d", MAX_PA_CHANS); inchans = MAX_PA_CHANS;}
! if (outchans > MAX_PA_CHANS) {post("output channels reduced to maximum %d", MAX_PA_CHANS); outchans = MAX_PA_CHANS;}
! if (inchans > 0) {
! for (j = 0, devno = 0; j < Pa_GetDeviceCount(); j++) {
const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
! int maxchans = info->maxInputChannels;
! if (maxchans > 0) {
! if (devno == indeviceno) {
! if (maxchans < inchans) inchans = maxchans;
pa_indev = j;
break;
***************
*** 107,123 ****
}
}
!
! if (outchans > 0)
! {
! for (j = 0, devno = 0; j < Pa_GetDeviceCount(); j++)
! {
const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
! int maxchans = info->maxOutputChannels;
! if (maxchans > 0)
! {
! if (devno == outdeviceno)
! {
! if (maxchans < outchans)
! outchans = maxchans;
pa_outdev = j;
break;
--- 78,88 ----
}
}
! if (outchans > 0) {
! for (j = 0, devno = 0; j < Pa_GetDeviceCount(); j++) {
const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
! int maxchans = info->maxOutputChannels;
! if (maxchans > 0) {
! if (devno == outdeviceno) {
! if (maxchans < outchans) outchans = maxchans;
pa_outdev = j;
break;
***************
*** 127,299 ****
}
}
!
! if (sys_verbose)
! {
! post("input device %d, channels %d", pa_indev, inchans);
post("output device %d, channels %d", pa_outdev, outchans);
post("latency advance %d", advance);
}
! if (inchans || outchans)
! {
#ifndef PABLOCKING
! if (schedmode == 1)
! {
#endif
! PaStreamParameters inputParameters, outputParameters;
!
! /* initialize input */
! inputParameters.device = pa_indev ;
! inputParameters.channelCount = inchans;
! inputParameters.sampleFormat = paFloat32 | paNonInterleaved;
! inputParameters.suggestedLatency = advance * 0.001;
! inputParameters.hostApiSpecificStreamInfo = NULL;
!
! /* initialize output */
! outputParameters.device = pa_outdev;
! outputParameters.channelCount = outchans;
! outputParameters.sampleFormat = paFloat32 | paNonInterleaved;
! outputParameters.suggestedLatency = advance * 0.001;
! outputParameters.hostApiSpecificStreamInfo = NULL;
!
! /* report to portaudio */
! err = Pa_OpenStream(&pa_stream,
! ( (pa_indev != -1) ? &inputParameters : 0),
! ( (pa_outdev != -1) ? &outputParameters : 0),
! rate,
! sys_dacblocksize,
! paClipOff, /* tb: we should be faster ;-) */
! pa_callback, NULL);
!
! if (err == paNoError)
! {
! const PaStreamInfo * streaminfo = Pa_GetStreamInfo (pa_stream);
! sys_schedadvance = 1e6 * streaminfo->outputLatency;
! }
!
#ifndef PABLOCKING
! }
! else
! {
! int nbuffers = sys_advance_samples / sys_dacblocksize;
! err = PD_OpenAudioStream( &pablio_stream, rate, paFloat32,
! inchans, outchans, sys_dacblocksize,
! nbuffers, pa_indev, pa_outdev);
! }
! #endif
}
! else
! err = 0;
!
! if ( err != paNoError )
! {
! post("Error number %d occured opening portaudio stream\n",
! err);
post("Error message: %s\n", Pa_GetErrorText( err ) );
Pa_Terminate();
sys_inchannels = sys_outchannels = 0;
! return (1);
! }
! else if (sys_verbose)
! post("... opened OK.");
pa_inchans = inchans;
pa_outchans = outchans;
-
#ifndef PABLOCKING
! if (schedmode)
#endif
! err = Pa_StartStream(pa_stream);
!
! if ( err != paNoError )
! {
! post("Error number %d occured starting portaudio stream\n",
! err);
post("Error message: %s\n", Pa_GetErrorText(err));
Pa_Terminate();
sys_inchannels = sys_outchannels = 0;
! return (1);
}
!
! post("successfully started");
!
! return (0);
}
-
void sys_peakmeters(void);
extern int sys_meters; /* true if we're metering */
int process (const void *input, void *output, unsigned long frameCount,
! const PaStreamCallbackTimeInfo* timeInfo,
! PaStreamCallbackFlags statusFlags, void *userData)
! {
! int i,j;
! int timeout = (float)frameCount / (float) sys_dacsr * 1e6;
!
! if (sys_timedlock(timeout) == ETIMEDOUT)
! /* we're late */
! {
! post("timeout %d", timeout);
! sys_log_error(ERR_SYSLOCK);
! return 0;
! }
! for (j = 0; j < sys_inchannels; j++)
! {
! t_sample * in = ((t_sample**)input)[j];
! 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];
! 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);
!
! sys_unlock();
!
return 0;
}
! void pa_close_audio( void)
! {
! post("closing portaudio");
! if (pa_inchans || pa_outchans)
! {
! if (pa_stream)
! {
! Pa_StopStream(pa_stream);
! Pa_CloseStream(pa_stream);
! pa_stream = NULL;
! }
! if (pablio_stream)
! {
! PD_CloseAudioStream(pablio_stream);
! pablio_stream = NULL;
! }
}
! post("portaudio closed");
pa_inchans = pa_outchans = 0;
}
-
/* for blocked IO */
! int pa_send_dacs(void)
! {
#ifdef PABLOCKING /* tb: blocking IO isn't really working for v19 yet */
double timenow, timebefore;
!
! if ( (pa_inchans && Pa_GetStreamReadAvailable(pa_stream)
! < sys_dacblocksize*0.8) &&
(pa_outchans && Pa_GetStreamWriteAvailable(pa_stream)
< sys_dacblocksize*0.8))
--- 92,209 ----
}
}
! if (sys_verbose) {
! post( "input device %d, channels %d", pa_indev, inchans);
post("output device %d, channels %d", pa_outdev, outchans);
post("latency advance %d", advance);
}
! if (inchans || outchans) {
#ifndef PABLOCKING
! if (schedmode == 1) {
#endif
! PaStreamParameters inputParameters, outputParameters;
! /* initialize input */
! inputParameters.device = pa_indev ;
! inputParameters.channelCount = inchans;
! inputParameters.sampleFormat = paFloat32 | paNonInterleaved;
! inputParameters.suggestedLatency = advance * 0.001;
! inputParameters.hostApiSpecificStreamInfo = NULL;
! /* initialize output */
! outputParameters.device = pa_outdev;
! outputParameters.channelCount = outchans;
! outputParameters.sampleFormat = paFloat32 | paNonInterleaved;
! outputParameters.suggestedLatency = advance * 0.001;
! outputParameters.hostApiSpecificStreamInfo = NULL;
! /* report to portaudio */
! err = Pa_OpenStream(&pa_stream,
! ( pa_indev!=-1 ? &inputParameters : 0),
! (pa_outdev!=-1 ? &outputParameters : 0),
! rate, sys_dacblocksize, paClipOff, /* tb: we should be faster ;-) */ pa_callback, NULL);
! if (err == paNoError) {
! const PaStreamInfo * streaminfo = Pa_GetStreamInfo (pa_stream);
! sys_schedadvance = 1e6 * streaminfo->outputLatency;
! }
#ifndef PABLOCKING
! } else {
! int nbuffers = sys_advance_samples / sys_dacblocksize;
! err = PD_OpenAudioStream( &pablio_stream, rate, paFloat32,
! inchans, outchans, sys_dacblocksize, nbuffers, pa_indev, pa_outdev);
}
! #endif
! } else err = 0;
! if (err != paNoError) {
! post("Error number %d occured opening portaudio stream\n", err);
post("Error message: %s\n", Pa_GetErrorText( err ) );
Pa_Terminate();
sys_inchannels = sys_outchannels = 0;
! return 1;
! } else if (sys_verbose) post("... opened OK.");
pa_inchans = inchans;
pa_outchans = outchans;
#ifndef PABLOCKING
! if (schedmode)
#endif
! err = Pa_StartStream(pa_stream);
! if (err != paNoError) {
! post("Error number %d occured starting portaudio stream\n", err);
post("Error message: %s\n", Pa_GetErrorText(err));
Pa_Terminate();
sys_inchannels = sys_outchannels = 0;
! return 1;
}
! post("successfully started");
! return 0;
}
void sys_peakmeters(void);
extern int sys_meters; /* true if we're metering */
int process (const void *input, void *output, unsigned long frameCount,
! const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void *userData) {
! int i,j;
! int timeout = (float)frameCount / (float) sys_dacsr * 1e6;
! if (sys_timedlock(timeout) == ETIMEDOUT) /* we're late */ {
! post("timeout %d", timeout);
! sys_log_error(ERR_SYSLOCK);
return 0;
+ }
+ for (j = 0; j < sys_inchannels; j++) {
+ t_sample * in = ((t_sample**)input)[j];
+ 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];
+ 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);
+ sys_unlock();
+ return 0;
}
! void pa_close_audio() {
! post("closing portaudio");
! if (pa_inchans || pa_outchans) {
! if (pa_stream) {
! Pa_StopStream(pa_stream);
! Pa_CloseStream(pa_stream);
! pa_stream = NULL;
}
! if (pablio_stream) {
! PD_CloseAudioStream(pablio_stream);
! pablio_stream = NULL;
! }
! }
! post("portaudio closed");
pa_inchans = pa_outchans = 0;
}
/* for blocked IO */
! int pa_send_dacs() {
#ifdef PABLOCKING /* tb: blocking IO isn't really working for v19 yet */
double timenow, timebefore;
! if ((pa_inchans && Pa_GetStreamReadAvailable(pa_stream) < sys_dacblocksize*0.8) &&
(pa_outchans && Pa_GetStreamWriteAvailable(pa_stream)
< sys_dacblocksize*0.8))
More information about the Pd-cvs
mailing list