Commit 13d9f965 authored by Miller Puckette's avatar Miller Puckette
Browse files

test06 - bonk and sigmund improvements; deleted flush for stdout

parent 634a77cc
#N canvas 202 17 779 858 12;
#N canvas 31 5 779 858 12;
#X obj 399 526 metro 100;
#X obj 212 472 phasor~;
#X obj 399 556 snapshot~;
......@@ -7,7 +7,7 @@
#X obj 23 461 phasor~;
#X floatatom 23 329 5 -100 1000 0 - - -;
#X obj 23 518 tabread4~ \$0-tab;
#X msg 281 330 0.5;
#X msg 290 329 0.5;
#X msg 326 329 0.01;
#X obj 398 455 loadbang;
#X msg 399 478 1;
......@@ -59,7 +59,6 @@
;
#X text 387 739 (approximately zero but not exactly because of;
#X text 389 753 truncation error!);
#X msg 340 408 0.5;
#X obj 341 383 t b f;
#X text 400 357 convert to samples;
#X text 385 384 set both last-onset and previous-onset;
......@@ -74,13 +73,13 @@
#X text 206 402 convert to;
#X text 469 472 in order to change onset to reflect it;
#X text 469 456 Each 100 msec \, poll phase of phasor~;
#X text 24 36 Here is how to use the tabread~ "onset" input to allow
#X text 24 29 Here is how to use the tabread~ "onset" input to allow
clean varispeed playback from a long table. At left \, a phasor~ is
naiveley rescaled to the size of the tble. At right \, the phasor~
gets only a 10000-point range about a moving "onset". Ten times per
second \, we poll tha phasor~ phase \, sum its value into the onset
\, and back up the phase of the phasor~ correspondingly.;
#X text 25 150 The tricky bits are \, first \, that we need to poll
#X text 24 138 The tricky bits are \, first \, that we need to poll
the phasor~ phase one sample into the future (so we add the per-sample
increment into the snapshot~ result). Second \, we can't just reset
the phasor~ to a fixed point - instead \, we measure how much the onset
......@@ -88,19 +87,22 @@ has actually increased (which has truncation error from summing in
the phase snapshot) \, and subtract that increase from the phase \,
giving a value that differs from zero by the truncation error but reflects
the true phase we should reset to for continuity.;
#X text 26 290 The metronome rate is arbitrary but should be fast enough
#X text 26 281 The metronome rate is arbitrary but should be fast enough
that the phasor~ never has time to wrap.;
#X text 518 539 extrapolate snapshot of phase by one;
#X text 517 552 sample to sync with next block;
#X text 41 617 BAD;
#X text 160 770 GOOD;
#X text 195 9 VARIABLE SPEED PLAYBACK FROM LONG TABLES;
#X msg 340 408 0;
#X text 369 328 <- reset phase. 0.5 causes trouble for the "bad" way.
;
#X connect 0 0 2 0;
#X connect 1 0 24 0;
#X connect 2 0 31 0;
#X connect 5 0 26 0;
#X connect 6 0 45 0;
#X connect 6 0 65 0;
#X connect 6 0 64 0;
#X connect 7 0 4 0;
#X connect 7 0 4 1;
#X connect 8 0 5 1;
......@@ -147,10 +149,10 @@ that the phasor~ never has time to wrap.;
#X connect 40 0 35 0;
#X connect 40 0 38 0;
#X connect 45 0 5 0;
#X connect 51 0 58 0;
#X connect 57 0 1 1;
#X connect 58 0 57 0;
#X connect 58 1 19 1;
#X connect 58 1 12 1;
#X connect 65 0 1 0;
#X connect 65 0 30 0;
#X connect 51 0 57 0;
#X connect 57 0 79 0;
#X connect 57 1 19 1;
#X connect 57 1 12 1;
#X connect 64 0 1 0;
#X connect 64 0 30 0;
#X connect 79 0 15 0;
/*
###########################################################################
# bonk~ - a Max/MSP external
# by miller puckette and ted appel
# by miller puckette and ted apel
# http://crca.ucsd.edu/~msp/
# Max/MSP port by barry threw
# http://www.barrythrew.com
......@@ -911,7 +911,7 @@ static void bonk_print(t_bonk *x, t_floatarg f)
h->h_before, h->h_countup);
}
post("filter details (frequencies are in units of %.2f-Hz. bins):",
x->x_sr);
x->x_sr/x->x_npoints);
for (j = 0; j < x->x_nfilters; j++)
post("%2d cf %.2f bw %.2f nhops %d hop %d skip %d npoints %d",
j,
......
......@@ -71,6 +71,7 @@ typedef struct _pd_tilde
t_object x_obj;
t_clock *x_clock;
t_outlet *x_outlet1; /* for messages back from subproc */
t_canvas *x_canvas;
#endif /* PD */
#ifdef MSP
t_pxobject x_obj;
......@@ -165,7 +166,8 @@ static void pd_tilde_readmessages(t_pd_tilde *x)
}
static void pd_tilde_donew(t_pd_tilde *x, char *pddir, char *schedlibdir,
char *pdargs, int ninsig, int noutsig, int fifo, float samplerate)
char *patchdir, char *pdargs, int ninsig, int noutsig, int fifo,
float samplerate)
{
int i, pid, pipe1[2], pipe2[2];
char cmdbuf[MAXPDSTRING], pdexecbuf[MAXPDSTRING], schedbuf[MAXPDSTRING];
......@@ -195,8 +197,8 @@ static void pd_tilde_donew(t_pd_tilde *x, char *pddir, char *schedlibdir,
}
}
snprintf(cmdbuf, MAXPDSTRING,
"%s -schedlib %s/pdsched -inchannels %d -outchannels %d -r %g %s\n",
pdexecbuf, schedlibdir, ninsig, noutsig, samplerate, pdargs);
"%s -schedlib %s/pdsched -path %s -inchannels %d -outchannels %d -r %g %s\n",
pdexecbuf, schedlibdir, patchdir, ninsig, noutsig, samplerate, pdargs);
#if 0
#ifdef PD
fprintf(stderr, "%s", cmdbuf);
......@@ -368,6 +370,7 @@ static void pd_tilde_pdtilde(t_pd_tilde *x, t_symbol *s,
{
t_symbol *sel = ((argc > 0 && argv->a_type == A_SYMBOL) ?
argv->a_w.w_symbol : gensym("?"));
char *patchdir;
if (sel == gensym("start"))
{
char pdargstring[MAXPDSTRING];
......@@ -383,6 +386,7 @@ static void pd_tilde_pdtilde(t_pd_tilde *x, t_symbol *s,
if (strlen(pdargstring) < MAXPDSTRING-1)
strcat(pdargstring, " ");
}
patchdir = canvas_getdir(x->x_canvas)->s_name;
#endif
#ifdef MAX
while (argc--)
......@@ -401,9 +405,11 @@ static void pd_tilde_pdtilde(t_pd_tilde *x, t_symbol *s,
strcat(pdargstring, " ");
argv++;
}
patchdir = ".";
#endif
pd_tilde_donew(x, x->x_pddir->s_name, x->x_schedlibdir->s_name,
pdargstring, x->x_ninsig, x->x_noutsig, x->x_fifo, x->x_sr);
patchdir, pdargstring, x->x_ninsig, x->x_noutsig, x->x_fifo,
x->x_sr);
}
else if (sel == gensym("stop"))
{
......@@ -540,6 +546,7 @@ static void *pd_tilde_new(t_symbol *s, int argc, t_atom *argv)
x->x_outfd = 0;
x->x_childpid = -1;
x->x_msgbuf = 0;
x->x_canvas = canvas_getcurrent();
for (j = 1, g = x->x_insig; j < ninsig; j++, g++)
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
x->x_outlet1 = outlet_new(&x->x_obj, 0);
......
......@@ -363,7 +363,7 @@ static void sigmund_getrawpeaks(int npts, float *insamps,
#define PITCHUNCERTAINTY 0.3
#define HALFTONEINC 0.059
#define SUBHARMONICS 16
#define DBPERHALFTONE 0.5
#define DBPERHALFTONE 0.0
static void sigmund_getpitch(int npeak, t_peak *peakv, float *freqp,
float npts, float srate, int loud)
......@@ -405,8 +405,6 @@ static void sigmund_getpitch(int npeak, t_peak *peakv, float *freqp,
for (i = 0; i < nsalient; i++)
{
t_peak *thispeak = bigpeaks[i];
float pitchuncertainty =
4 * PITCHUNCERTAINTY * fperbin / (HALFTONEINC * thispeak->p_freq);
float weightindex = (48./LOG2) *
log(thispeak->p_freq/(2.*fperbin));
float loudness = sqrt(thispeak->p_amp);
......@@ -415,8 +413,8 @@ static void sigmund_getpitch(int npeak, t_peak *peakv, float *freqp,
{
float subindex = weightindex -
(48./LOG2) * log(j + 1.);
int loindex = subindex - pitchuncertainty;
int hiindex = subindex + pitchuncertainty + 1;
int loindex = subindex - 0.5;
int hiindex = loindex+2;
if (hiindex < 0)
break;
if (hiindex >= npit)
......@@ -424,7 +422,7 @@ static void sigmund_getpitch(int npeak, t_peak *peakv, float *freqp,
if (loindex < 0)
loindex = 0;
for (k = loindex; k <= hiindex; k++)
weights[k] += loudness * 4. / (4. + j);
weights[k] += loudness * 6. / (6. + j);
}
sumweight += loudness;
}
......@@ -441,29 +439,35 @@ static void sigmund_getpitch(int npeak, t_peak *peakv, float *freqp,
freq = 0;
goto done;
}
for (i = bestbin+1; i < npit; i++)
if (bestbin > 0 && bestbin < npit-1)
{
if (weights[i] < bestweight)
break;
bestbin += 0.5;
int ibest = bestbin;
bestbin += (weights[ibest+1] - weights[ibest-1]) /
(weights[ibest+1] + weights[ibest] + weights[ibest-1]);
}
freq = 2*fperbin * exp((LOG2/48.)*bestbin);
for (sumamp = sumweight = sumfreq = 0, i = 0; i < nsalient; i++)
{
t_peak *thispeak = bigpeaks[i];
float thisloudness = sqrt(thispeak->p_amp);
float thisloudness = thispeak->p_amp;
float thisfreq = thispeak->p_freq;
float harmonic = thisfreq/freq;
float intpart = (int)(0.5 + harmonic);
float inharm = freq * (harmonic - intpart);
if (harmonic < 1)
continue;
if (inharm < 0.25*fperbin && inharm > -0.25*fperbin)
float inharm = harmonic - intpart;
#if 0
if (loud)
post("freq %f intpart %f inharm %f", freq, intpart, inharm);
#endif
if (intpart >= 1 && intpart <= 16 &&
inharm < 0.015 * intpart && inharm > - (0.015 * intpart))
{
float weight = thisloudness * intpart;
sumweight += weight;
sumfreq += weight*thisfreq/intpart;
#if 0
if (loud)
post("weight %f freq %f", weight, thisfreq);
#endif
}
}
if (sumweight > 0)
......
#N canvas 110 37 789 525 10;
#X msg 84 147 walk the dog;
#X msg 91 169 1;
#X msg 90 215 flush;
#X obj 84 240 stdout;
#X text 472 410 updated for Pd version 0.42;
#N canvas 121 60 488 321 12;
#X msg 126 203 walk the dog;
#X msg 117 156 1;
#X obj 117 240 stdout;
#X text 269 287 updated for Pd version 0.42;
#X obj 14 13 stdout;
#X text 67 14 - write messages to standard output;
#X msg 96 192 1 2;
#X connect 0 0 3 0;
#X connect 1 0 3 0;
#X connect 2 0 3 0;
#X connect 7 0 3 0;
#X msg 122 179 1 2;
#X obj 119 291 pd~;
#X text 44 291 see also:;
#X text 34 39 Sends messages to Pd's standard output. This is useful
in conjunction with the pd~ object \, which starts a pd sub-process.
Messages sent to the sub-process standard output appear on the output
of the pd~ object in the owning process. This might also be useful
in other situations. Note that there's no corresponding "stdin" object
- there seems to be no one canonical way such a thing should act.;
#X connect 0 0 2 0;
#X connect 1 0 2 0;
#X connect 6 0 2 0;
......@@ -37,7 +37,7 @@ static void stdout_anything(t_stdout *x, t_symbol *s, int argc, t_atom *argv)
printf("%s;\n", msgbuf);
}
static void stdout_flush(t_stdout *x)
static void stdout_free(t_stdout *x)
{
fflush(stdout);
}
......@@ -45,7 +45,6 @@ static void stdout_flush(t_stdout *x)
void stdout_setup(void)
{
stdout_class = class_new(gensym("stdout"), (t_newmethod)stdout_new,
(t_method)stdout_flush, sizeof(t_stdout), 0, 0);
class_addmethod(stdout_class, (t_method)stdout_flush, gensym("flush"), 0);
(t_method)stdout_free, sizeof(t_stdout), 0, 0);
class_addanything(stdout_class, stdout_anything);
}
File mode changed from 100644 to 100755
......@@ -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 */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment