Hacker News new | past | comments | ask | show | jobs | submit login
How to create minimal music with code in any programming language (zserge.com)
265 points by pmarin on Oct 30, 2020 | hide | past | favorite | 78 comments



A random suggestion to make for nicer, more interesting music: the article takes pitches from a table of equal tempered note frequencies relative to A440:

> For example, here’s a familiar riff “E B D E D B A B”. It uses only 4 notes - D and E from one octave and A + B from the other, lower octave. If we look at the note frequency table, the pitches of those notes in octaves 5 and 4 would be 659.2Hz (E), 587.3Hz (D), 440Hz (A) and 493.8Hz (B).

Instead of equal tempered pitches (which are generated by repeatedly multiplying by the 12th root of 2), use pitches that form whole number ratios with respect to the root of your key.

A decent 12-note chromatic scale would be something like 1:1, 16:15, 9:8, 6:5, 5:4, 4:3, 45:32, 3:2, 8:5, 5:3, 15:8, and 2:1. So, for instance if your root is C=256 hz, you'd have 256 hz for C, (25616)/15 for C#, (2569)/8 for D, and so on. This is a just intonation (JI) scale. An advantage of JI is that the musical intervals blend with each other better, whereas the advantage of equal temperament (ET) is that you can use any note as the root and change keys on the fly without causing problems. If you're doing electronic music, though, there's a lot less reason to stick with ET: you can always just multiply your whole tuning table by a constant if you want to switch key.

JI scales can be made with any ratios: the above maps well to most conventional music, but there's no rule that you have to limit yourself to 12 steps per octave. Using the harmonic series is another option, or adding in ratios that have a 7 in them.


I've had lots of fun experimenting with JI, but I think you're greatly understating the difficulty of using a scale like that for conventional music! Basic chords (like ii) are horribly out of tune due to the syntonic comma, and while you can retune things as you go (like a singer or string player would), it takes a lot of finesse -- the IV ii V I progression is tricky, and if you're not careful you create a comma pump, transposing things down just a little bit by the end.

In practice, 5/4 major thirds are at the very low end of acceptible major thirds, with the Pythagorean 81/64 at the top. I find slightly sharper major thirds to sounds better generally [for western common practice harmony].

An interesting system, which I wish I've had more time experimenting with before suggesting it, is 55EDO, using a system where each whole tone is broken into nine equal parts; a five part interval is a major semitone and a four part interval a minor semitone. The major scale is made from whole tones and two major semitones. A C# is slightly flatter than a Db in this system, and you only have to worry about enharmonics (old meaning: futzing with the small distances between similar pitches) in complicated chord progressions.

Not suggesting not to try JI of course, I'd recommend experimenting with it (including the suggested 7-limit JI as well)! Scales in the end can only be judged in the context of what you want to do with them -- they certainly all have tradeoffs.


Out of curiosity, how do you go about auditioning these systems in your own practice? Are you a performer playing an instrument by ear? Are you sequencing sounds in a DAW? Or are you tuning your sounds in a programming environment similar to the linked article?

I ask because I'm an electronic musician working in a DAW (Ableton mostly) and am trying to find the best workflow to start exploring these concepts. Ideally, there would be an interface for switching between tuning systems that's as easy as drawing in a time-signature change, but micro-tuning seems to be a low priority for most DAWs. The only one I know to even begin integrating alternate tuning systems is Logic, and those settings are tucked away deep in the preferences.

Does anyone here have a resource for starting to familiarize oneself with how to integrate alternate tunings into their composition? The simpler the better, I suppose. As soon as one sets their foot into the world of alternate tunings you're usually flooded with 40+ tunings. As someone who's worked in Equal Temperament their whole life I would like to pick ONE system and really drill down on it until I get a grip on how to integrate these tunings into programs that are built for ET.


I won't pretend to be an expert on the subject, but I think it's more a synth problem than a DAW problem. VST, for example, deals in 12TET, so the best a DAW could do to support alternate tuning systems would be to translate each pitch into a 12TET pitch + offset. Which is feasible, but like, not a feature I would expect to find. (I would be curious to know if any DAW actually can do this.)

Personally I have experimented with alternate tuning using SuperCollider. It definitely doesn't qualify as simple, but the upside of code-as-music is that if you can imagine it and express it, you can do it. I recently made a track that switches tuning systems periodically by responding to a particular MIDI CC. I have to imagine that those sorts of shenanigans would be pretty hard without some code.

