Mercurial > audlegacy-plugins
annotate src/vtx/ay8912.c @ 1307:fbeb9446aa2e audacious-plugins-1.4.0-DR1
Automated merge with ssh://hg.atheme.org//hg/audacious-plugins
author | William Pitcock <nenolod@atheme-project.org> |
---|---|
date | Fri, 20 Jul 2007 10:30:28 -0500 |
parents | 77dbd83ea6e4 |
children |
rev | line source |
---|---|
749
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
1 /* AY/YM emulator implementation. */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
2 |
1042
77dbd83ea6e4
[svn] Use proper integer types in the code, patch by Pavel Vymetalek <pvymetalek@seznam.cz>.
chainsaw
parents:
749
diff
changeset
|
3 #include <inttypes.h> |
749
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
4 #include "ayemu.h" |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
5 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
6 #define debuglog stderr; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
7 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
8 char *ayemu_err; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
9 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
10 static const char VERSION[] = "libayemu 0.9"; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
11 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
12 const int MAGIC1 = 0xcdef; /* for check ayemu_t structure inited */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
13 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
14 enum { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
15 /* Max amplitude value for stereo signal for avoiding for possible |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
16 folowwing SSRC for clipping */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
17 AYEMU_MAX_AMP = 24575, |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
18 AYEMU_DEFAULT_CHIP_FREQ = 1773400 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
19 }; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
20 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
21 /* sound chip volume envelops (will calculated by gen_env()) */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
22 static int bEnvGenInit = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
23 static int Envelope [16][128]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
24 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
25 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
26 /* AY volume table (c) by V_Soft and Lion 17 */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
27 static int Lion17_AY_table [16] = |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
28 { 0, 513, 828, 1239, 1923, 3238, 4926, 9110, |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
29 10344, 17876, 24682, 30442, 38844, 47270, 56402, 65535}; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
30 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
31 /* YM volume table (c) by V_Soft and Lion 17 */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
32 static int Lion17_YM_table [32] = |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
33 { 0, 0, 190, 286, 375, 470, 560, 664, |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
34 866, 1130, 1515, 1803, 2253, 2848, 3351, 3862, |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
35 4844, 6058, 7290, 8559, 10474, 12878, 15297, 17787, |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
36 21500, 26172, 30866, 35676, 42664, 50986, 58842, 65535}; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
37 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
38 /* AY volume table (c) by Hacker KAY */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
39 static int KAY_AY_table [16] = |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
40 { 0, 836, 1212, 1773, 2619, 3875, 5397, 8823, |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
41 10392, 16706, 23339, 29292, 36969, 46421, 55195, 65535}; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
42 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
43 /* YM volume table (c) by Hacker KAY */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
44 static int KAY_YM_table [32] = |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
45 { 0, 0, 248, 450, 670, 826, 1010, 1239, |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
46 1552, 1919, 2314, 2626, 3131, 3778, 4407, 5031, |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
47 5968, 7161, 8415, 9622, 11421, 13689, 15957, 18280, |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
48 21759, 26148, 30523, 34879, 41434, 49404, 57492, 65535}; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
49 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
50 /* default equlaizer (layout) settings for AY and YM, 7 stereo types */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
51 static const int default_layout [2][7][6] = { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
52 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
53 /* A_l, A_r, B_l, B_r, C_l, C_r */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
54 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
55 /* for AY */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
56 {100, 100, 100, 100, 100, 100}, // _MONO |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
57 {100, 33, 70, 70, 33, 100}, // _ABC |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
58 {100, 33, 33, 100, 70, 70}, // _ACB |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
59 {70, 70, 100, 33, 33, 100}, // _BAC |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
60 {33, 100, 100, 33, 70, 70}, // _BCA |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
61 {70, 70, 33, 100, 100, 33}, // _CAB |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
62 {33, 100, 70, 70, 100, 33}}, // _CBA |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
63 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
64 /* for YM */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
65 {100, 100, 100, 100, 100, 100}, // _MONO |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
66 {100, 5, 70, 70, 5, 100}, // _ABC |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
67 {100, 5, 5, 100, 70, 70}, // _ACB |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
68 {70, 70, 100, 5, 5, 100}, // _BAC |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
69 {5, 100, 100, 5, 70, 70}, // _BCA |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
70 {70, 70, 5, 100, 100, 5}, // _CAB |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
71 {5, 100, 70, 70, 100, 5}} // _CBA |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
72 }; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
73 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
74 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
75 static int check_magic(ayemu_ay_t *ay) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
76 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
77 if (ay->magic == MAGIC1) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
78 return 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
79 fprintf(stderr, "libayemu: passed pointer %p to uninitialized ayemu_ay_t structure\n", ay); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
80 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
81 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
82 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
83 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
84 /* make chip hardware envelop tables. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
85 Will execute once before first use. */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
86 static void gen_env() |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
87 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
88 int env; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
89 int pos; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
90 int hold; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
91 int dir; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
92 int vol; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
93 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
94 for (env = 0; env < 16; env++) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
95 hold = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
96 dir = (env & 4)? 1 : -1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
97 vol = (env & 4)? -1 : 32; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
98 for (pos = 0; pos < 128; pos++) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
99 if (!hold) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
100 vol += dir; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
101 if (vol < 0 || vol >= 32) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
102 if ( env & 8 ) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
103 if ( env & 2 ) dir = -dir; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
104 vol = (dir > 0 )? 0:31; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
105 if ( env & 1 ) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
106 hold = 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
107 vol = ( dir > 0 )? 31:0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
108 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
109 } else { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
110 vol = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
111 hold = 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
112 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
113 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
114 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
115 Envelope[env][pos] = vol; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
116 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
117 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
118 bEnvGenInit = 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
119 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
120 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
121 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
122 /** |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
123 * \retval ayemu_init none. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
124 * |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
125 */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
126 void ayemu_init(ayemu_ay_t *ay) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
127 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
128 ay->default_chip_flag = 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
129 ay->ChipFreq = AYEMU_DEFAULT_CHIP_FREQ; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
130 ay->default_stereo_flag = 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
131 ay->default_sound_format_flag = 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
132 ay->dirty = 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
133 ay->magic = MAGIC1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
134 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
135 ayemu_reset(ay); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
136 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
137 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
138 /** Reset AY/YM chip. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
139 * |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
140 * \arg \c ay - pointer to ayemu_ay_t structure. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
141 * \return none. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
142 */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
143 void ayemu_reset(ayemu_ay_t *ay) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
144 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
145 if (!check_magic(ay)) return; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
146 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
147 ay->cnt_a = ay->cnt_b = ay->cnt_c = ay->cnt_n = ay->cnt_e = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
148 ay->bit_a = ay->bit_b = ay->bit_c = ay->bit_n = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
149 ay->env_pos = ay->EnvNum = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
150 ay->Cur_Seed = 0xffff; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
151 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
152 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
153 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
154 static void set_table_ay (ayemu_ay_t *ay, int tbl[16]) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
155 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
156 int n; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
157 for (n = 0; n < 32; n++) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
158 ay->table[n] = tbl[n/2]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
159 ay->type = AYEMU_AY; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
160 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
161 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
162 static void set_table_ym (ayemu_ay_t *ay, int tbl[32]) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
163 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
164 int n; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
165 for (n = 0; n < 32; n++) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
166 ay->table[n] = tbl[n]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
167 ay->type = AYEMU_YM; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
168 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
169 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
170 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
171 /** Set chip type. */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
172 int ayemu_set_chip_type(ayemu_ay_t *ay, ayemu_chip_t type, int *custom_table) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
173 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
174 if (!check_magic(ay)) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
175 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
176 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
177 if (!(type == AYEMU_AY_CUSTOM || type == AYEMU_YM_CUSTOM) && custom_table != NULL) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
178 ayemu_err = "For non-custom chip type 'custom_table' param must be NULL"; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
179 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
180 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
181 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
182 switch(type) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
183 case AYEMU_AY: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
184 case AYEMU_AY_LION17: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
185 set_table_ay(ay, Lion17_AY_table); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
186 break; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
187 case AYEMU_YM: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
188 case AYEMU_YM_LION17: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
189 set_table_ym(ay, Lion17_YM_table); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
190 break; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
191 case AYEMU_AY_KAY: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
192 set_table_ay(ay, KAY_AY_table); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
193 break; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
194 case AYEMU_YM_KAY: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
195 set_table_ym(ay, KAY_YM_table); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
196 break; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
197 case AYEMU_AY_CUSTOM: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
198 set_table_ay(ay, custom_table); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
199 break; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
200 case AYEMU_YM_CUSTOM: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
201 set_table_ym(ay, custom_table); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
202 break; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
203 default: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
204 ayemu_err = "Incorrect chip type"; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
205 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
206 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
207 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
208 ay->default_chip_flag = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
209 ay->dirty = 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
210 return 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
211 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
212 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
213 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
214 /** Set chip frequency. */ |
1042
77dbd83ea6e4
[svn] Use proper integer types in the code, patch by Pavel Vymetalek <pvymetalek@seznam.cz>.
chainsaw
parents:
749
diff
changeset
|
215 void ayemu_set_chip_freq(ayemu_ay_t *ay, int32_t chipfreq) |
749
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
216 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
217 if (!check_magic(ay)) return; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
218 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
219 ay->ChipFreq = chipfreq; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
220 ay->dirty = 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
221 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
222 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
223 /*! Set output sound format |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
224 * \arg \c ay - pointer to ayemu_t structure |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
225 * \arg \c freq - sound freq (44100 for example) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
226 * \arg \c chans - number of channels (1-mono, 2-stereo) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
227 * \arg \c bits - now supported only 16 and 8. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
228 * \retval \b 1 on success, \b 0 if error occure |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
229 */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
230 int ayemu_set_sound_format (ayemu_ay_t *ay, int freq, int chans, int bits) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
231 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
232 if (!check_magic(ay)) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
233 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
234 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
235 if (!(bits == 16 || bits == 8)) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
236 ayemu_err = "Incorrect bits value"; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
237 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
238 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
239 else if (!(chans == 1 || chans == 2)) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
240 ayemu_err = "Incorrect number of channels"; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
241 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
242 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
243 else if (freq < 50) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
244 ayemu_err = "Incorrect output sound freq"; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
245 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
246 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
247 else { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
248 ay->sndfmt.freq = freq; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
249 ay->sndfmt.channels = chans; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
250 ay->sndfmt.bpc = bits; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
251 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
252 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
253 ay->default_sound_format_flag = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
254 ay->dirty = 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
255 return 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
256 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
257 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
258 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
259 /*! Set amplitude factor for each of channels (A,B anc C, tone and noise). |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
260 * Factor's value must be from (-100) to 100. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
261 * \arg ay - pointer to ayemu_t structure |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
262 * \arg stereo_type - type of stereo |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
263 * \arg custom_eq - NULL or pointer to custom table of mixer layout. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
264 * \retval 1 if OK, 0 if error occures. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
265 */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
266 int ayemu_set_stereo(ayemu_ay_t *ay, ayemu_stereo_t stereo_type, int *custom_eq) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
267 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
268 int i; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
269 int chip; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
270 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
271 if (!check_magic(ay)) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
272 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
273 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
274 if (stereo_type != AYEMU_STEREO_CUSTOM && custom_eq != NULL) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
275 ayemu_err = "Stereo type not custom, 'custom_eq' parametr must be NULL"; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
276 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
277 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
278 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
279 chip = (ay->type == AYEMU_AY)? 0 : 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
280 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
281 switch(stereo_type) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
282 case AYEMU_MONO: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
283 case AYEMU_ABC: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
284 case AYEMU_ACB: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
285 case AYEMU_BAC: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
286 case AYEMU_BCA: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
287 case AYEMU_CAB: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
288 case AYEMU_CBA: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
289 for (i = 0 ; i < 6 ; i++) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
290 ay->eq[i] = default_layout[chip][stereo_type][i]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
291 break; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
292 case AYEMU_STEREO_CUSTOM: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
293 for (i = 0 ; i < 6 ; i++) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
294 ay->eq[i] = custom_eq[i]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
295 break; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
296 default: |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
297 ayemu_err = "Incorrect stereo type"; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
298 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
299 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
300 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
301 ay->default_stereo_flag = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
302 ay->dirty = 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
303 return 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
304 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
305 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
306 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
307 #define WARN_IF_REGISTER_GREAT_THAN(r,m) \ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
308 if (*(regs + r) > m) \ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
309 fprintf(stderr, "ayemu_set_regs: warning: possible bad register data- R%d > %d\n", r, m) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
310 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
311 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
312 /** Assign values for AY registers. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
313 * |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
314 * You must pass array of char [14] to this function |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
315 */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
316 void ayemu_set_regs(ayemu_ay_t *ay, unsigned char *regs) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
317 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
318 if (!check_magic(ay)) return; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
319 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
320 WARN_IF_REGISTER_GREAT_THAN(1,15); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
321 WARN_IF_REGISTER_GREAT_THAN(3,15); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
322 WARN_IF_REGISTER_GREAT_THAN(5,15); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
323 WARN_IF_REGISTER_GREAT_THAN(8,31); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
324 WARN_IF_REGISTER_GREAT_THAN(9,31); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
325 WARN_IF_REGISTER_GREAT_THAN(10,31); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
326 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
327 ay->regs.tone_a = regs[0] + ((regs[1]&0x0f) << 8); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
328 ay->regs.tone_b = regs[2] + ((regs[3]&0x0f) << 8); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
329 ay->regs.tone_c = regs[4] + ((regs[5]&0x0f) << 8); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
330 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
331 ay->regs.noise = regs[6] & 0x1f; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
332 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
333 ay->regs.R7_tone_a = ! (regs[7] & 0x01); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
334 ay->regs.R7_tone_b = ! (regs[7] & 0x02); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
335 ay->regs.R7_tone_c = ! (regs[7] & 0x04); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
336 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
337 ay->regs.R7_noise_a = ! (regs[7] & 0x08); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
338 ay->regs.R7_noise_b = ! (regs[7] & 0x10); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
339 ay->regs.R7_noise_c = ! (regs[7] & 0x20); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
340 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
341 ay->regs.vol_a = regs[8] & 0x0f; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
342 ay->regs.vol_b = regs[9] & 0x0f; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
343 ay->regs.vol_c = regs[10] & 0x0f; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
344 ay->regs.env_a = regs[8] & 0x10; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
345 ay->regs.env_b = regs[9] & 0x10; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
346 ay->regs.env_c = regs[10] & 0x10; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
347 ay->regs.env_freq = regs[11] + (regs[12] << 8); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
348 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
349 if (regs[13] != 0xff) { /* R13 = 255 means continue curent envelop */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
350 ay->regs.env_style = regs[13] & 0x0f; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
351 ay->env_pos = ay->cnt_e = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
352 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
353 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
354 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
355 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
356 static void prepare_generation(ayemu_ay_t *ay) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
357 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
358 int vol, max_l, max_r; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
359 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
360 if (!ay->dirty) return; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
361 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
362 if (!bEnvGenInit) gen_env (); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
363 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
364 if (ay->default_chip_flag) ayemu_set_chip_type(ay, AYEMU_AY, NULL); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
365 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
366 if (ay->default_stereo_flag) ayemu_set_stereo(ay, AYEMU_ABC, NULL); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
367 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
368 if (ay->default_sound_format_flag) ayemu_set_sound_format(ay, 44100, 2, 16); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
369 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
370 ay->ChipTacts_per_outcount = ay->ChipFreq / ay->sndfmt.freq / 8; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
371 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
372 { /* GenVols */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
373 int n, m; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
374 int vol; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
375 for (n = 0; n < 32; n++) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
376 vol = ay->table[n]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
377 for (m=0; m < 6; m++) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
378 ay->vols[m][n] = (int) (((double) vol * ay->eq[m]) / 100); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
379 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
380 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
381 |
1042
77dbd83ea6e4
[svn] Use proper integer types in the code, patch by Pavel Vymetalek <pvymetalek@seznam.cz>.
chainsaw
parents:
749
diff
changeset
|
382 /* ������ ����������������� ���� |
77dbd83ea6e4
[svn] Use proper integer types in the code, patch by Pavel Vymetalek <pvymetalek@seznam.cz>.
chainsaw
parents:
749
diff
changeset
|
383 �������� ���vols [x][31] ��������������� TODO: �������� � ��;-) |
749
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
384 */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
385 max_l = ay->vols[0][31] + ay->vols[2][31] + ay->vols[3][31]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
386 max_r = ay->vols[1][31] + ay->vols[3][31] + ay->vols[5][31]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
387 vol = (max_l > max_r) ? max_l : max_r; // =157283 on all defaults |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
388 ay->Amp_Global = ay->ChipTacts_per_outcount *vol / AYEMU_MAX_AMP; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
389 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
390 ay->dirty = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
391 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
392 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
393 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
394 /*! Generate sound. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
395 * Fill sound buffer with current register data |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
396 * Return value: pointer to next data in output sound buffer |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
397 * \retval \b 1 if OK, \b 0 if error occures. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
398 */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
399 void *ayemu_gen_sound(ayemu_ay_t *ay, void *buff, size_t sound_bufsize) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
400 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
401 int mix_l, mix_r; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
402 int tmpvol; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
403 int m; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
404 int snd_numcount; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
405 unsigned char *sound_buf = buff; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
406 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
407 if (!check_magic(ay)) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
408 return 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
409 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
410 prepare_generation(ay); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
411 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
412 snd_numcount = sound_bufsize / (ay->sndfmt.channels * (ay->sndfmt.bpc >> 3)); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
413 while (snd_numcount-- > 0) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
414 mix_l = mix_r = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
415 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
416 for (m = 0 ; m < ay->ChipTacts_per_outcount ; m++) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
417 if (++ay->cnt_a >= ay->regs.tone_a) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
418 ay->cnt_a = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
419 ay->bit_a = ! ay->bit_a; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
420 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
421 if (++ay->cnt_b >= ay->regs.tone_b) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
422 ay->cnt_b = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
423 ay->bit_b = ! ay->bit_b; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
424 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
425 if (++ay->cnt_c >= ay->regs.tone_c) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
426 ay->cnt_c = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
427 ay->bit_c = ! ay->bit_c; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
428 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
429 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
430 /* GenNoise (c) Hacker KAY & Sergey Bulba */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
431 if (++ay->cnt_n >= (ay->regs.noise * 2)) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
432 ay->cnt_n = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
433 ay->Cur_Seed = (ay->Cur_Seed * 2 + 1) ^ \ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
434 (((ay->Cur_Seed >> 16) ^ (ay->Cur_Seed >> 13)) & 1); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
435 ay->bit_n = ((ay->Cur_Seed >> 16) & 1); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
436 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
437 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
438 if (++ay->cnt_e >= ay->regs.env_freq) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
439 ay->cnt_e = 0; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
440 if (++ay->env_pos > 127) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
441 ay->env_pos = 64; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
442 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
443 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
444 #define ENVVOL Envelope [ay->regs.env_style][ay->env_pos] |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
445 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
446 if ((ay->bit_a | !ay->regs.R7_tone_a) & (ay->bit_n | !ay->regs.R7_noise_a)) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
447 tmpvol = (ay->regs.env_a)? ENVVOL : ay->regs.vol_a * 2 + 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
448 mix_l += ay->vols[0][tmpvol]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
449 mix_r += ay->vols[1][tmpvol]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
450 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
451 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
452 if ((ay->bit_b | !ay->regs.R7_tone_b) & (ay->bit_n | !ay->regs.R7_noise_b)) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
453 tmpvol =(ay->regs.env_b)? ENVVOL : ay->regs.vol_b * 2 + 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
454 mix_l += ay->vols[2][tmpvol]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
455 mix_r += ay->vols[3][tmpvol]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
456 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
457 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
458 if ((ay->bit_c | !ay->regs.R7_tone_c) & (ay->bit_n | !ay->regs.R7_noise_c)) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
459 tmpvol = (ay->regs.env_c)? ENVVOL : ay->regs.vol_c * 2 + 1; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
460 mix_l += ay->vols[4][tmpvol]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
461 mix_r += ay->vols[5][tmpvol]; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
462 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
463 } /* end for (m=0; ...) */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
464 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
465 mix_l /= ay->Amp_Global; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
466 mix_r /= ay->Amp_Global; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
467 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
468 if (ay->sndfmt.bpc == 8) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
469 mix_l = (mix_l >> 8) | 128; /* 8 bit sound */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
470 mix_r = (mix_r >> 8) | 128; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
471 *sound_buf++ = mix_l; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
472 if (ay->sndfmt.channels != 1) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
473 *sound_buf++ = mix_r; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
474 } else { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
475 *sound_buf++ = mix_l & 0x00FF; /* 16 bit sound */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
476 *sound_buf++ = (mix_l >> 8); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
477 if (ay->sndfmt.channels != 1) { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
478 *sound_buf++ = mix_r & 0x00FF; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
479 *sound_buf++ = (mix_r >> 8); |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
480 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
481 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
482 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
483 return sound_buf; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
484 } |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
485 |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
486 /** Free all data allocated by emulator |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
487 * |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
488 * For now it do nothing. |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
489 */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
490 void ayemu_free (ayemu_ay_t *ay) |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
491 { |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
492 /* nothing to do here */ |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
493 return; |
26ff35aa9b2b
[svn] - vtx input plugin based on a submission from Pavel Vymetalek.
nenolod
parents:
diff
changeset
|
494 } |