From 5c1a81c657e5e635ff5973e53e86e77a4724df03 Mon Sep 17 00:00:00 2001 From: slack Date: Fri, 24 Jul 2009 23:39:14 +0200 Subject: [PATCH] added delay to synth --- synth.c | 22 +++++++++++++++++++++- synth.h | 5 +++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/synth.c b/synth.c index 70bf606..56b8d4c 100644 --- a/synth.c +++ b/synth.c @@ -6,6 +6,11 @@ extern float current_time; +float noise() +{ + return 2.0f*(rand()/(float)RAND_MAX)-1.0f; +} + float detune(float base, int coarse, int fine) { return base*powf(2.0f, (coarse+(fine/100.0f))/12.0f); @@ -63,7 +68,7 @@ uint8 synth(Voice *v, int len, float *mix_buf) break; } case NOISE: - v->waves[wave][i] = 2.0f*(rand()/(float)RAND_MAX)-1.0f; + v->waves[wave][i] = noise(); break; case SUM: @@ -107,7 +112,22 @@ uint8 synth(Voice *v, int len, float *mix_buf) v->waves[wave][i] = 1.0f - 1.0f/(1.0f+expf(-f*(time-d))); break; } + + /* + case DELAY: + { + // op1: delay (ms), op2: volume (%) + uint32 delay = op1*SAMPLE_RATE/1000.0f; + float *data = (float*)(v->data[wave]+4); + int *p = (int*)(v->data[wave]); + v->waves[wave][i] = (op2/100.0f)*data[*p]; + // circular buffer + data[*p] = v->waves[wave-1][i]; + *p = (*p + 1)%delay; + break; + } + */ default: goto end; } diff --git a/synth.h b/synth.h index 2383899..856f366 100644 --- a/synth.h +++ b/synth.h @@ -38,7 +38,7 @@ typedef struct // data buffer to store, for example, previous inputs/outputs for // filtering. It is as big as the wave buffer. Anyway, voices will be // created at bss, so they don't count for the file size :) - uint8 data[MAX_OPS][BUFFER_SIZE*sizeof(float)]; + uint8 data[MAX_OPS][20*BUFFER_SIZE*sizeof(float)]; // buffers generated by wave operations float waves[MAX_OPS][BUFFER_SIZE]; @@ -54,12 +54,13 @@ typedef struct #define HPF 7 #define NOISE 8 #define SIGMOID 9 +#define DELAY 10 #define ENDI 254 #define END 255 extern uint8 synth(Voice *v, int len, float *mix_buf); extern float detune(float base, int coarse, int fine); - +extern float noise(); #endif // SYNTH_H -- 2.34.1