To live a bit more in Ableton-land, you might be able to find a Max device that does something similar-- maybe a MIDI insert that converts MIDI notes to note + pitch bend?


VST does not deal in 12TET. VST2 delivers MIDI data to a plugin, which most plugins (not all) will interpret in 12TET. But the plugin may offer its own mechanism to change the mapping between MIDI note numbers and frequencies, or it might use the MIDI Tuning Standard to do so.

The only role for a DAW in this comes if the DAW labels MIDI data with note names. If you're not using 12TET, these labels will likely be wrong. But since MIDI itself doesn't inherently use 12TET, just 128 notes numbered from 0 to 127, any DAW can still be used to work in non-12TET tunings and scales.


Since I knew someone on HN would be pedantic about this, I looked it up before I posted anything:

> NoteOnEvent Struct Reference

> Detailed Description

> Note-on event specific data.

> Pitch uses the twelve-tone equal temperament tuning (12-TET).

https://steinbergmedia.github.io/vst3_doc/vstinterfaces/stru...

You can, of course, implement a synth that doesn't follow the spec, if you like.

(This documentation is for VST3, which does not use MIDI. VST2 has been deprecated for years.)


VST2 was officially deprecated last year by Steinberg. The majority of plugins at this point are still in VST2 format.

You missed the tuning field in the struct, which effectively makes it use 12TET only as a reference, not as the only tuning standard.


Perhaps you missed my original comment where I explicitly referred to using a 12TET pitch + offset? What you claim I missed is literally what I said.


I read through the MIDI 1.0 spec last night, and I was very surprised to see it said nothing about default note number to pitch mappings, other than that 60 is middle C. The only time frequencies seem to come up is for the (optionally implemented) messages to retune individual notes! (I'm not sure I have a copy of the whole thing, so I could be wrong.)

From what you say, it seems like the VST2 spec sets a standard scale to fill in this gap, which is interesting. It certainly would help with interoperability.

Anyway, I learned something from the clarifications arising from each of you correcting each other :-) (Though it's probably not worth continuing discussing whether there's any difference at all between "deals in 12-TET" and "uses 12-TET only as a reference" since you both seem to mean the same thing by these by now.)


MIDI doesn't explicitly mandate 12-TET, but attempting to do anything more complicated than a mild re-tuning of a 12 note-per-octave scale usually results in a poor user experience. For instance, it's no longer plug-and-play because the instrument and the synthesizer need to agree on a what each note means, and there isn't a way to communicate that. (Well, technically there is: the Midi tuning standard, but it's rarely implemented.) There's also the problem of the number of notes: 128 often isn't enough.

A standard workaround if you want to do microtonal MIDI is the one note per channel trick: each simultaneously-sounding voice is on its own channel, which can be independently pitch-bent.

For instance, if you want to play a note 10 cents above middle C, you pick a MIDI channel you're not using right now, send a pitch bend command to raise it by 10 cents, then send a note-on for note 60.

This gives you 16-voice polyphony (because MIDI has 16 channels). The downsides are that this only works on multitimbral synths (i.e. it works with most "romplers" but very few analog synths), and you need a convenient way to set all the channels parameters the same.

The one note per channel trick can also enable individual note volume swells by using channel volume. One note per channel has been standardized recently in MIDI as MPE.

There's also MIDI 2.0 now, which has per-note pitch bend among other features. Time will tell if it actually gets widely adopted, and whether synths actually implement the full spec or if they leave out features that only a small minority of their users care about.


I've mostly used Pure Data patches or a C program I wrote that interfaces with Jack. I like Johnston's notation for extended just intonation, and the C program lets you press buttons on your MIDI controller to alter notes by the various commas/accidentals. Eventually I'd like to have a sequencer for it...

His idea was actually pretty cool: you start out with an F, C, and G major chord tuned just like in the ratios a couple comments up, which gives you an entire C major scale, and then there are a handful of accidentals. The syntonic comma (+) is what turns A into the fifth above D rather than a third above F, # applied to the top note of a major third turns it into a minor third (defined by the division of a major triad into a major and minor third), 7 applied to a Bb lowers it to coincide with the 7th harmonic of C, 11 applied to an F slightly raises it to be the 11th harmonic of C, and so on. Each accidental also has an inverse operation. With just these accidentals above, the system is able to uniquely represent every ratio whose prime factorization contains numbers up to 11.

