From 2cceef3078d05956e8255eea95cf40b0161c7a9f Mon Sep 17 00:00:00 2001 From: slack Date: Tue, 21 Jul 2009 03:55:11 +0200 Subject: [PATCH] Instrument tests --- lolailo.c | 12 ++++++++++++ play.c | 17 +++++++++++------ play.h | 1 + song.h | 8 ++++---- synth.c | 6 +++--- synth.h | 1 + thesong.c | 46 +++++++++++++++++++++++++++++++++++++++------- 7 files changed, 71 insertions(+), 20 deletions(-) diff --git a/lolailo.c b/lolailo.c index 6897770..be489d8 100644 --- 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 bc4d97c..57583c2 100644 --- a/play.c +++ b/play.c @@ -6,20 +6,24 @@ #include -#define NUM_VOICES 3 +#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; inotes[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 adc13cb..e9f0c11 100644 --- 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 c4af8dc..b220ee2 100644 --- a/song.h +++ b/song.h @@ -10,10 +10,10 @@ // + 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 12 +#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 5ce0111..34818b0 100644 --- 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; iwaves[wave-1][i]; + mix_buf[i] += v->waves[wave-1][i]*v->vol; return 1; } diff --git a/synth.h b/synth.h index ea3a180..2383899 100644 --- 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); diff --git a/thesong.c b/thesong.c index 7c35ee1..f37a280 100644 --- 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 }; -- 2.34.1