From: slack Date: Mon, 15 Jun 2009 17:27:13 +0000 (+0200) Subject: MOAR WIP! MOAR! X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;h=3a41bd80344d5c7a9b3824e636816151b635b2a0;p=lolailo.git MOAR WIP! MOAR! --- diff --git a/lolailo.c b/lolailo.c index 08de771..8f4e484 100644 --- a/lolailo.c +++ b/lolailo.c @@ -17,13 +17,17 @@ SDL_AudioSpec desired={44100, 0, (void (*)(void *, Uint8 *, int)) play, &thesong}; + +float drawbuf[BUFFER_SIZE]; + #ifdef DEBUG int main(int argc, char *argv[]) #else void _start() #endif { - SDL_Init(SDL_INIT_AUDIO); + 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); SDL_PauseAudio(0); @@ -43,7 +47,51 @@ void _start() //MainWindow w(NULL); //w.show(); //int error = a.exec(); - getchar(); + SDL_Event ev; + int paused=0; + while(1) + { + while (SDL_PollEvent(&ev)) + { + if (ev.type == SDL_KEYDOWN) + { + if (ev.key.keysym.sym == SDLK_SPACE) { + paused = !paused; + SDL_PauseAudio(paused); + } + else + goto end; + } + + if (ev.type == SDL_QUIT) goto end; + } + + if (!paused) + { + memset(video->pixels, 0, video->pitch*video->h); + uint32 *p = (uint32*) video->pixels; + int y0=240; + for (int i=0; i1.0f) v = 1.0f; + if (v<0.0f) v = 0.0f; + + int y1 = (1.0f-v)*479.0f; + float ymin, ymax; + if (y0 < y1) { ymin=y0; ymax=y1; } + else { ymin=y1; ymax=y0; } + + for (int y=ymin; ypitch/4)*y+i] = 0x00FFFFFF; + p[(video->pitch/4)*y1+i] = 0x00FFFFFF; + y0=y1; + } + SDL_Flip(video); + } + } + +end: SDL_Quit(); _exit(0); //return error; diff --git a/play.c b/play.c index 21acb61..d8b2957 100644 --- a/play.c +++ b/play.c @@ -18,6 +18,8 @@ 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 +extern float drawbuf[BUFFER_SIZE]; + void play(void *s, uint8 *stream, int len) { Song *song = (Song*) s; @@ -57,11 +59,11 @@ void play(void *s, uint8 *stream, int len) */ for (uint8 i=0; ipatterns[cur_ptn][i]; - if (chanval) { - unsigned int trknum=(chanval & 0x0F)-1; + unsigned int trknum=song->patterns[cur_ptn][i]; + if (trknum) { + trknum--; Track *cur_trk = &song->tracks[trknum]; - uint8 trans = (chanval) >> 4; + int8 trans = song->transpose[cur_ptn][i]; unsigned int note = (cur_trk->notes[cur_row] & 0x0F); if (note) { @@ -91,13 +93,15 @@ void play(void *s, uint8 *stream, int len) } } + memcpy(drawbuf, mix_buf, num_samples*sizeof(float)); + // convertimos a Sint16 for (int i=0; i1.0f) tmp=1.0f; - else if(tmp<-1.0f) tmp=-1.0f; - buf[i]=(int16)(tmp*32640.0f); + else if(tmp<0.0f) tmp=0.0f; + buf[i]=(int16)(tmp*64000.0f)-32000; } #ifdef OUTFILE diff --git a/song.h b/song.h index 0e02389..c4af8dc 100644 --- a/song.h +++ b/song.h @@ -25,6 +25,7 @@ typedef struct typedef struct { uint8 patterns[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 4898b25..bd1f3f1 100644 --- a/synth.c +++ b/synth.c @@ -37,7 +37,7 @@ uint8 synth(Voice *v, int len, float *mix_buf) { // op1: signed coarse detune, op2: signed fine detune float pitch = detune(v->pitch, (int8) op1, (int8) op2); - v->waves[wave][i] = sinf(pitch*TWOPI*time); + v->waves[wave][i] = 0.5f*sinf(pitch*TWOPI*time)+0.5f; break; } @@ -45,28 +45,23 @@ uint8 synth(Voice *v, int len, float *mix_buf) { float pitch = detune(v->pitch, (int8) op1, 0); float pw = op2/100.0f; - float period = 1.0/pitch; + float period = 1.0f/pitch; if (fmodf(time, period) > (period*pw)) v->waves[wave][i] = 1.0f; else - v->waves[wave][i] = -1.0f; + v->waves[wave][i] = 0.0f; break; } case NOISE: v->waves[wave][i] = rand()/(float)RAND_MAX; break; - /* - case TO_0_1: - v->waves[wave][i] = v->waves[wave][i-1]*0.5f+0.5f; - break; - */ case SUM: case MUL: { // op1,2: wave indices to sum/mul if (ins == SUM) - v->waves[wave][i] = v->waves[op1][i]+v->waves[op2][i]; + v->waves[wave][i] = 0.5f*(v->waves[op1][i]+v->waves[op2][i]); else v->waves[wave][i] = v->waves[op1][i]*v->waves[op2][i]; break; diff --git a/thesong.c b/thesong.c index 6eb55a6..bbeda3e 100644 --- a/thesong.c +++ b/thesong.c @@ -5,13 +5,17 @@ Song thesong={ { // begin patterns {0x01, 0x00, 0x00, 0x00}, }, // end patterns + { // begin txpose + {-12, 0, 0, 0}, + }, // end txpose { // begin tracks {{45,0,0,0,43,0,0,0,41,0,0,0,40,0,0,0}, 0}, }, // end tracks { // begin instrument data - SINE,-70,0, - NOISE,0,0, - MUL,0,1, + SINE,24,0, + SQUARE,0,10, + SUM,0,1, + LPF,100,10, END, }, // end instrument data { // begin playlist