Unfortunately MIDI is not so good for non-12-EDO. Some instruments support SYSEX messages with per-note-number alterations. There's also a program out there, forgot the name, which takes a MIDI channel and splits it across multiple channels to apply independent pitch bends per note when there's polyphony. I hope MIDI 2 will help...

I don't know much about real DAWs, though there are some Adam Neely videos exploring microtonality and alternative tuning systems where he pulls up some plugin -- maybe that will help you find something.

Having seen a video of Jacob Collier's projects, it seems like he might do microtonality using only pitch correction. I think if you're familiar with your commas -- there aren't many after all -- you just learn how many cents you need.

Edit: I thought to look up Sevish, a microtonal musician who seems to actually care about making good music, and he has some resources on his site: https://sevish.com/music-resources/


> There's also a program out there, forgot the name, which takes a MIDI channel and splits it across multiple channels to apply independent pitch bends per note when there's polyphony. I hope MIDI 2 will help...

Perhaps you mean alt-tuner? http://www.tallkite.com/alt-tuner.html


Some VST instruments support alternate tunings. Here's a list:

https://en.xen.wiki/w/List_of_Microtonal_Software_Plugins


You can use jack or soundflower to pipe audio into Live from the outside.


For ii, I find it helps to add 10:9 to the list I gave earlier, I just omitted it to stay within the familiar framework of 12 notes-to-the-octave. 12 really isn't enough, though, in a lot of cases.

Here's a visualization I like, that uses 22 notes: https://www.youtube.com/watch?v=jA1C9VFqJKo

Speaking of large-number EDOs, some people I know locally are doing guitar conversions to 41-EDO. The trick that seems like it absolutely shouldn't work but it does is to omit half the frets, so that only half of the notes are available on each string.

https://en.xen.wiki/w/The_Kite_Guitar


Oh, that's a great visualization! (And that's a wonderfully low-tech way of animating it.) I appreciate the Johnston notation, too, which made it easy for me to follow.

The Well-Tuned Piano [1] also has a really nice lattice, though the Wikipedia page doesn't reflect this yet. (The B7+ should just be an A. I think scholars have taken La Monte Young too literally when he said everything was an overtone of an extremely low Eb.) Here, just drew a picture: https://imgur.com/S5OndL6.png (light gray is the piano key it's mapped to). It's illuminating taking the "chords" in Kyle Gann's paper and seeing them on this lattice, which shows major and minor septimal triads in each triangle.

[1] https://en.wikipedia.org/wiki/The_Well-Tuned_Piano


> comma pump

Well this is a fun rabbit hole!

https://en.xen.wiki/w/Comma_pump


One thing to note is that you don't have to always play a note at the same frequency, even in the same piece.

On the violin, it's common to adjust intonation to different concerns: to bring out multiple voices, to put emphasis on the melodic line, or to nail the chords.

I don't know how hard it would be to do this digitally though. I imagine it would be quite tedious to work on a fretless digital music software.


Maybe a decade ago, I read a story here on HN where somebody was analyzing a singer's audio to detect how close their pitch was, coming to the conclusion that the root was spot on but other notes were slightly sharp or flat.

Someone in the comments pointed out that the analysis was done assuming even temperament, and the singer was actually totally nailing just intonation.

It's one of those anecdotes that has stuck with me since as a reminder to try to not get tunnel vision on a specific metric.


It sounds like someone with a frequency measurement went to apply it to music without speaking with musicians. As long as they learned something eventually, I guess :)


Actually, the other way around really. Someone looked up the musical information and measured and found a discrepancy. Given that most western music does in fact use 12TET, the claimed "out of tune-ness" was reasonable to note. The problem is that there are cultures and genres of music that do not use 12TET. In the west these are rare, and many musicians would not know about this. But the measurer had the misfortune to be measuring music that did, and thus was incorrect.


I think Just intonation, or an approximation to that, is what people are instinctively using, unless they are consciously tuning themselves to a piano.

It sounds much more "in tune" to the ear, because of the nice ratios.

It really wouldn't surprise me that raw recordings of many singers are in fact more just than equal temperament.


This makes sense, but it would imply that they have "instinctively solved" the fundamental problems with modulation and harmony that just intonation creates. This seems unlikely.


