Skip to content

Repository files navigation

ape

golift.io/ape is a Go module that encodes and decodes Monkey's Audio (APE) files.

Cue-sheet splitting and copying existing frames exist in golift.io/xtractr. This module owns the codec. A checked encode item is implemented. Tests confirm encode by decoding the file with ffmpeg, and confirm decode by comparing the PCM.

Parity with Monkey's Audio 13.26

Encode

  • Version 3990 descriptor, header, and seek table
  • File MD5
  • Fast (1000), 73728 samples per frame
  • 16-bit little-endian PCM
  • Mono
  • Stereo, including mid/side, silence, and pseudo-stereo
  • Multiple frames and a short final frame
  • Flag so a decoder can build a WAV header
  • Normal (2000), neural-network filter 16/11
  • High (3000), neural-network filter 64/11
  • Extra high (4000), filters 256/13 then 32/10, frame size ×4
  • Insane (5000), filters 1280/15 then 256/13 then 16/11, frame size ×16
  • 8-bit
  • 24-bit
  • 32-bit integer
  • 32-bit float (ffmpeg 9 cannot decode either 32-bit form)
  • 3 to 32 channels (ffmpeg only decodes mono and stereo)
  • Keep an original WAV, AIFF, W64, SND, or CAF header and footer
  • APE tags
err := ape.Encode(file, pcm, ape.Stream{
    SampleRate: 44100,
    Channels:   2,
    Bits:       16,
}, nil)

NewEncoder writes the same file from PCM chunks. The sample count has to be known first, because the seek table is written in front of the audio.

enc, err := ape.NewEncoder(file, stream, samples, nil)

Decode

  • Version 3990
  • File versions 3.95 through 3.97
  • File versions 3.93 and 3.94 (needs testing)
  • APL image links (DecodeFile follows the link and returns that sample range)
pcm, stream, err := ape.Decode(file)

NewDecoder reads the header and returns one PCM frame at a time. The caller owns the reader.

dec, err := ape.NewDecoder(file)
frame, err := dec.Next()

pcm is interleaved little-endian samples. A nil options value selects fast compression and the usual 73728-sample frame.

Decode reads a version 3990 file, or a 3.93–3.99 file, and returns that PCM. DecodeFile does the same for a path, and if the path is an APL link it opens the image and returns only the linked sample range. Versions before 3.93 are not decoded. 3.93 and 3.94 use the older predictor; that path is in place and still needs a real file to check.

This module is BSD-3-Clause. See LICENSE.

About

Go module to encode and decode Monkey's Audio (APE) files.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages