Hi!
As you may know, the PSG has a noise generator. It is used for example to
create hi-hat sounds and explosions. I figured out the exact algorithm used
for this noise generator, this can be interesting to emulator programmers.
The noise generator produces a series of zeroes and ones in a pseudo-random
pattern. The speed at which new values are produced is set by the "noise
frequency" register (which is a confusing name, because real noise doesn't
have a frequency).
The noise generator uses a 17-bit seed and its output is periodic with period
2^17-1 values.
Initially the seed is all zeroes. Every step, the seed is shifted to the
right. The bit shifted out (old bit 0) is the output. The bit shifted in (new
bit 16) is the complement of the XOR of the old bit 0 and bit 3.
It can be implemented in a function like this:
int nextNoiseBit()
{
int ret = seed & 1;
seed >>= 1;
seed ^= (ret ? 0x02000 : 0x10000);
return ret;
}
This implementation doesn't check bit 3, it checks bit 0 three steps later
and then affects bit 13 instead of bit 16. I got this trick from the MAME
code. However, the MAME algorithm doesn't produce the same sequence as the
turbo R PSG does, for one thing the period is shorter.
This is the algorithm used by the engine-integrated PSG found in the MSX
turbo R GT. There is a chance that the original PSG (AY-3-8910) used a
slightly different algorithm. If anyone can sample the noise from an MSX1,
I'm interested in the resulting sample (contact me). The MAME code doesn't
say where they got their algorithm from, Sean Young will send a mail to the
MAME mailinglist, maybe that will bring some information.
By the way, it's not sure that the initial seed is 0. Every seed 17 bits long
except for one is used at one point of the period. The illegal seed is 14
ones, which produces 17 ones in the output and that's the only length 17
sequence that doesn't occur. Because the noise generator starts running as
soon as the MSX starts, it's impossible to tell exactly what is the initial
seed. Fortunately, that doesn't matter.
I would like to thank Diego Lont for his help in creating an algorithm that
matched the sampled sequence. Although his algorithm was a bit more complex
than the one listed above, it was correct and helped me find this one.
Bye,
Maarten
--
For info, see http://www.stack.nl/~wynke/MSX/listinfo.html