MCPcopy Create free account
hub / github.com/HertzDevil/0CC-FamiTracker / MakePeriodTables

Method MakePeriodTables

Source/FamiTrackerModule.cpp:194–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192}
193
194CPeriodTables CFamiTrackerModule::MakePeriodTables() const { // // //
195 CPeriodTables table;
196
197 const double A440_NOTE = 45. - GetTuningSemitone() - GetTuningCent() / 100.;
198 const double clock_ntsc = MASTER_CLOCK_NTSC / 16.;
199 const double clock_pal = MASTER_CLOCK_PAL / 16.;
200
201 for (int i = 0; i < NOTE_COUNT; ++i) {
202 // Frequency (in Hz)
203 double Freq = 440. * std::pow(2.0, (i - A440_NOTE) / 12.);
204 double Pitch;
205
206 // 2A07
207 Pitch = (clock_pal / Freq) - 0.5;
208 table.pal_period[i] = (unsigned int)(Pitch - GetDetuneOffset(1, i)); // // //
209
210 // 2A03 / MMC5 / VRC6
211 Pitch = (clock_ntsc / Freq) - 0.5;
212 table.ntsc_period[i] = (unsigned int)(Pitch - GetDetuneOffset(0, i)); // // //
213 table.s5b_period[i] = table.ntsc_period[i] + 1; // correction
214
215 // VRC6 Saw
216 Pitch = ((clock_ntsc * 16.0) / (Freq * 14.0)) - 0.5;
217 table.saw_period[i] = (unsigned int)(Pitch - GetDetuneOffset(2, i)); // // //
218
219 // FDS
220 Pitch = (Freq * 65536.0) / (clock_ntsc / 1.0) + 0.5;
221 table.fds_freq[i] = (unsigned int)(Pitch + GetDetuneOffset(4, i)); // // //
222
223 // N163
224 Pitch = ((Freq * GetNamcoChannels() * 983040.0) / clock_ntsc + 0.5) / 4; // // //
225 table.n163_freq[i] = (unsigned int)(Pitch + GetDetuneOffset(5, i)); // // //
226
227 if (table.n163_freq[i] > 0xFFFF) // 0x3FFFF
228 table.n163_freq[i] = 0xFFFF; // 0x3FFFF
229
230 // // // Sunsoft 5B uses NTSC table
231
232 // // // VRC7
233 if (i < NOTE_RANGE) {
234 Pitch = Freq * 262144.0 / 49716.0 + 0.5;
235 unsigned Reg = (unsigned int)(Pitch + GetDetuneOffset(3, i));
236 for (int j = 0; j < OCTAVE_RANGE; ++j)
237 table.vrc7_freq[i + j * NOTE_RANGE] = Reg; // // //
238 }
239 }
240
241 return table;
242}
243
244int CFamiTrackerModule::GetDetuneOffset(int chip, int note) const { // // //
245 return m_iDetuneTable[chip][note];

Callers 2

LoadDriverMethod · 0.80
SetupPeriodTablesMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected