[r4010]: Patch for SAA1099/Gameblaster emulation... (commited in r4010)

Here you can discuss the development of patches.

[r4010]: Patch for SAA1099/Gameblaster emulation... (commited in r4010)

Postby OPLx » 2014-2-15 @ 18:48

Hi everyone,

Since I just registered, I couldn't post this to the patches forum, so I'll try doing so here.

I had noticed a discrepancy between the Gameblaster note frequencies in DOSBox and that of actual hardware. From examining things a bit, it looks like SAA1099 emulator in DOSBox assumes that the clock frequency driving the chip is 8 MHz. This value is correct if one goes by the SAA1099's datasheet. Measuring the actual clock frequency on the Sound Blaster 1.5 that I have, it looks like it is actually somewhere around approximately 7.156 MHz.

While doing some related searches online, I found this formula for calculating the frequency (I'm assuming with an 8MHz clock):

Code: Select all
frequency = (15625 * (2^octave)) / (511-note)

"note" here is the value that would be set on the SAA1099's frequency register.

Looking at the datasheet, it's not immediately apparent to myself how this formula was ascertained, but I noticed that the "15625" value may be related to the clock rate, so I tried this:

Code: Select all
clock_divsor = 8000000 / 15625, the result being 512.

So doing a little math, one can figure out what the clock divisor should be for a particular input.

The generalized formulas seem to be:

Code: Select all
frequency = (sample_frequency * (2^octave)) / (511-note)
note = 511 - ( (sample_frequency * (2^octave)) / frequency )

In the case of the Gameblaster's 7.156MHz clock, sample_frequency would be:

Code: Select all
7156000 / 512 = 13977 (rounded up).

Inserting this value for the note and noise frequencies (noise is also driven off of multiples of the clock rate), DOSBox's Gameblaster sounds like that of actual hardware.

I've attached to this message the .diff/.patch file for gameblaster.cpp people to try out; I hope this is of use to everyone.
You do not have the required permissions to view the files attached to this post.
Last edited by OPLx on 2014-2-16 @ 00:07, edited 2 times in total.
OPLx
Member
 
Posts: 110
Joined: 2014-2-15 @ 17:02

Re: Patch for SAA1099/Gameblaster emulation...

Postby Great Hierophant » 2014-2-15 @ 21:15

You are essentially correct. Your base frequency is a little off, as the Gameblaster uses the oscillator pin for its timing and then divides it by two. The oscillator's frequency is 14,318,180, so divided by two makes 7,159,090. This makes the divisor 13983 (rounding up). The derived noise frequencies would be 27966, 13983 and 6991.5.

The values you give in your patch for the noise frequencies match, very closely those given in a document entitled C/MS Programming Information, copyright Creative Labs, Inc. 1990. It defines the frequencies at 28.0 kHz, 14.0 kHz and 6.8 kHz, whereas Phillips gave 31.3 kHz, 15.6 kHz and 7.6 kHz.

Interestingly, nowhere in that document does Creative discuss or even define the envelope generators. It also just gives the pre-defined noise frequencies, it does not discuss the frequency generator controlled noise frequency option.
http://nerdlypleasures.blogspot.com/ - Nerdly Pleasures - My Retro Gaming, Computing & Tech Blog
User avatar
Great Hierophant
l33t
 
Posts: 2374
Joined: 2003-4-27 @ 08:20

Re: Patch for SAA1099/Gameblaster emulation...

Postby Dominus » 2014-2-15 @ 21:55

Moved to the patches forum ;)
Btw, no non-moderator can start a new thread there (to keep it somewhat clean), so it had nothing to do with post count or register-age of you.
Thanks for the patch (even though I never encountered a game with gameblaster option ;))
User avatar
Dominus
DOSBox Moderator
 
Posts: 7644
Joined: 2002-10-03 @ 09:54
Location: Ludwigsburg

Re: Patch for SAA1099/Gameblaster emulation...

Postby OPLx » 2014-2-15 @ 22:26

Thank you for moving the thread over to the patches forum; it is unfortunate that there were not too many games that used the Gameblaster option. :)

Thank you also for the information about the oscillator's frequency; everything makes sense now. I had been doing some tests with an actual SAA1099 (@ 8 MHz) and was puzzled when my test program didn't sound the same on real hardware compared to DOSBox and the SAA1099 chip. I took a quick look at the C/MS Programming Information and it is a bit odd that there's no mention of the envelope generators. It's a shame because one of the unique aspects of the SAA1099 are the envelope generators. Hopefully I will (one day) be able to obtain an actual Gameblaster card.

Thank you again, and I hope the values Great Hierophant listed will be added to the patch for DOSBox!
OPLx
Member
 
Posts: 110
Joined: 2014-2-15 @ 17:02

Re: Patch for SAA1099/Gameblaster emulation...

Postby Great Hierophant » 2014-2-15 @ 22:42

I would be interested to know of any game that uses those envelope generators. Here is the patch with the values I listed above integrated.
You do not have the required permissions to view the files attached to this post.
http://nerdlypleasures.blogspot.com/ - Nerdly Pleasures - My Retro Gaming, Computing & Tech Blog
User avatar
Great Hierophant
l33t
 
