package llama_interactive

  1. Overview
  2. Docs
Visualization and live interaction for Llama synthesizer library

Install

Dune Dependency

Authors

Maintainers

Sources

0.0.1_rust-deps-vendored.tar.gz
sha256=2fb4da5b4478409118b6267f26c0c7f64f10c85d02cbb73c8ead648fc430e860
sha512=ab238268cf22fbb62d5955f849b1837bbee4a12470dde29feb0bf5237023daf01ce6d52dfad30e871948bde13b18808376d254dee90bfeeb82a8c2619d459a8f

Description

Published: 07 Jul 2023

README

Language for Live Audio Module Arrangement

The llama is a domesticated South American camelid.

About

llama is a library for building software-defined modular synthesizers in a declarative style. It can be used to implement programs that generate audio using components commonly found in synthesizers such as oscillators, envelope generators, and low/high pass filters. It can also be used from utop or other ocaml repl environments to perform music live.

Llama in Action

Videos showing off some of the example programs:

Getting Started

You will need to install rust to build the low level library that reads wav files and talks to the sound card. These parts are written in rust because rust has really good libraries for wav decoding (hound) and sound card interaction (cpal).

Then you should be able to build and some example programs:

$ dune exec ./examples/polyphonic_events.exe
$ dune exec ./examples/random_pentatonic.exe
$ dune exec ./examples/echo_effect.exe

Interactive Demo

Run dune exec examples/interactive.exe and then use the top two rows of letter keys on your keyboard to play music. The mouse position controls the frequency cutoff and resonance of a low-pass filter. Hack examples/interactive.ml to change how it sounds!

Concepts

The 'a Signal.t type represents a buffered stream of values of type 'a and is central to the API of llama. These are used to send audio and control signals through a network of components. For example:

(* This is a complete example. Paste this into a file and run it to see what
   it does, or just run:

   $ dune exec ./examples/from_readme.exe
*)

open Llama
open Dsl

(* [osc] represents a signal whose value varies between -1 and 1 according
   to a 440Hz sine wave. *)
let osc : float Signal.t = oscillator (const Sine) (const 440.0)

(* [note_clock] represents a signal whose value is either [true] or [false]
   which changes from [false] to [true] twice per second, and spends 30% of the
   time on. This is often used to communicate the fact that a key is pressed to
   a module that responds to such events. *)
let note_clock : bool Signal.t =
  pulse ~frequency_hz:(const 2.0) ~duty_01:(const 0.3)

(* [envelope] is a signal which is 0 while its [gate] argument is producing
   [false] values, but which raises to 1 over the course of [attack_s] seconds
   when [gate] transitions to [true], and transitions back to [false] when
   [gate] transitions to [false]. Note that even though it is also a [float
   Signal.t] like [osc] is, it doesn't contain audio data. Instead an envelope
   is typically used to modulate a signal in response to a key press, which we
   are simulating here with [note_clock]. *)
let envelope : float Signal.t =
  asr_linear ~gate:note_clock ~attack_s:(const 0.01) ~release_s:(const 0.2)

(* Multiply the oscillator with the envelope to produce a repeating
   burst of volume which gradually tapers off twice per second. *)
let output : float Signal.t = osc *.. envelope

(* Play the sound! *)
let () = play_signal output

Example Live Session

Start a utop session with the Llama module available by running dune utop, then enter this into the utop repl.

open Llama.Live;;

(* Define a sequence of frequencies and durations. *)
let steps = [ Some (110.0, 0.1); Some (123.47, 0.1); Some (98.0, 0.2); None ]
|> List.map (Option.map (fun (freq, period) -> { value = const freq; period_s = const period }));;

(* Create a sequencer to play the notes. *)
let { value = freq; gate } = sustained_step_sequencer steps (clock (const 4.0));;

(* Create an oscillator to buzz at the frequency selected by the sequencer. *)
let osc = oscillator (const Saw) freq;;

(* Create an envelope generator to shape the volume according to the gate. *)
let env = asr_linear ~gate ~attack_s:(const 0.01) ~release_s:(const 0.2);;

(* Use the envelope to control the volume of the oscillator. *)
let amp = osc *.. env

(* Create a player returning a `float t ref` which can be set to the signal we want to play. *)
let out = go ();;

(* Play! *)
out := amp;;

(* To silence playback you can change the output to [silence]. *)
out := silence;;

Dependencies (4)

  1. conf-pkg-config build
  2. tsdl >= "1"
  3. llama = version
  4. dune >= "3.0"

Dev Dependencies (1)

  1. odoc with-doc

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.