// start the currently-loaded track playing at beat startbeat. bool org_start(int startbeat) { org_stop(); // stop any old music // set all the note-tracking stuff to starting values song.beat = startbeat; song.haslooped = false; for(int i=0;i<16;i++) { song.instrument[i].curnote = 0; note_channel[i].volume = ORG_MAX_VOLUME; note_channel[i].panning = ORG_PAN_CENTERED; note_channel[i].length = 0; } // fill the first buffer and play it to jumpstart the playback cycle //lprintf(" ** org_start: Jumpstarting buffer cycle\n"); song.playing = true; song.fading = false; song.volume = OrgVolume; SSSetVolume(ORG_CHANNEL, song.volume); // kickstart the first buffer current_buffer = 0; generate_music(); queue_final_buffer(); buffers_full = 0; // tell org_run to generate the other buffer right away return 0; }
void org_close(void) { int d; org_stop(); free_buffers(); for(d=0;d<NUM_DRUMS;d++) if (drumtable[d].samples) free(drumtable[d].samples); }
int SDL_main(int argc, char *argv[]) { stat("Entering main loop"); testblit(); if (SSInit()) return 1; if (pxt_init()) return 1; if (pxt_LoadSoundFX(pxt_dir, sndcache, 0x75)) { printf("Can't load\n"); return 1; } if (org_init(org_wavetable, pxt_dir, ORG_VOLUME)) { staterr("Music failed to initialize"); return 1; } music(19); while(!quitting) { org_run(); SDL_Event pie; if (SDL_PollEvent(&pie)) { if (pie.type == SDL_KEYDOWN) { if(pie.key.keysym.sym == SDLK_F3) quitting = true; else if(pie.key.keysym.sym == SDLK_BTN_A) pxt_Play(-1, 1, 1); else if(pie.key.keysym.sym == SDLK_BTN_B) org_stop(); else if(pie.key.keysym.sym == SDLK_BTN_Y) music(random(1,42)); } } } pxt_freeSoundFX(); SSClose(); return 0; }
void music_set_enabled(int newstate) { if (newstate != settings->music_enabled) { stat("music_set_enabled(%d)", newstate); settings->music_enabled = newstate; bool play = should_music_play(cursong, newstate); if (play != org_is_playing()) { if (play) start_track(cursong); else org_stop(); } } }
static void start_track(int songno) { char fname[MAXPATHLEN]; if (songno == 0) { org_stop(); return; } strcpy(fname, org_dir); strcat(fname, org_names[songno]); strcat(fname, ".org"); if (!org_load(fname)) { org_start(0); } }
void music(int songno) { if (songno == cursong) return; lastsong = cursong; cursong = songno; stat(" >> music(%d)", songno); if (songno != 0 && !should_music_play(songno, settings->music_enabled)) { stat("Not playing track %d because music_enabled is %d", songno, settings->music_enabled); org_stop(); return; } start_track(songno); }
static void runfade() { uint32_t curtime = SDL_GetTicks(); if ((curtime - song.last_fade_time) >= 25) { int newvol = (song.volume - 1); if (newvol <= 0) { song.fading = false; org_stop(); } else { org_set_volume(newvol); } song.last_fade_time = curtime; } }
void music(int songno) { org_stop(); start_track(songno); }