git ssb

0+

cel / foostudio



Commit 1d67f693f364e55fe7c4f752a49923bb51c6875b

Make delay configurable via midi

cel committed on 11/5/2016, 1:20:52 AM
Parent: 17960117c91fac592902939ab1835bbd28b27189

Files changed

tune.cchanged
tune.cView
@@ -20,17 +20,19 @@
2020 // return in * 10;
2121 // return sin(2. * M_PI * time * 440.) * 0.1 + in * 0.9;
2222 struct {
2323 struct foobuf *buf;
24 + unsigned int delay;
2425 // float *keymap;
2526 } **statep = (void *)obj, *state;
2627
2728 if (struct_init(statep)) {
2829 warn("foobuf_init");
2930 return 0;
3031 }
3132 state = *statep;
32- if (foobuf_init(&state->buf, 48000)) {
33 + if (!state->delay) state->delay = 10;
34 + if (foobuf_init(&state->buf, state->delay)) {
3335 warn("foobuf_init");
3436 return 0;
3537 }
3638 // array_init(&state->keymap, 256);
@@ -46,16 +48,29 @@
4648 float out = 0;
4749
4850 if (midi_cmd) {
4951 // float val = sin(2. * M_PI * (float)i/buf_size * freq);
50- if (midi_cmd[0] == 0x90) {
51- // printf("key %u\n", midi_cmd[1]);
52- notes[midi_cmd[1]] += (float)midi_cmd[2]/255.;
53- dampen[midi_cmd[1]] = 0;
54- } else if (midi_cmd[0] == 0x80) {
55- dampen[midi_cmd[1]] += (float)midi_cmd[2]/255.;
56- } else {
57- // printf("midi %x %x %x\n", buf[0], buf[1], buf[2]);
52 + switch (midi_cmd[0]) {
53 + case 0x90:
54 + // printf("key %u\n", midi_cmd[1]);
55 + notes[midi_cmd[1]] += (float)midi_cmd[2]/255.;
56 + dampen[midi_cmd[1]] = 0;
57 + break;
58 + case 0x80:
59 + dampen[midi_cmd[1]] += (float)midi_cmd[2]/255.;
60 + break;
61 + case 0xb0:
62 + switch (midi_cmd[1]) {
63 + case 0x07:
64 + state->delay = midi_cmd[2] * 100;
65 + break;
66 + default:
67 + printf("info %x %x\n", midi_cmd[1], midi_cmd[2]);
68 + }
69 + break;
70 + default:
71 + printf("midi %x %x %x\n", midi_cmd[0], midi_cmd[1], midi_cmd[2]);
72 + break;
5873 }
5974 }
6075
6176 float total = 0;
@@ -63,22 +78,22 @@
6378 for (int i = 0; i < 256; i++) {
6479 if (notes[i] > 0.01) {
6580 float freq = midi_note_freq(i);
6681 total += notes[i];
67- out += notes[i] * saw(freq, time);
68- // out += notes[i] * sin(2. * M_PI * time * freq);
82 + // out += notes[i] * saw(freq, time);
83 + out += notes[i] * sin(2. * M_PI * time * freq);
6984 notes[i] *= 0.99999 * (1 - dampen[i] * 0.001);
7085 }
7186 if (dampen[i] > 0.001) dampen[i] *= 0.9999;
7287 }
7388
7489 // return sin(2. * M_PI * time * 440.) * 0.25 + in * 0.75;
7590
76- // out += foobuf_read(state->buf, 500)*0.9;
77- out += in*180;
91 + out += foobuf_read(state->buf, 0)*0.9;
92 + out += in*100;
7893 // out = in*0.1 + foobuf_read(state->buf, 48000)*0.9;
7994 foobuf_write(state->buf, out);
8095 // return out;
81- return out * 0.25;
96 + // return out * 0.25;
8297 // return out / total;
83- // return 1/(1. + exp(-out * 4)) * 0.99;
98 + return 0.99/(1. + exp(-out * 4));
8499 }

Built with git-ssb-web