Commit 61aa1bbe authored by Ivica Bukvic's avatar Ivica Bukvic
Browse files

backported audio driver support from 0.43 and the pd/extra folder with...

backported audio driver support from 0.43 and the pd/extra folder with supporting fixes/merges where needed. Removed outdated expr-help file in favor of new documentation.
parent 3925084d
#N canvas 43 123 1054 583 12;
#N canvas 0 0 1052 581 12;
#X obj 382 492 spigot;
#X msg 484 293 bang;
#X obj 483 454 bonk~;
......@@ -107,7 +107,7 @@ Bonk check the attack against a collection of stored templates to try
to guess which of two or more instruments was hit. Bonk is described
theoretically in the 1998 ICMC proceedings \, reprinted on crca.ucsd.edu/~msp
.;
#N canvas 723 241 701 719 creation-arguments 0;
#N canvas 0 0 699 717 creation-arguments 1;
#X text 228 14 creation arguments for bonk~;
#X text 70 272 -npts 256;
#X text 44 244 default value:;
......
......@@ -82,7 +82,9 @@ void *bonk_class;
static t_class *bonk_class;
#endif
#ifndef _MSC_VER
#ifdef _WIN32
#include <malloc.h>
#elif ! defined(_MSC_VER)
#include <alloca.h>
#endif
......@@ -195,6 +197,7 @@ typedef struct _bonk
t_object x_obj;
t_outlet *x_cookedout;
t_clock *x_clock;
t_canvas *x_canvas; /* ptr to current canvas --fbar */
#endif /* PD */
#ifdef MSP
t_pxobject x_obj;
......@@ -256,7 +259,12 @@ static void bonk_print(t_bonk *x, t_floatarg f);
static void bonk_bang(t_bonk *x);
static void bonk_write(t_bonk *x, t_symbol *s);
static void bonk_dowrite(t_bonk *x, t_symbol *s);
static void bonk_writefile(t_bonk *x, char *filename, short path);
static void bonk_read(t_bonk *x, t_symbol *s);
static void bonk_doread(t_bonk *x, t_symbol *s);
static void bonk_openfile(t_bonk *x, char *filename, short path);
void bonk_minvel_set(t_bonk *x, void *attr, long ac, t_atom *av);
void bonk_lothresh_set(t_bonk *x, void *attr, long ac, t_atom *av);
......@@ -960,13 +968,21 @@ static void bonk_bang(t_bonk *x)
bonk_tick(x);
}
#ifdef PD
static void bonk_read(t_bonk *x, t_symbol *s)
{
FILE *fd = fopen(s->s_name, "r");
float vec[MAXNFILTERS];
int i, ntemplate = 0, remaining;
float *fp, *fp2;
if (!fd)
/* fbar: canvas_open code taken from g_array.c */
FILE *fd;
char buf[MAXPDSTRING], *bufptr;
int filedesc;
if ((filedesc = canvas_open(x->x_canvas,
s->s_name, "", buf, &bufptr, MAXPDSTRING, 0)) < 0
|| !(fd = fdopen(filedesc, "r")))
{
post("%s: open failed", s->s_name);
return;
......@@ -998,14 +1014,103 @@ nomore:
x->x_ntemplate = ntemplate;
fclose(fd);
}
#endif
#ifdef MSP
static void bonk_read(t_bonk *x, t_symbol *s)
{
defer(x, (method)bonk_doread, s, 0, NULL);
}
static void bonk_doread(t_bonk *x, t_symbol *s)
{
long filetype = 'TEXT', outtype;
char filename[512];
short path;
if (s == gensym("")) {
if (open_dialog(filename, &path, &outtype, &filetype, 1))
return;
} else {
strcpy(filename, s->s_name);
if (locatefile_extended(filename, &path, &outtype, &filetype, 1)) {
object_error((t_object *) x, "%s: not found", s->s_name);
return;
}
}
// we have a file
bonk_openfile(x, filename, path);
}
static void bonk_openfile(t_bonk *x, char *filename, short path) {
float vec[MAXNFILTERS];
int i, ntemplate = 0, remaining;
float *fp, *fp2;
t_filehandle fh;
char **texthandle;
char *tokptr;
if (path_opensysfile(filename, path, &fh, READ_PERM)) {
object_error((t_object *) x, "error opening %s", filename);
return;
}
texthandle = sysmem_newhandle(0);
sysfile_readtextfile(fh, texthandle, 0, TEXT_LB_NATIVE);
sysfile_close(fh);
x->x_template = (t_template *)t_resizebytes(x->x_template,
x->x_ntemplate * sizeof(t_template), 0);
tokptr = strtok(*texthandle, " \n");
while(tokptr != NULL)
{
for (i = x->x_nfilters, fp = vec; i--; fp++) {
if (sscanf(tokptr, "%f", fp) < 1)
goto nomore;
tokptr = strtok(NULL, " \n");
}
x->x_template = (t_template *)t_resizebytes(x->x_template,
ntemplate * sizeof(t_template),
(ntemplate + 1) * sizeof(t_template));
for (i = x->x_nfilters, fp = vec,
fp2 = x->x_template[ntemplate].t_amp; i--;)
*fp2++ = *fp++;
ntemplate++;
}
nomore:
if (remaining = (ntemplate % x->x_ninsig))
{
post("bonk_read: %d templates not a multiple of %d; dropping extras");
x->x_template = (t_template *)t_resizebytes(x->x_template,
ntemplate * sizeof(t_template),
(ntemplate - remaining) * sizeof(t_template));
ntemplate = ntemplate - remaining;
}
sysmem_freehandle(texthandle);
post("bonk: read %d templates\n", ntemplate);
x->x_ntemplate = ntemplate;
}
#endif
#ifdef PD
static void bonk_write(t_bonk *x, t_symbol *s)
{
FILE *fd = fopen(s->s_name, "w");
FILE *fd;
char buf[MAXPDSTRING]; /* fbar */
int i, ntemplate = x->x_ntemplate;
t_template *tp = x->x_template;
float *fp;
if (!fd)
/* fbar: canvas-code as in g_array.c */
canvas_makefilename(x->x_canvas, s->s_name,
buf, MAXPDSTRING);
sys_bashfilename(buf, buf);
if (!(fd = fopen(buf, "w")))
{
post("%s: couldn't create", s->s_name);
return;
......@@ -1019,6 +1124,63 @@ static void bonk_write(t_bonk *x, t_symbol *s)
post("bonk: wrote %d templates\n", x->x_ntemplate);
fclose(fd);
}
#endif
#ifdef MSP
static void bonk_write(t_bonk *x, t_symbol *s)
{
defer(x, (method)bonk_dowrite, s, 0, NULL);
}
static void bonk_dowrite(t_bonk *x, t_symbol *s)
{
long filetype = 'TEXT', outtype;
char filename[MAX_FILENAME_CHARS];
short path;
if (s == gensym("")) {
sprintf(filename, "bonk_template.txt");
saveas_promptset("Save template as...");
if (saveasdialog_extended(filename, &path, &outtype, &filetype, 0))
return;
} else {
strcpy(filename, s->s_name);
path = path_getdefault();
}
bonk_writefile(x, filename, path);
}
void bonk_writefile(t_bonk *x, char *filename, short path)
{
int i, ntemplate = x->x_ntemplate;
t_template *tp = x->x_template;
float *fp;
long err;
long buflen;
t_filehandle fh;
char buf[20];
err = path_createsysfile(filename, path, 'TEXT', &fh);
if (err)
return;
for (; ntemplate--; tp++)
{
for (i = x->x_nfilters, fp = tp->t_amp; i--; fp++) {
snprintf(buf, 20, "%6.2f ", *fp);
buflen = strlen(buf);
sysfile_write(fh, &buflen, buf);
}
buflen = 1;
sysfile_write(fh, &buflen, "\n");
}
sysfile_close(fh);
}
#endif
static void bonk_free(t_bonk *x)
{
......@@ -1048,6 +1210,7 @@ static void *bonk_new(t_symbol *s, int argc, t_atom *argv)
firstbin = DEFFIRSTBIN, minbandwidth = DEFMINBANDWIDTH;
t_insig *g;
x->x_canvas = canvas_getcurrent(); /* fbar: bind current canvas to x */
if (argc > 0 && argv[0].a_type == A_FLOAT)
{
/* old style args for compatibility */
......@@ -1176,7 +1339,7 @@ void bonk_tilde_setup(void)
gensym("read"), A_SYMBOL, 0);
class_addmethod(bonk_class, (t_method)bonk_write,
gensym("write"), A_SYMBOL, 0);
post("bonk version 1.3");
post("bonk version 1.5");
}
#endif
......@@ -1265,7 +1428,7 @@ int main()
class_register(CLASS_BOX, c);
bonk_class = c;
post("bonk~ v1.3");
post("bonk~ v1.5");
return (0);
}
......@@ -1446,7 +1609,7 @@ void bonk_learn_set(t_bonk *x, void *attr, long ac, t_atom *av)
x->x_ntemplate * sizeof(x->x_template[0]), 0);
x->x_ntemplate = 0;
}
x->x_learn = (n != 0);
x->x_learn = n;
x->x_learncount = 0;
}
}
......
NAME=bonk~
CSYM=bonk_tilde
include ../makefile
include ../makefile.subdir
......@@ -18,7 +18,7 @@ static t_class *choice_class;
typedef struct _elem
{
float e_age;
float e_weight[DIMENSION];
t_float e_weight[DIMENSION];
} t_elem;
typedef struct _choice
......
NAME=choice
CSYM=choice
include ../makefile
include ../makefile.subdir
......@@ -6,7 +6,7 @@ install: install_linux
clean: clean_linux
PDEXTERN=/usr/local/lib/pd/externs
PDEXTERN=/usr/local/lib/pd/extra
# ----------------------- NT -----------------------
......@@ -89,7 +89,6 @@ LINUXINCLUDE = -I../../src
expr.pd_linux: $(LINUXOBJ)
$(CC) -shared -o expr.pd_linux $(LINUXOBJ) -lc -lm
strip --strip-unneeded expr.pd_linux
expr~.pd_linux: expr.pd_linux
-ln -s expr.pd_linux expr~.pd_linux
......@@ -110,12 +109,11 @@ install_linux:
install expr.pd_linux $(PDEXTERN)
rm -f $(PDEXTERN)/expr~.pd_linux
rm -f $(PDEXTERN)/fexpr~.pd_linux
cd $(PDEXTERN); \
-ln -s expr.pd_linux expr~.pd_linux
-ln -s expr.pd_linux fexpr~.pd_linux
cd $(PDEXTERN); ln -s expr.pd_linux expr~.pd_linux
cd $(PDEXTERN); ln -s expr.pd_linux fexpr~.pd_linux
linux_clean:
clean_linux:
rm -f *.pd_linux_o *.o
# ----------------------- MAC OSX -----------------------
......
......@@ -381,7 +381,7 @@ SDY the following coredumps why?
post("expr: internal error expr_new");
default:
pd_error(x, "expr: bad type (%lx) inlet = %d\n",
eptr->ex_type, i + 1, 0, 0, 0);
eptr->ex_type, i + 1);
break;
}
}
......@@ -955,7 +955,7 @@ if (!sym || !(garray = (t_garray *)pd_findbyclass(sym, garray_class)) || \
!garray_getfloatwords(garray, &size, &vec)) { \
optr->ex_type = ET_FLT; \
optr->ex_int = 0; \
error("no such table '%s'", sym->s_name); \
error("no such table '%s'", sym?(sym->s_name):"(null)"); \
return; \
}
......
NAME=fiddle~
CSYM=fiddle_tilde
include ../makefile
include ../makefile.subdir
#N canvas 33 0 647 662 12;
#N canvas 234 90 647 662 12;
#X floatatom 41 204 0 0 0 0 - - -;
#X obj 254 382 print~;
#X msg 254 347 bang;
......@@ -7,7 +7,7 @@
#X msg 55 252 bang;
#X obj 183 382 print~;
#X msg 183 347 bang;
#N canvas 0 0 450 300 graph1 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array array2 150000 float 0;
#X coords 0 1 150000 -1 200 150 1;
#X restore 393 464 graph;
......@@ -22,7 +22,6 @@
#X floatatom 96 303 0 0 0 0 - - -;
#X obj 96 326 *~ 1000;
#X msg 43 568 read ../doc/sound/bell.aiff array2;
#X msg 43 591 read ../doc/sound/vocal.aiff array2;
#X msg 47 229 set 0.5;
#X text 95 196 left signal input is transposition (1 is normal \, 2
is up an octave \, etc);
......@@ -46,6 +45,7 @@ that changing window size doesn't change the transposition.;
to zero--you should mute the output before doing so. This may be desirable
if you've set a large window size but then want to decrease it without
waiting for the next phase crossing.;
#X msg 43 591 read ../doc/sound/voice.wav array2;
#X connect 0 0 3 0;
#X connect 2 0 1 0;
#X connect 3 0 6 0;
......@@ -56,7 +56,7 @@ waiting for the next phase crossing.;
#X connect 4 0 3 1;
#X connect 5 0 3 0;
#X connect 7 0 6 0;
#X connect 11 0 28 0;
#X connect 11 0 27 0;
#X connect 12 0 16 0;
#X connect 14 0 13 0;
#X connect 14 0 13 1;
......@@ -65,10 +65,10 @@ waiting for the next phase crossing.;
#X connect 17 0 18 0;
#X connect 18 0 15 0;
#X connect 19 0 10 0;
#X connect 20 0 10 0;
#X connect 21 0 3 0;
#X connect 28 0 14 0;
#X connect 29 0 31 0;
#X connect 30 0 28 1;
#X connect 31 0 32 0;
#X connect 32 0 30 0;
#X connect 20 0 3 0;
#X connect 27 0 14 0;
#X connect 28 0 30 0;
#X connect 29 0 27 1;
#X connect 30 0 31 0;
#X connect 31 0 29 0;
#X connect 36 0 10 0;
......@@ -13,20 +13,24 @@ This file is downloadable from http://www.crca.ucsd.edu/~msp .
#ifdef PD
#include "m_pd.h"
#else
#define t_sample float
#endif
typedef struct _loopctl
{
double l_phase;
float l_invwindow;
float l_window;
t_sample l_invwindow;
t_sample l_window;
int l_resync;
} t_loopctl;
static void loopctl_run(t_loopctl *x, float *transposein,
float *windowin, float *rawout, float *windowout, int n)
static void loopctl_run(t_loopctl *x, t_sample *transposein,
t_sample *windowin, t_sample *rawout, t_sample *windowout, int n)
{
float window, invwindow;
t_sample window, invwindow;
double phase = x->l_phase;
if (x->l_resync)
{
......@@ -55,7 +59,7 @@ static void loopctl_run(t_loopctl *x, float *transposein,
{
double phaseinc = invwindow * *transposein++;
double newphase;
float nwind = *windowin++;
t_sample nwind = *windowin++;
if (phaseinc >= 1 || phaseinc < 0)
phaseinc = 0;
newphase = phase + phaseinc;
......@@ -77,7 +81,7 @@ static void loopctl_run(t_loopctl *x, float *transposein,
newphase -= 1.;
}
phase = newphase;
*rawout++ = (float)phase;
*rawout++ = (t_sample)phase;
*windowout++ = window;
}
x->l_invwindow = invwindow;
......@@ -124,10 +128,10 @@ static void *loop_new(void)
static t_int *loop_perform(t_int *w)
{
t_loopctl *ctl = (t_loopctl *)(w[1]);
t_float *in1 = (t_float *)(w[2]);
t_float *in2 = (t_float *)(w[3]);
t_float *out1 = (t_float *)(w[4]);
t_float *out2 = (t_float *)(w[5]);
t_sample *in1 = (t_sample *)(w[2]);
t_sample *in2 = (t_sample *)(w[3]);
t_sample *out1 = (t_sample *)(w[4]);
t_sample *out2 = (t_sample *)(w[5]);
int n = (int)(w[6]);
loopctl_run(ctl, in1, in2, out1, out2, n);
return (w+7);
......
NAME=loop~
CSYM=loop_tilde
include ../makefile
include ../makefile.subdir
......@@ -13,8 +13,8 @@ typedef struct _lrshift_tilde
static t_int *leftshift_perform(t_int *w)
{
t_float *in = (t_float *)(w[1]);
t_float *out= (t_float *)(w[2]);
t_sample *in = (t_sample *)(w[1]);
t_sample *out= (t_sample *)(w[2]);
int n = (int)(w[3]);
int shift = (int)(w[4]);
in += shift;
......@@ -28,8 +28,8 @@ static t_int *leftshift_perform(t_int *w)
static t_int *rightshift_perform(t_int *w)
{
t_float *in = (t_float *)(w[1]);
t_float *out= (t_float *)(w[2]);
t_sample *in = (t_sample *)(w[1]);
t_sample *out= (t_sample *)(w[2]);
int n = (int)(w[3]);
int shift = (int)(w[4]);
n -= shift;
......
NAME=lrshift~
CSYM=lrshift_tilde
include ../makefile
include ../makefile.subdir
NAME=pd~
CSYM=pd_tilde
include ../makefile
include ../makefile.subdir
pd_linux: pdsched.pd_linux
......@@ -11,5 +11,4 @@ d_ppc: pdsched.d_ppc
pdsched.pd_linux: pdsched.c
$(CC) $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c
$(CC) -shared -o $*.pd_linux $*.o -lc -lm
strip --strip-unneeded $*.pd_linux
rm -f $*.o
......@@ -17,15 +17,33 @@ outputs audio and messages. */
#define BUFSIZE 65536
static char inbuf[BUFSIZE];
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
void glob_watchdog(t_pd *dummy);
static void pollwatchdog( void)
{
static int sched_diddsp, sched_nextpingtime;
sched_diddsp++;
if (sys_nogui && sys_hipriority && (sched_diddsp - sched_nextpingtime > 0))
{
glob_watchdog(0);
/* ping every 2 seconds */
sched_nextpingtime = sched_diddsp +
2 * (int)(sys_dacsr /(double)sys_schedblocksize);
}
}
#endif
int pd_extern_sched(char *flags)
{
int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
int i, j, rate, advance, callback, chin, chout, fill = 0, c;
int i, j, rate, advance, callback, chin, chout, fill = 0, c, blocksize;
t_binbuf *b = binbuf_new();
sys_get_audio_params(&naudioindev, audioindev, chindev,
&naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback);
&naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback,
&blocksize);
chin = (naudioindev < 1 ? 0 : chindev[0]);
chout = (naudiooutdev < 1 ? 0 : choutdev[0]);
......@@ -57,6 +75,9 @@ int pd_extern_sched(char *flags)
*fp++ = 0;
sched_tick(sys_time+sys_time_per_dsp_tick);
sys_pollgui();
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
pollwatchdog();
#endif
printf(";\n");
for (i = chout*DEFDACBLKSIZE, fp = sys_soundout; i--; fp++)
{
......
......@@ -14,8 +14,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#ifdef NT
#ifdef _MSC_VER
#pragma warning (disable: 4305 4244)
#endif
......@@ -47,7 +48,7 @@ char *class_gethelpdir(t_class *c);
#endif
#ifdef __linux__
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
#ifdef __x86_64__
static char pd_tilde_dllextent[] = ".l_ia64",
pd_tilde_dllextent2[] = ".pd_linux";
......@@ -60,6 +61,9 @@ static char pd_tilde_dllextent[] = ".l_i386",
static char pd_tilde_dllextent[] = ".d_fat",
pd_tilde_dllextent2[] = ".pd_darwin";
#endif
#if defined(_WIN32) || defined(__CYGWIN__)
static char pd_tilde_dllextent[] = ".m_i386", pd_tilde_dllextent2[] = ".dll";
#endif
/* ------------------------ pd_tilde~ ----------------------------- */
......@@ -249,6 +253,8 @@ static void pd_tilde_donew(t_pd_tilde *x, char *pddir, char *schedlibdir,
/* OK, we're parent */
close(pipe1[0]);
close(pipe2[1]);
fcntl(pipe1[1], F_SETFD, FD_CLOEXEC);
fcntl(pipe2[0], F_SETFD, FD_CLOEXEC);
x->x_outfd = fdopen(pipe1[1], "w");
x->x_infd = fdopen(pipe2[0], "r");
x->x_childpid = pid;
......@@ -512,7 +518,7 @@ static void *pd_tilde_new(t_symbol *s, int argc, t_atom *argv)
int ninsig = 2, noutsig = 2, j, fifo = 5;
float sr = sys_getsr();
t_sample **g;
t_symbol *pddir = sys_guidir,
t_symbol *pddir = sys_libdir,
*scheddir = gensym(class_gethelpdir(pd_tilde_class));
/* fprintf(stderr, "pd %s, sched %s\n", pddir->s_name, scheddir->s_name); */
while (argc > 0)
......
NAME=pique
CSYM=pique
include ../makefile
include ../makefile.subdir
......@@ -51,7 +51,7 @@ static float hanning(float pidetune, float sinpidetune)
(sinpidetune/(pidetune+pi) + sinpidetune/(pidetune-pi)));
}