You might find the book "How Equal Temperament Ruined Harmony" interesting, which presents a reasonably strong case that pre-1900s western music treated enharmonics as distinct pitches ("enharmonic" in the old sense seems to have referred to the distinction). Singers knew about major and minor semitones, and they knew where to place commas. Though, no one seemed to go as far as doing full just intonation due to various kinds of obvious and non-obvious impracticalities.

All in all, I think it's safe to say that string players and singers prefer slightly flatter thirds in harmonies than 12-EDO -- which is what the above amounts to -- and deal with commas accordingly.


Realistically, they probably just sing an approximation that's close to JI while unconsciously allowing the pitch to drift a little bit so that comma pumps aren't a problem.

That seems more plausible than that people naturally sing in an artificial tuning based on repeated multiplication of the twelvth root of two, even if that's the musical context that people are most exposed to these days. Those whole-number ratios are just too good to resist, even if a singer isn't fully aware of what they're doing.


I think you have a misconception, western singers use "non 12TET" very well


Perhaps you could name some of the well known pieces in the western canon since the advent of 12TET that are written for non-12TET tuning/scale systems. Certainly there are folk traditions that veer closer to non-12TET but there's very little music for voice and instrument in western culture that isn't 12TET because so many of the instruments are tuned to 12TET.


Barbershop quartet is the style that comes to mind where it's used all the time


I did not know that - thanks very much for the enlightenment!

My wife and 1 daughter both sing in acapella groups, but their various different groups over the years have never done anything in JI, although my wife also sings Balkan songs which are whole other story of course.


I don't think that would change anything.

Maybe a portion of university-trained musicians might know it from their music history classes (or maybe they're Adam Neely viewers), but I believe most professional and amateur musicians have no idea about just intonation or equal temperament.


Thats funny. I am generally surprised how singers actually practise with a piano player (which seems to be done here often), since the piano is equally tempered. Wouldnt it make more sense tonpractise with a violin player?


I don't think it really matters: the piano or violin just offer a reference notes the vocalist needs to be able to match. For example, even though the piano is a limited instrument (frequency wise) it's perfectly possible for a violin player to practice "against" a piano. In the end, whatever the violinist plays is never going to be perfect. There are basically 3strategies to cope with that: micro-adjustments (correcting), add vibrato (masking) and stop playing that note and move to another note.


I mean in some sense yes, but more importantly, you probably want to practice with a harmony instrument, i.e. one that can play full chords, which probably means piano, guitar... I can't think of any such instruments where it's easy to tune on the fly as with a violin.


I like trying to make electronic music as a hobby, and I totally agree with your thoughts about just intonation. There's no reason to not at least try it once if you're making electronic music. I personally find it does often produce results that sound better or more interesting to me; chords and intervals are definitely (by definition and subjectively) more consonant and "pure".

However, not only must one adjust the tuning each time you want to switch keys, just intonation actually doesn't work for all intervals even within a single key: https://music.stackexchange.com/a/22017. This is something I often don't see mentioned.

If you're programming the music entirely in software, you could avoid this by basically forgetting about the notion of notes/pitch classes/scales/keys entirely and focus solely on the frequencies and ratios. I wouldn't be surprised if a lot of the best music of the distant future is partly created in such a way (by humans, AIs, and/or both working together). But if you're working in a DAW, the best option may be to consider a few intervals off-limits, if you want everything to be pure.


Regarding the "D-minor problem", the way I look at it is that problem is not with just intonation per se, but with how C major is defined and how it is used in equal temperament vs JI.

The probelm is solved in JI by re-defining the key of C major to include both 10:9 and 9:8. So, instead of one D, you have two slightly different Ds.

Equal temperament just uses a note almost half way in between to play the role of both notes, but that's just an approximation. (This double-role can be useful for certain chord progressions that work out in equal temperament even though mathematically they shouldn't.)

JI definitely becomes a lot more useful and interesting if you allow for more than 12 notes per octave. I'd consider 16 to be about a reasonable minimum for conventional 5-limit music, but having more opens up more possibilities.

In the context of the original article which seemed to be geared more to just implementing some sort of basic sequencer or picking random notes from a scale, I think picking notes from a JI scale rather than 12-tone equal temperament is an easy way to do something different from what everyone else does with a good chance of having a result that sounds good. More serious music composition or performance in JI generally requires more awareness of the various quirks of JI versus equal temperament. I do wish tooling was better; in some ways, MIDI kind of locked everyone into 12-tone equal temperament, and getting out of that rut is going to require some kind of large change. (MPE and Midi-2.0 are possibilities; time will tell if they pan out.)


