a bit smaller master
authorslack <slack@codemaniacs.com>
Sat, 25 Jul 2009 14:24:24 +0000 (16:24 +0200)
committerslack <slack@codemaniacs.com>
Sat, 25 Jul 2009 14:24:24 +0000 (16:24 +0200)
song.h
synth.c
thesong.c

diff --git a/song.h b/song.h
index e5007c7b33578bf5be1327fed900f16df300c4aa..012735aaad647d99507d81486d9b451a54520f6a 100644 (file)
--- a/song.h
+++ b/song.h
@@ -9,12 +9,12 @@
 //          + INSTRUMENT_DATA_LENGTH
 //          + PLAYLIST_LENGTH
 
-#define NUM_PATTERNS 20
-#define NUM_CHANNELS 12
-#define NUM_TRACKS 20 
+#define NUM_PATTERNS 17
+#define NUM_CHANNELS 8
+#define NUM_TRACKS 16 
 #define TRACK_LENGTH 12 
-#define INSTRUMENT_DATA_LENGTH 300
-#define PLAYLIST_LENGTH 50
+#define INSTRUMENT_DATA_LENGTH 193
+#define PLAYLIST_LENGTH 49
 
 typedef struct
 {
diff --git a/synth.c b/synth.c
index 06ca91a412772e2961ff60b3463c13ce981188a1..f65971b2f0af1cb2b9cdcd46d2563ddcc915d281 100644 (file)
--- a/synth.c
+++ b/synth.c
@@ -36,7 +36,10 @@ void synth(Voice *v, int len, float *mix_buf)
         for (int i=0; i<len; i++) {
             float pitch = detune(v->pitch, (int8) op1, 0);
             float time=(v->pos+i)*invSAMPLE_RATE;
-            //float global_time = current_time+i*invSAMPLE_RATE;
+            float pw = op2/100.0f;
+            float period = 1.0f/pitch; // wave period (in seconds)
+            float op1_sample = v->waves[wave-op1][i];
+            float prev_sample = v->waves[wave-1][i];
             switch (ins) {
                 case CONST:
                     {
@@ -46,22 +49,18 @@ void synth(Voice *v, int len, float *mix_buf)
                         break;
                     }
 
+                    /*
                 case SINE:
                     {
                         // op1: signed coarse detune, op2: phase (0-255)
                         v->waves[wave][i] = sinf(pitch*TWOPI*time+op2*PI/255.0f);
-                        //if (op2)
-                        //    v->waves[wave][i] = sinf(pitch*TWOPI*global_time);
-                        //else
-                        //    v->waves[wave][i] = sinf(pitch*TWOPI*time);
                         break;
                     }
+                    */
 
                 case SQUARE:
                     {
                         // op1: signed coarse detune, op2: pulse width (%)
-                        float pw = op2/100.0f;
-                        float period = 1.0f/pitch;
                         if (fmodf(time, period) < (period*pw))
                             v->waves[wave][i] = 1.0f;
                         else
@@ -70,15 +69,12 @@ void synth(Voice *v, int len, float *mix_buf)
                     }
                 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);
+                            v->waves[wave][i] = 1.0f-2.0f*(t-half_period)/(period-half_period);
                         }
                         break;
                     }
@@ -87,21 +83,21 @@ void synth(Voice *v, int len, float *mix_buf)
                     break;
 
                 case SUM:
-                    v->waves[wave][i] = v->waves[wave-op1][i]+v->waves[wave-1][i];
+                    v->waves[wave][i] = op1_sample + prev_sample;
                     break;
                 case MUL:
