Echo

From Sega Retro

Echo is a new sound-engine for the Sega Mega Drive created by Sik. It's Z80-based and allows full control over the sound hardware. Its purpose is to provide a free, open-source possibility to implement music and sound effects in programs, demos or games developed for the system. It is currently in beta state, albeit functional for the most part. Assembly, C with SGDK, and BasiEgaXorz interfaces are available, so nothing stops you from using this sound engine to its full potential!

Its current version number is 1.21

It was used and tested in a few projects already, such as

  • MDEM's first (Sega Mega Drive Demo)
    • Used Echo v0.3
  • In A Hall (32kb executable music release)
    • Used Echo v0.3
  • Super Generic Happy Game Intro Song (32kb executable music release)
    • Used Echo v0.9
  • Project MD (homebrew Jump'n'run game for the Sega Mega Drive)
    • Used Echo v0.9
  • overdrive (Sega Mega Drive Demo)
    • Used a custom version of Echo (1.3T)
  • Muhinae II (32kb executable music release)
    • Used Echo v1.2
  • Miniplanets (homebrew game involving a 3D world mechanic)
    • Currently using Echo v1.21


Several smaller demos and music players have been created with Echo.

Specifications and features

  • Supports background music and sound effects at the same time
    • Sound effects do channel locking, meaning when they play, SFXs have priority above BGMs (channels unused by the SFX will continue to play normally in the BGM)
  • Support for all FM and PSG channels
    • All PSG Noise types supported
    • PSG volume envelopes supported (similar format to SMPS's PSG envelopes, but Echo's support looping)
  • PCM support
    • PCM playback rate is precisely 10.650 KHz -- The 2Hz difference between PAL and NTSC can be ignored.
    • Locking and Unlocking of FM 6 is automatically managed. PCM has priority.
  • FM Stereo support
  • Supports looping and non-looping BGMs, with a custom loop point
  • Variable tempo mid-sfx or mid-bgm, as a delay command can have any amount of tics.

Echo Formats

Echo Stream Format (ESF)

The Echo Stream Format (ESF) ìs a headerless music and sound effect format used by Echo. It contains commands and instructions that are read by Echo and passed onto the sound hardware. It has an extensive amount of commands / instructions, and thereby has its own article describing it.

Echo Waveform Format (EWF)

The Echo Waveform Format (EWF) is the format used by PCM samples. There isn't much to it, as PCM data is stored as unsigned 8-bit, at 10650Hz mono. The bytes specifying the waveform data contain values ranging from $00 to $FE. When a byte with value $FF is found, the end of the waveform is indicated.

Echo Instrument Format (EIF)

The Echo Instrument Format is the format used for FM instruments in Echo. EIF instruments are essentially raw dumps of the YM2612 registers. They consist of 29 bytes, where each byte belongs to a different YM2612 register. The registers are stored in the following order (assuming the first FM channel):

$B0                     -- Algorithm and feedback
$30, $34, $38, $3C      -- Multiplier and detune
$40, $44, $48, $4C      -- Total level
$50, $54, $58, $5C      -- Attack rate
$60, $64, $68, $6C      -- Decay rate
$70, $74, $78, $7C      -- Sustain rate
$80, $84, $88, $8C      -- Release rate and sustain level
$90, $94, $98, $9C      -- SSG-EG

Some bits are unused and ignored by the YM2612. In an EIF instrument, they *must* be 0, since Echo will rely on this for optimization purposes.

Echo Envelope Format (EEF)

The Echo Envelope Format (EEF) is the format used to describe volume envelopes for the PSG channels in Echo. This format was kind of an afterthought. Later it may be improved to provide at least some kind of RLE-like compression, but for now, this is it.

EEF instruments consist of a list of volume levels. Each byte represents a different volume level, and the value ranges from $00 (loudest) to $0F (quietest). Each byte represents one tick (i.e. 1/60th of a second), and looping is possible. The start of the loop is marked by a byte with value $FE, while the end of the loop is marked by a byte with value $FF. There must be at least one volume byte between them or Echo will hang. To make a non-looping PSG instrument, just put the last volume value inside the loop.

Also, since PSG instruments are required to use PSG channels and many people do not want to mess with them at all, here's a flat PSG instrument (i.e. no envelope): <code=asm>

$FE,$00,$FF

Tools

pcm2ewf

pcm2ewf is a program that converts raw 8-bit mono PCM files to the slightly different format used by Echo (EWF, see above). It can be downloaded from Sik's Tools repository.

tfi2eif

tfi2eif is a program that converts files from the TFM Music Maker FM instrument format to the instrument format used by Echo (EIF). It can be downloaded from Sik's Tools repository.

xm2esf

xm2esf is a program written by Oerg866. At the moment it is the only program available and working that can produce ESF streams. It is, in addition to that, by far the most advanced Mega Drive music tool available today that produces real-time usable output (ESF). To enable the user to enjoy the comfort of any XM tracker he is used to, the program takes XM files as input, and outputs a stream readable by Echo. The tool is very advanced as it supports all major XM effects, such as:

  • 0xx (Arpeggio)
  • 1xx (Portamento Down)
  • 2xx (Portamento Up)
  • 3xx (Tone Portamento)
  • 4xx (Vibrato)
  • 8xx (Set Panning, hint: only left, center or right)
  • Axx (Volume Slide)
  • Cxx (Set volume, very accurate formulae used to calculate volume for FM and PSG)
  • Dxx (Pattern break, always interpreted as D00)
  • Fxx (Sets amount of delay per row to the amount specified in xx)

Hint: keep in mind that to make the ticks per row ("speed" in some trackers, default is 6) match an Echo tick's length, set "Tempo" to 150!

Xm2esf uses an inputfile called xif. It is short for XM information file. It contains parameters, channels, instrument assignments, channel transposes, channel volumes, noise type, etc. taken into account when converting. Distributed with xm2esf is a program called xm2eifgui. It is a frontend for creating the necessary XIF files for conversion.

To compare: xm2smps, xm3smps and xm4smps were not able to use any XM effects other than Dxx. This is why music can be created much faster and easier with echo than it can be done in any other accessible (be it free or reverse engineered) sound engine today.

For now, this program runs on Microsoft Windows, Linux and FreeBSD (some modifications might be necessary, as this has not been tested but theoretically should be completely possible). Binaries are included for Win32 and Linux in the github repository, whereas FreeBSD users have to compile the program first.

Xm2esf is currently in release candidate stage, the latest version being v1.00 RC3 as of October 2, 2012, and is available from GitHub.

esfopt

Esfopt is a small program written in C++ by Oerg866. It takes an ESF stream as an input file, and outputs an optimized file.

It...

  • Removes redundant note-on events
  • Fusions multiple delay-events into one
  • Removes redundant load-instrument events
  • etc.

It can be downloaded from GitHub

Links / Download