Page 2 of 2

Re: AY emulation testing

Posted: Fri Oct 12, 2018 9:36 pm
by Pegaz
Woody did a lot more than that.
When Ramsoft people revealed new ULA feature (four bright shades), ten years ago, Woody managed to implement this feature in SpecEmu in just a few days.
https://www.worldofspectrum.org/forums/ ... rlace-demo
https://www.worldofspectrum.org/forums/ ... edirect/p1

And this is not his only contribution to a better Spectrum emulation...

Re: AY emulation testing

Posted: Sat Oct 13, 2018 5:58 am
by djnzx48
I'm sorry, I hope I didn't come across as ungrateful towards emulator developers. It's just hard to get motivation for using these features and quirks when the most popular emulators don't support them and they haven't been updated in years.

Re: AY emulation testing

Posted: Sat Oct 13, 2018 11:15 am
by zx81
Ast A. Moore wrote: 8. No emulator is, of course, capable of displaying the Spectrum output at its native 50 fps. This isn’t the fault of any particular emulator, naturally, but rather the systems they runs on: most modern computers are locked to a 60 Hz refresh rate.
That's not exactly true, my friend... :)

The frame frequency on a 48k model is 50.0801 Hz and on a 128k model is 50.0211 Hz. These frequencies are basically impossible to reach on a TV or monitor where you can't control such frequencies (50 or 59.94 Hz, not 60 Hz). To get a precise 50 Hz refresh, the emulator needs to run slowly than real thing.

FPGA-based emulators, like the ZX-Uno, are capable to control the TV frame generation, so the "recreated" 48k runs at real speed. But, because the internal clocks have various limitations, the 128k model runs 8000 Hz away from real machine.

In ZXBaremulator the 48k model runs at the correct speed. So, when you configures the HDMI mode to 576i@50 Hz, you can see the interlaced effects without any trick in code, but with a small defect caused by the slightly different frequencies between TV and emulated Spectrum (50 vs 50.0801). For 128k models, the Raspberry only have a 1-Mhz timer, and I can't get the needed precision (a 128k frame lasts 19.99156356 ms), so it emulates frames of 19.991 ms long.

In theory, you can configure a HDMI mode with exact frequencies, but isn't easy to generate the needed numbers and can depend a bit of every TV-set, so I don't want to try this way. After all, the interlaced modes are "emulated" by modern TV-sets, and every model handles this with his own method.

I'm curious about the AY quality in ZXBaremulator, if somebody can try... ;)

Re: AY emulation testing

Posted: Sat Oct 13, 2018 12:00 pm
by Pegaz
zx81 wrote: Sat Oct 13, 2018 11:15 am
In theory, you can configure a HDMI mode with exact frequencies, but isn't easy to generate the needed numbers and can depend a bit of every TV-set, so I don't want to try this way. After all, the interlaced modes are "emulated" by modern TV-sets, and every model handles this with his own method.

I'm curious about the AY quality in ZXBaremulator, if somebody can try... ;)
Yes, I also came to a similar conclusion.
Actually, there are two ways, which allow me a perfectly smooth scroll on raspberry pi, at least on my TV set.
The first mthod is using the Unreal Speccy Portable emulator, as well as the latest beta version of your Baremulator for Pi 1 / Zero.
We've already talked about that and what you've said, in such a case Spectrum works slightly slower, for that difference between 50Hz vs 50.0801 Hz.
I recently discovered another method, which also gives an excellent result with Fuse version for Retroarch frontend on Raspberry Pi.
In this case, its possible to set the exact frequency at 50.0801 Hz in options and the result is also a perfectly smooth scroll without any interruptions.
I dont know if this particular settings is really precise or not, but in reality it works great.

btw, you previously wrote that the exact frequency for 48k Spectrum is 50.0802 Hz, so I'm interested in what is the correct number?

Re: AY emulation testing

Posted: Sat Oct 13, 2018 12:42 pm
by zx81
Pegaz wrote: Sat Oct 13, 2018 12:00 pm btw, you previously wrote that the exact frequency for 48k Spectrum is 50.0802 Hz, so I'm interested in what is the correct number?
3500000 / 69888 = 50.08012821

Re: AY emulation testing

