Mercurial > audlegacy
annotate Plugins/Input/adplug/core/diskopl.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 * diskopl.cpp - Disk Writer OPL, by Simon Peter <dn.tlp@gmx.net> | |
| 20 */ | |
| 21 | |
| 22 #include "diskopl.h" | |
| 23 | |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
24 //static const unsigned short note_table[12] = {363,385,408,432,458,485,514,544,577,611,647,686}; |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
25 const unsigned char CDiskopl::op_table[9] = {0x00, 0x01, 0x02, 0x08, 0x09, 0x0a, 0x10, 0x11, 0x12}; |
| 359 | 26 |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
27 CDiskopl::CDiskopl(std::string filename) |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
28 : old_freq(0.0f), del(1), nowrite(false) |
| 359 | 29 { |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
30 unsigned short clock = 0xffff; |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
31 |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
32 currType = TYPE_OPL3; |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
33 f = fopen(filename.c_str(),"wb"); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
34 fwrite("RAWADATA",8,1,f); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
35 fwrite(&clock,sizeof(clock),1,f); |
| 359 | 36 } |
| 37 | |
| 38 CDiskopl::~CDiskopl() | |
| 39 { | |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
40 fclose(f); |
| 359 | 41 } |
| 42 | |
| 43 void CDiskopl::update(CPlayer *p) | |
| 44 { | |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
45 unsigned short clock; |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
46 unsigned int wait; |
| 359 | 47 |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
48 if(p->getrefresh() != old_freq) { |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
49 old_freq = p->getrefresh(); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
50 del = wait = (unsigned int)(18.2f / old_freq); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
51 clock = (unsigned short)(1192737/(old_freq*(wait+1))); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
52 fputc(0,f); fputc(2,f); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
53 fwrite(&clock,2,1,f); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
54 } |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
55 if(!nowrite) { |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
56 fputc(del+1,f); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
57 fputc(0,f); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
58 } |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
59 } |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
60 |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
61 void CDiskopl::setchip(int n) |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
62 { |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
63 Copl::setchip(n); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
64 |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
65 if(!nowrite) { |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
66 fputc(currChip + 1, f); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
67 fputc(2, f); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
68 } |
| 359 | 69 } |
| 70 | |
| 71 void CDiskopl::write(int reg, int val) | |
| 72 { | |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
73 if(!nowrite) |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
74 diskwrite(reg,val); |
| 359 | 75 } |
| 76 | |
| 77 void CDiskopl::init() | |
| 78 { | |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
79 for (int i=0;i<9;i++) { // stop instruments |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
80 diskwrite(0xb0 + i,0); // key off |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
81 diskwrite(0x80 + op_table[i],0xff); // fastest release |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
82 } |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
83 diskwrite(0xbd,0); // clear misc. register |
| 359 | 84 } |
| 85 | |
| 86 void CDiskopl::diskwrite(int reg, int val) | |
| 87 { | |
|
428
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
88 fputc(val,f); |
|
15ca2ea93a30
[svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents:
359
diff
changeset
|
89 fputc(reg,f); |
| 359 | 90 } |
