On this page:
7.1 Program use
7.2 Program options
7.3 Racket functions
encoder-test
encoder-test-opus
encoder-test-flac
9.2.0.5

7 Encoder Test Program🔗ℹ

Hans Dijkema <hans@dijkewijk.nl>

 (require racket-audio/encoder-test) package: racket-audio

The racket-audio/encoder-test module is a small integration test and command-line wrapper around racket-audio/audio-encoder. It is useful for checking that the native encoder libraries are available and that a concrete source file can be transcoded to Opus or FLAC.

The module depends on "tests.rkt" for its default input file. For portable tests, pass an explicit input file.

7.1 Program use🔗ℹ

Run the test module directly to encode the default test file to a temporary Opus file:

racket encoder-test.rkt

Useful command-line examples:

racket encoder-test.rkt --encoder opus --input input.flac --output output.opus --bitrate-kbps 224

 

racket encoder-test.rkt --encoder flac --input input-96k.flac --output output-48k.flac --sample-rate 48000 --bits-per-sample 24 --compression-level 8

The program prints the selected encoder, settings, percentage progress, and a summary of the result hash returned by audio-encode. Progress is based on input frames read from the decoder.

7.2 Program options🔗ℹ

The command-line wrapper accepts these options:

  • -e, encoder: opus or flac.

  • -i, input: input audio file.

  • -o, output: output audio file.

  • sample-rate: target sample rate or source.

  • bits-per-sample: target FLAC bit depth or source.

  • bitrate-kbps: Opus bitrate in kbit/s.

  • compression-level: FLAC compression level.

  • no-tags: disable copying tags and embedded pictures.

7.3 Racket functions🔗ℹ

procedure

(encoder-test input-file    
  output-file    
  encoder    
  settings    
  [#:copy-tags? copy-tags?])  hash?
  input-file : path-string?
  output-file : (or/c path-string? #f)
  encoder : (or/c symbol? string?)
  settings : hash?
  copy-tags? : boolean? = #t
Runs one encode test and prints a human-readable summary. The return value is the result hash produced by audio-encode. When output-file is #f, a temporary output path is chosen from the encoder kind.

procedure

(encoder-test-opus input-file    
  [output-file    
  #:bitrate-kbps bitrate-kbps    
  #:sample-rate sample-rate    
  #:copy-tags? copy-tags?])  hash?
  input-file : path-string?
  output-file : (or/c path-string? #f) = #f
  bitrate-kbps : exact-positive-integer? = 160
  sample-rate : (or/c exact-positive-integer? 'source) = 'source
  copy-tags? : boolean? = #t
Encodes input-file to an Opus file using encoder-test. The bitrate argument is expressed in kbit/s and is converted to the 'bitrate setting used by the Opus backend.

The sample-rate argument is normally 'source. Opus encoding passes the input rate to libopusenc; libopusenc performs the internal resampling required for Opus output.

procedure

(encoder-test-flac input-file 
  [output-file 
  #:compression-level compression-level 
  #:sample-rate sample-rate 
  #:bits-per-sample bits-per-sample 
  #:copy-tags? copy-tags?]) 
  hash?
  input-file : path-string?
  output-file : (or/c path-string? #f) = #f
  compression-level : exact-nonnegative-integer? = 8
  sample-rate : (or/c exact-positive-integer? 'source) = 'source
  bits-per-sample : (or/c exact-positive-integer? 'source)
   = 'source
  copy-tags? : boolean? = #t
Encodes input-file to a FLAC file using encoder-test. When sample-rate or bits-per-sample is not 'source, the FLAC pipeline requests the corresponding output format from racket-audio/audio-encoder.