aboutsummaryrefslogtreecommitdiff
path: root/stksitar~
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2003-08-16 17:08:55 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2003-08-16 17:08:55 +0000
commit506b8e7dedb80d79bf015e47d92e8b8dd8284584 (patch)
tree6393e98add0a0ae7f92388665b3b6242977f5b64 /stksitar~
parent856eaf396d9a4d371a458a2c373a052bb72c8057 (diff)
added files straight from Yves' sources
svn path=/trunk/externals/unauthorized/; revision=864
Diffstat (limited to 'stksitar~')
-rw-r--r--stksitar~/INSTALL13
-rw-r--r--stksitar~/Makefile37
-rw-r--r--stksitar~/README22
-rw-r--r--stksitar~/help-stksitar~.pd73
-rw-r--r--stksitar~/mstksitar~.cc39
-rw-r--r--stksitar~/sitar-freqs166
-rw-r--r--stksitar~/sitar.cc105
-rw-r--r--stksitar~/sitar.h44
-rw-r--r--stksitar~/stksitar~.cc119
9 files changed, 618 insertions, 0 deletions
diff --git a/stksitar~/INSTALL b/stksitar~/INSTALL
new file mode 100644
index 0000000..09c76b3
--- /dev/null
+++ b/stksitar~/INSTALL
@@ -0,0 +1,13 @@
+install STK in /usr/local/stk
+or change STK paths in the makefile
+to your STK's location.
+
+untar in /my/pd/dir/externs
+
+cd /my/pd/dir/externs/stksitar~
+
+make
+
+make install
+
+open help-stksitar~.pd
diff --git a/stksitar~/Makefile b/stksitar~/Makefile
new file mode 100644
index 0000000..5314a78
--- /dev/null
+++ b/stksitar~/Makefile
@@ -0,0 +1,37 @@
+NAME=stksitar~
+CSYM=stksitar_tilde
+STK_HOME=/usr/local/stk
+
+current: pd_linux
+
+pd_linux: $(NAME).pd_linux
+
+.SUFFIXES: .pd_linux
+
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
+ -Wall -W -Wshadow -Wstrict-prototypes -Werror \
+ -Wno-unused -Wno-parentheses -Wno-switch
+
+LINUXCCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
+ -Wall -W -Wshadow -Werror \
+ -Wno-unused -Wno-parentheses -Wno-switch -g
+
+LINUXINCLUDE = -I../../src -I/usr/local/include
+
+.cc.pd_linux: sitar.o
+ g++ -O3 -Wall -D__OS_Linux_ -g -I$(STK_HOME)/include -c sitar.cc
+ g++ $(LINUXCCFLAGS) $(LINUXINCLUDE) -I$(STK_HOME)/include -o $*.o -c $*.cc
+ ld -export_dynamic -shared -o $*.pd_linux *.o $(STK_HOME)/src/stklib.a -lc -lm -lstdc++ -lg++
+ #strip --strip-unneeded $*.pd_linux
+ rm -f *.o ../$*.pd_linux
+ ln -s $*/$*.pd_linux ..
+
+test:
+ g++ -O3 -Wall -D__OS_Linux_ -g -I$(STK_HOME)/include -c sitar.cc
+ g++ -O3 -Wall -D__OS_Linux_ -g -I$(STK_HOME)/include -o mstksitar~ sitar.o $(STK_HOME)/src/stklib.a mstksitar~.cc
+
+clean:
+ rm -f *.o *.pd_* so_locations
+
+install:
+ cp help-*.pd *-freqs ../../doc/5.reference
diff --git a/stksitar~/README b/stksitar~/README
new file mode 100644
index 0000000..bb3db3d
--- /dev/null
+++ b/stksitar~/README
@@ -0,0 +1,22 @@
+*****************************************************************************
+Version 0.01
+embedding Perry Cook's ragamatic in Pure Data
+copyright 2001 by Perry Cook
+copyleft 2001 by Yves Degoyon
+tarballs and updates available @ http://ydegoyon.free.fr
+
+stksitar~ : embeds STK sitar simulation in Pure Data.
+
+To install stksitar~, follow the steps from INSTALL
+
+This software is published under GPL terms.
+
+This is software with ABSOLUTELY NO WARRANTY.
+Use it at your OWN RISK. It's possible to damage e.g. hardware or your hearing
+due to a bug or for other reasons.
+We do not warrant that the program is free of infringement of any third-party
+patents.
+
+*****************************************************************************
+
+
diff --git a/stksitar~/help-stksitar~.pd b/stksitar~/help-stksitar~.pd
new file mode 100644
index 0000000..986edd0
--- /dev/null
+++ b/stksitar~/help-stksitar~.pd
@@ -0,0 +1,73 @@
+#N canvas 33 1 784 529 10;
+#X obj 112 311 dac~;
+#X obj 115 248 stksitar~;
+#X obj 114 278 *~;
+#X floatatom 147 278 5 0 0;
+#X msg 162 172 stop;
+#X floatatom 196 200 5 52 100000;
+#X floatatom 238 248 5 5 35;
+#X text 247 335 stksitar~ : Object to embed stk-based sitar synthesis
+;
+#X text 247 360 Comments and bugs @ ydegoyon@free.fr;
+#X msg 113 346 \; pd dsp 1;
+#X msg 179 346 \; pd dsp 0;
+#X msg 24 34 bang;
+#X msg 93 99 play;
+#X msg 113 173 play;
+#X obj 195 248 / 100;
+#X text 276 279 Master level;
+#X obj 23 99 metro 2000;
+#X floatatom 52 75 5 0 0;
+#X obj 134 78 / 1000;
+#X obj 134 98 + 0.05;
+#X floatatom 182 98 5 0 0;
+#X obj 217 278 loadbang;
+#X text 301 258 ( min=0.05 \, max=0.35 \, default = 0.25 );
+#X text 303 248 Strength of plucking;
+#X text 239 205 ( min=52Hz \, default=250 Hz );
+#X text 241 195 Frequency;
+#X obj 231 77 qlist;
+#X msg 274 76 read sitar-freqs;
+#X msg 231 55 next;
+#X msg 274 55 rewind;
+#X text 247 348 Originally written by Perry Cook for STK/ragamatic
+;
+#X obj 386 76 loadbang;
+#X msg 189 278 40;
+#X obj 24 75 + 0;
+#X text 21 12 Ready for meditation ??;
+#X text 240 398 And now another message from Nancy Reagan : "Drugs
+destroy your brain";
+#X obj 134 59 random 200;
+#X obj 24 57 random 1000;
+#X connect 1 0 2 0;
+#X connect 2 0 0 0;
+#X connect 2 0 0 1;
+#X connect 3 0 2 1;
+#X connect 4 0 1 0;
+#X connect 5 0 1 1;
+#X connect 6 0 14 0;
+#X connect 11 0 16 0;
+#X connect 11 0 37 0;
+#X connect 12 0 1 0;
+#X connect 13 0 1 0;
+#X connect 14 0 1 2;
+#X connect 16 0 12 0;
+#X connect 16 0 28 0;
+#X connect 16 0 36 0;
+#X connect 16 0 37 0;
+#X connect 17 0 16 1;
+#X connect 18 0 19 0;
+#X connect 19 0 20 0;
+#X connect 19 0 1 2;
+#X connect 21 0 32 0;
+#X connect 26 0 5 0;
+#X connect 26 1 29 0;
+#X connect 27 0 26 0;
+#X connect 28 0 26 0;
+#X connect 29 0 26 0;
+#X connect 31 0 27 0;
+#X connect 32 0 3 0;
+#X connect 33 0 17 0;
+#X connect 36 0 18 0;
+#X connect 37 0 33 0;
diff --git a/stksitar~/mstksitar~.cc b/stksitar~/mstksitar~.cc
new file mode 100644
index 0000000..62edef6
--- /dev/null
+++ b/stksitar~/mstksitar~.cc
@@ -0,0 +1,39 @@
+/* stksitar~ -- apply a stksitar effect
+ * requires libDSP library
+ * Copyleft 2001 Yves Degoyon.
+ * Permission is granted to use this software for any purpose provided you
+ * keep this copyright notice intact.
+ *
+ * THE AUTHOR AND HIS EXPLOITERS MAKE NO WARRANTY, EXPRESS OR IMPLIED,
+ * IN CONNECTION WITH THIS SOFTWARE.
+ *
+*/
+
+#include "sitar.h"
+#include "unistd.h"
+#include "RtWvOut.h"
+
+sitar *x_stksitar = NULL;
+
+int main( int argc, char** argv )
+{
+
+ // int count=0;
+
+ x_stksitar = new sitar( 50.0 );
+ if ( x_stksitar == NULL )
+ {
+ printf( "mstksitar~: cannot build sitar instrument from STK" );
+ exit(-1);
+ }
+
+ x_stksitar->noteOn( 400.0, 0.25 ); // start sound
+ while (1)
+ {
+ double dare;
+
+ dare = (float) x_stksitar->tick();
+ printf( "%f\n", dare );
+ fwrite( (void*)&dare, sizeof(float), 1, stderr );
+ }
+}
diff --git a/stksitar~/sitar-freqs b/stksitar~/sitar-freqs
new file mode 100644
index 0000000..d8c6fd8
--- /dev/null
+++ b/stksitar~/sitar-freqs
@@ -0,0 +1,166 @@
+329.630000;
+349.230000;
+415.300000;
+440.000000;
+329.630000;
+329.630000;
+293.660000;
+293.660000;
+329.630000;
+261.630000;
+261.630000;
+261.630000;
+293.660000;
+329.630000;
+329.630000;
+293.660000;
+261.630000;
+293.660000;
+329.630000;
+349.230000;
+329.630000;
+293.660000;
+329.630000;
+329.630000;
+349.230000;
+349.230000;
+415.300000;
+415.300000;
+349.230000;
+329.630000;
+349.230000;
+415.300000;
+440.000000;
+440.000000;
+493.880000;
+349.230000;
+261.630000;
+293.660000;
+329.630000;
+349.230000;
+329.630000;
+329.630000;
+329.630000;
+329.630000;
+293.660000;
+261.630000;
+293.660000;
+261.630000;
+293.660000;
+261.630000;
+293.660000;
+329.630000;
+349.230000;
+415.300000;
+349.230000;
+415.300000;
+415.300000;
+440.000000;
+493.880000;
+440.000000;
+349.230000;
+415.300000;
+440.000000;
+440.000000;
+415.300000;
+415.300000;
+440.000000;
+293.660000;
+329.630000;
+329.630000;
+349.230000;
+415.300000;
+440.000000;
+415.300000;
+440.000000;
+440.000000;
+493.880000;
+493.880000;
+440.000000;
+493.880000;
+523.250000;
+493.880000;
+523.250000;
+659.260000;
+659.260000;
+698.460000;
+880.000000;
+880.000000;
+880.000000;
+880.000000;
+659.260000;
+698.460000;
+659.260000;
+698.460000;
+659.260000;
+659.260000;
+659.260000;
+523.250000;
+659.260000;
+698.460000;
+880.000000;
+440.000000;
+493.880000;
+415.300000;
+440.000000;
+415.300000;
+440.000000;
+493.880000;
+329.630000;
+329.630000;
+349.230000;
+415.300000;
+349.230000;
+415.300000;
+415.300000;
+440.000000;
+349.230000;
+293.660000;
+293.660000;
+329.630000;
+293.660000;
+261.630000;
+261.630000;
+261.630000;
+261.630000;
+293.660000;
+261.630000;
+261.630000;
+293.660000;
+329.630000;
+349.230000;
+329.630000;
+293.660000;
+293.660000;
+293.660000;
+329.630000;
+329.630000;
+329.630000;
+349.230000;
+415.300000;
+440.000000;
+415.300000;
+415.300000;
+440.000000;
+493.880000;
+523.250000;
+493.880000;
+523.250000;
+493.880000;
+440.000000;
+493.880000;
+415.300000;
+440.000000;
+493.880000;
+523.250000;
+523.250000;
+523.250000;
+523.250000;
+659.260000;
+698.460000;
+880.000000;
+880.000000;
+880.000000;
+880.000000;
+880.000000;
+880.000000;
diff --git a/stksitar~/sitar.cc b/stksitar~/sitar.cc
new file mode 100644
index 0000000..11cf35b
--- /dev/null
+++ b/stksitar~/sitar.cc
@@ -0,0 +1,105 @@
+ /******************************************/
+/* Karplus-Strong sitar string model */
+/* by Perry Cook, 1995-96 */
+/* */
+/* There exist at least two patents, */
+/* assigned to Stanford, bearing the */
+/* names of Karplus and/or Strong. */
+/******************************************/
+
+#include "sitar.h"
+
+#ifndef MY_FLOAT
+#warning "weird : MY_FLOAT undefined"
+#define MY_FLOAT double
+#endif
+
+sitar :: sitar(MY_FLOAT lowestFreq)
+{
+ length = (long) (SRATE / lowestFreq + 1);
+ loopGain = (MY_FLOAT) 0.999;
+ loopFilt = new OneZero();
+ loopFilt->setCoeff(0.01);
+ delayLine = new DLineA(length);
+ delay = length/2;
+ delayTarg = delay;
+ envelope = new ADSR();
+ noise = new Noise;
+ envelope->setAllTimes(0.001,0.04,0.0,0.5);
+ this->clear();
+}
+
+sitar :: ~sitar()
+{
+ delete loopFilt;
+ delete delayLine;
+ delete envelope;
+ delete noise;
+}
+
+void sitar :: clear()
+{
+ loopFilt->clear();
+ delayLine->clear();
+}
+
+void sitar :: setFreq(MY_FLOAT frequency)
+{
+ delayTarg = (SRATE / frequency);
+ delay = delayTarg * (1.0 + (0.05 * noise->tick()));
+ delayLine->setDelay(delay);
+ loopGain = (MY_FLOAT) 0.995 + (frequency * (MY_FLOAT) 0.000001);
+ if (loopGain>1.0) loopGain = (MY_FLOAT) 0.9995;
+}
+
+void sitar :: pluck(MY_FLOAT amplitude)
+{
+ envelope->keyOn();
+}
+
+void sitar :: noteOn(MY_FLOAT freq, MY_FLOAT amp)
+{
+ this->setFreq(freq);
+ this->pluck(amp);
+ amPluck = 0.05 * amp;
+#if defined(_debug_)
+ printf("sitar : NoteOn: Freq=%lf Amp=%lf\n",freq,amp);
+#endif
+}
+
+void sitar :: noteOff(MY_FLOAT amp)
+{
+ loopGain = (MY_FLOAT) 1.0 - amp;
+#if defined(_debug_)
+ printf("sitar : NoteOff: Amp=%lf\n",amp);
+#endif
+}
+
+MY_FLOAT sitar :: tick()
+{
+ MY_FLOAT temp;
+
+ temp = delayLine->lastOut();
+ if (fabs(temp) > 1.0) {
+ loopGain = 0.1;
+ this->noteOff(0.9);
+ delay = delayTarg;
+ delayLine->setDelay(delay);
+ }
+
+ temp *= loopGain;
+
+ if (fabs(delayTarg - delay) > 0.001) {
+ if (delayTarg < delay)
+ delay *= 0.99999;
+ else
+ delay *= 1.00001;
+ delayLine->setDelay(delay);
+ }
+
+ lastOutput = delayLine->tick(loopFilt->tick(temp)
+ + (amPluck * envelope->tick() * noise->tick()));
+
+ return lastOutput;
+}
+
diff --git a/stksitar~/sitar.h b/stksitar~/sitar.h
new file mode 100644
index 0000000..d787211
--- /dev/null
+++ b/stksitar~/sitar.h
@@ -0,0 +1,44 @@
+/******************************************/
+/* Karplus-Strong Sitar1 string model */
+/* by Perry Cook, 1995-96 */
+/* */
+/* There exist at least two patents, */
+/* assigned to Stanford, bearing the */
+/* names of Karplus and/or Strong. */
+/******************************************/
+
+#if !defined(__sitar_h)
+#define __sitar_h
+
+#include "Instrmnt.h"
+#include "DLineA.h"
+#include "OneZero.h"
+#include "ADSR.h"
+#include "Noise.h"
+#include "Object.h"
+
+class sitar : public Instrmnt
+{
+protected:
+ DLineA *delayLine;
+ OneZero *loopFilt;
+ ADSR *envelope;
+ Noise *noise;
+ long length;
+ MY_FLOAT loopGain;
+ MY_FLOAT amPluck;
+ MY_FLOAT delay;
+ MY_FLOAT delayTarg;
+public:
+ sitar(MY_FLOAT lowestFreq);
+ ~sitar();
+ void clear();
+ virtual void setFreq(MY_FLOAT frequency);
+ void pluck(MY_FLOAT amplitude);
+ virtual void noteOn(MY_FLOAT freq, MY_FLOAT amp);
+ virtual void noteOff(MY_FLOAT amp);
+ virtual MY_FLOAT tick();
+};
+
+#endif
+
diff --git a/stksitar~/stksitar~.cc b/stksitar~/stksitar~.cc
new file mode 100644
index 0000000..bd47817
--- /dev/null
+++ b/stksitar~/stksitar~.cc
@@ -0,0 +1,119 @@
+/* stksitar~ -- STK-based sitar synthesis
+ * requires STK library
+ * Copyleft 2001 Yves Degoyon.
+ * Permission is granted to use this software for any purpose provided you
+ * keep this copyright notice intact.
+ *
+ * THE AUTHOR AND HIS EXPLOITERS MAKE NO WARRANTY, EXPRESS OR IMPLIED,
+ * IN CONNECTION WITH THIS SOFTWARE.
+ *
+*/
+
+#include "m_pd.h"
+#include "sitar.h"
+
+#define DEFAULT_FREQ 250.0
+#define DEFAULT_PLUCK 0.25
+
+typedef struct _stksitar
+{
+ t_object x_obj;
+ sitar *x_stksitar;
+ t_int x_on;
+ t_float x_freq;
+ t_float x_pluck;
+} t_stksitar;
+
+static t_class *stksitar_class;
+
+static void *stksitar_new(void)
+{
+ t_stksitar *x = (t_stksitar *)pd_new(stksitar_class);
+ x->x_freq = DEFAULT_FREQ;
+ x->x_pluck = DEFAULT_PLUCK;
+ outlet_new(&x->x_obj, &s_signal);
+ inlet_new( &x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("freq") );
+ inlet_new( &x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("pluck") );
+ if( (x->x_stksitar = new sitar( 50.0 )) == NULL ) {
+ post( "stksitar~: cannot build sitar instrument from STK" );
+ return NULL;
+ } else {
+ return (x);
+ }
+}
+
+static void stksitar_freq(t_stksitar* x, t_float ffreq)
+{
+ if ( ffreq < 50.0 )
+ {
+ post("stksitar~ : wrong frequency" );
+ return;
+ }
+ x->x_stksitar->setFreq( (MY_FLOAT) ffreq );
+ x->x_freq = ffreq;
+}
+
+static void stksitar_pluck(t_stksitar* x, t_float fpluck)
+{
+ if ( fpluck < 0.05 || fpluck > 0.35 )
+ {
+ post("stksitar~ : wrong pluck argument" );
+ return;
+ }
+ x->x_stksitar->pluck( (MY_FLOAT) fpluck );
+ x->x_pluck = fpluck;
+}
+
+static void stksitar_play(t_stksitar* x)
+{
+ x->x_on = 1; // activate sound
+ x->x_stksitar->noteOn( x->x_freq, x->x_pluck ); // start sound
+}
+
+static void stksitar_stop(t_stksitar* x)
+{
+ x->x_on = 0; // deactivate sound
+}
+
+static t_int *stksitar_perform(t_int *w)
+{
+ t_float *out = (t_float *)(w[1]);
+ int n = (int)(w[2]);
+ t_stksitar* x = (t_stksitar*)(w[3]);
+
+ while ( n-- )
+ {
+ if ( x->x_on )
+ {
+ double dare;
+
+ dare = (float)x->x_stksitar->tick();
+ // post( "synthesis : %f", dare );
+ *out=dare;
+ }
+ else
+ {
+ *(out) = 0.0;
+ }
+ out++;
+ }
+
+ return (w+4);
+}
+
+static void stksitar_dsp(t_stksitar *x, t_signal **sp)
+{
+ dsp_add(stksitar_perform, 3, sp[0]->s_vec, sp[0]->s_n, x);
+}
+
+extern "C" void stksitar_tilde_setup(void)
+{
+ stksitar_class = class_new(gensym("stksitar~"), (t_newmethod)stksitar_new, 0,
+ sizeof(t_stksitar), 0, A_NULL);
+ class_sethelpsymbol(stksitar_class, gensym("help-stksitar~.pd"));
+ class_addmethod(stksitar_class, (t_method)stksitar_dsp, gensym("dsp"), A_NULL);
+ class_addmethod(stksitar_class, (t_method)stksitar_play, gensym("play") , A_NULL);
+ class_addmethod(stksitar_class, (t_method)stksitar_stop, gensym("stop") , A_NULL);
+ class_addmethod(stksitar_class, (t_method)stksitar_freq, gensym("freq") , A_DEFFLOAT, A_NULL);
+ class_addmethod(stksitar_class, (t_method)stksitar_pluck, gensym("pluck") , A_DEFFLOAT, A_NULL);
+}