From 51ea064ccd0b9786c6b86023c72b7bee9793f907 Mon Sep 17 00:00:00 2001 From: slack Date: Sat, 25 Jul 2009 15:05:25 +0200 Subject: [PATCH] Almost final version, HORA DE LAS REBAJAS! --- play.c | 2 ++ play.h | 3 +++ synth.c | 51 ++++++++++++++++++++++++++++++++------------------- synth.h | 2 +- thesong.c | 24 ++++++++++++++---------- 5 files changed, 52 insertions(+), 30 deletions(-) diff --git a/play.c b/play.c index 0aa7088..91a79bb 100644 --- a/play.c +++ b/play.c @@ -78,7 +78,9 @@ void play(void *s, uint8 *stream, int len) synth(&voices[i], num_samples, mix_buf); } +#ifdef IM_IN_UR_PREPROCESER_DRAWIN_UR_WAVES memcpy(drawbuf, mix_buf, num_samples*sizeof(float)); +#endif // convertimos a Sint16 for (int i=0; iins[iPC++]; //printf("wave %d, ins=%d (%d, %d)\n", wave, ins, op1, op2); for (int i=0; ipitch, (int8) op1, 0); float time=(v->pos+i)*invSAMPLE_RATE; //float global_time = current_time+i*invSAMPLE_RATE; switch (ins) { case CONST: { // op1: integer part, op2: decimal part * 100 - float value = ((int8) op1) + ((int8) op2/100.0); + float value = ((int8) op1) + ((int8) op2/100.0f); v->waves[wave][i] = value; break; } @@ -48,7 +49,6 @@ void synth(Voice *v, int len, float *mix_buf) case SINE: { // op1: signed coarse detune, op2: phase (0-255) - float pitch = detune(v->pitch, (int8) op1, 0); v->waves[wave][i] = sinf(pitch*TWOPI*time+op2*PI/255.0f); //if (op2) // v->waves[wave][i] = sinf(pitch*TWOPI*global_time); @@ -60,15 +60,28 @@ void synth(Voice *v, int len, float *mix_buf) case SQUARE: { // op1: signed coarse detune, op2: pulse width (%) - float pitch = detune(v->pitch, (int8) op1, 0); float pw = op2/100.0f; float period = 1.0f/pitch; - if (fmodf(time, period) > (period*pw)) + if (fmodf(time, period) < (period*pw)) v->waves[wave][i] = 1.0f; else v->waves[wave][i] = -1.0f; break; } + case TRIANGLE: + { + float pw = op2/100.0f; + float period = 1.0f/pitch; // wave period (in seconds) + float half_period = pw*period; + float t = fmodf(time,period); + if (t < half_period) + v->waves[wave][i] = 2.0f*(t/half_period)-1.0f; + else { + t-=half_period; + v->waves[wave][i] = 1.0f-2.0f*t/(period-half_period); + } + break; + } case NOISE: v->waves[wave][i] = noise(); break; @@ -113,22 +126,22 @@ void 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; - } - */ + /* + + 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 9b635b4..1911812 100644 --- a/synth.h +++ b/synth.h @@ -46,7 +46,7 @@ typedef struct #define CONST 0 #define SINE 1 #define SQUARE 2 -#define SAW 3 +#define TRIANGLE 3 #define SUM 4 #define MUL 5 #define LPF 6 diff --git a/thesong.c b/thesong.c index 867a3d9..0cba048 100644 --- a/thesong.c +++ b/thesong.c @@ -18,7 +18,8 @@ Song thesong={ {0x05, 0x07, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 12 - bongo+bass1+piano {0x05, 0x07, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 13 - bongo+bass1+piano {0x05, 0x07, 0x06, 0x06, 0x06, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 11 - bongo+piano+bass1+melody5 - {0x05, 0x07, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 11 - bongo+piano+bass1+melody5 + {0x05, 0x07, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 11 - bongo+piano+bass1+melody6 + {0x05, 0x07, 0x06, 0x06, 0x06, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 11 - bongo+piano+bass1+melody7 }, // end patterns { // begin txpose {-15, 0, 0, 0, 0}, // wind1 @@ -37,6 +38,7 @@ Song thesong={ {24,6,7,11,16}, // bongo+bass1+piano {24,9,7,11,14,25,}, // bongo+piano+bass1+melody5 {24,9,7,11,14,25,}, // bongo+piano+bass1+melody6 + {24,6,7,11,16,25,}, // bongo+piano+bass1+melody6 }, // end txpose { // begin tracks {{0,0,0,0,0,0,0,0,0,0,0,0}, 0}, @@ -52,17 +54,18 @@ Song thesong={ {{0,0,0,0,0,0,0,0,0,0,0,0x6e}, 143}, // a {{0x6b,0,0x69,0,0,0x67,0,0,0,0,0,0}, 115}, // b {{0,0,0,0,0,0,0,0,0,0,0,0x6e}, 171}, // c - {{0x6e,0,0,0,0,0x6c,0x6b,0,0x6c,0,0,0x6e}, 115}, // d + {{0x6e,0,0,0,0,0x6c,0x6b,0,0x6c,0,0,0x6e}, 171}, // d {{0x6f,0,0,0x6e,0,0,0x6c,0,0,0x6a,0,0}, 115}, // e - melody 5 {{0x67,0,0,0x65,0,0x63,0,0,0,0,0,0}, 115}, // f - melody 6 + {{0x6c,0,0,0x60,0,0x60,0,0,0x62,0x63,0,0}, 115}, // 10 - melody 7 }, // end tracks { // begin instrument data - // 0 (bongo) + // 0 (bongo) SIGMOID,10,1, - SQUARE,0,20, + SINE,0,20, LPF,2,40, MUL,3,0, - CONST,10,0, + CONST,8,0, MUL,2,0, ENDI, // 19 (wind) @@ -82,7 +85,7 @@ Song thesong={ CONST,0,30, CONST,0,10, SIGMOID,10,1, - SQUARE,0,15, + TRIANGLE,0,15, SQUARE,12,10, SQUARE,-12,20, SUM,2,0, @@ -95,12 +98,13 @@ Song thesong={ ENDI, // 93 (bass) SIGMOID, 8,3, - SINE,-20,20, + TRIANGLE,-20,1, SINE,-8,10, SUM,2,0, + LPF,4,0, CONST,0,80, MUL,2,0, - MUL,6,0, + MUL,7,0, ENDI, // 115 (lead) CONST,0,30, @@ -127,7 +131,7 @@ Song thesong={ // 171 (pad) CONST,0,80, SIGMOID, 1,14, - SINE,-8,0, + TRIANGLE,-8,50, CONST,0,5, MUL,2,0, MUL,4,0, @@ -135,7 +139,7 @@ Song thesong={ }, // end instrument data { // begin playlist - 0,1,2,1,3,3,3,3,4,5,6,7,4,5,6,7,8,9,10,11,8,9,10,11,12,12,13,13,12,12,13,13,14,15,14,15,255, + 0,1,2,1,3,3,3,3,4,5,6,7,4,5,6,7,8,9,10,11,8,9,10,11,12,12,13,13,12,12,13,13,14,15,16,13,14,15,16,13,14,15,16,13,14,15,16,13,255, }, // end playlist }; -- 2.34.1