Introduction
Shorten is an early lossless audio compressor, written by Tony Robinson in the early
1990s at Cambridge University and later developed by his company SoftSound. His technical report
“SHORTEN: Simple lossless and near-lossless waveform compression” (CUED/F-INFENG/TR.156, December 1994) describes the idea:
a simple predictive model of the waveform, then Rice coding of what the prediction leaves, with an optional lossy mode
that zeros low bits. In the late 1990s it
became the standard format for trading live concert recordings online, before FLAC
took its place. Many old archives of live music are still in .shn
files. Version 3.x of the program (3.6.1 is the last, from 2007) was kept up by volunteers, who added AIFF support and the seek tables.
The program is free for non-commercial use. There is no written specification of the stream apart from the program’s source and the
report, which its own manual page calls wrong about the bit layout; the pages here follow the source.
Structure
A Shorten file starts with the four bytes ajkg and a version byte (0 to 3). The
rest is a single bit stream with no byte-aligned structure, stored as 32-bit words: a
header of variable-length numbers giving the
file type (8 or 16-bit integers of either sign and byte order, µ-law or A-law), channel count, block size, maximum prediction order, the number of
blocks the mean estimator averages and some skipped bytes, then a series of
commands: DIFF0 to DIFF3, QLPC and ZERO
carry a block of one channel (blocks go round the channels in turn), BLOCKSIZE and BITSHIFT change a setting,
VERBATIM carries bytes of the original file, QUIT ends the stream. A block’s samples are rebuilt from a
polynomial or linear prediction of the
previous samples plus Rice-coded differences. The original WAV or AIFF header is stored
verbatim in the stream so that decoding rebuilds the whole file, and the header is also where the sample rate is.
The bit stream itself has no index, so a player has to decode from the start to
reach a point in the middle. Shorten 3.x can add seek tables, appended to the file or
kept in a separate .skt file.
Sample files
The reader in the explorer was checked against:
- the six
.shnfiles that come with shorten 3.6.1 (mono and stereo, 16-bit, a WAV file and an AIFF file each, and the two of them with a seek table appended). The original.wavor.aiffis beside each: every decoded file, header and sound, is identical to it, byte for byte, and every entry of the two real seek tables agrees with the state of the decoder at that place; - FFmpeg’s test sample
luckynight-partial.shn(stereo, 16-bit, cut at 1 MiB, 396,544 frames of the music): every sample equals FFmpeg’s; - streams written by the real program: shorten 3.6.1 was built from its source and used as an encoder, and the streams it wrote were decoded by the
explorer and compared with what went in. 412 lossless streams (all eleven file types, versions 0, 1 and 2, one to three channels, linear prediction of order 3 to 32 and
the polynomial predictors, block sizes from 4 to 4,000, 0 to 9 mean blocks, WAV and AIFF input, skipped bytes) decode to exactly the bytes they were made from, and the
tree of each has no gaps. A re-check with about 650 more (short last blocks of 1 to 20 samples, silence in the middle, QLPC blocks of order 0, bit shifts, 9 channels, seek
tables of up to 150 blocks, the lossy options) found no difference. Of all 856 streams the real program wrote, the explorer’s rebuilt file equals the real program’s own
shorten -xoutput byte for byte for 828, the lossy ones (-r,-q,-n,-u) included; the other 28 (-p 12 -v 0: version 0 has no room for the prediction order) the real program cannot decode itself (the explorer reads them as far as the numbers stay valid and reports the rest as invalid or cut short); - 216 files made by a small encoder written for this check, which reaches what the real program’s options cannot: all four versions, all eleven file types, mono to eight channels and 300, block sizes from 1 to 9,000, linear prediction of order 1 to 64, 0 to 32 mean blocks, bit shifts, zero blocks, stored WAV and AIFF headers and trailers, skipped bytes, bytes and an ID3v2 tag in front, ID3v1 and APEv2 tags behind, and seek tables. Each decodes to the exact bytes it was made from, and FFmpeg decodes 134 of them (those it can read: a stored header, unsigned 8-bit or signed 16-bit samples) to the same samples.
The decoder is checked in pieces too: reading the file in windows of 700 bytes, starting the decoder from a checkpoint in the middle, and showing the sound in small parts give the same samples as decoding straight through.
Not described
These pages follow the source of shorten 3.6.1, its manual page, its test files and FFmpeg’s decoder. The parts below are not covered or not confirmed.
How the viewer shows what the format defines, and what is not part of it:
- The waveform is linked to the bytes of its blocks both ways: a click on it selects the bytes of the command that holds that frame, and a byte picked in the tree or the hex view moves the playhead to its frame. The blocks are of different sizes, so each command of the first channel is one unit of the link, none left out, whatever the length of the part. The Commands table and the tree give each command’s bytes too. The tree puts every byte in one node, but a command or field that starts and ends inside one byte has no byte of its own: it is listed in the text of the node that owns that byte, and the Commands table gives exact bit positions.
- The sound is shown in parts of 16 Mi samples (all channels), each its own waveform decoded from the nearest checkpoint, so that every frame of every channel can be seen and played. The size of a part is a choice of the viewer, not of the format.
- A stream with more than 2 channels is decoded in full, but its seek table cannot describe it: an entry of the format holds the history and means of channels 0 and 1 only (see the seek table page), so such a stream cannot be resumed from a table and none is checked. This is a limit of the format, not of the viewer.
- Seek tables of revision 0 (written by shorten 3.0 to 3.5.2; 3.6.0 raised the number after a bug fix) have the same header, 80-byte entries and trailer as revision 1: a table of a 2000 concert recording (8,059,716 frames, 315 entries, 25,224 bytes with its trailer) was read and every entry agrees with the stream.
- The original file is rebuilt as an entry (Original file) that opens in the explorer as the WAV or AIFF it was, with every chunk read there; the stored header and trailer are also read on the Stored header section of the stream’s own view.
Known, not yet covered
- None.
Unknown
- Reference: the revision 0 bug, as far as the sources show: the only change to the decoder code between shorten 3.5.2 and 3.6.0 is that
bitshift = 0;was added at the start of decoding. The program keeps onebitshiftvariable for both its encoding pass and the second, decoding pass that makes an appended table, so in 3.5.2 and earlier that pass began with the encoder’s last bit shift instead of 0. Until the stream’s first BITSHIFT command, the entries of such a table would then carry a wrong bit shift and means (and, through them, possibly wrong history). The ChangeLog says tables made by-k,-sor-Swere not affected. This is read from a diff of the two source trees; shorten 3.5.2 itself was not built. The effect is on the writer’s table only: the decoder and the stream do not depend on it, and the explorer’s Checks list every table entry that disagrees with the stream.
Links
Software
- shorten – the original program by Tony Robinson, maintained as 3.6.1 (source, manual page, test files; free for non-commercial use)
- FFmpeg – command-line tool that decodes Shorten, but cannot write it (Windows, macOS, Linux)
- VLC media player – free player for almost any audio or video file (Windows, macOS, Linux, mobile)