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);
//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; i<BUFFER_SIZE; i++)
+ {
+ float v = drawbuf[i];
+ if (v>1.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; y<ymax; y++)
+ p[(video->pitch/4)*y+i] = 0x00FFFFFF;
+ p[(video->pitch/4)*y1+i] = 0x00FFFFFF;
+ y0=y1;
+ }
+ SDL_Flip(video);
+ }
+ }
+
+end:
SDL_Quit();
_exit(0);
//return error;
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;
*/
for (uint8 i=0; i<NUM_CHANNELS; ++i) {
- unsigned int chanval=song->patterns[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) {
}
}
+ memcpy(drawbuf, mix_buf, num_samples*sizeof(float));
+
// convertimos a Sint16
for (int i=0; i<num_samples; ++i)
{
float tmp = mix_buf[i];
if (tmp>1.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
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];
{
// 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;
}
{
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;
{ // 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