Troubles with sound
There is such a widely known in narrow
circles people like Marat Fayzullin. From-
he is famous for being the author of many
many domestic emulators (many with
open source, which is very
influenced the development of emulator construction)
various 8-bit machines, such as:
MSX (fMSX), Coleco (ColEm), NES (iNES),
Sega Master System (MasterGear), Nintendo
Gameboy (VGB), Gameboy Advance (VGBA).
Emulators, frankly speaking, are weak (for-
then one of the very first!), and in some places
very free ($35 per emulator)
iNES, which is much inferior to modern analogue
logam - don't want to? ;). But they have a
more precisely, in their older versions (in new ones the feature
removed) one interesting feature: discounts-
generate a data stream for an audio chip in a special
al format, with the extension .snd (this is not
that .snd, which is an 8-bit sample). Chips that
Of course, all consoles are very different. But
sound in older emulators was output through
Adlib, the reliability of the emulation was very
low, and the .snd format was for all emulators
Marat's tori is unified.One day an idea came to my mind,
having no practical npumehe-
niya, but having a purely sporting interest:
what if we take it and intercept it in some
or emulator data stream for audio
chip, translate into a list of channel numbers,
frequencies, volumes, etc., and then pro-
play the whole thing on AY? Operating principle
The effects of all PSG chips (including AY) are similar.
Of course, some sound chips have
more channels, other possibilities
possibilities, but they can be reasonably trimmed.
I began to think about how to do this. For na-
I had to come up with something like nepexba-
tit data stream - decided to find open-
source emulator and make the necessary modifications
ki. But at the first search on Google,
stumbled upon a completely different thing: already
implemented idea, but for C64 - player
music from NES (chip 2A03) to SID 8) Name-
this thing NESSIDPlay (who is interested)
obviously, link at the end of the article).
NESSIDPlay used .snd-
Marat emulator files (from iNES, VGB,
MasterGear). Thus, the need
There is no need to search for and modify emulators.
After searching some more (for quite a long time), I found
description of the .snd format (it is attached to
iNes version 0.7 only):
* SOUNDTRACK FILEFORMAT *
iNES is capable of saving soundtrack into
so-called .SND files, also used by my
other emulators. You can find tools to
work with these files in the EMUTools
package. .SND files have quite simple
format described below:
[ iNES can save audio tracks in
so-called .SND files used and
in my other emulators. Toolkit
for working with such files can be found in
EMUTools package. .SND files are quite
but a simple format which is described below: ]
┌───────┬───── ──────────────────────────┐
│ Byte │ Contents │
├───────┼─────────── ────────────────────┤
│ 0-3 │ String "SND^Z" │
│ 4 │ Version number │
│ 5 │ Number of channels │
│ 6 │ Clock frequency, in Hz │
│ 7-15 │ Reserved, must be zeroes! │
│ 16-EOF│ Sound records of │
│ │ following types: │
│ │ a) channel# | frequency.l | │
│ │ frequency.h | volume │
│ │Change sound on a givenchannel│
│ │to new frequency (Hz) │
│ │ and volume (0..255). │
│ │ b) FFh │
│ │A single clock "tick". │
│ │ c) FDh | number of ticks │
│ │Multiple clock "ticks" (0..255)│
│ │ d) FEh | channel# | sound type│
│ │Change sound type at a given │
│ │channel. Default type is │
│ │MELODIC for all channels. │
│ │ Currently defined types: │
│ │ 0 - MELODIC │
│ │ 1 - WHITE NOISE │
│ │ 2 - PERIODIC NOISE │
└───────┴─────────── ────────────────────┘
This is a description of the format of the first version. Su-
there were subsequent, more complex ones,
not backward compatible. To
make sure that the file is in the required version format
this, you need to check byte number 5 (start+
4), if it is less than 2, then everything is OK.
Some inconvenience was caused by the fact that
frequency values in this format are stored in
hertz - recalculate them on the fly into
The values for tone registers AY are quite
boring and uninteresting. I did it simply
- wrote a small program for PC,
which converted .snd to modification
modified format where frequencies were stored
immediately in the meanings for tonalregi-
strove, and more compactly. It was possible
would make such a transformation and
Speccy, when loading a file, but I'm corny
lazy :)
We need to explain what tick is. Data
from the file must be sent to the sound chip with
frequency specified in byte start+6 (i
took 50 hertz, i.e. interrupt frequency
Speccy - on consoles this frequency is equal to
50 or 60 hertz, depending on PAL/NTSC
systems). We read the data and send it to
chip until we encounter the FFh byte
(tick) - then we wait for the next interruption.
Or, up to the FDh byte, and wait as long as
kov, how much is indicated in the next one
byte (this must be done in
files are full of these values).
Now about how I solved the problem
matching the capabilities of 2A03 (NES chip,
I was only counting on music for it)
and A.Y. To do this, it is necessary to explain that
some 2A03, and what it can do.
2A03 is not an independent chip
(does not have its own body) - it is uhterpupo-
van into the core of a modified processor
6502, used in the NES (this is his
main modification :). It has 4 PSG-
channel, and one digital (DMC, Sbit, has
DMA - this channel was not in the original
online Famicom,Japanese NES version).
The digital channel in the iNES emulator is not emulated
is copied and not written to .snd, so
o him (and drums in many games with good
our music;) you can forget. Channels 0 and 1
PSGs generate a square tone in the range
54.6Hz..12.4KHz, they are completely the same.
Channel 2 produces a triangle tone in the range
27.3Hz..55.9KHz, used for bass
parties. Last, channel number 3, generator
noise (pseudo-random generator, often
you 29.3Hz..447KHz). At square channels,
triangle channel and noise channel are available
various unique features (details
read the documentation), but what's the point?
no way - they are not emulated in iNES,
and are not written to the file.
Since we have abandoned the digital channel,
all we have to do is push 4 channels
(three tones and noise) through the available three channels -
lam AY (after all, the noise generator on it is not
has its own adjustable volume). I
I did this: bass played on one of the channels
and noise (with bass volume, I also tried
shaft to change the noise frequency instead of volume,
a frequency value from file urhopupo-
vat). There was another option - to implement
triangle channel with envelope (to obtain
similar to the real triangle sound channel
ka), but due to my laziness I did not
didn't.The result was something vaguely reminiscent of
passing the original melody on the NES, occupying
about 10-15 kilobytes per short
melody (what did you want from the PSG format?
:). Unfortunately, the player's source code has been destroyed.
were due to reasons beyond my control, and I
I can’t demonstrate this miracle in pa-
both. But if anyone cares about this problem,
seemed interesting - links to necessary
My information is at the end of the article, assembler
into your hands :)
By the way, interesting information for having
NES consoles built on dis-
specific elements (having a processor in
DIPHO-case). It is quite easy to do
Pseudo-stereo output: on the first leg
chip outputs a signal from both square channels
fishing, on the second - triangle and noise. Soldering iron
into your hands ;)
Finally, I will say for those who want
perform similar experiments: do not
try to use music formats from
modern emulators (such as .nsf) are
not the command stream for the sound chip, but
player torn from the game + data (if
playback has to emulate not
only the sound chip, but also the processor, and
all the necessary hardware - similar to AY-
Emulator).
Сайт Marat'a:
http://fms.komkon.org/
NESSIDPlay:
http://www.zyx.com/chrisc/nessidplay.html
Описание 2A03:
http://web.textfiles.com/
games/nessound.txt
Share your thoughts about the article