Browse Source

some bugfixes, and got a nice bass going

vampirefrog 3 years ago
parent
commit
60af68fb58
6 changed files with 18 additions and 23 deletions
  1. 2
    2
      filter.c
  2. 8
    8
      main.c
  3. 3
    8
      synth.c
  4. 2
    2
      synth.h
  5. 2
    2
      voice.c
  6. 1
    1
      voice.h

+ 2
- 2
filter.c View File

@@ -46,8 +46,8 @@ void filter_set_resonance(struct Filter *filter, float resonance) {
46 46
 float filter_sample(struct Filter *filter, float input) {
47 47
 	if(++filter->last_calc >= 16) {
48 48
 		filter->last_calc = 0;
49
-		filter->cutoff_calc = pow (0.5, 8.5 - (filter->cutoff)*8  );
50
-		filter->resonance_calc = filter->resonance;
49
+		filter->cutoff_calc = pow(0.5, 8.5 - filter->cutoff * 8);
50
+		filter->resonance_calc = pow(0.5, (1.0 - filter->resonance) * 4.5);
51 51
 	}
52 52
 	float cutoff = filter->cutoff_calc;
53 53
 	float resonance = filter->resonance_calc;

+ 8
- 8
main.c View File

@@ -245,19 +245,19 @@ int main(int argc, char **argv) {
245 245
 	sr = jack_get_sample_rate(client);
246 246
 
247 247
 	synth_init(&synth);
248
-	synth.osc_env.attack = 2;
249
-	synth.osc_env.decay = 200;
248
+	synth.osc_env.attack = 1;
249
+	synth.osc_env.decay = 0;
250 250
 	synth.osc_env.sustain = 100;
251 251
 	synth.osc_env.release = 100;
252
-	synth.filter_env.attack = 150;
253
-	synth.filter_env.decay = 100;
254
-	synth.filter_env.sustain = 100;
255
-	synth.filter_env.release = 100;
256
-	synth.filter_eg_intensity = .8;
252
+	synth.filter_env.attack = 1;
253
+	synth.filter_env.decay = 300;
254
+	synth.filter_env.sustain = 0;
255
+	synth.filter_env.release = 0;
256
+	synth.filter_eg_intensity = .9;
257 257
 	synth.filter_kbd_track = .5;
258 258
 	sine_osc_set_freq(&synth.lfo_osc, 6);
259 259
 	synth.pitch_bend_range = 12; // semitones
260
-//	synth.monophonic = 1;
260
+	synth.monophonic = 1;
261 261
 
262 262
 	if (jack_activate(client)) {
263 263
 		fprintf (stderr, "cannot activate client");

+ 3
- 8
synth.c View File

@@ -9,7 +9,7 @@
9 9
 #include "tables.inc"
10 10
 
11 11
 void synth_init(struct Synth *synth) {
12
-	synth_set_cutoff_freq(synth, 127);
12
+	synth_set_cutoff_freq(synth, 0);
13 13
 	synth_set_resonance(synth, 0);
14 14
 	srandom(1234);
15 15
 	synth->key_stack_size = 0;
@@ -133,11 +133,6 @@ void synth_note_off(struct Synth *synth, uint8_t note, uint8_t velocity) {
133 133
 				voice_stop(&synth->voices[i]);
134 134
 			}
135 135
 		}
136
-		printf("voices: ");
137
-		for(int i = 0; i < SYNTH_NUM_VOICES; i++) {
138
-			printf("%d%d ", synth->voices[i].osc_env.state, synth->voices[i].filter_env.state);
139
-		}
140
-		printf("\n");
141 136
 	}
142 137
 }
143 138
 
@@ -175,11 +170,11 @@ void synth_set_resonance(struct Synth *synth, uint8_t f) {
175 170
 }
176 171
 
177 172
 void synth_set_unison_spread(struct Synth *synth, uint8_t w) {
178
-	synth->unison_spread = w;
173
+	synth->unison_spread = w / 127.0;
179 174
 }
180 175
 
181 176
 void synth_set_stereo_spread(struct Synth *synth, uint8_t w) {
182
-	synth->stereo_spread = w;
177
+	synth->stereo_spread = w / 127.0;
183 178
 }
184 179
 
185 180
 void synth_set_volume(struct Synth *s, uint8_t vol) {

+ 2
- 2
synth.h View File

@@ -20,8 +20,8 @@ struct Key {
20 20
 struct Synth {
21 21
 	struct Voice voices[SYNTH_NUM_VOICES];
22 22
 	struct Envelope osc_env, filter_env;
23
-	uint8_t unison_spread;
24
-	uint8_t stereo_spread;
23
+	float unison_spread;
24
+	float stereo_spread;
25 25
 	uint8_t monophonic;
26 26
 
27 27
 	float tuning; // 440.0Hz

+ 2
- 2
voice.c View File

@@ -8,8 +8,8 @@ void voice_render_sample(struct Voice *v, float *out) {
8 8
 	float s = oscillator_render_sample(&v->osc);
9 9
 	filter_set_cutoff(&v->filter, v->synth->cutoff + cutoff * v->synth->filter_eg_intensity);
10 10
 	float f = filter_sample(&v->filter, v->volume * amplitude * s / 32768.0);
11
-	out[0] = (127 + v->pan) * f / 255.0;
12
-	out[1] = (127 - v->pan) * f / 255.0;
11
+	out[0] = (1 + v->pan) * f / 2;
12
+	out[1] = (1 - v->pan) * f / 2;
13 13
 	v->time++;
14 14
 }
15 15
 

+ 1
- 1
voice.h View File

@@ -13,7 +13,7 @@ struct Voice {
13 13
 	uint8_t note;
14 14
 	float detune;
15 15
 	float volume;
16
-	int8_t pan;
16
+	float pan;
17 17
 	uint32_t time;
18 18
 
19 19
 	struct Envelope osc_env, filter_env;

Loading…
Cancel
Save