Mercurial > audlegacy
annotate Plugins/Input/adplug/core/raw.cpp @ 919:c19c3ea7d29d trunk
[svn] - fading fix
| author | nenolod |
|---|---|
| date | Thu, 06 Apr 2006 11:03:26 -0700 |
| parents | 15ca2ea93a30 |
| children | f12d7e208b43 |
| rev | line source |
|---|---|
| 359 | 1 /* |
| 2 * Adplug - Replayer for many OPL2/OPL3 audio file formats. | |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
3 * Copyright (C) 1999 - 2005 Simon Peter, <dn.tlp@gmx.net>, et al. |
| 359 | 4 * |
| 5 * This library is free software; you can redistribute it and/or | |
| 6 * modify it under the terms of the GNU Lesser General Public | |
| 7 * License as published by the Free Software Foundation; either | |
| 8 * version 2.1 of the License, or (at your option) any later version. | |
| 9 * | |
| 10 * This library is distributed in the hope that it will be useful, | |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 * Lesser General Public License for more details. | |
| 14 * | |
| 15 * You should have received a copy of the GNU Lesser General Public | |
| 16 * License along with this library; if not, write to the Free Software | |
| 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 18 * | |
| 19 * raw.c - RAW Player by Simon Peter <dn.tlp@gmx.net> | |
| 20 */ | |
| 21 | |
| 22 #include "raw.h" | |
| 23 | |
| 24 /*** public methods *************************************/ | |
| 25 | |
| 26 CPlayer *CrawPlayer::factory(Copl *newopl) | |
| 27 { | |
| 28 return new CrawPlayer(newopl); | |
| 29 } | |
| 30 | |
| 31 bool CrawPlayer::load(const std::string &filename, const CFileProvider &fp) | |
| 32 { | |
| 33 binistream *f = fp.open(filename); if(!f) return false; | |
| 34 char id[8]; | |
| 35 unsigned long i; | |
| 36 | |
| 37 // file validation section | |
| 38 f->readString(id, 8); | |
| 39 if(strncmp(id,"RAWADATA",8)) { fp.close (f); return false; } | |
| 40 | |
| 41 // load section | |
| 42 clock = f->readInt(2); // clock speed | |
| 43 length = (fp.filesize(f) - 10) / 2; | |
| 44 data = new Tdata [length]; | |
| 45 for(i = 0; i < length; i++) { | |
| 46 data[i].param = f->readInt(1); | |
| 47 data[i].command = f->readInt(1); | |
| 48 } | |
| 49 | |
| 50 fp.close(f); | |
| 51 rewind(0); | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 bool CrawPlayer::update() | |
| 56 { | |
| 57 bool setspeed; | |
| 58 | |
| 59 if(pos >= length) return false; | |
| 60 | |
| 61 if(del) { | |
| 62 del--; | |
| 63 return !songend; | |
| 64 } | |
| 65 | |
| 66 do { | |
| 67 setspeed = false; | |
| 68 switch(data[pos].command) { | |
| 69 case 0: del = data[pos].param - 1; break; | |
| 70 case 2: | |
| 71 if(!data[pos].param) { | |
| 72 pos++; | |
| 73 speed = data[pos].param + (data[pos].command << 8); | |
| 74 setspeed = true; | |
| 75 } else | |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
76 opl->setchip(data[pos].param - 1); |
| 359 | 77 break; |
| 78 case 0xff: | |
| 79 if(data[pos].param == 0xff) { | |
| 80 rewind(0); // auto-rewind song | |
| 81 songend = true; | |
| 82 return !songend; | |
| 83 } | |
| 84 break; | |
| 85 default: | |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
86 opl->write(data[pos].command,data[pos].param); |
| 359 | 87 break; |
| 88 } | |
| 89 } while(data[pos++].command || setspeed); | |
| 90 | |
| 91 return !songend; | |
| 92 } | |
| 93 | |
| 94 void CrawPlayer::rewind(int subsong) | |
| 95 { | |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
96 pos = del = 0; speed = clock; songend = false; |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
97 opl->init(); opl->write(1, 32); // go to 9 channel mode |
| 359 | 98 } |
| 99 | |
| 100 float CrawPlayer::getrefresh() | |
| 101 { | |
| 102 return 1193180.0 / (speed ? speed : 0xffff); // timer oscillator speed / wait register = clock frequency | |
| 103 } |
