Debian Codegraph @

src/audio/resid/residctrl.cpp

raw symbols SCIP
1 /* reSID interface
2 *
3 * much of the code here is from GOATTRACKER, (c) Cadaver
4 */
5 #define PALCLOCKRATEcxx . . $ `src/audio/resid/residctrl.cpp:5:9`! 985248
6 #define NTSCCLOCKRATEcxx . . $ `src/audio/resid/residctrl.cpp:6:9`! 1022727
7
8 #define NUMSIDREGScxx . . $ `src/audio/resid/residctrl.cpp:8:9`! 0x19
9 #define SIDWRITEDELAYcxx . . $ `src/audio/resid/residctrl.cpp:9:9`! 9 // lda $xxxx,x 4 cycles, sta $d400,x 5 cycles
10 #define SIDWAVEDELAYcxx . . $ `src/audio/resid/residctrl.cpp:10:9`! 4 // and $xxxx,x 4 cycles extra
11
12 #include <stdlib.h>
13 #include <resid/sid.h>cxx . . $ `<file>/src/resid/sid.h`/
14 #include <resid-fp/sidfp.h>cxx . . $ `<file>/src/resid-fp/sidfp.h`/
15 //#include <assert.h>
16 #include <stdio.h>
17
18 extern "C" {
19 typedef struct
20 {
21 float distortionrate;
22 float distortionpoint;
23 float distortioncfthreshold;
24 float type3baseresistance;
25 float type3offset;
26 float type3steepness;
27 float type3minimumfetresistance;
28 float type4k;
29 float type4b;
30 float voicenonlinearity;
31 } FILTERPARAMS;
32
33 int clockrate;
34 int samplerate;
35 unsigned char sidreg[NUMSIDREGScxx . . $ `src/audio/resid/residctrl.cpp:8:9`!];
36 const unsigned char sidorder[] = {
37 0x0e,0x0f,0x14,0x13,0x10,0x11,0x12,
38 0x07,0x08,0x0d,0x0c,0x09,0x0a,0x0b,
39 0x00,0x01,0x06,0x05,0x02,0x03,0x04,
40 0x16,0x17,0x18,0x15
41 };
42 SIDcxx . . $ SID# *sid= 0;
43 SIDFPcxx . . $ SIDFP# *sidfp = 0;
44 int residdelay = 0;
45 int usefp = 0;
46
47 void sid_close() {
48 if(sid) delete sid;
49 if(sidfp) delete sidfp;
50 }
51
52 void sid_init(int fp, FILTERPARAMS *fparams, int speed, unsigned m, unsigned ntsc, unsigned interpolate, unsigned customclockrate)
53 {
54 int c;
55
56 usefp = fp;
57
58 if (ntsc) clockrate = NTSCCLOCKRATEcxx . . $ `src/audio/resid/residctrl.cpp:6:9`!;
59 else clockrate = PALCLOCKRATEcxx . . $ `src/audio/resid/residctrl.cpp:5:9`!;
60
61 if (customclockrate)
62 clockrate = customclockrate;
63
64 samplerate = speed;
65
66 if (!sidfp) sidfp = new SIDFPcxx . . $ SIDFP#SIDFP(49f6e7a06ebc5aa8).();
67 if (!sid) sid = new SIDcxx . . $ SID#SID(49f6e7a06ebc5aa8).();
68
69 if(usefp) {
70 switch(interpolate)
71 {
72 case 0:
73 sidfp->set_sampling_parameterscxx . . $ SIDFP#set_sampling_parameters(9b00e6c4292bcdca).(clockrate, SAMPLE_INTERPOLATEcxx . . $ SAMPLE_INTERPOLATE., speed);
74 break;
75 default:
76 sidfp->set_sampling_parameterscxx . . $ SIDFP#set_sampling_parameters(9b00e6c4292bcdca).(clockrate, SAMPLE_RESAMPLE_INTERPOLATEcxx . . $ SAMPLE_RESAMPLE_INTERPOLATE., speed);
77 break;
78 }
79 sidfp->resetcxx . . $ SIDFP#reset(49f6e7a06ebc5aa8).();
80 for (c = 0; c < NUMSIDREGScxx . . $ `src/audio/resid/residctrl.cpp:8:9`!; c++) {
81 sidreg[c] = 0x00;
82 }
83
84 if (m == 1)
85 sidfp->set_chip_modelcxx . . $ SIDFP#set_chip_model(cea143c94d31b99f).(MOS8580cxx . . $ MOS8580.);
86 else
87 sidfp->set_chip_modelcxx . . $ SIDFP#set_chip_model(cea143c94d31b99f).(MOS6581cxx . . $ MOS6581.);
88 sidfp->get_filtercxx . . $ SIDFP#get_filter(b2e2d83b865a240b).().set_distortion_propertiescxx . . $ FilterFP#set_distortion_properties(bd1040fe176e0786).(
89 fparams->distortionrate,
90 fparams->distortionpoint,
91 fparams->distortioncfthreshold);
92 sidfp->get_filtercxx . . $ SIDFP#get_filter(b2e2d83b865a240b).().set_type3_propertiescxx . . $ FilterFP#set_type3_properties(7e9a355db6148521).(
93 fparams->type3baseresistance,
94 fparams->type3offset,
95 fparams->type3steepness,
96 fparams->type3minimumfetresistance);
97 sidfp->get_filtercxx . . $ SIDFP#get_filter(b2e2d83b865a240b).().set_type4_propertiescxx . . $ FilterFP#set_type4_properties(5102ef758adc0ae7).(
98 fparams->type4k,
99 fparams->type4b);
100 sidfp->set_voice_nonlinearitycxx . . $ SIDFP#set_voice_nonlinearity(9364e6e7bff7660).(
101 fparams->voicenonlinearity);
102 sidfp->enable_filtercxx . . $ SIDFP#enable_filter(b45ddcbc8423892c).(true);
103 }
104 else {
105 switch(interpolate)
106 {
107 case 0:
108 sid->set_sampling_parameterscxx . . $ SID#set_sampling_parameters(80f037a0a5be2f87).(clockrate, SAMPLE_FASTcxx . . $ SAMPLE_FAST., speed, 20000);
109 break;
110 default:
111 sid->set_sampling_parameterscxx . . $ SID#set_sampling_parameters(80f037a0a5be2f87).(clockrate, SAMPLE_INTERPOLATEcxx . . $ SAMPLE_INTERPOLATE., speed, 20000);
112 break;
113 }
114 sid->resetcxx . . $ SID#reset(49f6e7a06ebc5aa8).();
115 for (c = 0; c < NUMSIDREGScxx . . $ `src/audio/resid/residctrl.cpp:8:9`!; c++) {
116 sidreg[c] = 0x00;
117 }
118
119 if (m == 1) {
120 sid->set_chip_modelcxx . . $ SID#set_chip_model(cea143c94d31b99f).(MOS8580cxx . . $ MOS8580.);
121 }
122 else {
123 sid->set_chip_modelcxx . . $ SID#set_chip_model(cea143c94d31b99f).(MOS6581cxx . . $ MOS6581.);
124 }
125 }
126 }
127
128 unsigned char sid_getorder(unsigned char index) {
129 return sidorder[index];
130 }
131
132 int sid_fillbuffer(short *ptr, int samples, const int cyc) {
133 int os = samples;
134 int rc = cyc / 3; // NUMVOICE
135 int badline = randcxx . . $ rand(9efc7249d839d30e).() % NUMSIDREGScxx . . $ `src/audio/resid/residctrl.cpp:8:9`!;
136 int tdelta;
137 int tdelta2;
138 int result;
139 int total = 0;
140 int c;
141
142 tdelta = clockrate * samples / samplerate;
143
144 for (c = 0; c < NUMSIDREGScxx . . $ `src/audio/resid/residctrl.cpp:8:9`!; c++) {
145 unsigned char o = sid_getorder(c);
146
147 // Extra delay per music routine iteration
148 if (cyc > 0 &&
149 ((c == 0) || (c == 7) || (c == 14))) {
150 tdelta2 = rc;
151 if(usefp)
152 result = sidfp->clockcxx . . $ SIDFP#clock(1a782d52ea0fd1a5).(tdelta2, ptr, samples);
153 else
154 result = sid->clockcxx . . $ SID#clock(1a782d52ea0fd1a5).(tdelta2, ptr, samples);
155 total += result;
156 ptr += result;
157 samples -= result;
158 tdelta -= rc;
159 }
160
161 // Possible random badline delay once per writing
162 /*
163 if ((badline == c) && (residdelay)) {
164 tdelta2 = residdelay;
165 result = sid->clock(tdelta2, ptr, samples);
166 total += result;
167 ptr += result;
168 samples -= result;
169 tdelta -= residdelay;
170 }
171 */
172 if(usefp)
173 sidfp->writecxx . . $ SIDFP#write(b4d55b1286ff73e8).(o, sidreg[o]);
174 else
175 sid->writecxx . . $ SID#write(b4d55b1286ff73e8).(o, sidreg[o]);
176
177 tdelta2 = SIDWRITEDELAYcxx . . $ `src/audio/resid/residctrl.cpp:9:9`!;
178 if(usefp)
179 result = sidfp->clockcxx . . $ SIDFP#clock(1a782d52ea0fd1a5).(tdelta2, ptr, samples);
180 else
181 result = sid->clockcxx . . $ SID#clock(1a782d52ea0fd1a5).(tdelta2, ptr, samples);
182 total += result;
183 ptr += result;
184 samples -= result;
185 tdelta -= SIDWRITEDELAYcxx . . $ `src/audio/resid/residctrl.cpp:9:9`!;
186 }
187
188 if(usefp)
189 result = sidfp->clockcxx . . $ SIDFP#clock(1a782d52ea0fd1a5).(tdelta, ptr, samples);
190 else
191 result = sid->clockcxx . . $ SID#clock(1a782d52ea0fd1a5).(tdelta, ptr, samples);
192
193 total += result;
194 // assert(total <= os);
195 return total;
196 }
197 }