Skip to main content

Exploration of music theory.

Project description

Cadenza

Experiments

This repository contains various loosely related experiments related to music theory and audio engineering. Below are some brief descriptions of the experiments.

Chord parser

The chord parser evaluates a string representation of a chord. It parses out the chord quality, extensions, and alterations. This works for simple chords like C or more complex chords like F#maj7b5/D.

Overtone/tremolo synthesizer

The synthesizer decomposes a voicing of a chord into frequencies and synthesizes them into an audio waveform. This component also augments the pure tones in the chord with harmonics of the fundamental. The synthesized audio has the timbre of a pipe organ.

The synthesizer also supports tremolo of various speeds. There is a preset for a Hammond organ sound that combines high frequency tremolo with a low frequency Leslie tremolo effect.

Just intonation optimizer

By default the synthesizer uses a reference frequency of 440.0 Hz (for the pitch A4) to compute other pitches. All pitches are tuned with equal temperament. If you want to convert a chord into just intonation you can run the optimizer to approximate simple ratios for all intervals in the chord.

A video of oscilloscope visualizations of just intonation vs equal temperament

Chord library

You can find a collection of songs with chords transcribed in songs.yaml.

Installation

Install from PyPI:

pip install cadenza-music

Most commands (playback, synthesis, filters) need the audio extra, and the --visualize flag needs the plot extra:

pip install "cadenza-music[audio,plot]"

The import name and cz CLI command are unchanged:

import cadenza

To work on Cadenza itself, clone the repo and use uv:

uv sync

Usage examples

Chord command

Play a single chord

# Play a chord
cz chord A

# Play a different voicing/inversion
cz chord Bbm7 --inversion 2

# Change the octave (default is 4)
cz chord G#m7 --octave 3

# Transpose a chord up or down by a number of semitones
cz chord G#m7 --transpose 2

# Change the duration of the notes (default is 3 seconds)
cz chord Em --duration 1

# Add pipe organ overtones
cz chord F#dim --overtones

# Add tremolo
cz chord E7b9/G# --tremolo

# Apply a lowpass filter
cz chord Cadd6 --overtones --lowpass 120

# Analyze a chord without playing it
cz chord Dmaj7 --no-play

# Save chord audio to a file
cz chord F/G --filepath audio.wav

# Save chord audio to a file with a different sample rate
cz chord Cmaj7/A --filepath audio.wav --sample-rate 48000

# Visualize the mel spectrogram
cz chord A7b5sus2 --visualize

Chords command

Play a series of chords

# Play several chords in a loop
cz chords --tempo 60 --repeat 3 "E C#madd9 Amaj7"

Song command

Play a full song. The song command takes a query followed by a path to a library YAML file (see songs.yaml).

# Play a song by title
cz song homesick songs.yaml

# Change the octave (default is 4)
cz song homesick songs.yaml --octave 5

# Transpose a song into a different key by a number of semitones
cz song homesick songs.yaml --transpose -2

# Change the tempo (in beats per minute)
cz song homesick songs.yaml --tempo 120

# Change the duration of each chord
cz song homesick songs.yaml --chord-duration eighth

# Change the note associated with one beat
cz song homesick songs.yaml --beat-duration half

# Add pipe organ overtones
cz song homesick songs.yaml --overtones

# Add tremolo
cz song homesick songs.yaml --tremolo

# Add reverb
cz song homesick songs.yaml --reverb

# Apply a highpass filter
cz song homesick songs.yaml --overtones --highpass 450

# Save song audio to a file
cz song homesick songs.yaml --filepath audio.wav

# Save a song to a file without playing it
cz song homesick songs.yaml --filepath audio.wav --no-play

# Save song audio to a file with a different sample rate
cz song homesick songs.yaml --filepath audio.wav --sample-rate 48000

# Visualize the mel spectrogram
cz song homesick songs.yaml --visualize

Optimize command

Optimize a chord from equal temperament to just intonation

# Optimize a chord
cz optimize C

# Turn on debug logging to see the optimization trace
cz optimize C --debug

# Adjust the learning rate to speed up convergence
cz optimize C --debug -lr 0.05

# Optimizing chords with complex frequency ratios requires adjusting the granularity of optimization
cz optimize Cmaj7 --debug --max-denominator 12

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cadenza_music-0.1.1.tar.gz (107.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cadenza_music-0.1.1-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file cadenza_music-0.1.1.tar.gz.

File metadata

  • Download URL: cadenza_music-0.1.1.tar.gz
  • Upload date:
  • Size: 107.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for cadenza_music-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8939aeef09de16bb780c6234c14c3a7feccd59bf4feb77b450391a8fc22d65f7
MD5 56f5c3d5d11c1f38a2bfd0984d1ebe76
BLAKE2b-256 22d9f69127a34982db5f83615f3cbb6bb4bbf995a6657d0b2eb7d19a65ba8967

See more details on using hashes here.

File details

Details for the file cadenza_music-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cadenza_music-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 36.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for cadenza_music-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8685252475b0a04e3354e413829487a018ae67873b74ab5f513d9f2dbc28c4ed
MD5 37a22559199ca3fdc4ca5f52b972588b
BLAKE2b-256 096e00ea88e9e55f414d83e9029ad8b4a423f6a0ff3e2357902d3e596ec93898

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page