SND file v3 handler

0. Contents

This is the documentation of sndtool2-3.3.0.1.
   1. Purpose
   2. SND file format
   3. Examples
   4. Development status
   5. How to use
   6. Development ideas
   7. Copying
   8. Requirements
   9. See also
   10. Downloading

1. Purpose

Read SND file, play it, convert it to S3M or MIDI.

2. SND file format

SND is a file format for storing NES (and some other console) music (almost) losslessly.
SND version 3 file format:
   Position Length Description
   0        4      Signature: "SND",26
   4        1      Version of file format. We use 3.
   5        1      Channelcount. For NES, 5.
   6        1      Rate (unsigned integer)
                   How many rows does it play in a second?
                   General values are 50 and 60.
   7        9      Unused, set to zero
   0x10     n      Events, see below
   
Event format:
   Data         Bytes Description
   0xFF          1     Next row (submit this row)
   0xFD x        2     Submit this row x times
   0xFE c t      3     Set channel c (zero based) type:
                        type 1: square
                        type 2: noise
                        type 3: triangle
                        type 4: dpcm
   0xFB n sl sh  2+s   Redefine PCM sample number n (1-based)
                        Size = sh:sl
                        PCM data follows (bytes 0x60..0x9F)
   0xdv c wl wh  4     Alter square wave on channel c:
                        Set duty = d (2,4,8,12)
                        Volume = v (0..15)
                        Wavelen = wh:wl (0..0x7FF)
   c wl wh v     4     Alter channel c
                        For triangle and noise:
                         Wavelen = wh:wl (0..0x7FF)
                         Volume = v (0..15)
                        For dpcm:
                         Sample number = v (set to 0 to stop sample)
                         Wavelen = wh:wl (0..0x7FF)

SNDv3 files are generated by nezplay (produced by
a patch to nezplug) from NSF and GBS files.

SNDv2 format was proposed to Martin Korth (no$gmb author)
for Game Boy music logging, but he ignored the proposition.

SNDv1 files were generated by older versions
of iNES from NES gaming sessions.

Note that SNDv3 files use wavelengths whereas SNDv2
and SNDv1 files use frequencies. Therefore this format
isn't backwards compatible.
The program converts the SND to MidiS3M with Adlib instruments.
PCM samples are converted into S3M digital samples.
Conversion to MIDI format is also supported, but it doesn't save the PCM samples.

3. Examples

This zip file contains some S3M files generated by sndtool2 (only the instrument list has been finetuned by hand) and one MIDI generated by sndtool2 (not edited).
Note that the S3M files use adlib instruments.
Most mod players are unable to playback them, and most of the rest which can, only use an emulator which isn't perfect.

4. Development status

The program works, but isn't yet ready for users.
Command line options have to be implemented and the instrument type heuristics enhanced.
Three primary goals are:

5. How to use

  1. First you have a SND file. You could create it with nezplay by giving it the -l option on commandline (press L to stop logging and save).
  2. Edit instrument.cc from sndtool2. Find the GM and GP parts, edit the numbers as you want. The numbers correspond to General MIDI instrument numbers, for example GM(1) is acoustic grand piano. You can find the complete list of instruments in midi-gm.c.
  3. Recompile: make snd
  4. Run: ./snd sndfilename.snd >/dev/null 2> tmptmp
    • Short version: ./snd sndfilename.snd &> /dev/null
  5. After running, you will have a logfile in tmptmp (less -SR tmptmp to view), a S3M file in test.s3m and a MIDI file in test.mid. (No logfile in case of the short version.)
  6. Listen the MIDI file and repeat steps 2-6 as needed.
The >/dev/null part of the command is important to prevent your terminal being flooded with binary data. The binary data is actually PCM data: the program will resynthesize the song into stdout. If you want to listen it, you can try this: ./snd sndfilename.snd 2>tmptmp | ecat -m. You can find the ecat program here.

The 2> tmptmp part of the commandline instructs the shell to redirect the stderr of the program into the specified file. If the shell works properly, the program won't receive the "2" as a commandline parameter.

You can acquire nezplay by following these steps:

By the way... you almost certainly need an unix environment to do this all. I guess Cygwin will do for Windows users.
Nezplay may require Linux, at least if you want it to output audible sound. It can always output to a file however.

6. Development ideas

7. Copying

sndtool2 has been written by Joel Yliluoma, a.k.a. Bisqwit,
and is distributed under the following terms:
* No warranty. You are free to modify this source and to
* distribute the modified sources, as long as you keep the
* existing copyright messages intact and as long as you
* remember to add your own copyright markings.
* You are not allowed to distribute the program or modified versions
* of the program without including the source code (or a reference to
* the publicly available source) and this notice with it.

8. Requirements

GNU tools are always good to have near.

9. See also

10. Downloading

The official home page of sndtool2 is at http://iki.fi/bisqwit/source/sndtool2.html.
Check there for new versions.

Generated from progdesc.php (last updated: Fri, 10 Feb 2006 01:12:18 +0200)
with docmaker.php (last updated: Sun, 12 Jun 2005 06:08:02 +0300)
at Fri, 10 Feb 2006 01:12:20 +0200