Something that works rather well is taking ratios a/b with, say, a and b in the range 2 through 10, and then changing a or b by a small amount and avoiding a=b. You get some nice harmonies if you have multiple of these running simultaneously in a few octaves.


I've been using MPE with the Roli Seaboard and Bitwig and it's definitely extremely expressive and fun to use. Highly recommended.


Equal tempered tuning dissonant on oscilloscope:

https://www.youtube.com/watch?v=6NlI4No3s0M

Exploring the lattice, JI and ET:

https://www.youtube.com/watch?v=I49bj-X7fH0

https://www.youtube.com/watch?v=M5OJgsHXSmY

> the Tonnetz (German: tone-network) is a conceptual lattice diagram representing tonal space first described by Leonhard Euler in 1739.

https://en.wikipedia.org/wiki/Tonnetz


Just intonation is interesting, but it sort of explodes the composition complexity, because for each note the next (or concurrent) note can be based either on some root note or the current note. For example going up major thirds in C would be C-E-G#, but with just intonation you have to make the choice if that last note should be (C * 5/4) * 5/4 , or C * 8/5. The magic of equal temperament makes the distinction go away, so things are simpler.


Only if you insist on using harmony and/or modulation. There's plenty of musical cultures around the world that don't use harmony to the extent that western music does (if at all), and in these cultures, the issues caused by just intonation (or any tuning/scale system, really) are not anywhere near as much of a problem (if the exist at all).


This is a great article! I've been interested in music software and hardware for decades and my lockdown hobby has been finally spending the time to really dig into it. It is both very challenging and very rewarding.

If you want to go a little deeper than the article, here's a few more notes:

The way the author generates the sawtooth and square waves is "analytically". That means treating them like a function of time and simply calculating the waveform position each point in time. As you can see, it's really simple. Unfortunately, it also introduces a ton of aliasing and will sound pretty harsh, especially at higher pitches. If you're familiar with nearest-neighbor sampling in image resizing, think about how nasty and chunky the resulting image looks when you scale it down using nearest neighbor. Analytic waveforms do the equivalent thing for audio.

Fixing that problem is surprisingly hard. It's a lot like texture rendering in games where there's a bunch of filtering, tricks, and hacks you can do to make things look smooth without burning a ton of CPU cycles.

---

The clever trick the author uses to simulate strings is: https://en.wikipedia.org/wiki/Karplus%E2%80%93Strong_string_...

---

The low-pass filter they show is a simple first-order 6 dB/octave digital low-pass filter. Filtering is fundamental to electronic music. The majority of synthesizers you hear in electronic music use "subtractive synthesis" which means to start with the simple sawtooth and square waves introduced early in the article and use filters to tame their harsh overtones. I find the math behind filter design, especially the moving filters used for synths, really difficult, but also interesting.


Small nitpick: CD quality is in fact 44.1khz. The nyquist theorem essentially says you need to use a sampling rate twice as high as the highest frequencies you want to record and reproduce. The article gets the gist of this right, just the cd quality numbers wrong. Izotope has a really good article that goes into digital to analog conversion, sampling rates, and the history behind them.

https://www.izotope.com/en/learn/digital-audio-basics-sample...



Thank you! For weeks now I've been thinking about how handy it'd be if I could audibly 'listen' to the output of a command. I had no idea it was as easy as piping it to aplay.

`tail -f output.txt | aplay`

I know this is a lame takeaway, but I'm just so happy to learn about this.


I find the lack of a common API for audio across OSes a tragedy. The waves are so deadly simple to work with that you could even use them as exercises to start learning programming. You would also need to be aware of the buffer you send the audio samples to; yes, you need to be aware that latency exists, there's no way around that. But in practice it's much more annoying: you have to deal with the APIs on each OS, which treat audio devices differently. Even getting info about the devices might be poorly documented and rather cumbersome, and then each device might or might not support the sample format you need/want, and might or might not support the buffer sizes you need/want. And if you try to work with a language that's not C/C++, then you have to resort to C wrappers to connect to the APIs (which in many languages is not trivial). 99% of the things we want to do could be so easy (give me a format that's 100% supported everywhere, a minimum buffer size supported everywhere, and support for 2 channels everywhere)... but nope.


