aboutsummaryrefslogtreecommitdiff
path: root/pd/src
diff options
context:
space:
mode:
authorMiller Puckette <millerpuckette@users.sourceforge.net>2008-12-08 20:14:40 +0000
committerMiller Puckette <millerpuckette@users.sourceforge.net>2008-12-08 20:14:40 +0000
commit22c0a77781368cddcbd273009d3c55a765e9200a (patch)
tree61f2117cf389f34d3702d364bb12c741bb505e8d /pd/src
parenta798f231a5d048cb9126003b856281d508946703 (diff)
0.42-0test06
svn path=/trunk/; revision=10432
Diffstat (limited to 'pd/src')
-rw-r--r--pd/src/d_array.c8
-rw-r--r--pd/src/d_osc.c2
-rw-r--r--pd/src/m_pd.h2
-rw-r--r--pd/src/m_sched.c19
-rw-r--r--pd/src/notes.txt2
-rw-r--r--pd/src/s_audio_alsa.c73
-rw-r--r--pd/src/s_audio_pa.c49
-rw-r--r--pd/src/s_main.c11
-rw-r--r--pd/src/u_main.tk2
9 files changed, 133 insertions, 35 deletions
diff --git a/pd/src/d_array.c b/pd/src/d_array.c
index 73a18418..11a55b5d 100644
--- a/pd/src/d_array.c
+++ b/pd/src/d_array.c
@@ -373,6 +373,7 @@ typedef struct _tabread4_tilde
t_word *x_vec;
t_symbol *x_arrayname;
t_float x_f;
+ t_float x_onset;
} t_tabread4_tilde;
static void *tabread4_tilde_new(t_symbol *s)
@@ -381,7 +382,9 @@ static void *tabread4_tilde_new(t_symbol *s)
x->x_arrayname = s;
x->x_vec = 0;
outlet_new(&x->x_obj, gensym("signal"));
+ floatinlet_new(&x->x_obj, &x->x_onset);
x->x_f = 0;
+ x->x_onset = 0;
return (x);
}
@@ -393,6 +396,7 @@ static t_int *tabread4_tilde_perform(t_int *w)
int n = (int)(w[4]);
int maxindex;
t_word *buf = x->x_vec, *wp;
+ double onset = x->x_onset;
int i;
maxindex = x->x_npoints - 3;
@@ -417,7 +421,7 @@ static t_int *tabread4_tilde_perform(t_int *w)
for (i = 0; i < n; i++)
{
- t_sample findex = *in++;
+ double findex = *in++ + onset;
int index = findex;
t_sample frac, a, b, c, d, cminusb;
static int count;
@@ -431,8 +435,6 @@ static t_int *tabread4_tilde_perform(t_int *w)
b = wp[0].w_float;
c = wp[1].w_float;
d = wp[2].w_float;
- /* if (!i && !(count++ & 1023))
- post("fp = %lx, shit = %lx, b = %f", fp, buf->b_shit, b); */
cminusb = c-b;
*out++ = b + frac * (
cminusb - 0.1666667f * (1.-frac) * (
diff --git a/pd/src/d_osc.c b/pd/src/d_osc.c
index 93b1a89e..8336dd34 100644
--- a/pd/src/d_osc.c
+++ b/pd/src/d_osc.c
@@ -86,7 +86,7 @@ static t_int *phasor_perform(t_int *w)
t_float *in = (t_float *)(w[2]);
t_float *out = (t_float *)(w[3]);
int n = (int)(w[4]);
- double dphase = x->x_phase + UNITBIT32;
+ double dphase = x->x_phase + (double)UNITBIT32;
union tabfudge tf;
int normhipart;
float conv = x->x_conv;
diff --git a/pd/src/m_pd.h b/pd/src/m_pd.h
index 438b9f61..3e686aa1 100644
--- a/pd/src/m_pd.h
+++ b/pd/src/m_pd.h
@@ -11,7 +11,7 @@ extern "C" {
#define PD_MAJOR_VERSION 0
#define PD_MINOR_VERSION 42
#define PD_BUGFIX_VERSION 0
-#define PD_TEST_VERSION "test5"
+#define PD_TEST_VERSION "test6"
/* old name for "MSW" flag -- we have to take it for the sake of many old
"nmakefiles" for externs, which will define NT and not MSW */
diff --git a/pd/src/m_sched.c b/pd/src/m_sched.c
index 76f24a78..411d1963 100644
--- a/pd/src/m_sched.c
+++ b/pd/src/m_sched.c
@@ -450,11 +450,11 @@ static void m_pollingscheduler( void)
if (!(idlecount & 31))
{
static double idletime;
- if (sched_useaudio != SCHED_AUDIO_POLL)
- {
- bug("m_pollingscheduler\n");
- return;
- }
+ if (sched_useaudio != SCHED_AUDIO_POLL)
+ {
+ bug("m_pollingscheduler\n");
+ return;
+ }
/* on 32nd idle, start a clock watch; every
32 ensuing idles, check it */
if (idlecount == 32)
@@ -566,6 +566,15 @@ int m_mainloop(void)
return (0);
}
+int m_batchmain(void)
+{
+ sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
+ ((double)sys_schedblocksize) / sys_dacsr;
+ while (sys_quit != SYS_QUIT_QUIT)
+ sched_tick(sys_time + sys_time_per_dsp_tick);
+ return (0);
+}
+
/* ------------ thread locking ------------------- */
#ifdef THREAD_LOCKING
diff --git a/pd/src/notes.txt b/pd/src/notes.txt
index 70209b65..a64e02dc 100644
--- a/pd/src/notes.txt
+++ b/pd/src/notes.txt
@@ -15,6 +15,8 @@ mac:
Gnome: why don't windows pop up when clicked on?
problems:
+if .pdsettings asks for an alsa device out of range, dialog
+ comes up with empty list
find asdf$1 (e.g.) doesn't work
check real-time gaps in writesf~
fix declare to update current patch when changed
diff --git a/pd/src/s_audio_alsa.c b/pd/src/s_audio_alsa.c
index 6733182d..a5034c8d 100644
--- a/pd/src/s_audio_alsa.c
+++ b/pd/src/s_audio_alsa.c
@@ -25,6 +25,7 @@
#include <sched.h>
#include <sys/mman.h>
#include "s_audio_alsa.h"
+#include <endian.h>
/* Defines */
#define DEBUG(x) x
@@ -117,17 +118,33 @@ static int alsaio_setup(t_alsa_dev *dev, int out, int *channels, int *rate,
if (err < 0)
return (-1);
check_error(err, "snd_pcm_hw_params_set_access");
+#if 0 /* enable this to print out which formats are available */
+ {
+ int i;
+ for (i = 0; i <= SND_PCM_FORMAT_LAST; i++)
+ fprintf(stderr, "%d -> %d\n",
+ i, snd_pcm_hw_params_test_format(dev->a_handle, hw_params, i));
+ }
+#endif
/* Try to set 32 bit format first */
err = snd_pcm_hw_params_set_format(dev->a_handle,
hw_params, SND_PCM_FORMAT_S32);
if (err < 0)
{
/* fprintf(stderr,
- "PD-ALSA: 32 bit format not available - using 16\n"); */
+ "PD-ALSA: 32 bit format not available - trying 24\n"); */
err = snd_pcm_hw_params_set_format(dev->a_handle, hw_params,
- SND_PCM_FORMAT_S16);
- check_error(err, "snd_pcm_hw_params_set_format");
- dev->a_sampwidth = 2;
+ SND_PCM_FORMAT_S24_3LE);
+ if (err < 0)
+ {
+ /* fprintf(stderr,
+ "PD-ALSA: 32/24 bit format not available - using 16\n"); */
+ err = snd_pcm_hw_params_set_format(dev->a_handle, hw_params,
+ SND_PCM_FORMAT_S16);
+ check_error(err, "snd_pcm_hw_params_set_format");
+ dev->a_sampwidth = 2;
+ }
+ else dev->a_sampwidth = 3;
}
else dev->a_sampwidth = 4;
@@ -426,17 +443,42 @@ int alsa_send_dacs(void)
if (alsa_outdev[iodev].a_sampwidth == 4)
{
for (i = 0; i < chans; i++, ch++, fp1 += DEFDACBLKSIZE)
- for (j = ch, k = DEFDACBLKSIZE, fp2 = fp1; k--;
+ for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--;
j += thisdevchans, fp2++)
{
float s1 = *fp2 * INT32_MAX;
((t_alsa_sample32 *)alsa_snd_buf)[j] = CLIP32(s1);
}
for (; i < thisdevchans; i++, ch++)
- for (j = ch, k = DEFDACBLKSIZE; k--; j += thisdevchans)
+ for (j = i, k = DEFDACBLKSIZE; k--; j += thisdevchans)
((t_alsa_sample32 *)alsa_snd_buf)[j] = 0;
}
- else
+ else if (alsa_outdev[iodev].a_sampwidth == 3)
+ {
+ for (i = 0; i < chans; i++, ch++, fp1 += DEFDACBLKSIZE)
+ for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--;
+ j += thisdevchans, fp2++)
+ {
+ int s = *fp2 * 8388352.;
+ if (s > 8388351)
+ s = 8388351;
+ else if (s < -8388351)
+ s = -8388351;
+#if BYTE_ORDER == LITTLE_ENDIAN
+ ((char *)(alsa_snd_buf))[3*j] = (s & 255);
+ ((char *)(alsa_snd_buf))[3*j+1] = ((s>>8) & 255);
+ ((char *)(alsa_snd_buf))[3*j+2] = ((s>>16) & 255);
+#else
+ fprintf(stderr("big endian 24-bit not supported");
+#endif
+ }
+ for (; i < thisdevchans; i++, ch++)
+ for (j = i, k = DEFDACBLKSIZE; k--; j += thisdevchans)
+ ((char *)(alsa_snd_buf))[3*j] =
+ ((char *)(alsa_snd_buf))[3*j+1] =
+ ((char *)(alsa_snd_buf))[3*j+2] = 0;
+ }
+ else /* 16 bit samples */
{
for (i = 0; i < chans; i++, ch++, fp1 += DEFDACBLKSIZE)
for (j = ch, k = DEFDACBLKSIZE, fp2 = fp1; k--;
@@ -525,6 +567,23 @@ int alsa_send_dacs(void)
* (1./ INT32_MAX);
}
}
+ else if (alsa_indev[iodev].a_sampwidth == 3)
+ {
+#if BYTE_ORDER == LITTLE_ENDIAN
+ for (i = 0; i < chans; i++, ch++, fp1 += DEFDACBLKSIZE)
+ {
+ for (j = ch, k = DEFDACBLKSIZE, fp2 = fp1; k--;
+ j += thisdevchans, fp2++)
+ *fp2 = ((float) (
+ (((unsigned char *)alsa_snd_buf)[3*j] << 8)
+ | (((unsigned char *)alsa_snd_buf)[3*j+1] << 16)
+ | (((unsigned char *)alsa_snd_buf)[3*j+2] << 24)))
+ * (1./ INT32_MAX);
+ }
+#else
+ fprintf(stderr("big endian 24-bit not supported");
+#endif
+ }
else
{
for (i = 0; i < chans; i++, ch++, fp1 += DEFDACBLKSIZE)
diff --git a/pd/src/s_audio_pa.c b/pd/src/s_audio_pa.c
index e02cbc9e..4ceeb6c6 100644
--- a/pd/src/s_audio_pa.c
+++ b/pd/src/s_audio_pa.c
@@ -11,6 +11,7 @@
#include "s_stuff.h"
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <portaudio.h>
#include "s_audio_pablio.h"
@@ -29,6 +30,34 @@ static t_audiocallback pa_callback;
int pa_foo;
+static void pa_init(void)
+{
+ static int initialized;
+ if (!initialized)
+ {
+ /* Initialize PortAudio */
+ /* for some reason Pa_Initialize(0 closes file descriptor 1.
+ As a workaround, dup it to another number and dup2 it back
+ afterward. */
+ int newfd = dup(1);
+ int err = Pa_Initialize();
+ if (newfd >= 0)
+ {
+ dup2(newfd, 1);
+ close(newfd);
+ }
+ if ( err != paNoError )
+ {
+ fprintf( stderr,
+ "Error number %d occured initializing portaudio\n",
+ err);
+ fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
+ return;
+ }
+ initialized = 1;
+ }
+}
+
static int pa_lowlevel_callback(const void *inputBuffer,
void *outputBuffer, unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *outTime, PaStreamCallbackFlags myflags,
@@ -155,25 +184,11 @@ int pa_open_audio(int inchans, int outchans, int rate, t_sample *soundin,
int indeviceno, int outdeviceno, t_audiocallback callbackfn)
{
PaError err;
- static int initialized;
int j, devno, pa_indev = 0, pa_outdev = 0;
pa_callback = callbackfn;
/* fprintf(stderr, "open callback %d\n", (callbackfn != 0)); */
- if (!initialized)
- {
- /* Initialize PortAudio */
- int 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);
- }
- initialized = 1;
- }
+ pa_init();
/* post("in %d out %d rate %d device %d", inchans, outchans, rate, deviceno); */
if (inchans > MAX_PA_CHANS)
{
@@ -349,7 +364,7 @@ void pa_listdevs(void) /* lifted from pa_devs.c in portaudio */
int numDevices;
const PaDeviceInfo *pdi;
PaError err;
- Pa_Initialize();
+ pa_init();
numDevices = Pa_GetDeviceCount();
if( numDevices < 0 )
{
@@ -390,7 +405,7 @@ void pa_getdevs(char *indevlist, int *nindevs,
int i, nin = 0, nout = 0, ndev;
*canmulti = 1; /* one dev each for input and output */
- Pa_Initialize();
+ pa_init();
ndev = Pa_GetDeviceCount();
for (i = 0; i < ndev; i++)
{
diff --git a/pd/src/s_main.c b/pd/src/s_main.c
index 0bc5a191..cb4bf7af 100644
--- a/pd/src/s_main.c
+++ b/pd/src/s_main.c
@@ -35,6 +35,7 @@ void sys_findprogdir(char *progname);
int sys_startgui(const char *guipath);
int sys_rcfile(void);
int m_mainloop(void);
+int m_batchmain(void);
void sys_addhelppath(char *p);
#ifdef USEAPI_ALSA
void alsa_adddev(char *name);
@@ -75,6 +76,7 @@ static int sys_listplease;
int sys_externalschedlib;
char sys_externalschedlibname[MAXPDSTRING];
+static int sys_batch;
int sys_extraflags;
char sys_extraflagsstring[MAXPDSTRING];
int sys_run_scheduler(const char *externalschedlibname,
@@ -299,6 +301,8 @@ int sys_main(int argc, char **argv)
if (sys_externalschedlib)
return (sys_run_scheduler(sys_externalschedlibname,
sys_extraflagsstring));
+ else if (sys_batch)
+ return (m_batchmain());
else
{
/* open audio and MIDI */
@@ -394,6 +398,7 @@ static char *(usagemessage[]) = {
"-nosleep -- spin, don't sleep (may lower latency on multi-CPUs)\n",
"-schedlib <file> -- plug in external scheduler\n",
"-extraflags <s> -- string argument to send schedlib\n",
+"-batch -- run off-line as a batch process\n",
};
static void sys_parsedevlist(int *np, int *vecp, int max, char *str)
@@ -828,6 +833,12 @@ int sys_argparse(int argc, char **argv)
argv += 2;
argc -= 2;
}
+ else if (!strcmp(*argv, "-batch"))
+ {
+ sys_batch = 1;
+ sys_printtostderr = sys_nogui = 1;
+ argc--; argv++;
+ }
#ifdef UNISTD
else if (!strcmp(*argv, "-rt") || !strcmp(*argv, "-realtime"))
{
diff --git a/pd/src/u_main.tk b/pd/src/u_main.tk
index 9d68b58e..ee971e50 100644
--- a/pd/src/u_main.tk
+++ b/pd/src/u_main.tk
@@ -4449,7 +4449,7 @@ proc ddd_dialog {id dialogname} {
set fieldname [lindex $ddd_fields $x 0]
set $varname [lindex $ddd_fields $x 1]
frame $id.frame$x
- pack $id.frame$x -side top
+ pack $id.frame$x -side top -anchor e
label $id.frame$x.label -text $fieldname
entry $id.frame$x.entry -textvariable $varname -width 20
bind $id.frame$x.entry <KeyPress-Return> [concat ddd_ok $id]