From 501b98d9aa5b5a48885af169e0bc67de7ec8bd42 Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Thu, 2 Jun 2016 01:01:49 -0400 Subject: [PATCH] port f92dc617867c18216bf4a0e32ece6122b70abc5b from Pd-l2ork: updated bonk~, added bob~, updated makefile to properly build bob~ --- pd/extra/Makefile.am | 2 +- pd/extra/bonk~/bonk~-help.pd | 108 ++++++++--------- pd/extra/bonk~/bonk~.c | 220 +++++++++++++++++++++-------------- pd/src/makefile.in | 1 + 4 files changed, 186 insertions(+), 145 deletions(-) diff --git a/pd/extra/Makefile.am b/pd/extra/Makefile.am index c3a077369..18be7000c 100644 --- a/pd/extra/Makefile.am +++ b/pd/extra/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=bonk~ choice expr~ fiddle~ loop~ lrshift~ pd~ pique sigmund~ stdout +SUBDIRS=bob~ bonk~ choice expr~ fiddle~ loop~ lrshift~ pd~ pique sigmund~ stdout DIST_SUBDIRS=$(SUBDIRS) diff --git a/pd/extra/bonk~/bonk~-help.pd b/pd/extra/bonk~/bonk~-help.pd index 4666d6f55..bd81eb1a8 100644 --- a/pd/extra/bonk~/bonk~-help.pd +++ b/pd/extra/bonk~/bonk~-help.pd @@ -1,11 +1,11 @@ -#N canvas 0 0 1052 581 12; -#X obj 382 492 spigot; -#X msg 484 293 bang; -#X obj 483 454 bonk~; -#X msg 483 357 print; -#X obj 435 428 adc~; -#X msg 637 506 \; pd dsp 1; -#X obj 300 492 spigot; +#N canvas 118 87 1124 603 12; +#X obj 402 492 spigot; +#X msg 504 293 bang; +#X obj 503 454 bonk~; +#X msg 503 357 print; +#X obj 455 428 adc~; +#X msg 657 506 \; pd dsp 1; +#X obj 320 492 spigot; #N canvas 366 126 604 404 synth 0; #X obj 112 24 r bonk-cooked; #X obj 112 49 unpack; @@ -57,35 +57,35 @@ #X connect 21 0 1 0; #X connect 22 0 6 0; #X connect 23 0 9 0; -#X restore 869 523 pd synth; -#X floatatom 869 500 0 0 0 0 - - -; -#X msg 869 470 0; -#X msg 900 470 90; -#X text 625 472 click here; -#X text 626 485 to start DSP; -#X text 5 285 In this patch \, after starting DSP \, you can print +#X restore 889 523 pd synth; +#X floatatom 889 500 0 0 0 0 - - -; +#X msg 889 470 0; +#X msg 920 470 90; +#X text 645 472 click here; +#X text 646 485 to start DSP; +#X text 5 291 In this patch \, after starting DSP \, you can print out the raw or cooked output using the two "spigots" or listen to a synthesizer output by raising its volume.; -#X text 770 469 output volume; -#X text 784 487 (0-100); -#X msg 483 138 mask 4 0.7; -#X text 578 120 Describes how energy in each frequency band masks later +#X text 772 470 output volume; +#X text 786 488 (0-100); +#X msg 503 138 mask 4 0.7; +#X text 600 120 Describes how energy in each frequency band masks later energy in the band. Here the masking is total for 4 analysis periods and then drops by 0.7 each period.; -#X text 528 286 Poll the current spectrum via "raw" outlet \, You can +#X text 548 286 Poll the current spectrum via "raw" outlet \, You can set a very high threshold if you don't want attacks mixed in.; -#X msg 483 331 debug 0; -#X text 561 331 turn debugging on or off.; -#X obj 349 493 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +#X msg 503 331 debug 0; +#X text 581 331 turn debugging on or off.; +#X obj 369 493 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; -#X obj 431 493 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +#X obj 451 493 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; -#X obj 382 522 print cooked; -#X obj 300 522 print raw; -#X text 162 491 enable printout:; -#X text 560 202 Minimum "velocity" to output (quieter notes are ignored.) +#X obj 402 522 print cooked; +#X obj 320 522 print raw; +#X text 182 491 enable printout:; +#X text 580 202 Minimum "velocity" to output (quieter notes are ignored.) ; -#X obj 485 481 s bonk-cooked; +#X obj 505 481 s bonk-cooked; #X text 8 145 Bonk's two outputs are the raw spectrum of the attack (provided as a list of 11 numbers giving the signal "loudness" in the 11 frequency bands used) \, and the "cooked" output which gives only @@ -94,12 +94,12 @@ an instrument number (counting up from zero) and a "velocity". This bands \, normalized so that 100 is an attack of amplitude of about 1 The instrument number is significant only if Bonk has a "template set" in memory.; -#X text 580 35 Set low and high thresholds. Signal growth must exceed +#X text 612 35 Set low and high thresholds. Signal growth must exceed the high one and then fall to the low one to make an attack. The unit is the sum of the proportional growth in the 11 filter bands. Proportional growth is essentially the logarithmic time derivative.; -#X msg 483 384 print 1; -#X text 551 386 print out filterbank settings; +#X msg 503 384 print 1; +#X text 571 386 print out filterbank settings; #X text 9 33 The Bonk object takes an audio signal input and looks for "attacks" defined as sharp changes in the spectral envelope of the incoming sound. Optionally \, and less reliably \, you can have @@ -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 0 0 699 717 creation-arguments 1; +#N canvas 2 52 699 717 creation-arguments 0; #X text 228 14 creation arguments for bonk~; #X text 70 272 -npts 256; #X text 44 244 default value:; @@ -143,15 +143,15 @@ be at least 1.5.; #X text 212 567 center frequency \, in bins \, of the lowest filter. The others are computed from this.; #X restore 147 414 pd creation-arguments; -#N canvas 660 173 579 589 templates 0; -#X msg 76 197 learn 0; -#X msg 76 227 forget; -#X msg 76 257 write templates.txt; -#X msg 76 287 read templates.txt; -#X msg 76 107 debounce 0; -#X msg 76 137 learn 10; -#X obj 62 431 outlet; -#X text 155 133 Forget all templates and start learning new ones. The +#N canvas 411 161 680 476 templates 0; +#X msg 58 197 learn 0; +#X msg 58 227 forget; +#X msg 58 257 write templates.txt; +#X msg 58 287 read templates.txt; +#X msg 58 107 debounce 0; +#X msg 58 137 learn 10; +#X obj 31 402 outlet; +#X text 155 134 Forget all templates and start learning new ones. The argument gives the number of times you will hit each instrument (10 recommended.) Turn on the output volume above for audible feedback as you train Bonk. "Learn 0" exits learn mode.; @@ -167,24 +167,24 @@ to erase and record over a template.; #X connect 3 0 6 0; #X connect 4 0 6 0; #X connect 5 0 6 0; -#X restore 500 421 pd templates; -#X msg 483 68 thresh 2.5 5; -#X msg 483 173 attack-frames 1; -#X text 608 174 number of frames over which to measure growth; -#X text 605 422 more messages for managing templates; -#X msg 483 201 minvel 7; -#X msg 483 228 spew 0; -#X text 550 230 Turn spew mode on/off; -#X msg 483 255 useloudness 0; -#X text 597 254 experimental: use alternative loudness units; +#X restore 520 421 pd templates; +#X msg 503 68 thresh 2.5 5; +#X msg 503 173 attack-frames 1; +#X text 628 174 number of frames over which to measure growth; +#X text 625 422 more messages for managing templates; +#X msg 503 201 minvel 7; +#X msg 503 228 spew 0; +#X text 570 230 Turn spew mode on/off; +#X msg 503 255 useloudness 0; +#X text 617 254 experimental: use alternative loudness units; #X text 212 9 BONK~ - attack detection and spectral envelope measurement ; -#X text 734 552 Updated for Pd version 0.42; +#X text 754 552 Updated for Pd version 0.42; #X text 5 344 By default bonk's analysis is carried out on a 256-point window (6 msec at 44.1 kHz) and the analysis period is 128 samples. These and other parameters may be overridden using creation arguments as shown in the subpatch below:; -#X text 552 356 Print out settings and templates.; +#X text 572 356 Print out settings and templates.; #X connect 0 0 23 0; #X connect 1 0 2 0; #X connect 2 0 6 0; diff --git a/pd/extra/bonk~/bonk~.c b/pd/extra/bonk~/bonk~.c index f1d49c9c1..33e19701b 100644 --- a/pd/extra/bonk~/bonk~.c +++ b/pd/extra/bonk~/bonk~.c @@ -114,19 +114,19 @@ typedef struct _filterkernel int k_hoppoints; int k_skippoints; int k_nhops; - float k_centerfreq; /* center frequency, bins */ - float k_bandwidth; /* bandwidth, bins */ - float *k_stuff; + t_float k_centerfreq; /* center frequency, bins */ + t_float k_bandwidth; /* bandwidth, bins */ + t_float *k_stuff; } t_filterkernel; typedef struct _filterbank { int b_nfilters; /* number of filters in bank */ int b_npoints; /* input vector size */ - float b_halftones; /* filter bandwidth in halftones */ - float b_overlap; /* overlap; default 1 for 1/2-power pts */ - float b_firstbin; /* freq of first filter in bins, default 1 */ - float b_minbandwidth; /* minimum bandwidth, default 1.5 */ + t_float b_halftones; /* filter bandwidth in halftones */ + t_float b_overlap; /* overlap; default 1 for 1/2-power pts */ + t_float b_firstbin; /* freq of first filter in bins, default 1 */ + t_float b_minbandwidth; /* minimum bandwidth, default 1.5 */ t_filterkernel *b_vec; /* filter kernels */ int b_refcount; /* number of bonk~ objects using this */ struct _filterbank *b_next; /* next in linked list */ @@ -166,16 +166,16 @@ static t_filterbank *bonk_filterbanklist; typedef struct _hist { - float h_power; - float h_before; - float h_outpower; + t_float h_power; + t_float h_before; + t_float h_outpower; int h_countup; - float h_mask[MASKHIST]; + t_float h_mask[MASKHIST]; } t_hist; typedef struct template { - float t_amp[MAXNFILTERS]; + t_float t_amp[MAXNFILTERS]; } t_template; typedef struct _insig @@ -187,8 +187,8 @@ typedef struct _insig #ifdef MSP void *g_outlet; /* outlet for raw data */ #endif - float *g_inbuf; /* buffered input samples */ - t_float *g_invec; /* new input samples */ + t_float *g_inbuf; /* buffered input samples */ + t_sample *g_invec; /* new input samples */ } t_insig; typedef struct _bonk @@ -209,18 +209,18 @@ typedef struct _bonk int x_npoints; /* number of points in input buffer */ int x_period; /* number of input samples between analyses */ int x_nfilters; /* number of filters requested */ - float x_halftones; /* nominal halftones between filters */ - float x_overlap; - float x_firstbin; - float x_minbandwidth; - float x_hithresh; /* threshold for total growth to trigger */ - float x_lothresh; /* threshold for total growth to re-arm */ - float x_minvel; /* minimum velocity we output */ - float x_maskdecay; + t_float x_halftones; /* nominal halftones between filters */ + t_float x_overlap; + t_float x_firstbin; + t_float x_minbandwidth; + t_float x_hithresh; /* threshold for total growth to trigger */ + t_float x_lothresh; /* threshold for total growth to re-arm */ + t_float x_minvel; /* minimum velocity we output */ + t_float x_maskdecay; int x_masktime; int x_useloudness; /* use loudness spectra instead of power */ - float x_debouncedecay; - float x_debouncevel; + t_float x_debouncedecay; + t_float x_debouncevel; double x_learndebounce; /* debounce time (in "learn" mode only) */ int x_attackbins; /* number of bins to wait for attack */ @@ -239,7 +239,7 @@ typedef struct _bonk int x_learncount; /* countup for "learn" mode */ int x_spew; /* if true, always generate output! */ int x_maskphase; /* phase, 0 to MASKHIST-1, for mask history */ - float x_sr; /* current sample rate in Hz. */ + t_float x_sr; /* current sample rate in Hz. */ int x_hit; /* next "tick" called because of a hit, not a poll */ } t_bonk; @@ -247,8 +247,14 @@ typedef struct _bonk static void *bonk_new(t_symbol *s, long ac, t_atom *av); static void bonk_tick(t_bonk *x); static void bonk_doit(t_bonk *x); +static void bonk_perform_generic(t_bonk *x, int n); static t_int *bonk_perform(t_int *w); +static void bonk_perform64(t_bonk *x, t_object *dsp64, double **ins, + long numins, double **outs, long numouts, + long sampleframes, long flags, void *userparam); static void bonk_dsp(t_bonk *x, t_signal **sp); +static void bonk_dsp64(t_bonk *x, t_object *dsp64, short *count, + double samplerate, long maxvectorsize, long flags); void bonk_assist(t_bonk *x, void *b, long m, long a, char *s); static void bonk_free(t_bonk *x); void bonk_setup(void); @@ -278,10 +284,11 @@ void bonk_useloudness_set(t_bonk *x, void *attr, long ac, t_atom *av); void bonk_attackbins_set(t_bonk *x, void *attr, long ac, t_atom *av); void bonk_learn_set(t_bonk *x, void *attr, long ac, t_atom *av); -float qrsqrt(float f); +t_float qrsqrt(t_float f); double clock_getsystime(); double clock_gettimesince(double prevsystime); char *strcpy(char *s1, const char *s2); +#define SETFLOAT A_SETFLOAT #endif static void bonk_tick(t_bonk *x); @@ -290,10 +297,10 @@ static void bonk_tick(t_bonk *x); #define SLIDE 0.25 /* relative slide between filter subwindows */ static t_filterbank *bonk_newfilterbank(int npoints, int nfilters, - float halftones, float overlap, float firstbin, float minbandwidth) + t_float halftones, t_float overlap, t_float firstbin, t_float minbandwidth) { int i, j; - float cf, bw, h, relspace; + t_float cf, bw, h, relspace; t_filterbank *b = (t_filterbank *)getbytes(sizeof(*b)); b->b_npoints = npoints; b->b_nfilters = nfilters; @@ -319,8 +326,8 @@ static t_filterbank *bonk_newfilterbank(int npoints, int nfilters, bw = (0.5*minbandwidth); for (i = 0; i < nfilters; i++) { - float *fp, newcf, newbw; - float normalizer = 0; + t_float *fp, newcf, newbw; + t_float normalizer = 0; int filterpoints, skippoints, hoppoints, nhops; filterpoints = npoints * HALFWIDTH/bw; @@ -339,11 +346,11 @@ static t_filterbank *bonk_newfilterbank(int npoints, int nfilters, hoppoints = SLIDE * npoints * HALFWIDTH/bw; - nhops = 1. + (npoints-filterpoints)/(float)hoppoints; + nhops = 1. + (npoints-filterpoints)/(t_float)hoppoints; skippoints = 0.5 * (npoints-filterpoints - (nhops-1) * hoppoints); b->b_vec[i].k_stuff = - (float *)getbytes(2 * sizeof(float) * filterpoints); + (t_float *)getbytes(2 * sizeof(t_float) * filterpoints); b->b_vec[i].k_filterpoints = filterpoints; b->b_vec[i].k_nhops = nhops; b->b_vec[i].k_hoppoints = hoppoints; @@ -353,9 +360,9 @@ static t_filterbank *bonk_newfilterbank(int npoints, int nfilters, for (fp = b->b_vec[i].k_stuff, j = 0; j < filterpoints; j++, fp+= 2) { - float phase = j * cf * (2*3.14159/ npoints); - float wphase = j * (2*3.14159 / filterpoints); - float window = sin(0.5*wphase); + t_float phase = j * cf * (2*3.141592653589793 / npoints); + t_float wphase = j * (2*3.141592653589793 / filterpoints); + t_float window = sin(0.5*wphase); fp[0] = window * cos(phase); fp[1] = window * sin(phase); normalizer += window; @@ -389,7 +396,7 @@ static void bonk_freefilterbank(t_filterbank *b) int i; if (bonk_filterbanklist == b) bonk_filterbanklist = b->b_next; - else for (b2 = bonk_filterbanklist; b3 = b2->b_next; b2 = b3) + else for (b2 = bonk_filterbanklist; (b3 = b2->b_next); b2 = b3) if (b3 == b) { b2->b_next = b3->b_next; @@ -398,17 +405,17 @@ static void bonk_freefilterbank(t_filterbank *b) for (i = 0; i < b->b_nfilters; i++) if (b->b_vec[i].k_stuff) freebytes(b->b_vec[i].k_stuff, - b->b_vec[i].k_filterpoints * sizeof(float)); + b->b_vec[i].k_filterpoints * sizeof(t_float)); freebytes(b, sizeof(*b)); } static void bonk_donew(t_bonk *x, int npoints, int period, int nsig, - int nfilters, float halftones, float overlap, float firstbin, - float minbandwidth, float samplerate) + int nfilters, t_float halftones, t_float overlap, t_float firstbin, + t_float minbandwidth, t_float samplerate) { int i, j; t_hist *h; - float *fp; + t_float *fp; t_insig *g; t_filterbank *fb; for (j = 0, g = x->x_insig; j < nsig; j++, g++) @@ -420,7 +427,7 @@ static void bonk_donew(t_bonk *x, int npoints, int period, int nsig, h->h_mask[j] = 0; } /* we ought to check for failure to allocate memory here */ - g->g_inbuf = (float *)getbytes(npoints * sizeof(float)); + g->g_inbuf = (t_float *)getbytes(npoints * sizeof(t_float)); for (i = npoints, fp = g->g_inbuf; i--; fp++) *fp = 0; } if (!period) period = npoints/2; @@ -475,25 +482,25 @@ static void bonk_tick(t_bonk *x) t_atom at[MAXNFILTERS], *ap, at2[3]; int i, j, k, n; t_hist *h; - float *pp, vel = 0, temperature = 0; - float *fp; + t_float *pp, vel = 0., temperature = 0.; + t_float *fp; t_template *tp; int nfit, ninsig = x->x_ninsig, ntemplate = x->x_ntemplate, nfilters = x->x_nfilters; t_insig *gp; #ifdef _MSC_VER - float powerout[MAXNFILTERS*MAXCHANNELS]; + t_float powerout[MAXNFILTERS*MAXCHANNELS]; #else - float *powerout = alloca(x->x_nfilters * x->x_ninsig * sizeof(*powerout)); + t_float *powerout = alloca(x->x_nfilters * x->x_ninsig * sizeof(*powerout)); #endif for (i = ninsig, pp = powerout, gp = x->x_insig; i--; gp++) { for (j = 0, h = gp->g_hist; j < nfilters; j++, h++, pp++) { - float power = h->h_outpower; - float intensity = *pp = (power > 0 ? 100. * qrsqrt(qrsqrt(power)) : 0); + t_float power = h->h_outpower; + t_float intensity = *pp = (power > 0. ? 100. * qrsqrt(qrsqrt(power)) : 0.); vel += intensity; - temperature += intensity * (float)j; + temperature += intensity * (t_float)j; } } if (vel > 0) temperature /= vel; @@ -527,11 +534,11 @@ static void bonk_tick(t_bonk *x) { int countup = x->x_learncount; /* normalize to 100 */ - float norm; + t_float norm; for (i = nfilters * ninsig, norm = 0, pp = powerout; i--; pp++) norm += *pp * *pp; if (norm < 1.0e-15) norm = 1.0e-15; - norm = 100.f * qrsqrt(norm); + norm = 100. * qrsqrt(norm); /* check if this is the first strike for a new template */ if (!countup) { @@ -554,7 +561,7 @@ static void bonk_tick(t_bonk *x) for (j = nfilters, fp = x->x_template[oldn].t_amp; j--; pp++, fp++) *fp = (countup * *fp + *pp * norm) - /(countup + 1.0f); + /(countup + 1.0); } } countup++; @@ -566,13 +573,13 @@ static void bonk_tick(t_bonk *x) x->x_learndebounce = clock_getsystime(); if (ntemplate) { - float bestfit = -1e30; + t_float bestfit = -1e30; int templatecount; nfit = -1; for (i = 0, templatecount = 0, tp = x->x_template; templatecount < ntemplate; i++) { - float dotprod = 0; + t_float dotprod = 0; for (k = 0, pp = powerout; k < ninsig && templatecount < ntemplate; k++, tp++, templatecount++) @@ -610,7 +617,7 @@ static void bonk_tick(t_bonk *x) pp = powerout + nfilters * (ninsig-1); n < ninsig; n++, gp--, pp -= nfilters) { - float *pp2; + t_float *pp2; for (i = 0, ap = at, pp2 = pp; i < nfilters; i++, ap++, pp2++) { @@ -626,7 +633,7 @@ static void bonk_doit(t_bonk *x) int i, j, ch, n; t_filterkernel *k; t_hist *h; - float growth = 0, *fp1, *fp3, *fp4, hithresh, lothresh; + t_float growth = 0, *fp1, *fp3, *fp4, hithresh, lothresh; int ninsig = x->x_ninsig, nfilters = x->x_nfilters, maskphase = x->x_maskphase, nextphase, oldmaskphase; t_insig *gp; @@ -646,8 +653,8 @@ static void bonk_doit(t_bonk *x) for (i = 0, k = x->x_filterbank->b_vec, h = gp->g_hist; i < nfilters; i++, k++, h++) { - float power = 0, maskpow = h->h_mask[maskphase]; - float *inbuf= gp->g_inbuf + k->k_skippoints; + t_float power = 0, maskpow = h->h_mask[maskphase]; + t_float *inbuf= gp->g_inbuf + k->k_skippoints; int countup = h->h_countup; int filterpoints = k->k_filterpoints; /* if the user asked for more filters that fit under the @@ -665,10 +672,10 @@ static void bonk_doit(t_bonk *x) for (fp1 = inbuf, n = 0; n < k->k_nhops; fp1 += k->k_hoppoints, n++) { - float rsum = 0, isum = 0; + t_float rsum = 0, isum = 0; for (fp3 = fp1, fp4 = k->k_stuff, j = filterpoints; j--;) { - float g = *fp3++; + t_float g = *fp3++; rsum += g * *fp4++; isum += g * *fp4++; } @@ -681,8 +688,8 @@ static void bonk_doit(t_bonk *x) { if (x->x_useloudness) growth += qrsqrt(qrsqrt( - power/(h->h_mask[oldmaskphase] + 1.0e-15))) - 1.f; - else growth += power/(h->h_mask[oldmaskphase] + 1.0e-15) - 1.f; + power/(h->h_mask[oldmaskphase] + 1.0e-15))) - 1.; + else growth += power/(h->h_mask[oldmaskphase] + 1.0e-15) - 1.; } if (!x->x_willattack && countup >= x->x_masktime) maskpow *= x->x_maskdecay; @@ -738,10 +745,7 @@ static void bonk_doit(t_bonk *x) x->x_debouncevel *= x->x_debouncedecay; } -static t_int *bonk_perform(t_int *w) -{ - t_bonk *x = (t_bonk *)(w[1]); - int n = (int)(w[2]); +static void bonk_perform_generic(t_bonk *x, int n) { int onset = 0; if (x->x_countdown >= n) x->x_countdown -= n; @@ -762,13 +766,13 @@ static t_int *bonk_perform(t_int *w) n : (x->x_npoints - infill)); for (i = 0, gp = x->x_insig; i < ninsig; i++, gp++) { - float *fp = gp->g_inbuf + infill; - t_float *in1 = gp->g_invec + onset; + t_float *fp = gp->g_inbuf + infill; + t_sample *in1 = gp->g_invec + onset; for (j = 0; j < m; j++) *fp++ = *in1++; } infill += m; - x->x_infill = infill; + x->x_infill = infill; if (infill == x->x_npoints) { bonk_doit(x); @@ -780,11 +784,11 @@ static t_int *bonk_perform(t_int *w) if (x->x_period < x->x_npoints) { int overlap = x->x_npoints - x->x_period; - float *fp1, *fp2; + t_float *fp1, *fp2; for (n = 0, gp = x->x_insig; n < ninsig; n++, gp++) for (i = overlap, fp1 = gp->g_inbuf, fp2 = fp1 + x->x_period; i--;) - *fp1++ = *fp2++; + *fp1++ = *fp2++; x->x_infill = overlap; } else x->x_infill = 0; @@ -793,6 +797,13 @@ static t_int *bonk_perform(t_int *w) onset += m; } } +} + +static t_int *bonk_perform(t_int *w) +{ + t_bonk *x = (t_bonk *)(w[1]); + int n = (int)(w[2]); + bonk_perform_generic(x, n); return (w+3); } @@ -973,7 +984,8 @@ static void bonk_read(t_bonk *x, t_symbol *s) { float vec[MAXNFILTERS]; int i, ntemplate = 0, remaining; - float *fp, *fp2; + float *fp; + t_float *fp2; /* fbar: canvas_open code taken from g_array.c */ FILE *fd; @@ -1002,7 +1014,7 @@ static void bonk_read(t_bonk *x, t_symbol *s) ntemplate++; } nomore: - if (remaining = (ntemplate % x->x_ninsig)) + 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, @@ -1017,6 +1029,30 @@ nomore: #endif #ifdef MSP +static void bonk_perform64(t_bonk *x, t_object *dsp64, double **ins, + long numins, double **outs, long numouts, + long sampleframes, long flags, void *userparam) +{ + int n = sampleframes; + + int i = sampleframes, ninsig = x->x_ninsig; + t_insig *gp; + + for (i = 0, gp = x->x_insig; i < ninsig; i++, gp++) + gp->g_invec = ins[0]; + + bonk_perform_generic(x, n); +} + +static void bonk_dsp64(t_bonk *x, t_object *dsp64, short *count, + double samplerate, long maxvectorsize, long flags) +{ + + x->x_sr = samplerate; + object_method(dsp64, gensym("dsp_add64"), x, bonk_perform64, 0, NULL); +} + + static void bonk_read(t_bonk *x, t_symbol *s) { defer(x, (method)bonk_doread, s, 0, NULL); @@ -1024,7 +1060,7 @@ static void bonk_read(t_bonk *x, t_symbol *s) static void bonk_doread(t_bonk *x, t_symbol *s) { - long filetype = 'TEXT', outtype; + t_fourcc filetype = 'TEXT', outtype; char filename[512]; short path; @@ -1043,20 +1079,23 @@ static void bonk_doread(t_bonk *x, t_symbol *s) } static void bonk_openfile(t_bonk *x, char *filename, short path) { - float vec[MAXNFILTERS]; + t_float vec[MAXNFILTERS]; int i, ntemplate = 0, remaining; - float *fp, *fp2; + t_float *fp, *fp2; t_filehandle fh; char **texthandle; char *tokptr; + t_ptr_size size; + if (path_opensysfile(filename, path, &fh, READ_PERM)) { object_error((t_object *) x, "error opening %s", filename); return; } - texthandle = sysmem_newhandle(0); + sysfile_geteof(fh, &size); + texthandle = sysmem_newhandleclear(size + 1); sysfile_readtextfile(fh, texthandle, 0, TEXT_LB_NATIVE); sysfile_close(fh); @@ -1081,7 +1120,7 @@ static void bonk_openfile(t_bonk *x, char *filename, short path) { ntemplate++; } nomore: - if (remaining = (ntemplate % x->x_ninsig)) + 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, @@ -1103,7 +1142,7 @@ static void bonk_write(t_bonk *x, t_symbol *s) char buf[MAXPDSTRING]; /* fbar */ int i, ntemplate = x->x_ntemplate; t_template *tp = x->x_template; - float *fp; + t_float *fp; /* fbar: canvas-code as in g_array.c */ canvas_makefilename(x->x_canvas, s->s_name, @@ -1134,7 +1173,7 @@ static void bonk_write(t_bonk *x, t_symbol *s) static void bonk_dowrite(t_bonk *x, t_symbol *s) { - long filetype = 'TEXT', outtype; + t_fourcc filetype = 'TEXT', outtype; char filename[MAX_FILENAME_CHARS]; short path; @@ -1154,9 +1193,9 @@ void bonk_writefile(t_bonk *x, char *filename, short path) { int i, ntemplate = x->x_ntemplate; t_template *tp = x->x_template; - float *fp; + t_float *fp; long err; - long buflen; + t_ptr_size buflen; t_filehandle fh; @@ -1191,7 +1230,7 @@ static void bonk_free(t_bonk *x) dsp_free((t_pxobject *)x); #endif for (i = 0, gp = x->x_insig; i < ninsig; i++, gp++) - freebytes(gp->g_inbuf, x->x_npoints * sizeof(float)); + freebytes(gp->g_inbuf, x->x_npoints * sizeof(t_float)); clock_free(x->x_clock); if (!--(x->x_filterbank->b_refcount)) bonk_freefilterbank(x->x_filterbank); @@ -1206,7 +1245,7 @@ static void *bonk_new(t_symbol *s, int argc, t_atom *argv) t_bonk *x = (t_bonk *)pd_new(bonk_class); int nsig = 1, period = DEFPERIOD, npts = DEFNPOINTS, nfilters = DEFNFILTERS, j; - float halftones = DEFHALFTONES, overlap = DEFOVERLAP, + t_float halftones = DEFHALFTONES, overlap = DEFOVERLAP, firstbin = DEFFIRSTBIN, minbandwidth = DEFMINBANDWIDTH; t_insig *g; @@ -1412,6 +1451,7 @@ int main() class_addattr(c, attr); class_addmethod(c, (method)bonk_dsp, "dsp", A_CANT, 0); + class_addmethod(c, (method)bonk_dsp64, "dsp64", A_CANT, 0); class_addmethod(c, (method)bonk_bang, "bang", A_CANT, 0); class_addmethod(c, (method)bonk_forget, "forget", 0); class_addmethod(c, (method)bonk_thresh, "thresh", A_FLOAT, A_FLOAT, 0); @@ -1437,7 +1477,7 @@ static void *bonk_new(t_symbol *s, long ac, t_atom *av) short j; t_bonk *x; - if (x = (t_bonk *)object_alloc(bonk_class)) { + if ((x = (t_bonk *)object_alloc(bonk_class))) { t_insig *g; @@ -1512,7 +1552,7 @@ static void *bonk_new(t_symbol *s, long ac, t_atom *av) void bonk_minvel_set(t_bonk *x, void *attr, long ac, t_atom *av) { if (ac && av) { - float f = atom_getfloat(av); + t_float f = atom_getfloat(av); if (f < 0) f = 0; x->x_minvel = f; } @@ -1521,7 +1561,7 @@ 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) { if (ac && av) { - float f = atom_getfloat(av); + t_float f = atom_getfloat(av); if (f > x->x_hithresh) post("bonk: warning: low threshold greater than hi threshold"); x->x_lothresh = (f <= 0 ? 0.0001 : f); @@ -1531,7 +1571,7 @@ void bonk_lothresh_set(t_bonk *x, void *attr, long ac, t_atom *av) void bonk_hithresh_set(t_bonk *x, void *attr, long ac, t_atom *av) { if (ac && av) { - float f = atom_getfloat(av); + t_float f = atom_getfloat(av); if (f < x->x_lothresh) post("bonk: warning: low threshold greater than hi threshold"); x->x_hithresh = (f <= 0 ? 0.0001 : f); @@ -1549,7 +1589,7 @@ void bonk_masktime_set(t_bonk *x, void *attr, long ac, t_atom *av) void bonk_maskdecay_set(t_bonk *x, void *attr, long ac, t_atom *av) { if (ac && av) { - float f = atom_getfloat(av); + t_float f = atom_getfloat(av); f = (f < 0) ? 0 : f; f = (f > 1) ? 1 : f; x->x_maskdecay = f; @@ -1559,7 +1599,7 @@ void bonk_maskdecay_set(t_bonk *x, void *attr, long ac, t_atom *av) void bonk_debouncedecay_set(t_bonk *x, void *attr, long ac, t_atom *av) { if (ac && av) { - float f = atom_getfloat(av); + t_float f = atom_getfloat(av); f = (f < 0) ? 0 : f; f = (f > 1) ? 1 : f; x->x_debouncedecay = f; @@ -1631,7 +1671,7 @@ double clock_gettimesince(double prevsystime) return ((gettime() - prevsystime)); } -float qrsqrt(float f) +t_float qrsqrt(t_float f) { return 1/sqrt(f); } diff --git a/pd/src/makefile.in b/pd/src/makefile.in index 6dc86e6e7..5562efbea 100644 --- a/pd/src/makefile.in +++ b/pd/src/makefile.in @@ -149,6 +149,7 @@ else endif externs: + make -C ../extra/bob~ @EXTERNTARGET@ make -C ../extra/bonk~ @EXTERNTARGET@ make -C ../extra/choice @EXTERNTARGET@ make -C ../extra/expr~ @EXTERNTARGET@ -- GitLab