Accuracy of emulation of SAA1099 different emulators
Hello dear friends.
Sorry for my french :-)
I want to touch on the topic that interests me.
I've never had (and unlikely to be) the original Sam Coupe, so I use the emulator, of course, SimCoupe. I want to note immediately that this is the only emulator working for me, other emulators, for example ascd100 / asd098 do not work at all, overload the computer with BlueScreen :)), or ZEsarUX - there is nothing to download.
But SAA1099 is emulated not only in SimCoupe, but also in two or three software emulators ZX Spectrum.and in several hardware emul FPGA on MiST / MiSTer
And of course there are melodies that are better or worse reproduced in these emulators, but they all lose in different ways :( Sadly.
That's why a small test utility was written, which works equally in the Sam Coupe and ZX Spectrum emulators (with the SAA1099 module). The test contains several dozen test patterns, especially the patterns with envelope, I think most of the errors are precisely when emulating envelope
So, I would like the owners of REAL Sam Coupe to launch this test and shoot the video (about 6 minutes), preferably with a good sound for a direct comparison of the sound.
Unless of course it does not.
This is the previous version of the test in the Unreal emulator
This is a link to the archive with both versions of the test
both the last and the previous one. I would certainly like to see and hear the previous version, as it sounds on real, especially at the end there are three real melodies. It would be desirable to hear any of them only with the included envelope, for this purpose it is necessary to switch off freq (F7) and noise (F8)
p.s. I would like to thank Sir David for the excellent utility "scadm", with her help I created a disk image for Sam Coupe and ported my test with Spectrum. Thank you !!!
Very interested in the outcomes!
I no longer have my Sam... But this is essentially the procedure I used when I implemented the SAA1099 emulation module used by SimCoupe . I plugged my Sam audio output into a capture card and analysed the waveforms while writing little test programs like these :-)
So I'm very interested in the outcome and will happily respond to bug reports etc.
Emulation is known to be substandard at high frequencies if sample rate is set lower than 44.1 kHz. And there's aliasing noise due to the oversimplified square wave generator. Maybe I'll fix those one day.
Trivia
When emulating sample playback, empirically (and with help from the Philips datasheets) I determined that only 3-bit resolution was available (I.e 8 discrete levels per sample). This is implemented in SAASound. This surprised Edwin Blink, the author of the first original sample playback demos for Sam Coupe! It was previously (but incorrectly) assumed that sample resolution was 4 bits.
As a result, SAASound has both an 'accurate' (3 bit) mode and a 'sounds nicer' (4 bit) mode. This is available in SimCoupe settings. It affects the envelope generation (since it is the behaviour of the envelope generator that is exploited when rendering sampled audio in a real Sam)
I shall give this a go, I’m…
I shall give this a go, I’m not sure how good the audio will be on an iPhone though.
I recall being amazed by the…
I recall being amazed by the 3 vs 4 bit revelation and trying it out on my real SAM back in the day. I just can't recall if I adjusted the volume tables for the SAM MOD Player.
test SAA1099
I will be grateful for any help.
Yes, this is a very interesting program, I used it!
test SAA1099
I'll try to explain why all this is necessary. For a real Sam Coupe, the test is useless, but for the emulators and SAA1099 emulators it is very necessary. After all, compare the sound of the work, where six channels are playing at once - it is necessary to have not only an absolute musical ear, but also a very good memory :)
In my test, you can turn off almost everything. The keyboard keys from '1' to '0' and 'Space'
'Space' - the next test, not waiting for the end of the current
'1' - on / off amplitude in channel 1
'2' - on / off amplitude in channel 2
'3' - on / off amplitude in channel 3
'4' - on / off amplitude in channel 4
'5' - on / off amplitude in channel 5
'6' - on / off amplitude in channel 6
'7' - on / off frequency all channels (R14)
'8' - on / off noise in all channels (R15)
'9' - on / off envelope in all channels (R18 / R19)
'0' - on / off automatic continuation of tests one after another (after 10 seconds)
For example, the "J" test is a very popular Popcorn tune, when AUTO is on it will play exactly 10 seconds, if you disable this option it will play indefinitely, you can practice and press keys from 1 to 9.
If you press only '7' - there will be noise and envelope, if you press another '8' - only the envelope will remain
So I think that with emulation of the envelope option, the most problems in some emulators, just 3 or 4 bit mode, or incorrectly emulate, or even ignored. There are also possible problems with a mixer of sounds and with the volume of the envelope.
But the authors of the emulators in one voice say - leave us a standard, what to compare, then we can fix it: (
Here is an example of the program code from the Unreal emulator
https://github.com/tslabs/zx-evo/blob/master/pentevo/unreal/Unreal/saa1099.cpp
so I can give an example code for FPGA
Here is my latest version of the test
http://rgho.st/85jWhZ7cv
Almost everything is the same, the melody Popcorn is added at the end, on its example it would be desirable to only mix 6 channel with off off frequency '7' and disabled channels 1-5,
so that only the envelope can be heard in the sixth channel. If it does not, too. Thank you.
SimCoupe audio emulation source code
Just a reminder that the source code for SAASound (as used by SimCoupe) is freely downloadable on both Simon Owen's pages and from sourceforge . I released it under a GPLv2 license. I'll probably just move it to BSD and upload to github over the weekend :-)
I'm fairly certain it accurately matches the real Sam Coupe (although of course I am biased!!) but I'm not aware of any discrepancies (and plenty of previous discrepancies have been reported and fixed in the past). So I'm super interested in this for a variety of reasons (including extra scrutiny and the crowdsourced test cases)
Edited to add: @azesmborg - your utility is AWESOME . And something sounds very bad in simcoupe..
@stripwax And something…
In reply to SimCoupe audio emulation source code by stripwax
Yes, I noticed that too.
In the Unreal emulator, this test plays better, and the code is 100% the same. Therefore it would be interesting to compare it with real sound.
Some parts of the test are made as a generator, but some are just like a song in the ETracker editor, so you can listen and compare them in SAAemu
This is all so fascinating for me
I had no idea there was an FPGA emulator (either for SAM Coupe or for anything else) and I has never heard of MiST and it's crazy that the FPGA emulation of the SAA in MiST (and also SAAEmu) also uses SAASound! If there's any bugs in these it all points to my code :-) so the authors of the emulators should be asking me :-)
And there's on going discussion elsewhere. DOSBox emulates an SAA1099 , and that code was used as the basis for the emulation in Mame/Mess, and this too seems to be (still) evolving. I literally haven't looked at this stuff for nearly 20 years so I was amazed to find this. I will of course take a look at incorporating these recent discoveries and update SAASound accordingly :-) the DOSBox implementation sounds really like the 'right way' to do all this (emulate the chip at 8MHz, and filter/downsample to get a 44kHz audio output) instead of what everybody else is doing!
https://www.vogons.org/viewtopic.php?f=9&t=51695
FPGA Sam Coupe
Good. For those who first hear about the hardware emulation of the Sam Coupe - several links:
Hardware FPGA emulator Sam Coupe for ZX-Uno from mcleod_ideafix (Miguel Angel Rodriguez Jodar)
http://www.zxuno.com/forum/viewtopic.php?f=15&t=9
Problems with the SAA1099 module(SAA1099.v code from Miguel Angel Rodriguez Jodar
// Based on SAASound code from Dave Hooper)
http://www.zxuno.com/forum/viewtopic.php?f=52&t=684&start=100#p23378
Hardware FPGA emulator Sam Coupe for MiST from Sorgelig
https://github.com/sorgelig/SAMCoupe_MIST
module saa1099 (Based on SAA1099.v code from Miguel Angel Rodriguez Jodar)
https://github.com/sorgelig/SAMCoupe_MIST/blob/master/saa1099.sv
Hardware FPGA emulator Sam Coupe for MiSTer from Sorgelig
https://github.com/MiSTer-devel/SAM-Coupe_MiSTer
module saa1099
https://github.com/MiSTer-devel/SAM-Coupe_MiSTer/blob/master/saa1099.sv
Hardware FPGA emulator ZX-Spectrum_MISTer for MiSTer from Sorgelig
https://github.com/MiSTer-devel/ZX-Spectrum_MISTer
module saa1099 for ZX-Spectrum
https://github.com/MiSTer-devel/ZX-Spectrum_MISTer/blob/master/saa1099.sv
The first synthesized core Sam Coupe in FPGA in 2015 for ZX Uno mcleod_ideafix, but it is very simple, loads two dozen TAP files from the tape input and that's it.
in the year 2016, Sorgelig, who ported and reworked the core for MiST and managed to work with disks
In 2017, Sorgelig moved its core to MiSTer and further improved it and continues to improve if it explicitly points out flaws.
module saa1099 in the sam Coupe (and Spectrum128 :), he thinks that it works perfectly, or says, let's compare it to real sounds, if something is wrong.
The module from mcleod_ideafix works the least correctly, there are clearly audible errors, but mcleod_ideafix is unlikely to correct them, but Sorgelig hopefully will fix it, but you must explicitly indicate that it does not sound right, or works in the Sam Coupe itself
That's why I'm asking for help.
And yes, Sorgelig has an open project, open source, in contrast to, for example, projects such as NEXT :(
I hope no one is against the heritage of the Sam Coupe remained in the memory of descendants, not only in software emulators, but also in hardware
Suggestion for test enhancements :)
I can certainly imagine a broad category of very-rapidly-changing cases that might not work well in SAASound. In steady state (updates to SAA registers on the order of once per frame) everything ought to sound correct, and updates faster than that might not have been well tested (other than updates to volume registers up to around 44kHz for digital audio emulation). But if registers keep uodating every tick, for example, especially envelope registers or enable flags or sync flags, might sound quite 'dirty' since SAASound only runs at 44kHz - whereas a real SAA1099 runs at 8Mhz.
I wonder if it's those approximations that are causing the horrendous noises on channel 6 in those first few test examples
So can I request a small change/enhancement to the test please? Could you add a 'pause' button? So that the SAA emulation can be left to continue making audio output in steady-state. I'd like to see if the bad noise comes from the SAA generator or from the continuous changes in SAA state...
test SAA1099
Of course. The test is open to suggestions, maybe I also came up with not all the options. Regarding stopping the test \ pause I already thought, made the simplest version -
keyb_0: DI
HALT
jp $
In the first test called test_saa_old on the button '0' - the program hangs of course, but the generation in the SAA remains. Try it, can this option work? Well, or otherwise, you can make an output to an infinite loop
Here we go: Test 1: https:/…
Here we go:
Test 1: https://www.youtube.com/watch?v=e_68MGy04Yc
Test 2: https://www.youtube.com/watch?v=gEvO21XCqMM
Sounds terrible on both my SAM's, regardless of speakers, headphones or whatever :-)
It sounds like SAASound nailed it :-)
It's great how bad it sounds :-)
The challenge will be to determine if the bad sounds coming out of a real Coupe are a good match for the bad sounds coming out of the emulator but it seems pretty close to me.
Sounds terrible on both my…
Excellent!!!
Thanks for both tests, I now have something to compare soft and hard emulators. I hope I find the difference and try to level it out if possible.
Thank you!
p.s. For the first time I saw on the video how the real Sam Coupe works, and even more so on my program :)
SAASound updates
Moved permanently to github:
https://github.com/stripwax/SAASound
Also I've updated my contact details. People should be able to get hold of me easily now.
I've incorporated the 'official' LFSR (per DosBox) into SAASound , and I'll start to take a look at reconciling any other remaining differences. I doubt the LFSR change will be noticable/audible at all, plus we don't know the initial seeds in any case..
It also seems that (coincidentally! about 4 weeks ago!) Simon Owen recently pushed his own variant of SAASound also to github! In that it looks like he's added a pull request for a non-8MHz clock, which is interesting (not sure what's driving that request , maybe a different emulator entirely! May well be related to the aforementioned vogons thread where accurate GameBlaster emulation requires a non-8MHz .. and it looks like a key participant in that conversation also produced the changes for Simon Owen so that's interesting too!)
I'll work with him to reconcile all this into a single project.
SimCoupé 1.1 alpha - potential glitch in SAA emulation??
Try this as an experiment:
Load up Simcoupé v1.1 alpha and fire up a copy of SAM Defender - start a game and do nothing except press the thrust key. Listen to the "engine" noise of your ship. As soon as one of the enemies fires a shot the pitch of the engine noise will increase. Certain other sounds cause this to happen too. The pitch increase will remain until certain other sounds (like firing your laser for example) cause it to revert back to its lower pitch.
This is under Windows. Not sure if it would be the same running under a different OS?
Now try the same experiment on a real SAM. This engine pitch change doesn't occur (at least to my ears on my portable TV) and it remains constant regardless of other sounds.
Strange?
Fascinating. I can reproduce…
Fascinating. I can reproduce in SimCoupe. Not yet sure this is a bug or not, as I don't have a real SAM to compare, but from dumping out the SAA registers it does seem to be a bug in SAASound.
I've dumped out the register changes as far as SAASound sees them, and it looks like the initialisation of the "engine" noise is as follows:
sound 22,&33
sound 21,9
sound 20,0
sound 0,&22
sound 3,&22
sound 8,8
sound 16,3
sound 11,0
sound 17,&30
sound 28,1
And at a later point (after the pitch has changed), I've dumped out the registers and they're the same... even though the noise is now different. Let me investigate this.
EDIT oh, interesting. It looks like at certain points, the sync bit (28,2) gets set, and the engine noise reinitialised as above, and it seems that the noise generator frequency doesn't correctly get reset when the sync bit is set. Another day, another sync bit bug
Looks like an easy fix. New…
Looks like an easy fix. New DLL released here (sorry, you need to still use SimCoupe1.0 to be able to swap the SAASound dll). https://github.com/stripwax/SAASound/releases
That's fixed the Defender …
In reply to Looks like an easy fix. New… by stripwax
That's fixed the Defender "engine" anomaly Dave! :)
There's always something new…
There's always something new to report here... I introduced a regression in one of these earlier changes, which I have corrected, along with some other quality improvements, in the latest releases, which is now 3.4 . And with the latest version of SimCoupe, you can now drop in SAASound upgrades over the top (just by downloading the SAASound dll from the release - linked below)
https://github.com/stripwax/SAASound/releases/tag/3.4