Skip to content

shwestrick/sml-audio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Standard ML library for audio manipulation and I/O, designed to work well with the smlpkg package manager. Includes IIR comb and all-pass filters, artificial reverberation, mu-law compression, and I/O for .wav files (8- or 16-bit PCM).

This library is well optimized and---if compiled with MPL---highly parallel. Check out Sam's blog to learn about the algorithms implemented here!

Library sources

There are two source files:

  • lib/github.com/shwestrick/sml-audio/sml-audio.mlb
  • lib/github.com/shwestrick/sml-audio/sml-audio.mpl.mlb

The .mlb is for use with normal SML (e.g. MLton) and the .mpl.mlb is for use with MPL. Both supply the same interface, described below.

Interface

structure WavIO:
sig
  type sound = {sr: int, data: real ArraySlice.slice}
  (* A sound is a sequence of samples at the given
   * sample rate, sr (measured in Hz).
   * Each sample is in range [-1.0, +1.0].
   *)

  val readSound: string -> sound
  (* Read the contents of a .wav file. Currently supports 8-bit and
   * 16-bit PCM. If there are multiple channels, these are mixed
   * into a single channel.
   *)

  val writeSound: sound -> string -> unit
  (* Write a sound as a .wav file *)
end
structure Signal:
sig
  type sound = WavIO.sound

  val compress: real -> sound -> sound
  (* Essentially mu-law compression. Normalizes to [-1,+1] and compresses
   * the dynamic range slightly. The first parameter should be >= 1; use
   * larger values for higher compression.
   *)

  val delay: real -> real -> sound -> sound
  (* A tape-delay effect, or equivalently an IIR comb filter.
   * [delay ds a s] produces equally spaced echoes of the input sound
   * at intervals [ds] seconds wide. Each echo is attenuated by [a],
   * which should be in the range [0,1]
   *)

  val allPass: real -> real -> sound -> sound
  (* An IIR all-pass filter. The parameters are again: a delay (in seconds)
   * and an attenuation parameter (in the range [0,1]).
   *)

  val reverb: sound -> sound
  (* Applies a digital reverb effect to the input sound. Currently not
   * configurable, although this would be an easy change. Works best
   * at a sample rate of 44.1 kHz.
   *)
end

About

A library for working with audio in SML

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published