Lack of a common API is a problem even inside OSs. Here's Windows: http://shanekirk.com/2015/10/a-brief-history-of-windows-audi...

And I disagree that it's deadly simple... Even sound synthesis (where it's "just math") is very hard, because you have to watch out for aliasing. Same if you're changing pitch or doing anything other than playing back a WAV.

Also, it's hard-realtime, which limits the programming languages you can use. Then, if you're not using the OS audio mixer (lots of different reasons not to), you gotta do the mixing yourself, which is another can of worms.


I have worked a bit with ALSA and dabbled in VST development and I understand some of these issues. I agree with you, but these are the inherently hard problems that we can't remove; I still believe accessibility can be much improved.

By the way, the article you linked is really good, thanks for that. Anyone else reading this discussion will surely be interested in that article too.


What's the common API for drawing across OSes?

What's the common API for video across OSes?

What's the common API for "put this string in a message dialog on the screen" across OSes?

And meanwhile there's JACK, RtAudio, PortAudio and several other crossplatform APIs, most of which have wrappers in non-C languages (despite the problems with realtime audio that this can lead to).


This is most decidedly not lame! I'm sitting there looking at the code poem trying to figure out how the sound happens, it looks like it's just writing bytes to a file. I figured there was some driver or something but "sound driver from file" is not super googleable.

aplay was the missing link.


There’s /dev/dsp that you can write to (and read from).

https://en.wikipedia.org/wiki/Open_Sound_System


This is a good way to blow out your laptop's speakers. One simple `cat /vmlinuz > /dev/dsp` and poof.


Do you mean hearing it read aloud? I pipe to espeak for that.


This somewhat related talk about functional composition (in lisp) is also quite interesting: https://www.youtube.com/watch?v=jyNqHsN3pEc


I think I've seen that one. I also like this presentation by extempore's author [1]. It is pretty cool in that it shows how to model instruments out of simple waves and "attack, decay, sustain and release" envelope modeling. Pretty quickly he comes up with something that kind of starts sounding like real instruments (squinting a bit... :-).

1: https://www.youtube.com/watch?v=phYHOUICe7Q


A Sorenson lecture I haven't seen yet! Thank you!

Sorenson is low key one of the most innovative minds in the scene. Extempore is such a blast to work with.


The "code poem" at the beginning of the post reminds me of the "Bit Shift Variations in C-Minor" [1] by Robert S K Miles (chiptune music in 214 bytes of C; featured in the computerphile video "Code Golf & the Bitshift Variations").

[1] http://txti.es/bitshiftvariationsincminor


Pete Elmore also recently wrote an interesting post about Bytebeat and Algorithmic Composition:

http://debu.gs/entries/making-music-with-computers-two-uncon...


