From 08ecb90b245a8749ad7465087fb19f699e85f6d0 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Tue, 5 Oct 2010 22:17:23 +0200 Subject: fixed some memory corruption bugs in adplug ADL module --- plugins/adplug/adplug-db.cpp | 35 +++++++++++++++++++++-------------- plugins/adplug/adplug/adl.cpp | 16 +++++++++------- plugins/adplug/adplug/player.cpp | 2 -- 3 files changed, 30 insertions(+), 23 deletions(-) (limited to 'plugins') diff --git a/plugins/adplug/adplug-db.cpp b/plugins/adplug/adplug-db.cpp index 86323d45..6aa46dab 100644 --- a/plugins/adplug/adplug-db.cpp +++ b/plugins/adplug/adplug-db.cpp @@ -79,10 +79,12 @@ adplug_init (DB_fileinfo_t *_info, DB_playItem_t *it) { info->subsong = it->tracknum; info->decoder->rewind (info->subsong); - info->totalsamples = info->decoder->songlength (info->subsong) / 1000.f * samplerate; + float dur = deadbeef->pl_get_item_duration (it); + info->totalsamples = dur * samplerate; info->currentsample = 0; info->toadd = 0; + printf ("playing subtrack %d dur %f\n", info->subsong, dur); // fill in mandatory plugin fields _info->plugin = &adplug_plugin; _info->bps = bps; @@ -247,25 +249,30 @@ adplug_insert (DB_playItem_t *after, const char *fname) { int subsongs = p->getsubsongs (); for (int i = 0; i < subsongs; i++) { // prepare track for addition + float dur = p->songlength (i)/1000.f; + if (dur < 0.1) { + continue; + } + printf ("adding subtrack %d dur %f\n", i, dur); DB_playItem_t *it = deadbeef->pl_item_alloc (); it->decoder_id = deadbeef->plug_get_decoder_id (adplug_plugin.plugin.id); it->fname = strdup (fname); it->filetype = adplug_get_extension (fname); it->tracknum = i; - deadbeef->pl_set_item_duration (it, p->songlength (i)/1000.f); + deadbeef->pl_set_item_duration (it, dur); // add metainfo -// if (p->gettitle()[0]) { -// adplug_add_meta (it, "title", p->gettitle()); -// } -// else { -// deadbeef->pl_add_meta (it, "title", NULL); -// } -// if (p->getdesc()[0]) { -// adplug_add_meta (it, "comment", p->getdesc()); -// } -// if (!p->getauthor()[0]) { -// adplug_add_meta (it, "artist", p->getauthor()); -// } + if (p->gettitle()[0]) { + adplug_add_meta (it, "title", p->gettitle()); + } + else { + deadbeef->pl_add_meta (it, "title", NULL); + } + if (p->getdesc()[0]) { + adplug_add_meta (it, "comment", p->getdesc()); + } + if (!p->getauthor()[0]) { + adplug_add_meta (it, "artist", p->getauthor()); + } deadbeef->pl_add_meta (it, "title", NULL); // insert after = deadbeef->pl_insert_item (after, it); diff --git a/plugins/adplug/adplug/adl.cpp b/plugins/adplug/adplug/adl.cpp index 0ad196e9..66f1d227 100644 --- a/plugins/adplug/adplug/adl.cpp +++ b/plugins/adplug/adplug/adl.cpp @@ -277,7 +277,8 @@ public: // * One for instruments, starting at offset 500. uint8 *getProgram(int progId) { - return _soundData + READ_LE_UINT16(_soundData + 2 * progId); + int offset = READ_LE_UINT16(_soundData + 2 * progId); + return _soundData + offset; } uint8 *getInstrument(int instrumentId) { @@ -2274,7 +2275,7 @@ void CadlPlayer::playSoundEffect(uint8_t track) { void CadlPlayer::play(uint8_t track) { uint8 soundId = _trackEntries[track]; - if ((int8)soundId == -1 || !_soundDataPtr) + if (soundId == 0xff || !_soundDataPtr) return; soundId &= 0xFF; _driver->callback(16, 0); @@ -2379,11 +2380,12 @@ bool CadlPlayer::load(const char *filename, const CFileProvider &fp) // _soundFileLoaded = file; // find last subsong - for(int i = 199; i >= 0; i--) - if(_trackEntries[i] != 0xff) { - numsubsongs = i + 1; - break; - } + for(int i = 119; i >= 0; i--) { + if(_trackEntries[i] != 0xff) { + numsubsongs = i + 1; + break; + } + } fp.close(f); cursubsong = 2; diff --git a/plugins/adplug/adplug/player.cpp b/plugins/adplug/adplug/player.cpp index 03d26902..71960966 100644 --- a/plugins/adplug/adplug/player.cpp +++ b/plugins/adplug/adplug/player.cpp @@ -32,8 +32,6 @@ const unsigned char CPlayer::op_table[9] = {0x00, 0x01, 0x02, 0x08, 0x09, 0x0a, 0x10, 0x11, 0x12}; CPlayer::CPlayer(Copl *newopl) -// : opl(newopl) - //, db(CAdPlug::database) { opl = newopl; } -- cgit v1.2.3