Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7922
Modified Files:
Tag: devel_0_38
s_audio_pa.c
Log Message:
- we are able to use blocking io again ...
- fix for missing pa_device
Index: s_audio_pa.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_audio_pa.c,v
retrieving revision 1.4.4.4
retrieving revision 1.4.4.5
diff -C2 -d -r1.4.4.4 -r1.4.4.5
*** s_audio_pa.c 11 May 2005 16:41:16 -0000 1.4.4.4
--- s_audio_pa.c 15 May 2005 15:50:20 -0000 1.4.4.5
***************
*** 17,20 ****
--- 17,32 ----
#include <errno.h>
+
+ #ifdef MSW
+ /* jmz thinks that we have to include:
+ * on Windows: <malloc.h> (probably this is already included?)
+ * 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 */
***************
*** 23,34 ****
#define MAX_PA_CHANS 32
- #define PA19
/* portaudio's blocking api is not working, yet: */
/* #define PABLOCKING */
static int pa_inchans, pa_outchans;
- static float *pa_soundin[MAX_PA_CHANS], *pa_soundout[MAX_PA_CHANS];
static PaStream *pa_stream;
static PaStreamCallback *pa_callback = NULL;
--- 35,49 ----
#define MAX_PA_CHANS 32
/* portaudio's blocking api is not working, yet: */
/* #define PABLOCKING */
+ #ifndef PABLOCKING
+ #include "s_audio_pablio.h"
+ #endif
+
static int pa_inchans, pa_outchans;
static PaStream *pa_stream;
+ static PABLIO_Stream *pablio_stream;
static PaStreamCallback *pa_callback = NULL;
***************
*** 44,56 ****
int j, devno, pa_indev = 0, pa_outdev = 0;
- #ifndef PABLOCKING
- schedmode = 1;
- #endif
-
if (schedmode == 1)
pa_callback = process;
else
pa_callback = NULL;
!
sys_keepsched = 0;
sys_callbackscheduler = schedmode;
--- 59,67 ----
int j, devno, pa_indev = 0, pa_outdev = 0;
if (schedmode == 1)
pa_callback = process;
else
pa_callback = NULL;
!
sys_keepsched = 0;
sys_callbackscheduler = schedmode;
***************
*** 121,147 ****
if (inchans || outchans)
{
! 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, (inchans ? &inputParameters : 0),
! (outchans ? &outputParameters : 0),
! rate,
! sys_dacblocksize,
! paClipOff, /* tb: we should be faster ;-) */
! pa_callback, NULL);
}
else
--- 132,172 ----
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 ? &inputParameters : 0),
! (pa_outdev ? &outputParameters : 0),
! rate,
! sys_dacblocksize,
! paClipOff, /* tb: we should be faster ;-) */
! pa_callback, NULL);
! #ifndef PABLOCKING
! }
! else
! {
! int nbuffers = sys_advance_samples / sys_dacblocksize;
! err = OpenAudioStream( &pablio_stream, rate, paFloat32,
! inchans, outchans, sys_dacblocksize,
! nbuffers, pa_indev, pa_outdev);
! }
! #endif
}
else
***************
*** 162,166 ****
pa_outchans = outchans;
! err = Pa_StartStream(pa_stream);
if ( err != paNoError )
{
--- 187,195 ----
pa_outchans = outchans;
! #ifndef PABLOCKING
! if (schedmode)
! #endif
! err = Pa_StartStream(pa_stream);
!
if ( err != paNoError )
{
***************
*** 175,191 ****
post("successfully started");
- for (j = 0; j != MAX_PA_CHANS; ++j)
- {
- if (j < inchans)
- pa_soundin[j] = sys_soundin + j * sys_dacblocksize;
- else
- pa_soundin[j] = 0;
-
- if (j < outchans)
- pa_soundout[j] = sys_soundout + j * sys_dacblocksize;
- else
- pa_soundout[j] = 0;
- }
-
return (0);
}
--- 204,207 ----
***************
*** 204,237 ****
if (sys_timedlock(timeout) == ETIMEDOUT)
/* we're late */
- return 0;
-
- #if 0
- for (i = 0; i < frameCount / sys_dacblocksize; ++i)
{
! for (j = 0; j < sys_inchannels; j++)
! {
! t_sample * in = ((t_sample**)input)[j];
! copyvec(sys_soundin + j * sys_dacblocksize,
! in + i * sys_dacblocksize,
! 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 + i * sys_dacblocksize,
! sys_soundout + j * sys_dacblocksize,
! sys_dacblocksize);
! }
! /* update peak meters */
! if (sys_meters)
! sys_peakmeters();
!
! /* clear the output buffer */
! zerovec_simd(sys_soundout, pa_outchans * sys_dacblocksize);
}
- #else
for (j = 0; j < sys_inchannels; j++)
{
--- 220,228 ----
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++)
{
***************
*** 256,266 ****
/* clear the output buffer */
! zerovec_simd(sys_soundout, pa_outchans * sys_dacblocksize);
!
! #endif
sys_unlock();
-
- return 0;
}
--- 247,255 ----
/* clear the output buffer */
! zerovec(sys_soundout, pa_outchans * sys_dacblocksize);
!
sys_unlock();
+ return 0;
}
***************
*** 270,275 ****
if (pa_inchans || pa_outchans)
{
! Pa_StopStream(pa_stream);
! Pa_CloseStream(pa_stream);
}
post("portaudio closed");
--- 259,273 ----
if (pa_inchans || pa_outchans)
{
! if (pa_stream)
! {
! Pa_StopStream(pa_stream);
! Pa_CloseStream(pa_stream);
! pa_stream = NULL;
! }
! if (pablio_stream)
! {
! CloseAudioStream(pablio_stream);
! pablio_stream = NULL;
! }
}
post("portaudio closed");
***************
*** 296,302 ****
if (pa_outchans)
! Pa_WriteStream(pa_stream, pa_soundout, sys_dacblocksize);
if (pa_inchans)
! Pa_ReadStream(pa_stream, pa_soundin, sys_dacblocksize);
zerovec(sys_soundout, pa_inchans * sys_dacblocksize);
--- 294,300 ----
if (pa_outchans)
! Pa_WriteStream(pa_stream, &sys_soundout, sys_dacblocksize);
if (pa_inchans)
! Pa_ReadStream(pa_stream, &sys_soundin, sys_dacblocksize);
zerovec(sys_soundout, pa_inchans * sys_dacblocksize);
***************
*** 307,313 ****
{
if (pa_outchans)
! Pa_WriteStream(pa_stream, pa_soundout, sys_dacblocksize);
if (pa_inchans)
! Pa_ReadStream(pa_stream, pa_soundin, sys_dacblocksize);
zerovec(sys_soundout, pa_inchans * sys_dacblocksize);
--- 305,311 ----
{
if (pa_outchans)
! Pa_WriteStream(pa_stream, &sys_soundout, sys_dacblocksize);
if (pa_inchans)
! Pa_ReadStream(pa_stream, &sys_soundin, sys_dacblocksize);
zerovec(sys_soundout, pa_inchans * sys_dacblocksize);
***************
*** 321,327 ****
else
return SENDDACS_YES;
! #else
! /* we should never reach this point */
! return 0;
#endif
}
--- 319,389 ----
else
return SENDDACS_YES;
!
! #else /* for now we're using pablio */
!
! float *samples, *fp1, *fp2;
! int i, j;
! double timebefore;
!
! samples=(float*)alloca(sizeof(float) * MAX_PA_CHANS * sys_dacblocksize);
!
! timebefore = sys_getrealtime();
! if ((pa_inchans && GetAudioStreamReadable(pablio_stream) < sys_dacblocksize) ||
! (pa_outchans && GetAudioStreamWriteable(pablio_stream) < sys_dacblocksize))
! {
! if (pa_inchans && pa_outchans)
! {
! int synced = 0;
! while (GetAudioStreamWriteable(pablio_stream) > 2*sys_dacblocksize)
! {
! for (j = 0; j < pa_outchans; j++)
! for (i = 0, fp2 = samples + j; i < sys_dacblocksize; i++,
! fp2 += pa_outchans)
! {
! *fp2 = 0;
! }
! synced = 1;
! WriteAudioStream(pablio_stream, samples, sys_dacblocksize);
! }
! while (GetAudioStreamReadable(pablio_stream) > 2*sys_dacblocksize)
! {
! synced = 1;
! ReadAudioStream(pablio_stream, samples, sys_dacblocksize);
! }
! /* if (synced) */
! /* post("sync"); */
! }
! return (SENDDACS_NO);
! }
! if (pa_inchans)
! {
! ReadAudioStream(pablio_stream, samples, sys_dacblocksize);
! for (j = 0, fp1 = sys_soundin; j < pa_inchans; j++, fp1 += sys_dacblocksize)
! for (i = 0, fp2 = samples + j; i < sys_dacblocksize; i++,
! fp2 += pa_inchans)
! {
! fp1[i] = *fp2;
! }
! }
! if (pa_outchans)
! {
! for (j = 0, fp1 = sys_soundout; j < pa_outchans; j++,
! fp1 += sys_dacblocksize)
! for (i = 0, fp2 = samples + j; i < sys_dacblocksize; i++,
! fp2 += pa_outchans)
! {
! *fp2 = fp1[i];
! fp1[i] = 0;
! }
! WriteAudioStream(pablio_stream, samples, sys_dacblocksize);
! }
!
! if (sys_getrealtime() > timebefore + sys_sleepgrain * 1e-6)
! {
! /* post("slept"); */
! return (SENDDACS_SLEPT);
! }
! else return (SENDDACS_YES);
!
#endif
}