Reply 20 of 55, by superfury
This is my current rendering loop converting the PIT samples into a 44.1kHz sample:
//render_ticks contains the output samples to process! Calculate the duty cycle by low pass filter and use it to generate a sample!
for (dutycyclei = render_ticks;dutycyclei;)
{
if (!readfifobuffer(PITchannels[2].rawsignal, ¤tsample)) break; //Failed to read the sample? Stop counting!
speaker_currentsample = currentsample?SHRT_MAX:SHRT_MIN; //Convert the current result to the 16-bit data, signed instead of unsigned!
#ifdef SPEAKER_LOGRAW
writeWAVMonoSample(speakerlograw,(short)speaker_currentsample); //Log the mono sample to the WAV file, converted as needed!
#endif
#ifdef SPEAKER_LOWPASS
//We're applying the low pass filter for the speaker!
applySoundLowpassFilter(SPEAKER_LOWPASS, TIME_RATE, &speaker_currentsample, &speaker_last_result, &speaker_last_sample, &speaker_first_sample);
#endif
#ifdef SPEAKER_LOGDUTY
writeWAVMonoSample(speakerlogduty,(short)speaker_currentsample); //Log the mono sample to the WAV file, converted as needed!
#endif
}
The output once again sounds exactly the same. The low pass filter is set to (1000000.0f/60.0f) Hz, so about 16666 2/3 Hz. It doesn't change the actual output much (although being accurate output according to your latest information, provided the PIT is generating correct samples at 1.19MHz(I think it doesn't, as both the raw and duty recordings give invalid data with the 'jamming'/noise signal through it, like about 50-100Hz at the 8088 MPH credits)?).
This is my current emulation code: https://bitbucket.org/superfury/x86emu/src/d2 … pit.c?at=master
It seems to still generate the same output, even though it's only filtering the 1.19MHz stream using a 16666 2/3kHz low pass filter and downsampling it to 44.1kHz by skipping 1.19MHz samples. This process seems to work, because output is the same with that and when playing either recorded .wav file using Windows 10's audio player.
So I think I can safely conclude that either the CPU isn't running at correct speeds (causing the strange effects) and/or the PIT 1.19MHz stream is at fault. Anyone can see what's going wrong there(top half of tickPIT function or simply listen to the recordings)?
These are the current recordings: http://www.filedropper.com/speakerlog201603021934
Speakerduty.wav contains the PIT 2 samples which are low pass filtered at 16666 2/3Hz.
Speakerraw.wav contains the PIT 2 samples simply converted to SHRT_MIN and SHRT_MAX(-32768 and 32767), so it's resultant square wave.
Warning with those recordings: If the PC speaker is turned off by software(e.g. outputting 0s) it will create the minimum voltage (-5V) as Direct Current (DC) which will blow up/burn through non-AC coupled speakers with ~4 seconds of silence, except when the player/OS removes the 0Hz frequency.
Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io