s32 mp3_reader(void *fp, void *dat, s32 size) { s32 ret, rcnt = 0; retry: while (music_paused) usleep(10000); if (!music_f) return -1; mp3_read_busy = 1; ret = fread(dat, 1, size, music_f); mp3_read_busy = 0; //if (ret != size) printf("mp3 read: %d\n", ret); if (ret == 0 && rcnt == 0) { // eof - reopen fclose(music_f); ret = get_music_file(); if (ret==0) return ret; rcnt++; goto retry; } return ret; }
void test_music (void) { struct music_file *mp; struct audio_chunk *cp; if ((mp = get_music_file ("SOVTYP")) == NULL) { fprintf (stderr, "can't find music file\n"); exit (1); } if (mp->buf == NULL || mp->size == 0) { fprintf (stderr, "can't get music\n"); exit (1); } cp = calloc (1, sizeof *cp); cp->data = (void *)mp->buf; cp->size = mp->size; cp->loop = 1; play (cp); }
void _Music_Start() { int ret; // always init SND, so banner sounds play if music disabled ASND_Init(); ASND_Pause(0); if (CFG.music == 0) { dbg_printf(gt("Music: Disabled")); dbg_printf("\n"); return; } else { dbg_printf(gt("Music: Enabled")); dbg_printf("\n"); } was_playing = false; //get a music file ret = get_music_file(); if (ret==0) return; if (music_format == FORMAT_MP3) { MP3Player_Init(); MP3Player_Volume(0x80); // of 255 //ret = MP3Player_PlayBuffer(music_buf, music_size, NULL); ret = MP3Player_PlayFile(music_f, mp3_reader, NULL); dbg_printf("mp3 play: %s (%d)\n", ret? gt("ERROR"):gt("OK"), ret); if (ret) goto err_play; usleep(10000); // wait 10ms and verify if playing if (!MP3Player_IsPlaying()) { err_play: printf(gt("Error playing %s"), music_fname); printf("\n"); Music_Stop(); sleep(1); } } else { music_buf = malloc(music_size); if (!music_buf) { printf(gt("music file too big (%d) %s"), music_size, music_fname); printf("\n"); sleep(1); music_format = 0; return; } //printf("Loading...\n"); ret = fread(music_buf, music_size, 1, music_f); //printf("size: %d %d\n", music_size, ret); sleep(2); fclose(music_f); music_f = NULL; if (ret != 1) { printf(gt("error reading: %s (%d)"), music_fname, music_size); printf("\n"); sleep(2); free(music_buf); music_buf = NULL; music_size = 0; music_format = 0; return; } MODPlay_Init(&mod); ret = MODPlay_SetMOD(&mod, music_buf); dbg_printf("mod play: %s (%d)\n", ret?gt("ERROR"):gt("OK"), ret); if (ret < 0 ) { Music_Stop(); } else { MODPlay_SetVolume(&mod, 32,32); // fix the volume to 32 (max 64) MODPlay_Start(&mod); // Play the MOD } } }