Posted: Sun Oct 14, 2018 5:01 am
by djnzx48
What about the more recent LCD monitors that support FreeSync or G-Sync adaptive sync? They can be set to arbitrary refresh rates, so couldn't you obtain a proper 50Hz display using one?

Re: AY emulation testing

Posted: Thu Oct 25, 2018 9:52 am
by djnzx48
I've made some simple fixes for a few emulators to fix wrong-sounding AY without needing in-game workarounds. To be safe I won't distribute the patched executables here, but you can apply the patches quite easily using a hex editor. I used Frhed but there are a number of free ones available. Make sure you make backups first in case you make a mistake.

You may have to run the editor as administrator if you're editing files contained in Program Files. Once you've opened the file, press Ctrl+G to goto the address starting with '0x' - note that all the addresses are in hex. Then enter the new values on the rest of the line. Repeat this for the other address and values. Finally, save the file and if all has gone well you should now have improved AY sound.

Here are the patches:

Spectaculator 8.0: the file to edit is ay8912.dll in the Spectaculator\drivers directory.

Code: Select all

0x2063: E9 FA 08 00 00 90 90
0x2962: 0F B6 71 52 D1 E6 8B 51 78 E9 FA F6 FF FF
SpecEmu 3.1.b120516: the file to edit is specemu.exe. (I know it's an old version but it's the newest one I could find.)

Code: Select all

0x2025:  E9 0A C1 02 00
0x2E134: 14 00 D1 E0 88 46 20 E9 EA 3E FD FF
ZXSpin 0.7s: the file to edit is ZXSpin.exe.

Code: Select all

0x9078A: D1 E0 88 46 13 8B 86 90 00 00 00 E9 0E 10 06
0xF179F: E9 E6 EF F9 FF 00 90 90 90
The results:

Image

And that's it. I also have a working fix for ZXSpin 0.666 but the executable is packed, so applying the patch is not so simple. I'll put the fix for that here if I can get it to work.

Re: AY emulation testing

Posted: Thu Oct 25, 2018 10:26 am
by hikoki
there you have a newer SpecEmu
SpecEmu - 3.1.b160318

[mention]Woodster[/mention] google drive links don't expire ;) thanks!

Re: AY emulation testing

Posted: Sat Mar 30, 2019 10:31 pm
by chernandezba
Hi
I’ve just discovered this old thread, very interesting!
By the way, AY emulation in ZEsarUX is a custom code made my me, so probably audio doesn’t look like other emulators. Also, I don’t add audio filters, so it’s just the audio wave with my own algorithms ;)

Cheers!
Cesar

Re: AY emulation testing

Posted: Wed Sep 11, 2019 11:12 pm
by djnzx48
I made another small patch for Spectaculator. Apparently if an AY channel has tone and noise activated at the same time, the resulting output level is double what it would be if tone or noise were used independently. The patch seems to work as intended, but I can't say for sure how accurate the results are.
Spoiler
>ay8912.dll
00002063:0F->E9
00002064:B6->FA
00002065:71->08
00002066:52->00
00002067:8B->00
00002068:51->90
00002069:78->90
00002225:66->E9
00002226:8B->46
00002227:04->07
00002228:55->00
00002229:98->00
0000222A:30->90
0000222B:00->90
0000222C:67->90
00002962:00->0F
00002963:00->B6
00002964:00->71
00002965:00->52
00002966:00->D1
00002967:00->E6
00002968:00->8B
00002969:00->51
0000296A:00->78
0000296B:00->E9
0000296C:00->FA
0000296D:00->F6
0000296E:00->FF
0000296F:00->FF
00002970:00->66
00002971:00->8B
00002972:00->04
00002973:00->55
00002974:00->98
00002975:00->30
00002977:00->67
00002978:00->51
00002979:00->B2
0000297A:00->09
0000297B:00->8B
0000297C:00->CF
0000297D:00->D2
0000297E:00->E2
0000297F:00->59
00002980:00->22
00002981:00->51
00002982:00->53
00002983:00->0F
00002984:00->85
00002985:00->A4
00002986:00->F8
00002987:00->FF
00002988:00->FF
00002989:00->66
0000298A:00->03
0000298B:00->C0
0000298C:00->E9
0000298D:00->9C
0000298E:00->F8
0000298F:00->FF
00002990:00->FF
Would anyone like to confirm this effect on a real chip? Here's a .tap file I used for testing: NoiseVolTest.tap

