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 using 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cadenza_music-0.1.0.tar.gz.
File metadata
- Download URL: cadenza_music-0.1.0.tar.gz
- Upload date:
- Size: 107.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61a3ce4e923810b8734ccace95615a0224e6a2eeb5a5583c1da877009454650c
|
|
| MD5 |
66f1315b383b66c07eff8838c8411dac
|
|
| BLAKE2b-256 |
945f81839e460cf29ccb28763c727371d23969c756a435439e69b6df37646b16
|
File details
Details for the file cadenza_music-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cadenza_music-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c37afaeb0ce4515ed35917f56a465634269dc6cb3e49829bce2e0cf9f8a4cf1
|
|
| MD5 |
d3e19bc1e32a0c79f38dbbd054c230e7
|
|
| BLAKE2b-256 |
0e7f161eacbb4a5a9733a2c149fa683b352c62e204298cbc9d57caf9627cbec0
|