Coding 2026-04-08
All right, I said I was going to try to do something, and here's something. I took longer than I would have liked with some paperwork tonight. So I'm just going to lay out some plans.
I've been thinking more about audio synthesis and music, and calendar systems. Really getting into sinusoids, I guess. It's getting late, so I'm going to take some quick notes for later:
- Many instruments can be approximated by a combination of pure harmonics.
- Pure harmonics can be obtained via additive synthesis, or via phase modulation.
- Phase modulation is of interest because that's how many iconic synth sounds are produced.
- Additive synthesis can be used to produce negative harmonics, and other inharmonic sounds.
- Obviously inharmonic sounds are important for instruments like bells and struck bars or plates.
- Subtle inharmonicity can be used to change the consonances and dissonances of intervals in a given tuning system.
- Either approach should be not-too-hard to implement via linear interpolation of a wavetable of a sine function, or simply calling numpy.sin directly.
- Another aspect of an instrument is its envelope; I tried implementing ADSR before, and it wasn't clear whether it was actually doing anything.
- I'm planning to work with numpy arrays, and initially just write the results to a wav file, but also look into streaming.
- Would like to work with notes in a somewhat MIDI-like way.
- Overlapping them, I've thought of using the heapq module to sort upcoming notes by onset time, and playing notes by time to finish contributing; this would potentially be a workable basis for real-time-ish effects.
- Possibly notes could be separated into tracks, which could then apply pink noise offsets to timing and amplitude.
- I want to start with writing a public-domain song to a file, using sine waves with no envelope.
- Near-term improvements include envelopes, additive synthesis (including naturalistic inharmonicity) and phase modulation, streaming, and pink noise.
- Further-term improvements include alternative scales, and inharmonics to match alternative scales.
- I'll keep Numba in mind for this, since it's served me so well in the context of image processing, but I want to hold off on writing things for it right off the bat; I'd rather rewrite for Numba if I see that things are too slow.
Anyway, it's super late, so I'm just going to wrap things up now.
Good night.