summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO4
-rw-r--r--TODO.done4
-rw-r--r--synth/defines.h29
-rw-r--r--synth/main.cpp71
-rw-r--r--synth/waveforms.txt67
5 files changed, 143 insertions, 32 deletions
diff --git a/TODO b/TODO
index cb13c19..d81ad27 100644
--- a/TODO
+++ b/TODO
@@ -5,10 +5,6 @@
wenn man danach die noten spielen will. nicht reproduzierbar
TODO für den synth
- o square- und sawtooth mit einstellbarer pulsweite
- -> invers-saw (0,1) = saw(1,0)
- -> dreieck = saw(0.5,0.5)
- o invertierter pulse-sin
o file-watcher ist unsauber: inotify_map_mutex und prog_load_mutex
werden eigentlich zu spät erstellt; bei EXTREM schnellen events
könnte ein noch nicht existenter mutex gelockt werden
diff --git a/TODO.done b/TODO.done
index 56f7ed0..edd8294 100644
--- a/TODO.done
+++ b/TODO.done
@@ -82,6 +82,10 @@ TODO für den synth
(o)bei filter-envelopes: ksr/ksl? nää.
(o)resonanz-tremolo bei tiefpass? nää.
* RAM aufräumen? [keine leaks, und linux macht das schon]
+ x square- und sawtooth mit einstellbarer pulsweite
+ -> invers-saw (0,1) = saw(1,0)
+ -> dreieck = saw(0.5,0.5)
+ x invertierter pulse-sin
TODO fürs CLI
diff --git a/synth/defines.h b/synth/defines.h
index fb1d63b..1ec5b18 100644
--- a/synth/defines.h
+++ b/synth/defines.h
@@ -56,7 +56,34 @@ extern float LFO_FREQ_HZ[];
#define WAVE_RES 44100
-#define N_WAVEFORMS 8
+
+
+// saw_start must be >= n_normal
+// pulse_start must be > saw_end
+// holes are allowed
+
+// 0..6 different stuff
+// 10..19 saw
+// 20..29 square is allowed, for example
+
+//SAW_N and PULSE_N should be odd numbers, otherwise you won't
+//get equal ratios for falling/rising or high/low
+//in english: you won't get a "normal" triangle wave or a "normal"
+// square wave then
+#define N_NORMAL_WAVEFORMS 6
+#define WAVE_SAW_START 100
+#define WAVE_SAW_N 201
+#define WAVE_PULSE_START 400
+#define WAVE_PULSE_N 201
+
+#if ( (WAVE_SAW_START < N_NORMAL_WAVEFORMS) || \
+ (WAVE_PULSE_START < WAVE_SAW_START+WAVE_SAW_N) )
+ #error NORMAL WAVEFORMS, SAW- AND PULSE-WAVES MAY NOT OVERLAP!
+#endif
+
+#define N_WAVEFORMS (WAVE_PULSE_START+WAVE_PULSE_N)
+
+
#define NO_CONT 128
diff --git a/synth/main.cpp b/synth/main.cpp
index 32b2b84..f9f1e57 100644
--- a/synth/main.cpp
+++ b/synth/main.cpp
@@ -96,22 +96,69 @@ int main(int argc, char** argv)
load_program(programfile[i],program_settings[i]);
}
+ fixed_t* temp=new fixed_t[WAVE_RES];
+ for (i=0;i<WAVE_RES;i++)
+ temp[i]=0;
+
for (i=0;i<N_WAVEFORMS;++i)
+ wave[i]=temp;
+
+ for (i=0;i<N_NORMAL_WAVEFORMS;i++)
+ wave[i]=new fixed_t[WAVE_RES];
+
+ for (i=WAVE_SAW_START; i<WAVE_SAW_START+WAVE_SAW_N; i++)
wave[i]=new fixed_t[WAVE_RES];
+
+ for (i=WAVE_PULSE_START; i<WAVE_PULSE_START+WAVE_PULSE_N; i++)
+ wave[i]=new fixed_t[WAVE_RES];
+
+ for (i=0;i<WAVE_RES;++i) //init the "normal" waves
+ {
+ fixed_t temp1, temp2;
+ temp1=ONE*sin(i*2.0*3.141592654/WAVE_RES);
+ temp2=ONE*sin(i*3.141592654/WAVE_RES);
+ wave[0][i]=temp1;
+ wave[1][i]=temp2;
+ wave[2][i]= (i<=WAVE_RES/2) ? temp1 : 0;
+ wave[3][i]= (i<=WAVE_RES/2) ? temp2 : 0;
+ wave[4][i]= (i<=WAVE_RES/2) ? 0 : temp2;
+ wave[5][i]=float(rand() - RAND_MAX/2) / (RAND_MAX/2) *ONE;
+ }
+
+ for (int j=WAVE_SAW_START; j<WAVE_SAW_START+WAVE_SAW_N; j++) //init the saws
+ {
+ float rising, falling;
+ falling=(float) (j-WAVE_SAW_START)/(WAVE_SAW_N-1);
+ rising=1.0-falling;
+
+ int a,b,c;
+ a=WAVE_RES*(rising/2);
+ b=WAVE_RES*(rising/2 + falling);
+ c=WAVE_RES*falling;
+
+ for (i=0;i<a;i++)
+ wave[j][i]=ONE * i/a;
- for (i=0;i<WAVE_RES;++i)
+ for (i=a;i<b;i++)
+ wave[j][i]=ONE - 2*ONE * (i-a)/c;
+
+ for (i=b;i<WAVE_RES;i++)
+ wave[j][i]=ONE * (i-b)/a - ONE;
+ }
+
+ for (int j=WAVE_PULSE_START; j<WAVE_PULSE_START+WAVE_PULSE_N; j++) //init the pulses
{
- float temp1, temp2;
- temp1=sin(i*2.0*3.141592654/WAVE_RES);
- temp2=sin(i*3.141592654/WAVE_RES);
- wave[0][i]=temp1*ONE;
- wave[1][i]=temp2*ONE;
- wave[2][i]=(i<=WAVE_RES/2) ? wave[0][i] : 0;
- wave[3][i]= (i<=WAVE_RES/2) ? wave[1][i] : 0;
- wave[4][i]=(i<WAVE_RES/2) ? ONE : -ONE;
- wave[5][i]=(i<=WAVE_RES/2) ? (ONE*2*i/WAVE_RES) : (ONE*2*i/WAVE_RES - 2*ONE);
- wave[6][i]=(i<=WAVE_RES/2) ? (ONE*2*i/WAVE_RES) : (ONE*2*(WAVE_RES-i)/WAVE_RES);
- wave[7][i]=float(rand() - RAND_MAX/2) / (RAND_MAX/2) *ONE;
+ float high, low;
+ high=(float) (j-WAVE_PULSE_START)/(WAVE_PULSE_N-1);
+ low=1.0-high;
+
+ int a=WAVE_RES*high;
+
+ for (i=0;i<a;i++)
+ wave[j][i]=ONE;
+
+ for (i=a;i<WAVE_RES;i++)
+ wave[j][i]=-ONE;
}
for (int i=0;i<N_CHANNELS;++i)
diff --git a/synth/waveforms.txt b/synth/waveforms.txt
index efaa703..6439af4 100644
--- a/synth/waveforms.txt
+++ b/synth/waveforms.txt
@@ -13,18 +13,55 @@
3 pulse-sine / | / |
/ |____/ |____
- _____ _____
-4 square
- _____ _____
-
- . | . |
-5 sawtooth . ' | . ' |
- . ' |. ' |
-
- / \ / \
-6 triangle / \ / \
- \ / \ /
- \ / \ /
-
-7 noise
-
+ ---. ---.
+4 inverted | \ | \
+ pulse-sine ____| \____| \
+
+
+5 noise
+
+
+100 to 300: sawtooth with variable rising/falling phases
+
+ . | . |
+100: normal sawtooth . ' | . ' |
+ . ' |. ' |
+ . .
+in between . ' \ . ' \
+ . ' \. ' \
+
+ / \ / \
+200: triangle / \ / \
+ \ / \ /
+ \ / \ /
+ . .
+in between / ' . / ' .
+ / ' ./ ' .
+
+ | . | .
+300: inverted sawtooth | ' . | ' .
+ | ' .| ' .
+
+
+
+400 to 600: pulse with variable high/low ratio
+
+ 1
+400 DC 0 _ _ _ _ _ _
+ -1 ____________________
+
+ 1 ___ ___
+in between 0 _ _ _ _ _ _
+ -1 _______ _______
+
+ 1 _____ _____
+500 square 0 _ _ _ _ _ _
+ -1 _____ _____
+
+ 1 _______ _______
+in between 0 _ _ _ _ _ _
+ -1 ___ ___
+
+ 1 ____________________
+600 DC 0 _ _ _ _ _ _
+ -1