int csid_seek (DB_fileinfo_t *_info, float time) { sid_info_t *info = (sid_info_t *)_info; float t = time; if (t < _info->readpos) { // reinit info->sidplay->load (info->tune); csid_mute_voices (info, chip_voices); } else { t -= _info->readpos; } info->resid->filter (false); int samples = t * _info->fmt.samplerate; samples *= (_info->fmt.bps>>3) * _info->fmt.channels; uint16_t buffer[2048 * _info->fmt.channels]; while (samples > 0) { int n = min (samples, 2048) * _info->fmt.channels; int done = info->sidplay->play (buffer, n); if (done < n) { trace ("sid seek failure\n"); return -1; } samples -= done; } info->resid->filter (true); _info->readpos = time; return 0; }
int csid_init (DB_fileinfo_t *_info, DB_playItem_t *it) { sid_info_t *info = (sid_info_t *)_info; // libsidplay crashes if file doesn't exist // so i have to check it here deadbeef->pl_lock (); const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI")); deadbeef->pl_unlock (); DB_FILE *fp = deadbeef->fopen (uri); if (!fp ){ return -1; } deadbeef->fclose (fp); info->sidplay = new sidplay2; info->resid = new ReSIDBuilder ("wtf"); info->resid->create (info->sidplay->info ().maxsids); info->resid->filter (true); int samplerate = deadbeef->conf_get_int ("sid.samplerate", 44100); int bps = deadbeef->conf_get_int ("sid.bps", 16); if (bps != 16 && bps != 8) { bps = 16; } info->resid->sampling (samplerate); info->duration = deadbeef->pl_get_item_duration (it); deadbeef->pl_lock (); info->tune = new SidTune (deadbeef->pl_find_meta (it, ":URI")); deadbeef->pl_unlock (); info->tune->selectSong (deadbeef->pl_find_meta_int (it, ":TRACKNUM", 0)+1); sid2_config_t conf; conf = info->sidplay->config (); conf.frequency = samplerate; conf.precision = bps; conf.playback = deadbeef->conf_get_int ("sid.mono", 0) ? sid2_mono : sid2_stereo; conf.sidEmulation = info->resid; conf.optimisation = 0; info->sidplay->config (conf); info->sidplay->load (info->tune); _info->plugin = &sid_plugin; _info->fmt.channels = conf.playback == sid2_stereo ? 2 : 1; _info->fmt.bps = bps; _info->fmt.samplerate = conf.frequency; _info->fmt.channelmask = _info->fmt.channels == 1 ? DDB_SPEAKER_FRONT_LEFT : (DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT); _info->readpos = 0; chip_voices = deadbeef->conf_get_int ("chip.voices", 0xff); csid_mute_voices (info, chip_voices); return 0; }
int csid_read (DB_fileinfo_t *_info, char *bytes, int size) { sid_info_t *info = (sid_info_t *)_info; if (_info->readpos > info->duration) { return 0; } if (chip_voices_changed) { chip_voices = deadbeef->conf_get_int ("chip.voices", 0xff); chip_voices_changed = 0; csid_mute_voices (info, chip_voices); } int rd = info->sidplay->play (bytes, size); int samplesize = (_info->fmt.bps>>3) * _info->fmt.channels; _info->readpos += rd / samplesize / (float)_info->fmt.samplerate; return size; }