LOGG_Stream* logg_get_stream(const char* filename, int volume, int pan, int loop) { LOGG_Stream* s = calloc(1, sizeof(LOGG_Stream)); if (!s) { return 0; } s->filename = strdup(filename); if (!s->filename) { free(s); return 0; } if (logg_open_file_for_streaming(s)) { logg_destroy_stream(s); return 0; } s->volume = volume; s->pan = pan; s->loop = loop; if (logg_play_stream(s)) { logg_destroy_stream(s); return 0; } return s; }
static int logg_play_stream(LOGG_Stream* s) { int len; int i; s->current_page = 0; s->playing_page = -1; len = logg_bufsize / (s->stereo ? 2 : 1) / (s->bits / (sizeof(char)*8)); s->audio_stream = play_audio_stream(len, s->bits, s->stereo, s->freq, s->volume, s->pan); if (!s->audio_stream) { return 1; } for (i = 0; i < OGG_PAGES_TO_BUFFER; i++) { s->buf[i] = malloc(logg_bufsize); if (!s->buf[i]) { logg_destroy_stream(s); return 1; } if (read_ogg_data(s) < 0) { return 1; } } return 0; }
void CDStop(void) { if (stream) { logg_destroy_stream(stream); stream = NULL; trackNum = 0; } }
void CDPlay(int track) { if (trackNum == track && stream != NULL && isPlaying) { return; // Already playing that track } char buf[32]; sprintf(buf, "sound/mus%03d.ogg", track); trackNum = track; if (stream != NULL) logg_destroy_stream(stream); stream = logg_get_stream(buf, 128, 128, 0); }
bool stopMusic() { int music_size = music.size(); int music_end = music_size-1; if (music_size > 0) { if (music[music_end]) logg_destroy_stream(music[music_end]); music.pop_back(); music_size = music.size(); music_end = music_size-1; if (music_size > 0) { logg_restart_stream(music[music_end]); } return true; } return false; }
void startMusic(const char* name) { char resName[1000]; strcpy(resName, getResource("music/%s", name)); int music_size = music.size(); int music_end = music_size-1; if (music_size != 0 && music[music_end] && !strcmp(music[music_end]->filename, resName)) { return; } LOGG_Stream* s = logg_get_stream(resName, config.getMusicVolume(), 128, 1); if (music_size == 0) { music.push_back(s); } else { if (music[music_end]) { logg_destroy_stream(music[music_end]); } music[music_end] = s; } }