My first hacking as it were was loading the Apple ][ game Lemonade and then writing my own programs. Because Lemonade loaded a bit of code that played music and I could figure out how to play notes and durations once the magic code was loaded but not how to do the magic code myself. It took quite a while and a book on 6502 assembly and my high-school's Franklin Apple clones (Franklin had a built in assembler in the ROM) to figure out how to make that speaker beep actually play notes. My first great hack was finally being able to write a program that played music on the other Bell & Howell Black Apple machines. Then I got an Amiga and that musical note playing became trivial. Article seems a bit bogus by not going down to speaker-on/speaker-off and delay loops.


Back when I was kid playing with a C64, it was the DATA section at the end of BASIC programs that blew my mind. If you programmed line 10 wrong with a typo or other syntax sin, then the entire thing would fail. If you had a typo in the DATA section that was (now I know as) Hex, then the program would not fail but glitch, and it was typically with the sound/music of the game. I had no idea what Hex was, but I did realize that it was only 0-9A-F. That made the confusion of 0(zero) and O(upper-case 'oh') less of a problem during transcription. I never understood it enough to modify any of it in a useful manner, but it definitely helped avoid hunt&peck typos for a kid


That reminds me of the evolution of magazine code listings, which eventually came with per-line CRC values. If I remember correctly, there was a mod for Atari 800 BASIC where it would spit out the CRC after you typed each line of code.


There used to be a magazine or book that had this one BASIC program that you had to type in really carefully. That program let you type in a bunch of hex characters with a CRC and would tell you if you typed a line wrong. The rest of the programs in the book while still just BASIC programs were printed all encoded as a bunch of hex digit lines. It was great, once you got it typed in you knew there weren't any typos. Then you could list or save or run it just like any other BASIC program.


That's actually where I was getting my BASIC code from to transcribe. I don't remember exactly which magazine, but in my fuzzy memory, I think it was Byte.


The article and this whole thread is awesome; there’s so much to learn.

My only contribution is to point out that the late Hudak was very interested in making music with software and spent a significant portion of The Haskell School of Expression, https://books.google.com/books/about/The_Haskell_School_of_E... on it.


Functional Composition by Chris Ford: https://www.youtube.com/watch?v=Mfsnlbd-4xQ


Very interesting article.

However, this is false:

“ that’s why CD music had a sample rate of 22000 Hz. Modern sound cards however tend to use sampling rates twice as high - 44100 Hz or 48000 Hz”

CDs are/were 44100 hz, they were never 22000, because you need two samples per wave and because you need slight over sampling and to make the conversion from 48k in to bad math to discourage DAT machine as a lossless copy format for the masses.


DAT has no influence on how CD rate was choosen, because DAT came after CDs (but at least early DAT recorders indeed didn't allow digital sources to be recorded at 44,1 kHz due to music industry pressure, and later copy protection mechanisms were added)


> you need slight over sampling and to make the conversion from 48k in to bad math to discourage DAT machine as a lossless copy format for the masses

What do you mean by this?


I might be wrong about the 48k vs 44.1k thing. My impression is that the difference in sample rate between the formats was some sort of attempt to discourage lossless copying of published music. Recall that we couldn’t just throw it on a computer and resample it back then.

But regardless, you need to slightly over sample when doing A/D conversion because you need to do a very strong low pass filter before you hit the sample rate to avoid harmonic distortion. So you need the filter to be some amount higher than the target maximum reproduced frequency, because the filter is in the analog domain and itself introduces audible artifacts.

So you must sample at a higher frequency than you intend target. 48k makes sense because you have more ‘extra’ frequencies to work with, so it’s easier to get the filtering out of the audible space.


Converting from 44.1k to 48k is lossless, and has always been. Converting from 48k to 44.1k is practically lossless: You lose frequencies above 28KHz, but that's about the range at which human hearing drops off anyway.

> Recall that we couldn’t just throw it on a computer and resample it back then.

Of course you could. How else do you think CDs were mastered and produced? The CD was developed with the idea of using it on computers, and for computer storage. And if, in practice, someone wanted to copy it, they'd just record the CD to tape using analog out (not quite lossless, but nobody cared back then), or copy CD/CD with no resampling required.

The 44.1k is a mostly historical accident, and it goes back to the Red Book CD audio spec being reused from an earlier project for digital audio that Sony was working on, the U-matic, where 44.1k was basically how much audio would fit evenly into some number of lines in the tape's storage.


You may be correct about the origins of 44.1, sounds plausible.

I don’t think we are aiming at the same concept. I was there, as perhaps you were too.

Average consumers did not posses, could not afford, technology to duplicate CDs easily or to convert a CD to DAT.

I can’t recall all this after so much time has passed, but the gist is that somehow the record industry influenced the deployment of technology to reduce lossless duplication ability for consumers.

It wasn’t until home computers became so fast and ubiquitous that this changed.


I thought CDs had a sampling rate of 44kHz? You need twice as many samples as the frequency you want to represent, after all (to make a wave you need both a positive anda negative sample in the same period). This is the essence of the Nyquist-Shannon a.k.a. the sampling theorem.


That's neat, but doing sound design and creating listenable/good compositions are two different endeavors. You'd likely be better off writing an actual DSP engine in C than trying to diddle with frequencies in this way. Use Supercollider if you actually want to make music with code rather than just do little experiments like this.


I wrote this trying to compress the notes: https://github.com/amb007/sound-series


Great stuff! Now who's the first person to listen to the entire linux kernel source code? ;)


Hyped to see someone implement this in C#. This is great!


Is there any hum to sound software?


Cds were 44100Hz, right?


Obligatory plug to TidalCycles [1], which is a Haskell based system folks have begun to use for live coding with IMO impressive results.

[1] https://www.youtube.com/watch?v=sNj-I2pZwX8




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: