summaryrefslogtreecommitdiff
path: root/synth
diff options
context:
space:
mode:
authorFlorian Jung <flo@thinkpad.(none)>2011-02-12 16:02:01 +0100
committerFlorian Jung <flo@thinkpad.(none)>2011-02-12 16:02:01 +0100
commitd4e928c4eecdcb12ebc96054c92cfc7b701c9a83 (patch)
tree51114a0abd08b7fd4343fcf3093aea563cd7adde /synth
parentf8f00a7afde4c534fe47ddf47673167edae4f33e (diff)
Sawtooth and pulse-waves have now variable phases
for sawtooth, the ratio rising:falling phase is adjustable for pulse, the ratio high:low is adjustable
Diffstat (limited to 'synth')
-rw-r--r--synth/defines.h29
-rw-r--r--synth/main.cpp71
-rw-r--r--synth/waveforms.txt67
3 files changed, 139 insertions, 28 deletions
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