The drums at the start of Robocop will also work.

This behaviour has serious consequences if it works as described, as it affects thousands of games and demos made in the last 20 years that are based on an incorrect model. Many tunes sound very noticeably wrong after applying this patch - assuming I didn't mess up the implementation.

Re: AY emulation testing

Posted: Fri Sep 13, 2019 10:03 am
by djnzx48
Is anyone willing to try running the test?

Meanwhile, I found yet another bug: envelope type 13 is broken in Spectaculator. It's supposed to ramp up to the maximum level and stay there, but instead it drops back to 0, resulting in silence. You can see the cause of the problem here:

Image

The envelope level is incremented, but does not get set back to 15 when the cycle ends, causing it to overflow and become silence.

Re: AY emulation testing

Posted: Fri Sep 13, 2019 12:18 pm
by Guesser
I've said it before, but I believe the only way to get really accurate AY sound is to first determine how the DACs actually work and then calculate the resulting levels and apply suitable filtering per machine. No fiddling with look-up-table values is going to correctly emulate a +3 for instance.

Re: AY emulation testing

Posted: Sat Sep 14, 2019 5:15 am
by djnzx48
Guesser wrote: Fri Sep 13, 2019 12:18 pm I've said it before, but I believe the only way to get really accurate AY sound is to first determine how the DACs actually work and then calculate the resulting levels and apply suitable filtering per machine. No fiddling with look-up-table values is going to correctly emulate a +3 for instance.
Could you elaborate on that? What does a current emulator (using accurate measurements) get wrong that would require proper DAC emulation to rectify? I'm not sure that I see much value in trying to emulate the faulty sound of the +3.

I found some recordings taken from AY and YM chips, and I couldn't detect any volume differences in the tone+noise parts. Or if they are there, the difference is more subtle than claimed. But it's hard to tell without an isolated recording.

I also fixed the envelope 13 bug, here's the patch if anyone wants to apply it.
Spoiler
000021D5:C7->E9
000021D6:00->B7
000021D7:03->07
000021DA:00->90
00002991:00->C7
00002993:00->03
00002997:00->89
00002998:00->1A
00002999:00->E9
0000299A:00->3D
0000299B:00->F8
0000299C:00->FF
0000299D:00->FF

Re: AY emulation testing

Posted: Sat Sep 14, 2019 10:49 am
by 1024MAK
Amstrad messed up the audio circuitry on the +2A/+3 PCB hence the AY audio is distorted. Note that most +2A machines use a later PCB where they corrected the circuit design.

Also, what type of digital to analogue converter does the AY actually use? And is there good repeatability between chips of different batches...

Mark

Re: AY emulation testing

Posted: Sat Sep 14, 2019 12:29 pm
by Ast A. Moore
djnzx48 wrote: Fri Sep 13, 2019 10:03 am Is anyone willing to try running the test?
Sure. Here’s the audio from my +2A(B). Recorded from the TV speaker.
Matches the output of Fuse, by the way.

Re: AY emulation testing

Posted: Sat Sep 14, 2019 12:50 pm
by djnzx48
Thanks. So the 'noise doubling' doesn't seem to occur on a real chip.

I wonder how EvgenRU managed to observe the effect.

Re: AY emulation testing

Posted: Sat Sep 14, 2019 4:35 pm
by Guesser
djnzx48 wrote: Sat Sep 14, 2019 5:15 am Could you elaborate on that?
The different models of Spectrum all have different circuits for the AY, though the +3 is where this has the most significant effect on the resulting audio signal as the amplification is all wrong. The +3 and Black +2 circuits both have some low pass filtering too.

Re: AY emulation testing

Posted: Sat Sep 14, 2019 4:37 pm
by Guesser
1024MAK wrote: Sat Sep 14, 2019 10:49 am Also, what type of digital to analogue converter does the AY actually use? And is there good repeatability between chips of different batches...
And what effect does shorting the channels together vs mixing them with a resistor network have on the resulting signal.

Re: AY emulation testing

Posted: Thu Feb 13, 2020 3:40 pm
by goodboy
full reverse of AY-3-8910 1979 G.I. CORP
http://dlcorp.nedopc.com/download/file.php?id=3033