Posts: 2374
Joined: 2003-4-27 @ 08:20

Re: Patch for SAA1099/Gameblaster emulation...

Postby OPLx » 2014-2-16 @ 00:10

Thanks for updating the patch! I'm not sure if there are any games that used the envelope generators; it would be very nice if there was one out there. I also updated my initial post by changing "clock_multiplier" to "sample_frequency" per the information I was recently reading about here: OPL chip.
OPLx
Member
 
Posts: 110
Joined: 2014-2-15 @ 17:02

Re: Patch for SAA1099/Gameblaster emulation...

Postby NewRisingSun » 2014-2-16 @ 08:37

Properly self-documenting code does not do such calculations and especially roundings by hand, but merely specifies the master clock divisors and lets the compiler do the job. See below. That way, it can be easily adjusted to different master clocks by changing the MASTER_CLOCK constant. That is the way it is done in the SN76489 emulator, and that is the way it should be done here.

Code: Select all
--- gameblaster.cpp.old   2013-01-15 12:10:04 +0000
+++ gameblaster.cpp   2014-02-16 22:13:33 +0000
@@ -32,6 +32,7 @@
 #define RIGHT   0x01
 #define CMS_BUFFER_SIZE 128
 #define CMS_RATE 22050
+#define MASTER_CLOCK 7159090
 
 
 typedef Bit8u UINT8;
@@ -205,9 +206,9 @@
     {
       switch (saa->noise_params[ch])
       {
-      case 0: saa->noise[ch].freq = 31250.0 * 2; break;
-      case 1: saa->noise[ch].freq = 15625.0 * 2; break;
-      case 2: saa->noise[ch].freq =  7812.5 * 2; break;
+      case 0: saa->noise[ch].freq = MASTER_CLOCK/256 * 2; break;
+      case 1: saa->noise[ch].freq = MASTER_CLOCK/512 * 2; break;
+      case 2: saa->noise[ch].freq = MASTER_CLOCK/1024* 2; break;
       case 3: saa->noise[ch].freq = saa->channels[ch * 3].freq; break;
       }
    }
@@ -221,7 +222,7 @@
       for (ch = 0; ch < 6; ch++)
       {
             if (saa->channels[ch].freq == 0.0)
-                saa->channels[ch].freq = (double)((2 * 15625) << saa->channels[ch].octave) /
+                saa->channels[ch].freq = (double)((2 * MASTER_CLOCK/512) << saa->channels[ch].octave) /
                     (511.0 - (double)saa->channels[ch].frequency);
 
             /* check the actual position in the square wave */
@@ -229,7 +230,7 @@
          while (saa->channels[ch].counter < 0)
          {
             /* calculate new frequency now after the half wave is updated */
-            saa->channels[ch].freq = (double)((2 * 15625) << saa->channels[ch].octave) /
+            saa->channels[ch].freq = (double)((2 * MASTER_CLOCK/512) << saa->channels[ch].octave) /
                (511.0 - (double)saa->channels[ch].frequency);
 
             saa->channels[ch].counter += sample_rate;
Last edited by NewRisingSun on 2014-2-16 @ 22:14, edited 1 time in total.
NewRisingSun
Oldbie
 
Posts: 798
Joined: 2005-9-02 @ 02:26

Re: Patch for SAA1099/Gameblaster emulation...

Postby Great Hierophant » 2014-2-16 @ 22:00

Understood. NRS's code is missing one instance where the calculated value is used. Understood. NRS's code is missing one instance where the calculated value is used. Both lines like this :

Code: Select all
                saa->channels[ch].freq = (double)((2 * 15625) << saa->channels[ch].octave) /


must be changed to

Code: Select all
                saa->channels[ch].freq = (double)((2 * MASTER_CLOCK/512) << saa->channels[ch].octave) /
http://nerdlypleasures.blogspot.com/ - Nerdly Pleasures - My Retro Gaming, Computing & Tech Blog
User avatar
Great Hierophant
l33t
 
Posts: 2374
Joined: 2003-4-27 @ 08:20

Re: Patch for SAA1099/Gameblaster emulation...

Postby NewRisingSun » 2014-2-16 @ 22:11

Eh? It's right there in my snippet...

Edit: I see what you mean; the frequency line appears twice. I have updated the previous post.
NewRisingSun
Oldbie
 
Posts: 798
Joined: 2005-9-02 @ 02:26

Re: Patch for SAA1099/Gameblaster emulation...

Postby kazblox » 2015-6-29 @ 22:59

https://github.com/mamedev/mame/pull/232

I pushed into MAME as a pull request. Thanks NewRisingSun for creating the patch and OPLx for bringing it up in the first place!
kazblox
Newbie
 
Posts: 33
Joined: 2014-12-25 @ 22:28

Re: Patch for SAA1099/Gameblaster emulation...

Postby Qbix » 2017-5-02 @ 14:15

commited in r4010
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10649
Joined: 2002-11-27 @ 14:50
Location: Fryslan


Return to DOSBox Patches

Who is online

Users browsing this forum: No registered users and 2 guests