AY emulation testing

Struggling with Fuse or trying to find an emulator with a specific feature. Ask your questions here.
User avatar
djnzx48
Microbot
Posts: 177
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

AY emulation testing

Post by djnzx48 » Wed Oct 10, 2018 8:53 am

One thing I've noticed with regards to AY in emulators is that they all have a slightly different sound. In particular, the noise generator sounds a bit off in some of the emulators I've tried. I decided to run some tests to investigate this further, and here are the results I've obtained.

First I recorded the output of a simple noise filter sweep from a random selection of emulators I had installed, and put it through a frequency analyser.
Image

Here AY_Emul and Fuse give similar looking output, and the graphs from the other emulators also match up with each other. (For some reason the output isn't very clear, but the ZEsarUX graph seems to match up with the Fuse and AY_Emul graphs.)

When I compared the differing frequencies of the graphs, a suspicious-looking pattern began to emerge. Here I've stretched the output from AY_Emul to double width, and then overlaid the Spectaculator graph on the left hand side at regular size.
Image

They match up perfectly! So it looks like Spectaculator and the other emulators are using half the noise period of Fuse and AY_Emul. To test this, I modified the PT3 player code found here to double all the noise periods before outputting them, thus reducing the frequency to compensate:

Code: Select all

pl2:
    ld ix,ChanA
    ld hl,(AYREGS+AR_TonA)
    call chregs
    ld (AYREGS+AR_TonA),hl
    ld a,(Ampl)
    ld (AYREGS+AR_AmplA),a
    ld ix,ChanB
    ld hl,(AYREGS+AR_TonB)
    call chregs
    ld (AYREGS+AR_TonB),hl
    ld a,(Ampl)
    ld (AYREGS+AR_AmplB),a
    ld ix,ChanC
    ld hl,(AYREGS+AR_TonC)
    call chregs
    ld (AYREGS+AR_TonC),hl
    ld hl,(ns_base_AddToNs)
    ld a,h
    add a,l

    ; add this bit to double the noise period
    add a,a
    cp $20
    jr c, skip_noise_cap

    ld a, $1f

skip_noise_cap:

    ; rest of code
    
    ld (AYREGS+AR_Noise),a
Testing this code in Spectaculator gave a consistent result to the unmodified player in Fuse, except for the noise periods above $0f being clipped to $1f and so half the frequency range being lost.

What's the reason for the discrepancies between emulators? I thought it might have something to do with how the chip divides the clock internally, but I'm just guessing here. I don't own a 128 so I can't test this to see which implementation is correct. Does anyone have any measurements from real hardware to confirm?

If anyone's interested, here's the program I used to test. You can use BREAK and RUN 40 to restart it when it stops.
noise.tap
3 x

User avatar
Ast A. Moore
Manic Miner
Posts: 689
Joined: Mon Nov 13, 2017 3:16 pm

Re: AY emulation testing

Post by Ast A. Moore » Wed Oct 10, 2018 11:35 am

Can’t run the test on real hardware at the moment, but I just ran it in Fuse, and my results don’t match yours. I get a nice picture with a cutoff at 22 kHz, like you have in other emulators. Maybe you have some additional filtering enabled in Fuse?

Image


I’ll try to run your test on my Toast Rack later tonight, if I have the time.
1 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Ast A. Moore
Manic Miner
Posts: 689
Joined: Mon Nov 13, 2017 3:16 pm

Re: AY emulation testing

Post by Ast A. Moore » Wed Oct 10, 2018 6:22 pm

Here’s the spectrogram from my Toast Rack. It’s pretty close to what I get in Fuse. There’s a horizontal line at about 15.5 kHz, though. Not sure what this is. Might be interference from another component, or some weird harmonic. Also note, that there’s no rolloff at higher frequencies.

Image

However, I noticed a strong DC offset in the waveform generated by Fuse:

Image

The output from the Spectrum swings both more or less equally above and below zero, but is a little less perfectly square:

Image

Note: Both waveform screenshots are taken from the very end of the generated noise sequence.
4 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Fred
Berk
Posts: 37
Joined: Tue Feb 27, 2018 3:15 am

Re: AY emulation testing

Post by Fred » Wed Oct 10, 2018 8:35 pm

Turn on the filter to get the dc offset addressed in Fuse.
0 x

User avatar
djnzx48
Microbot
Posts: 177
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: AY emulation testing

Post by djnzx48 » Wed Oct 10, 2018 8:43 pm

Thanks for taking the time to run those tests. Could the differences in the Fuse spectrograms be some kind of folding due to aliasing? It's possible it was just a filter though.

So Fuse is showing correct behaviour here, and the emulators that are halving the period are doing it wrong? Interesting that this went unnoticed for so long. Maybe I'll run the test on some more emulators and get some more results.
0 x

User avatar
Ast A. Moore
Manic Miner
Posts: 689
Joined: Mon Nov 13, 2017 3:16 pm

Re: AY emulation testing

Post by Ast A. Moore » Wed Oct 10, 2018 9:20 pm

Fred wrote:
Wed Oct 10, 2018 8:35 pm
Turn on the filter to get the dc offset addressed in Fuse.
I normally have the “TV speaker” filter on and I only turned it off for the test.
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Ast A. Moore
Manic Miner
Posts: 689
Joined: Mon Nov 13, 2017 3:16 pm

Re: AY emulation testing

Post by Ast A. Moore » Wed Oct 10, 2018 9:25 pm

djnzx48 wrote:
Wed Oct 10, 2018 8:43 pm
Could the differences in the Fuse spectrograms be some kind of folding due to aliasing? It's possible it was just a filter though.
Possibly. But I’d rerun the test, just to be sure. Also, it might be platform-dependent. I run Fuse on macOS.
djnzx48 wrote:
Wed Oct 10, 2018 8:43 pm
So Fuse is showing correct behaviour here, and the emulators that are halving the period are doing it wrong? Interesting that this went unnoticed for so long. Maybe I'll run the test on some more emulators and get some more results.
That would be interesting.
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Sokurah
Dizzy
Posts: 72
Joined: Tue Nov 14, 2017 10:38 am

Re: AY emulation testing

Post by Sokurah » Wed Oct 10, 2018 9:48 pm

I love it. I don't understand much about sound generation and frequencies in general, but I love the fact some some people delve into something as specific as sound and analyse how well some emulators perform compared to "the rest". Interesting read. Good job :)
1 x
Website: Tardis Remakes / Mostly remakes of Arcade and ZX Spectrum games.
My games for the Spectrum: Dingo, The Speccies, The Speccies 2, Vallation & Sqij.
Twitter: Sokurah

User avatar
Fred
Berk
Posts: 37
Joined: Tue Feb 27, 2018 3:15 am

Re: AY emulation testing

Post by Fred » Thu Oct 11, 2018 5:27 am

Ast A. Moore wrote:
Wed Oct 10, 2018 9:25 pm
Possibly. But I’d rerun the test, just to be sure. Also, it might be platform-dependent. I run Fuse on macOS.
There are no platform specific behaviours in this part of Fuse so you don’t need to worry about that :)
1 x

User avatar
djnzx48
Microbot
Posts: 177
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: AY emulation testing

Post by djnzx48 » Thu Oct 11, 2018 8:23 am

I tried a few more emulators, but a surprising proportion of them suffered from serious audio dropouts, at least on my low end hardware (that's the reason for the black bars on the Unreal Speccy pic). I was going to test Spectramine as well but the only link I found for it was a password protected zip.

Anyway, these AY emulators all match the output from a real Spectrum:
Image

Also, I reran the Fuse test making sure the filter was disabled, but still got the same result.
0 x

Post Reply