annotate src/console/Spc_Dsp.cxx @ 3168:7e58928783b3

alsa-ng: Set thread handles to NULL when threads exit.
author William Pitcock <nenolod@atheme.org>
date Fri, 15 May 2009 00:05:48 -0500
parents a1fccf242404
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
1 // snes_spc 0.9.0. http://www.slack.net/~ant/
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
2
1498
a1fccf242404 made SPC playback reverb a configuration option till the problem can be
mf0102 <0102@gmx.at>
parents: 1153
diff changeset
3 // TODO: we can remove this as soon as the reverb problem is fixed. -- mf0102
a1fccf242404 made SPC playback reverb a configuration option till the problem can be
mf0102 <0102@gmx.at>
parents: 1153
diff changeset
4 #include "Audacious_Config.h"
a1fccf242404 made SPC playback reverb a configuration option till the problem can be
mf0102 <0102@gmx.at>
parents: 1153
diff changeset
5
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
6 #include "Spc_Dsp.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
7
316
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
8 #include "blargg_endian.h"
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
9 #include <string.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
10
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
11 /* Copyright (C) 2007 Shay Green. This module is free software; you
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
12 can redistribute it and/or modify it under the terms of the GNU Lesser
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
13 General Public License as published by the Free Software Foundation; either
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
14 version 2.1 of the License, or (at your option) any later version. This
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
15 module is distributed in the hope that it will be useful, but WITHOUT ANY
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
316
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
18 details. You should have received a copy of the GNU Lesser General Public
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
19 License along with this module; if not, write to the Free Software Foundation,
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
20 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
21
316
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
22 #include "blargg_source.h"
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
23
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
24 #ifdef BLARGG_ENABLE_OPTIMIZER
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
25 #include BLARGG_ENABLE_OPTIMIZER
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
26 #endif
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
27
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
28 #if INT_MAX < 0x7FFFFFFF
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
29 #error "Requires that int type have at least 32 bits"
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
30 #endif
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
31
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
32
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
33 // TODO: add to blargg_endian.h
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
34 #define GET_LE16SA( addr ) ((BOOST::int16_t) GET_LE16( addr ))
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
35 #define GET_LE16A( addr ) GET_LE16( addr )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
36 #define SET_LE16A( addr, data ) SET_LE16( addr, data )
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
37
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
38 static BOOST::uint8_t const initial_regs [Spc_Dsp::register_count] =
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
39 {
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
40 0x45,0x8B,0x5A,0x9A,0xE4,0x82,0x1B,0x78,0x00,0x00,0xAA,0x96,0x89,0x0E,0xE0,0x80,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
41 0x2A,0x49,0x3D,0xBA,0x14,0xA0,0xAC,0xC5,0x00,0x00,0x51,0xBB,0x9C,0x4E,0x7B,0xFF,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
42 0xF4,0xFD,0x57,0x32,0x37,0xD9,0x42,0x22,0x00,0x00,0x5B,0x3C,0x9F,0x1B,0x87,0x9A,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
43 0x6F,0x27,0xAF,0x7B,0xE5,0x68,0x0A,0xD9,0x00,0x00,0x9A,0xC5,0x9C,0x4E,0x7B,0xFF,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
44 0xEA,0x21,0x78,0x4F,0xDD,0xED,0x24,0x14,0x00,0x00,0x77,0xB1,0xD1,0x36,0xC1,0x67,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
45 0x52,0x57,0x46,0x3D,0x59,0xF4,0x87,0xA4,0x00,0x00,0x7E,0x44,0x9C,0x4E,0x7B,0xFF,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
46 0x75,0xF5,0x06,0x97,0x10,0xC3,0x24,0xBB,0x00,0x00,0x7B,0x7A,0xE0,0x60,0x12,0x0F,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
47 0xF7,0x74,0x1C,0xE5,0x39,0x3D,0x73,0xC1,0x00,0x00,0x7A,0xB3,0xFF,0x4E,0x7B,0xFF
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
48 };
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
49
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
50 // if ( io < -32768 ) io = -32768;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
51 // if ( io > 32767 ) io = 32767;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
52 #define CLAMP16( io )\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
53 {\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
54 if ( (int16_t) io != io )\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
55 io = (io >> 31) ^ 0x7FFF;\
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
56 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
57
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
58 // Access global DSP register
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
59 #define REG(n) m.regs [r_##n]
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
60
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
61 // Access voice DSP register
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
62 #define VREG(r,n) r [v_##n]
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
63
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
64 #define WRITE_SAMPLES( l, r, out ) \
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
65 {\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
66 out [0] = l;\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
67 out [1] = r;\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
68 out += 2;\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
69 if ( out >= m.out_end )\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
70 {\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
71 check( out == m.out_end );\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
72 check( m.out_end != &m.extra [extra_size] || \
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
73 (m.extra <= m.out_begin && m.extra < &m.extra [extra_size]) );\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
74 out = m.extra;\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
75 m.out_end = &m.extra [extra_size];\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
76 }\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
77 }\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
78
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
79 void Spc_Dsp::set_output( sample_t* out, int size )
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
80 {
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
81 require( (size & 1) == 0 ); // must be even
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
82 if ( !out )
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
83 {
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
84 out = m.extra;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
85 size = extra_size;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
86 }
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
87 m.out_begin = out;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
88 m.out = out;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
89 m.out_end = out + size;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
90 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
91
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
92 // Volume registers and efb are signed! Easy to forget int8_t cast.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
93 // Prefixes are to avoid accidental use of locals with same names.
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
94
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
95 // Interleved gauss table (to improve cache coherency)
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
96 // interleved_gauss [i] = gauss [(i & 1) * 256 + 255 - (i >> 1 & 0xFF)]
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
97 static short const interleved_gauss [512] =
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
98 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
99 370,1305, 366,1305, 362,1304, 358,1304, 354,1304, 351,1304, 347,1304, 343,1303,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
100 339,1303, 336,1303, 332,1302, 328,1302, 325,1301, 321,1300, 318,1300, 314,1299,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
101 311,1298, 307,1297, 304,1297, 300,1296, 297,1295, 293,1294, 290,1293, 286,1292,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
102 283,1291, 280,1290, 276,1288, 273,1287, 270,1286, 267,1284, 263,1283, 260,1282,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
103 257,1280, 254,1279, 251,1277, 248,1275, 245,1274, 242,1272, 239,1270, 236,1269,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
104 233,1267, 230,1265, 227,1263, 224,1261, 221,1259, 218,1257, 215,1255, 212,1253,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
105 210,1251, 207,1248, 204,1246, 201,1244, 199,1241, 196,1239, 193,1237, 191,1234,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
106 188,1232, 186,1229, 183,1227, 180,1224, 178,1221, 175,1219, 173,1216, 171,1213,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
107 168,1210, 166,1207, 163,1205, 161,1202, 159,1199, 156,1196, 154,1193, 152,1190,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
108 150,1186, 147,1183, 145,1180, 143,1177, 141,1174, 139,1170, 137,1167, 134,1164,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
109 132,1160, 130,1157, 128,1153, 126,1150, 124,1146, 122,1143, 120,1139, 118,1136,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
110 117,1132, 115,1128, 113,1125, 111,1121, 109,1117, 107,1113, 106,1109, 104,1106,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
111 102,1102, 100,1098, 99,1094, 97,1090, 95,1086, 94,1082, 92,1078, 90,1074,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
112 89,1070, 87,1066, 86,1061, 84,1057, 83,1053, 81,1049, 80,1045, 78,1040,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
113 77,1036, 76,1032, 74,1027, 73,1023, 71,1019, 70,1014, 69,1010, 67,1005,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
114 66,1001, 65, 997, 64, 992, 62, 988, 61, 983, 60, 978, 59, 974, 58, 969,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
115 56, 965, 55, 960, 54, 955, 53, 951, 52, 946, 51, 941, 50, 937, 49, 932,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
116 48, 927, 47, 923, 46, 918, 45, 913, 44, 908, 43, 904, 42, 899, 41, 894,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
117 40, 889, 39, 884, 38, 880, 37, 875, 36, 870, 36, 865, 35, 860, 34, 855,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
118 33, 851, 32, 846, 32, 841, 31, 836, 30, 831, 29, 826, 29, 821, 28, 816,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
119 27, 811, 27, 806, 26, 802, 25, 797, 24, 792, 24, 787, 23, 782, 23, 777,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
120 22, 772, 21, 767, 21, 762, 20, 757, 20, 752, 19, 747, 19, 742, 18, 737,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
121 17, 732, 17, 728, 16, 723, 16, 718, 15, 713, 15, 708, 15, 703, 14, 698,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
122 14, 693, 13, 688, 13, 683, 12, 678, 12, 674, 11, 669, 11, 664, 11, 659,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
123 10, 654, 10, 649, 10, 644, 9, 640, 9, 635, 9, 630, 8, 625, 8, 620,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
124 8, 615, 7, 611, 7, 606, 7, 601, 6, 596, 6, 592, 6, 587, 6, 582,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
125 5, 577, 5, 573, 5, 568, 5, 563, 4, 559, 4, 554, 4, 550, 4, 545,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
126 4, 540, 3, 536, 3, 531, 3, 527, 3, 522, 3, 517, 2, 513, 2, 508,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
127 2, 504, 2, 499, 2, 495, 2, 491, 2, 486, 1, 482, 1, 477, 1, 473,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
128 1, 469, 1, 464, 1, 460, 1, 456, 1, 451, 1, 447, 1, 443, 1, 439,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
129 0, 434, 0, 430, 0, 426, 0, 422, 0, 418, 0, 414, 0, 410, 0, 405,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
130 0, 401, 0, 397, 0, 393, 0, 389, 0, 385, 0, 381, 0, 378, 0, 374,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
131 };
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
132
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
133
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
134 //// Counters
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
135
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
136 #define RATE( rate, div )\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
137 (rate >= div ? rate / div * 8 - 1 : rate - 1)
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
138
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
139 static unsigned const counter_mask [32] =
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
140 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
141 RATE( 2,2), RATE(2048,4), RATE(1536,3),
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
142 RATE(1280,5), RATE(1024,4), RATE( 768,3),
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
143 RATE( 640,5), RATE( 512,4), RATE( 384,3),
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
144 RATE( 320,5), RATE( 256,4), RATE( 192,3),
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
145 RATE( 160,5), RATE( 128,4), RATE( 96,3),
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
146 RATE( 80,5), RATE( 64,4), RATE( 48,3),
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
147 RATE( 40,5), RATE( 32,4), RATE( 24,3),
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
148 RATE( 20,5), RATE( 16,4), RATE( 12,3),
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
149 RATE( 10,5), RATE( 8,4), RATE( 6,3),
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
150 RATE( 5,5), RATE( 4,4), RATE( 3,3),
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
151 RATE( 2,4),
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
152 RATE( 1,4)
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
153 };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
154 #undef RATE
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
155
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
156 inline void Spc_Dsp::init_counter()
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
157 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
158 // counters start out with this synchronization
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
159 m.counters [0] = 1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
160 m.counters [1] = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
161 m.counters [2] = -0x20u;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
162 m.counters [3] = 0x0B;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
163
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
164 int n = 2;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
165 for ( int i = 1; i < 32; i++ )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
166 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
167 m.counter_select [i] = &m.counters [n];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
168 if ( !--n )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
169 n = 3;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
170 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
171 m.counter_select [ 0] = &m.counters [0];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
172 m.counter_select [30] = &m.counters [2];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
173 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
174
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
175 inline void Spc_Dsp::run_counter( int i )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
176 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
177 int n = m.counters [i];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
178 if ( !(n-- & 7) )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
179 n -= 6 - i;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
180 m.counters [i] = n;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
181 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
182
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
183 #define READ_COUNTER( rate )\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
184 (*m.counter_select [rate] & counter_mask [rate])
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
185
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
186
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
187 //// Emulation
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
188
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
189 void Spc_Dsp::run( int clock_count )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
190 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
191 int new_phase = m.phase + clock_count;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
192 int count = new_phase >> 5;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
193 m.phase = new_phase & 31;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
194 if ( !count )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
195 return;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
196
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
197 uint8_t* const ram = m.ram;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
198 uint8_t const* const dir = &ram [REG(dir) * 0x100];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
199 int const slow_gaussian = (REG(pmon) >> 1) | REG(non);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
200 int const noise_rate = REG(flg) & 0x1F;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
201
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
202 // Global volume
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
203 int mvoll = (int8_t) REG(mvoll);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
204 int mvolr = (int8_t) REG(mvolr);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
205 if ( mvoll * mvolr < m.surround_threshold )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
206 mvoll = -mvoll; // eliminate surround
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
207
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
208 do
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
209 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
210 // KON/KOFF reading
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
211 if ( (m.every_other_sample ^= 1) != 0 )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
212 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
213 m.new_kon &= ~m.kon;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
214 m.kon = m.new_kon;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
215 m.t_koff = REG(koff);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
216 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
217
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
218 run_counter( 1 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
219 run_counter( 2 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
220 run_counter( 3 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
221
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
222 // Noise
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
223 if ( !READ_COUNTER( noise_rate ) )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
224 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
225 int feedback = (m.noise << 13) ^ (m.noise << 14);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
226 m.noise = (feedback & 0x4000) ^ (m.noise >> 1);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
227 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
228
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
229 // Voices
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
230 int pmon_input = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
231 int main_out_l = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
232 int main_out_r = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
233 int echo_out_l = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
234 int echo_out_r = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
235 voice_t* v = m.voices;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
236 uint8_t* v_regs = m.regs;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
237 int vbit = 1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
238 do
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
239 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
240 #define SAMPLE_PTR(i) GET_LE16A( &dir [VREG(v_regs,srcn) * 4 + i * 2] )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
241
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
242 int brr_header = ram [v->brr_addr];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
243 int kon_delay = v->kon_delay;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
244
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
245 // Pitch
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
246 int pitch = GET_LE16A( &VREG(v_regs,pitchl) ) & 0x3FFF;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
247 if ( REG(pmon) & vbit )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
248 pitch += ((pmon_input >> 5) * pitch) >> 10;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
249
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
250 // KON phases
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
251 if ( --kon_delay >= 0 )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
252 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
253 v->kon_delay = kon_delay;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
254
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
255 // Get ready to start BRR decoding on next sample
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
256 if ( kon_delay == 4 )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
257 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
258 v->brr_addr = SAMPLE_PTR( 0 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
259 v->brr_offset = 1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
260 v->buf_pos = v->buf;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
261 brr_header = 0; // header is ignored on this sample
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
262 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
263
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
264 // Envelope is never run during KON
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
265 v->env = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
266 v->hidden_env = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
267
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
268 // Disable BRR decoding until last three samples
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
269 v->interp_pos = (kon_delay & 3 ? 0x4000 : 0);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
270
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
271 // Pitch is never added during KON
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
272 pitch = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
273 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
274
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
275 int env = v->env;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
276
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
277 // Gaussian interpolation
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
278 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
279 int output = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
280 VREG(v_regs,envx) = (uint8_t) (env >> 4);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
281 if ( env )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
282 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
283 // Make pointers into gaussian based on fractional position between samples
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
284 int offset = (unsigned) v->interp_pos >> 3 & 0x1FE;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
285 short const* fwd = interleved_gauss + offset;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
286 short const* rev = interleved_gauss + 510 - offset; // mirror left half of gaussian
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
287
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
288 int const* in = &v->buf_pos [(unsigned) v->interp_pos >> 12];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
289
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
290 if ( !(slow_gaussian & vbit) ) // 99%
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
291 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
292 // Faster approximation when exact sample value isn't necessary for pitch mod
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
293 output = (fwd [0] * in [0] +
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
294 fwd [1] * in [1] +
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
295 rev [1] * in [2] +
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
296 rev [0] * in [3]) >> 11;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
297 output = (output * env) >> 11;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
298 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
299 else
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
300 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
301 output = (int16_t) (m.noise * 2);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
302 if ( !(REG(non) & vbit) )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
303 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
304 output = (fwd [0] * in [0]) >> 11;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
305 output += (fwd [1] * in [1]) >> 11;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
306 output += (rev [1] * in [2]) >> 11;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
307 output = (int16_t) output;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
308 output += (rev [0] * in [3]) >> 11;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
309
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
310 CLAMP16( output );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
311 output &= ~1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
312 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
313 output = (output * env) >> 11 & ~1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
314 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
315
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
316 // Output
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
317 int l = output * v->volume [0];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
318 int r = output * v->volume [1];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
319
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
320 main_out_l += l;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
321 main_out_r += r;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
322
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
323 if ( REG(eon) & vbit )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
324 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
325 echo_out_l += l;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
326 echo_out_r += r;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
327 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
328 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
329
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
330 pmon_input = output;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
331 VREG(v_regs,outx) = (uint8_t) (output >> 8);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
332 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
333
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
334 // Soft reset or end of sample
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
335 if ( REG(flg) & 0x80 || (brr_header & 3) == 1 )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
336 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
337 v->env_mode = env_release;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
338 env = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
339 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
340
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
341 if ( m.every_other_sample )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
342 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
343 // KOFF
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
344 if ( m.t_koff & vbit )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
345 v->env_mode = env_release;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
346
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
347 // KON
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
348 if ( m.kon & vbit )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
349 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
350 v->kon_delay = 5;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
351 v->env_mode = env_attack;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
352 REG(endx) &= ~vbit;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
353 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
354 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
355
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
356 // Envelope
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
357 if ( !v->kon_delay )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
358 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
359 if ( v->env_mode == env_release ) // 97%
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
360 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
361 env -= 0x8;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
362 v->env = env;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
363 if ( env <= 0 )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
364 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
365 v->env = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
366 goto skip_brr; // no BRR decoding for you!
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
367 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
368 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
369 else // 3%
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
370 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
371 int rate;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
372 int const adsr0 = VREG(v_regs,adsr0);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
373 int env_data = VREG(v_regs,adsr1);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
374 if ( adsr0 >= 0x80 ) // 97% ADSR
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
375 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
376 if ( v->env_mode > env_decay ) // 89%
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
377 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
378 env--;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
379 env -= env >> 8;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
380 rate = env_data & 0x1F;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
381
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
382 // optimized handling
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
383 v->hidden_env = env;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
384 if ( READ_COUNTER( rate ) )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
385 goto exit_env;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
386 v->env = env;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
387 goto exit_env;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
388 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
389 else if ( v->env_mode == env_decay )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
390 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
391 env--;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
392 env -= env >> 8;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
393 rate = (adsr0 >> 3 & 0x0E) + 0x10;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
394 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
395 else // env_attack
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
396 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
397 rate = (adsr0 & 0x0F) * 2 + 1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
398 env += rate < 31 ? 0x20 : 0x400;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
399 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
400 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
401 else // GAIN
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
402 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
403 int mode;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
404 env_data = VREG(v_regs,gain);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
405 mode = env_data >> 5;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
406 if ( mode < 4 ) // direct
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
407 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
408 env = env_data * 0x10;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
409 rate = 31;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
410 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
411 else
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
412 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
413 rate = env_data & 0x1F;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
414 if ( mode == 4 ) // 4: linear decrease
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
415 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
416 env -= 0x20;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
417 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
418 else if ( mode < 6 ) // 5: exponential decrease
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
419 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
420 env--;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
421 env -= env >> 8;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
422 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
423 else // 6,7: linear increase
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
424 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
425 env += 0x20;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
426 if ( mode > 6 && (unsigned) v->hidden_env >= 0x600 )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
427 env += 0x8 - 0x20; // 7: two-slope linear increase
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
428 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
429 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
430 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
431
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
432 // Sustain level
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
433 if ( (env >> 8) == (env_data >> 5) && v->env_mode == env_decay )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
434 v->env_mode = env_sustain;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
435
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
436 v->hidden_env = env;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
437
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
438 // unsigned cast because linear decrease going negative also triggers this
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
439 if ( (unsigned) env > 0x7FF )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
440 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
441 env = (env < 0 ? 0 : 0x7FF);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
442 if ( v->env_mode == env_attack )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
443 v->env_mode = env_decay;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
444 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
445
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
446 if ( !READ_COUNTER( rate ) )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
447 v->env = env; // nothing else is controlled by the counter
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
448 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
449 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
450 exit_env:
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
451
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
452 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
453 // Apply pitch
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
454 int old_pos = v->interp_pos;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
455 int interp_pos = (old_pos & 0x3FFF) + pitch;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
456 if ( interp_pos > 0x7FFF )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
457 interp_pos = 0x7FFF;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
458 v->interp_pos = interp_pos;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
459
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
460 // BRR decode if necessary
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
461 if ( old_pos >= 0x4000 )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
462 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
463 // Arrange the four input nybbles in 0xABCD order for easy decoding
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
464 int nybbles = ram [(v->brr_addr + v->brr_offset) & 0xFFFF] * 0x100 +
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
465 ram [(v->brr_addr + v->brr_offset + 1) & 0xFFFF];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
466
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
467 // Advance read position
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
468 int const brr_block_size = 9;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
469 int brr_offset = v->brr_offset;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
470 if ( (brr_offset += 2) >= brr_block_size )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
471 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
472 // Next BRR block
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
473 int brr_addr = (v->brr_addr + brr_block_size) & 0xFFFF;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
474 assert( brr_offset == brr_block_size );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
475 if ( brr_header & 1 )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
476 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
477 brr_addr = SAMPLE_PTR( 1 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
478 if ( !v->kon_delay )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
479 REG(endx) |= vbit;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
480 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
481 v->brr_addr = brr_addr;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
482 brr_offset = 1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
483 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
484 v->brr_offset = brr_offset;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
485
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
486 // Decode
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
487
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
488 // 0: >>1 1: <<0 2: <<1 ... 12: <<11 13-15: >>4 <<11
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
489 static unsigned char const shifts [16 * 2] = {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
490 13,12,12,12,12,12,12,12,12,12,12, 12, 12, 16, 16, 16,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
491 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
492 };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
493 int const scale = brr_header >> 4;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
494 int const right_shift = shifts [scale];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
495 int const left_shift = shifts [scale + 16];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
496
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
497 // Write to next four samples in circular buffer
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
498 int* pos = v->buf_pos;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
499 int* end;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
500
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
501 // Decode four samples
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
502 for ( end = pos + 4; pos < end; pos++, nybbles <<= 4 )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
503 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
504 // Extract upper nybble and scale appropriately
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
505 int s = ((int16_t) nybbles >> right_shift) << left_shift;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
506
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
507 // Apply IIR filter (8 is the most commonly used)
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
508 int const filter = brr_header & 0x0C;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
509 int const p1 = pos [brr_buf_size - 1];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
510 int const p2 = pos [brr_buf_size - 2] >> 1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
511 if ( filter >= 8 )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
512 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
513 s += p1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
514 s -= p2;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
515 if ( filter == 8 ) // s += p1 * 0.953125 - p2 * 0.46875
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
516 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
517 s += p2 >> 4;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
518 s += (p1 * -3) >> 6;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
519 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
520 else // s += p1 * 0.8984375 - p2 * 0.40625
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
521 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
522 s += (p1 * -13) >> 7;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
523 s += (p2 * 3) >> 4;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
524 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
525 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
526 else if ( filter ) // s += p1 * 0.46875
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
527 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
528 s += p1 >> 1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
529 s += (-p1) >> 5;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
530 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
531
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
532 // Adjust and write sample
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
533 CLAMP16( s );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
534 s = (int16_t) (s * 2);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
535 pos [brr_buf_size] = pos [0] = s; // second copy simplifies wrap-around
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
536 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
537
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
538 if ( pos >= &v->buf [brr_buf_size] )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
539 pos = v->buf;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
540 v->buf_pos = pos;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
541 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
542 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
543 skip_brr:
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
544 // Next voice
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
545 vbit <<= 1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
546 v_regs += 0x10;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
547 v++;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
548 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
549 while ( vbit < 0x100 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
550
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
551 // Echo position
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
552 int echo_offset = m.echo_offset;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
553 uint8_t* const echo_ptr = &ram [(REG(esa) * 0x100 + echo_offset) & 0xFFFF];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
554 if ( !echo_offset )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
555 m.echo_length = (REG(edl) & 0x0F) * 0x800;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
556 echo_offset += 4;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
557 if ( echo_offset >= m.echo_length )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
558 echo_offset = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
559 m.echo_offset = echo_offset;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
560
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
561 // FIR
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
562 int echo_in_l = GET_LE16SA( echo_ptr + 0 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
563 int echo_in_r = GET_LE16SA( echo_ptr + 2 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
564
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
565 int (*echo_hist_pos) [2] = m.echo_hist_pos;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
566 if ( ++echo_hist_pos >= &m.echo_hist [echo_hist_size] )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
567 echo_hist_pos = m.echo_hist;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
568 m.echo_hist_pos = echo_hist_pos;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
569
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
570 echo_hist_pos [0] [0] = echo_hist_pos [8] [0] = echo_in_l;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
571 echo_hist_pos [0] [1] = echo_hist_pos [8] [1] = echo_in_r;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
572
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
573 #define CALC_FIR_( i, in ) ((in) * (int8_t) REG(fir + i * 0x10))
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
574 echo_in_l = CALC_FIR_( 7, echo_in_l );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
575 echo_in_r = CALC_FIR_( 7, echo_in_r );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
576
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
577 #define CALC_FIR( i, ch ) CALC_FIR_( i, echo_hist_pos [i + 1] [ch] )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
578 #define DO_FIR( i )\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
579 echo_in_l += CALC_FIR( i, 0 );\
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
580 echo_in_r += CALC_FIR( i, 1 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
581 DO_FIR( 0 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
582 DO_FIR( 1 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
583 DO_FIR( 2 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
584 #if defined (__MWERKS__) && __MWERKS__ < 0x3200
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
585 __eieio(); // keeps compiler from stupidly "caching" things in memory
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
586 #endif
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
587 DO_FIR( 3 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
588 DO_FIR( 4 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
589 DO_FIR( 5 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
590 DO_FIR( 6 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
591
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
592 // Echo out
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
593 if ( !(REG(flg) & 0x20) )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
594 {
1498
a1fccf242404 made SPC playback reverb a configuration option till the problem can be
mf0102 <0102@gmx.at>
parents: 1153
diff changeset
595 unsigned shift = audcfg.inc_spc_reverb ? 14 : 16;
a1fccf242404 made SPC playback reverb a configuration option till the problem can be
mf0102 <0102@gmx.at>
parents: 1153
diff changeset
596 int l = (echo_out_l >> 7) + ((echo_in_l * (int8_t) REG(efb)) >> shift);
a1fccf242404 made SPC playback reverb a configuration option till the problem can be
mf0102 <0102@gmx.at>
parents: 1153
diff changeset
597 int r = (echo_out_r >> 7) + ((echo_in_r * (int8_t) REG(efb)) >> shift);
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
598
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
599 // just to help pass more validation tests
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
600 #if SPC_MORE_ACCURACY
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
601 l &= ~1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
602 r &= ~1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
603 #endif
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
604
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
605 CLAMP16( l );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
606 CLAMP16( r );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
607
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
608 SET_LE16A( echo_ptr + 0, l );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
609 SET_LE16A( echo_ptr + 2, r );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
610 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
611
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
612 // Sound out
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
613 int l = (((main_out_l * mvoll + echo_in_l * (int8_t) REG(evoll)) >> 14) * m.gain) >> 8;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
614 int r = (((main_out_r * mvolr + echo_in_r * (int8_t) REG(evolr)) >> 14) * m.gain) >> 8;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
615
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
616 CLAMP16( l );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
617 CLAMP16( r );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
618
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
619 if ( (REG(flg) & 0x40) )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
620 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
621 l = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
622 r = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
623 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
624
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
625 sample_t* out = m.out;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
626 WRITE_SAMPLES( l, r, out );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
627 m.out = out;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
628 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
629 while ( --count );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
630 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
631
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
632
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
633 //// Setup
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
634
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
635 void Spc_Dsp::mute_voices( int mask )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
636 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
637 m.mute_mask = mask;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
638 for ( int i = 0; i < voice_count; i++ )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
639 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
640 m.voices [i].enabled = (mask >> i & 1) - 1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
641 update_voice_vol( i * 0x10 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
642 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
643 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
644
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
645 void Spc_Dsp::init( void* ram_64k )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
646 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
647 m.ram = (uint8_t*) ram_64k;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
648 set_gain( gain_unit );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
649 mute_voices( 0 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
650 disable_surround( false );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
651 set_output( 0, 0 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
652 reset();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
653
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
654 #ifndef NDEBUG
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
655 // be sure this sign-extends
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
656 assert( (int16_t) 0x8000 == -0x8000 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
657
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
658 // be sure right shift preserves sign
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
659 assert( (-1 >> 1) == -1 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
660
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
661 // check clamp macro
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
662 int i;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
663 i = +0x8000; CLAMP16( i ); assert( i == +0x7FFF );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
664 i = -0x8001; CLAMP16( i ); assert( i == -0x8000 );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
665
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
666 blargg_verify_byte_order();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
667 #endif
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
668 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
669
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
670 void Spc_Dsp::soft_reset_common()
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
671 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
672 require( m.ram ); // init() must have been called already
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
673
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
674 m.noise = 0x4000;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
675 m.echo_hist_pos = m.echo_hist;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
676 m.every_other_sample = 1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
677 m.echo_offset = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
678 m.phase = 0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
679
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
680 init_counter();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
681 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
682
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
683 void Spc_Dsp::soft_reset()
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
684 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
685 REG(flg) = 0xE0;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
686 soft_reset_common();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
687 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
688
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
689 void Spc_Dsp::load( uint8_t const regs [register_count] )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
690 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
691 memcpy( m.regs, regs, sizeof m.regs );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
692 memset( &m.regs [register_count], 0, offsetof (state_t,ram) - register_count );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
693
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
694 // Internal state
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
695 int i;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
696 for ( i = voice_count; --i >= 0; )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
697 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
698 voice_t& v = m.voices [i];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
699 v.brr_offset = 1;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
700 v.buf_pos = v.buf;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
701 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
702 m.new_kon = REG(kon);
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
703
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
704 mute_voices( m.mute_mask );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
705 soft_reset_common();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
706 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
707
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
708 void Spc_Dsp::reset() { load( initial_regs ); }