Instrument tests
authorslack <slack@codemaniacs.com>
Tue, 21 Jul 2009 01:55:11 +0000 (03:55 +0200)
committerslack <slack@codemaniacs.com>
Tue, 21 Jul 2009 01:55:11 +0000 (03:55 +0200)
lolailo.c
play.c
play.h
song.h
synth.c
synth.h
thesong.c

index 6897770e83c6d94f6c6684ca2538cb4c77b0a6cb..be489d83915f1be2954cba3e05a35b758d209471 100644 (file)
--- a/lolailo.c
+++ b/lolailo.c
@@ -20,12 +20,21 @@ SDL_AudioSpec desired={44100,
 
 float drawbuf[BUFFER_SIZE];
 
+#ifdef OUTFILE
+FILE *fout;
+#endif
+
+
 #ifdef DEBUG
 int main(int argc, char *argv[])
 #else
 void _start()
 #endif
 {
+    #ifdef OUTFILE
+       fout = fopen(OUTFILE, "wb");
+       #endif
+    
     SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
     SDL_Surface *video = SDL_SetVideoMode(BUFFER_SIZE,480,32,SDL_SWSURFACE | SDL_DOUBLEBUF);
     SDL_OpenAudio(&desired, NULL);
@@ -92,6 +101,9 @@ void _start()
     }
     
 end:
+    #ifdef OUTFILE
+       fclose(fout);
+       #endif
     SDL_Quit();
     _exit(0);
     //return error;
diff --git a/play.c b/play.c
index bc4d97c6d1d9ae7a1ff7d10f82f2e3c525a477f9..57583c26e38e59692d880decb438184813f4e779 100644 (file)
--- a/play.c
+++ b/play.c
@@ -6,20 +6,24 @@
 #include <string.h>
 
 
-#define NUM_VOICES 
+#define NUM_VOICES 20
 
-float row_duration=60.0f/570.0f; // denominator == RPM
+float row_duration=60.0f/320.0f; // denominator == RPM
 Voice voices[NUM_VOICES];
 float mix_buf[BUFFER_SIZE]={0};
 uint8  last_voice_used=0;
 
 float  current_time=0.0f;
 uint32 rows_played=0; // total of rows played
-uint8  cur_pos= 0;    // current position in the pattern playlist
-uint8  cur_row=-1;    // current row in the current pattern
+uint8  cur_pos= 255;    // current position in the pattern playlist
+int8  cur_row=-1;    // current row in the current pattern
 
 extern float drawbuf[BUFFER_SIZE];
 
+#ifdef OUTFILE
+extern FILE *fout;
+#endif
+
 void play(void *s, uint8 *stream, int len)
 {
     Song *song = (Song*) s;
@@ -43,6 +47,7 @@ void play(void *s, uint8 *stream, int len)
         }
 
         uint8 cur_ptn=song->playlist[cur_pos];
+       //printf("rows_played=%d, cur_pos=%d, cur_ptn=%d, cur_row=%d\n", rows_played, cur_pos, cur_ptn, cur_row);
 
         /*
         for (i=0; i<NUM_RHYTHM_CHANNELS; ++i) {
@@ -67,7 +72,7 @@ void play(void *s, uint8 *stream, int len)
 
                 unsigned int note = (cur_trk->notes[cur_row] & 0x0F);
                 if (note) {
-                    float vol = ((cur_trk->notes[cur_row])>>4) * 0.0625f;
+                    float vol = ((cur_trk->notes[cur_row])>>4) * 0.125f;
                     note+=trans;
 
                     uint8 j = last_voice_used; 
@@ -76,7 +81,7 @@ void play(void *s, uint8 *stream, int len)
                     voices[j].pitch = detune(440.0f,note-21,0);
                     voices[j].pos = buf_start;
                     voices[j].ins = &song->instrument_data[cur_trk->instrument];
-                    voices[j].vol = 0.19921875f*vol;
+                    voices[j].vol = vol;
                     voices[j].active = 1;
                 }
             }
diff --git a/play.h b/play.h
index adc13cb5741c58ad3f7e788d52f9e1501e5a3842..e9f0c11f18b27543701b4e10e7f917d20c1130c6 100644 (file)
--- a/play.h
+++ b/play.h
@@ -4,5 +4,6 @@
 #include "sizedtypes.h"
 
 void play(void *songdata, uint8 *stream, int len);
+//#define OUTFILE "salida.raw"
 
 #endif // PLAY_H
diff --git a/song.h b/song.h
index c4af8dc1c61f26eb7ea7b172c5313a869f503b34..b220ee282f8fa5e9bdc815870e879d01b4c0b258 100644 (file)
--- a/song.h
+++ b/song.h
 //          + PLAYLIST_LENGTH
 
 #define NUM_PATTERNS 20
-#define NUM_CHANNELS 4
+#define NUM_CHANNELS 8
 #define NUM_TRACKS 15 
-#define TRACK_LENGTH 16
-#define INSTRUMENT_DATA_LENGTH 100
+#define TRACK_LENGTH 1
+#define INSTRUMENT_DATA_LENGTH 200
 #define PLAYLIST_LENGTH 50
 
 typedef struct
@@ -25,7 +25,7 @@ typedef struct
 typedef struct
 {
        uint8 patterns[NUM_PATTERNS][NUM_CHANNELS];
-        int8 transpose[NUM_PATTERNS][NUM_CHANNELS];
+    int8 transpose[NUM_PATTERNS][NUM_CHANNELS];
        Track tracks[NUM_TRACKS];
        uint8 instrument_data[INSTRUMENT_DATA_LENGTH];
        uint8 playlist[PLAYLIST_LENGTH];
diff --git a/synth.c b/synth.c
index 5ce011198025a10b8961f194213fb7263ec26cad..34818b033e351974bde769ec4af2d03fe7f355e9 100644 (file)
--- a/synth.c
+++ b/synth.c
@@ -32,7 +32,7 @@ uint8 synth(Voice *v, int len, float *mix_buf)
             switch (ins) {
                 case CONST:
                 {
-                    float value = ((int8) op1/10.0);
+                    float value = ((int8) op1) + ((int8) op2/100.0);
                     v->waves[wave][i] = value;
                     break;
                 }
@@ -106,7 +106,7 @@ uint8 synth(Voice *v, int len, float *mix_buf)
                     v->waves[wave][i] = 1.0f - 1.0f/(1.0f+expf(-f*(time-d)));
                     break;
                 }
-
+               
                 default:
                     goto end;
             }
@@ -117,7 +117,7 @@ uint8 synth(Voice *v, int len, float *mix_buf)
 end:
     v->pos+=len;
     for (int i=0; i<len; i++)
-        mix_buf[i] += v->waves[wave-1][i];
+        mix_buf[i] += v->waves[wave-1][i]*v->vol;
     return 1;
 }
 
diff --git a/synth.h b/synth.h
index ea3a180e79e95fa7cf5be833da5abf093ef68186..2383899bcf089a5e4fdc265ed4c427f91cee7499 100644 (file)
--- a/synth.h
+++ b/synth.h
@@ -54,6 +54,7 @@ typedef struct
 #define HPF      7
 #define NOISE    8
 #define SIGMOID  9
+#define ENDI   254
 #define END    255
 
 extern uint8 synth(Voice *v, int len, float *mix_buf);
index 7c35ee161281a001218583f7e7bf68ecda66fbec..f37a280e9d34307466cf1dc815c5610d62c16d7e 100644 (file)
--- a/thesong.c
+++ b/thesong.c
@@ -3,22 +3,54 @@
 
 Song thesong={
     {  // begin patterns
-        {0x01, 0x02, 0x03, 0x00},
+        {0x01, 0x01, 0x01, 0x03, 0x04, 0x02, 0x00, 0x00},
+        {0x00, 0x00, 0x00, 0x03, 0x04, 0x02, 0x00, 0x00},
     }, // end patterns
     {  // begin txpose
-        {-12, 0, 0, 0},
+        {0, -9, -5, 24, -12},
+        {0, -9, -5, 24, -12},
     }, // end txpose
     {  // begin tracks
-        {{45,0,0,0,45,0,0,0,45,0,0,0,45,0,0,0}, 0},
+        {{0x14,0,0,0,0,0,0,0,0,0,0,0}, 0},
+        {{45,0,0,45,0,0,45,0,0,45,0,0}, 46},
+        {{0xF4,0x74,0x24,0xF4,0x74,0x24,0xF4,0x74,0x24,0xF4,0x74,0x24,}, 65},
+        {{0xf4,0,0,0,0,0xfb,0xf4,0,0,0xf2,0,0}, 65},
     }, // end tracks
     {  // begin instrument data
-        SIGMOID,15,0,
-        NOISE,0,30,
+       CONST,0,35,
+       CONST,0,25,
+       SUM,1,2,
+       SINE,0,0,
+       SQUARE,12,50,
+       SINE,-12,1,
+       SUM,2,3,
+       SUM,1,2,
+       CONST,0,13,
+       MUL,1,2,
+       LPF,8,10,
+       LPF,10,0,
+       SIGMOID,-10,5,
+       SIGMOID,1,10,
+       MUL,1,2,
+       MUL,1,4,
+       ENDI,
+       // 43
+        SIGMOID,12,0,
+        NOISE,0,0,
         LPF,2,40,
-        END,
+       MUL,1,3,
+       CONST,100,0,
+       MUL,1,2,
+        ENDI,
+       //19
+        SIGMOID,10,1,
+       SQUARE,0,20,
+        LPF,2,20,
+       MUL,1,3,
+       END,
     }, // end instrument data
     {  // begin playlist
-        0,255,
+        1,255,
     }, // end playlist
 };