comparison src/adplug/core/raw.cxx @ 12:3da1b8942b8b trunk

[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author nenolod
date Mon, 18 Sep 2006 03:14:20 -0700
parents src/Input/adplug/core/raw.cxx@13389e613d67
children cae46214b8bf
comparison
equal deleted inserted replaced
11:cff1d04026ae 12:3da1b8942b8b
1 /*
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2005 Simon Peter, <dn.tlp@gmx.net>, et al.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
76 opl->setchip(data[pos].param - 1);
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:
86 opl->write(data[pos].command,data[pos].param);
87 break;
88 }
89 } while(data[pos++].command || setspeed);
90
91 return !songend;
92 }
93
94 void CrawPlayer::rewind(int subsong)
95 {
96 pos = del = 0; speed = clock; songend = false;
97 opl->init(); opl->write(1, 32); // go to 9 channel mode
98 }
99
100 float CrawPlayer::getrefresh()
101 {
102 return 1193180.0 / (speed ? speed : 0xffff); // timer oscillator speed / wait register = clock frequency
103 }