static void vtx_free (DB_fileinfo_t *_info) { // free everything allocated in _init vtx_info_t *info = (vtx_info_t *)_info; if (_info) { if (info->decoder) { ayemu_vtx_free (info->decoder); info->decoder = NULL; } ayemu_reset (&info->ay); free (_info); } }
void play (const char *filename) { ayemu_vtx_t *vtx; int len; vtx = ayemu_vtx_load_from_file(filename); if (!vtx) return; if (!qflag) printf(" Title: %s\n Author: %s\n From: %s\n Comment: %s\n Year: %d\n", vtx->title, vtx->author, vtx->from, vtx->comment, vtx->year); int audio_bufsize = freq * chans * (bits >> 3) / vtx->playerFreq; if ((audio_buf = malloc (audio_bufsize)) == NULL) { fprintf (stderr, "Can't allocate sound buffer\n"); goto free_vtx; } ayemu_reset(&ay); ayemu_set_chip_type(&ay, vtx->chiptype, NULL); ayemu_set_chip_freq(&ay, vtx->chipFreq); ayemu_set_stereo(&ay, vtx->stereo, NULL); size_t pos = 0; while (pos++ < vtx->frames) { ayemu_vtx_getframe (vtx, pos, regs); ayemu_set_regs (&ay, regs); ayemu_gen_sound (&ay, audio_buf, audio_bufsize); if ((len = write(audio_fd, audio_buf, audio_bufsize)) == -1) { fprintf (stderr, "Error writting to sound device, break.\n"); break; } } free_vtx: ayemu_vtx_free(vtx); }