-                    v->waves[wave][i] = v->waves[wave-op1][i]*v->waves[wave-1][i];
+                    v->waves[wave][i] = op1_sample * prev_sample;
                     break;
 
                 case LPF:
                 case HPF:
                     {
                         // op1, op2: cutoff(wave), resonance
-                        float cutoff = v->waves[wave-op1][i];
+                        float input = prev_sample;
+                        float cutoff = op1_sample;
                         float r = (op2)/10.0f;
                         //printf("op1=%d, op2=%d, cutoff=%f; r=%f\n", op1, op2, cutoff, r);
 
-                        float input = v->waves[wave-1][i];
                         float *data = (float*)v->data[wave];
                         // data[0-3] == pole1..pole4
                         // Arif Ove Karlsen's 24dB Ladder Approximation, 3.nov 2007
index 0cba04888a7005dfd31c33af379116a436699709..48b3a95aa32d0ffc98be40442828a724c9ddc665 100644 (file)
--- a/thesong.c
+++ b/thesong.c
@@ -3,42 +3,42 @@
 
 Song thesong={
     {  // begin patterns
-        {0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //  0 - wind 1
-        {0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //  1 - wind 2
-        {0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //  2 - wind 3
-        {0x05, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //  3 - bongo+wind
-        {0x05, 0x07, 0x00, 0x00, 0x00, 0x0d, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00}, //  4 - bongo+bass1
-        {0x05, 0x07, 0x00, 0x00, 0x00, 0x0c, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00}, //  5 - bongo+bass2
-        {0x05, 0x07, 0x00, 0x00, 0x00, 0x0c, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00}, //  6 - bongo+bass1
-        {0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00}, //  7 - bongo+bass2
-        {0x05, 0x07, 0x06, 0x06, 0x06, 0x09, 0x0a, 0x0d, 0x0d, 0x00, 0x00, 0x00}, //  8 - bongo+piano+bass1+melody1
-        {0x05, 0x07, 0x06, 0x06, 0x06, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00}, //  9 - bongo+piano+bass1+melody2
-        {0x05, 0x07, 0x06, 0x06, 0x06, 0x09, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00}, // 10 - bongo+piano+bass1+melody3
-        {0x05, 0x07, 0x06, 0x06, 0x06, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 11 - bongo+piano+bass1+melody4
-        {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+melody6
-        {0x05, 0x07, 0x06, 0x06, 0x06, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 11 - bongo+piano+bass1+melody7
+        {0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //  0 - wind 1
+        {0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, //  1 - wind 2
+        {0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}, //  2 - wind 3
+        {0x02, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00}, //  3 - bongo+wind
+        {0x07, 0x0c, 0x01, 0x02, 0x05, 0x00, 0x00, 0x00}, //  4 - bongo+bass1
+        {0x07, 0x0b, 0x01, 0x03, 0x05, 0x00, 0x00, 0x00}, //  5 - bongo+bass2
+        {0x07, 0x0b, 0x01, 0x02, 0x05, 0x00, 0x00, 0x00}, //  6 - bongo+bass1
+        {0x07, 0x03, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00}, //  7 - bongo+bass2
+        {0x07, 0x06, 0x06, 0x06, 0x08, 0x09, 0x0c, 0x05}, //  8 - bongo+piano+bass1+melody1
+        {0x07, 0x06, 0x06, 0x06, 0x00, 0x00, 0x0b, 0x05}, //  9 - bongo+piano+bass1+melody2
+        {0x07, 0x06, 0x06, 0x06, 0x08, 0x0b, 0x00, 0x05}, // 10 - bongo+piano+bass1+melody3
+        {0x07, 0x06, 0x06, 0x06, 0x0a, 0x00, 0x00, 0x05}, // 11 - bongo+piano+bass1+melody4
+        {0x07, 0x06, 0x06, 0x06, 0x05, 0x00, 0x00, 0x00}, // 12 - bongo+bass1+piano
+        {0x07, 0x06, 0x06, 0x06, 0x05, 0x00, 0x00, 0x00}, // 13 - bongo+bass1+piano
+        {0x07, 0x06, 0x06, 0x06, 0x0d, 0x05, 0x00, 0x00}, // 14 - bongo+piano+bass1+melody5
+        {0x07, 0x06, 0x06, 0x06, 0x0e, 0x05, 0x00, 0x00}, // 15 - bongo+piano+bass1+melody6
+        {0x07, 0x06, 0x06, 0x06, 0x0f, 0x05, 0x00, 0x00}, // 16 - bongo+piano+bass1+melody7
     }, // end patterns
     {  // begin txpose
-        {-15, 0, 0, 0, 0}, // wind1
-        {-9, 0, -3, 0, 0}, // wind2
-        {0, -20, 0, -5, 0}, // wind3
-        {24,-15,0,0,0},     // bongo
-        {24,9,7,11,14,21,-15,-9}, // bongo+bass1
-        {24,9,7,11,14,23,-15,-3}, // bongo+bass1
-        {24,6,7,11,16,21,-15,-9}, // bongo+bass1
-        {24,6,7,11,16,21,-3,-9}, // bongo+bass1
-        {24,9,7,11,14,21,21,21,21}, // bongo+piano+bass1+melody1
-        {24,9,7,11,14,21,23,23}, // bongo+piano+bass1+melody2
-        {24,6,7,11,16,21,21,21}, // bongo+piano+bass1+melody3
-        {24,6,7,11,16,21,21,21}, // bongo+piano+bass1+melody4
-        {24,9,7,11,14}, // bongo+bass1+piano
-        {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
+        {-15,0}, // 0 - wind1
+        {-9,0,-3}, // 1 - wind2
+        {0,-20,0,-5}, // 2 - wind3
+        {-15,0,0},     // 3 - bongo
+        {9,21,-15,-9,0}, // 4 - bongo+bass1
+        {9,23,-15,-3,0}, // 5 - bongo+bass1
+        {6,21,-15,-9,0}, // 6 - bongo+bass1
+        {6,-3,-9,0}, // 7 - bongo+bass1
+        {9,7,11,14,21,21,21,0}, // 8 - bongo+piano+bass1+melody1
+        {9,7,11,14,23,23,23,0}, // 9 - bongo+piano+bass1+melody2
+        {6,7,11,16,21,21,21,0}, // 10 - bongo+piano+bass1+melody3
+        {6,7,11,16,21,21,21,0}, // 11 - bongo+piano+bass1+melody4
+        {9,7,11,14,0}, // 12 - bongo+bass1+piano
+        {6,7,11,16,0}, // 13 - bongo+bass1+piano
+        {9,7,11,14,25,0}, // 14 - bongo+piano+bass1+melody5
+        {9,7,11,14,25,0}, // 15 - bongo+piano+bass1+melody6
+        {6,7,11,16,25,0}, // 16 - bongo+piano+bass1+melody6
     }, // end txpose
     {  // begin tracks
        {{0,0,0,0,0,0,0,0,0,0,0,0}, 0},
@@ -49,30 +49,29 @@ Song thesong={
         {{0,0,0,0xb4,0x74,0xa4,0,0,0,0xa4,0,0xa4,}, 0}, // 5 - bongo rhythm
         {{0,0,0,0xf1,0,0xb1,0,0,0,0xf1,0,0}, 53}, // 6 - piano rhythm
        {{0x57,0,0x17,0x37,0,0,0x52,0,0,0x37,0,0,}, 93}, // 7 - bassline 1
-       {{0x54,0,0x14,0x34,0,0,0x59,0,0,0x39,0,0,}, 93}, // 8 - bassline 2 (FREE)
-       {{0x6b,0,0,0x6b,0,0,0x6b,0,0,0x6c,0,0}, 115}, // 9
-       {{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}, 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
+       {{0x6b,0,0,0x6b,0,0,0x6b,0,0,0x6c,0,0}, 115}, // 8
+       {{0,0,0,0,0,0,0,0,0,0,0,0x6e}, 143}, // 9
+       {{0x6b,0,0x69,0,0,0x67,0,0,0,0,0,0}, 115}, // a
+       {{0,0,0,0,0,0,0,0,0,0,0,0x6e}, 171}, // b
+       {{0x6e,0,0,0,0,0x6c,0x6b,0,0x6c,0,0,0x6e}, 171}, // c
+       {{0x6f,0,0,0x6e,0,0,0x6c,0,0,0x6a,0,0}, 115}, // d - melody 5
+       {{0x67,0,0,0x65,0,0x63,0,0,0,0,0,0}, 115}, // e - melody 6
+       {{0x6c,0,0,0x60,0,0x60,0,0,0x62,0x63,0,0}, 115}, // f - melody 7
     }, // end tracks
     {  // begin instrument data
        // 0 (bongo)
        SIGMOID,10,1,
-        SINE,0,20,
+        TRIANGLE,24,50,
         LPF,2,40,
         MUL,3,0,
        CONST,8,0,
        MUL,2,0,
-        ENDI,
+        END,
        // 19 (wind)
        SIGMOID,2,15,
        SIGMOID,-10,6,
        MUL,2,0,
-       SINE,-110,200,
+       TRIANGLE,-110,20,
        CONST,0,5,
        MUL,2,0,
        CONST,0,10,
@@ -80,7 +79,7 @@ Song thesong={
        NOISE,0,0,
        LPF,2,10,
        MUL,8,0,
-       ENDI,
+       END,
        // 53 (piano-ish)
        CONST,0,30,
        CONST,0,10,
@@ -95,17 +94,17 @@ Song thesong={
        LPF,10,20,
        CONST,0,70,
        MUL,2,0,
-       ENDI,
+       END,
        // 93 (bass)
        SIGMOID, 8,3,
        TRIANGLE,-20,1,
-       SINE,-8,10,
+       TRIANGLE,-8,50,
        SUM,2,0,
        LPF,4,0,
        CONST,0,80,
        MUL,2,0,
        MUL,7,0,
-       ENDI,
+       END,
        // 115 (lead)
        CONST,0,30,
        SIGMOID, 8,4,
@@ -116,7 +115,7 @@ Song thesong={
        CONST,0,20,
        MUL,2,0,
        MUL,7,0,
-       ENDI,
+       END,
        // 143 (lead)
        CONST,0,30,
        SIGMOID, 3,10,
@@ -127,7 +126,7 @@ Song thesong={
        CONST,0,10,
        MUL,2,0,
        MUL,7,0,
-       ENDI,
+       END,
        // 171 (pad)
        CONST,0,80,
        SIGMOID, 1,14,
@@ -139,7 +138,18 @@ 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,16,13,14,15,16,13,14,15,16,13,14,15,16,13,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
 };