Browse code

[NCSF] Fix PSG output.

* Changed the base timer and actually utilize the note number from the note definition even for PSG. Thanks to Kurausukun for informing me about the issue and helping to provide a sample to demonstrate the issue.
* Correct the frequency output in the debug sound view (using DeSmuME's method directly resulted in frequencies that were 3 octaves higher than what they should have been).

Naram Qashat authored on 2020/07/31 10:00:12
Showing 2 changed files
... ...
@@ -165,8 +165,7 @@ int Track::NoteOn(int key, int vel, int len)
165 165
 			chn = &this->ply->channels[nCh];
166 166
 			chn->tempReg.CR = SOUND_FORMAT_PSG | SCHANNEL_ENABLE | SOUND_DUTY(noteDef->swav & 0x7);
167 167
 		}
168
-		// TODO: figure out what pNoteDef->tnote means for PSG channels
169
-		chn->tempReg.TIMER = -SOUND_FREQ(440 * 8); // key #69 (A4)
168
+		chn->tempReg.TIMER = -SOUND_FREQ(262 * 8); // key #60 (C4)
170 169
 		chn->reg.samplePosition = -1;
171 170
 		chn->reg.psgX = 0x7FFF;
172 171
 	}
... ...
@@ -192,7 +191,7 @@ int Track::NoteOn(int key, int vel, int len)
192 191
 	chn->flags.reset();
193 192
 	chn->prio = this->prio;
194 193
 	chn->key = key;
195
-	chn->orgKey = bIsPCM ? noteDef->noteNumber : 69;
194
+	chn->orgKey = noteDef->noteNumber;
196 195
 	chn->velocity = Cnv_Sust(vel);
197 196
 	chn->pan = static_cast<int>(noteDef->pan) - 64;
198 197
 	chn->modDelayCnt = 0;
... ...
@@ -305,7 +305,7 @@ void XSFConfig_NCSF::RefreshSoundView()
305 305
 
306 306
 			std::wstring tmpBuf = ConvertFuncs::StringToWString(NumToHexString(chn.reg.timer)).substr(2);
307 307
 			buf = L"$" + tmpBuf + L" (";
308
-			tmpBuf = wstringify((ARM7_CLOCK / 2) / static_cast<double>(0x10000 - chn.reg.timer));
308
+			tmpBuf = wstringify((ARM7_CLOCK / 2) / static_cast<double>(0x10000 - chn.reg.timer) / 8);
309 309
 			if (tmpBuf.find('.') != std::wstring::npos)
310 310
 				tmpBuf = tmpBuf.substr(0, tmpBuf.find('.') + 2);
311 311
 			buf += tmpBuf + L" Hz)";