Hacker News new | ask | show | jobs
by exDM69 4396 days ago
Writing sound/music-generating applications is one of the most fun things you can do with your computer!

Here's a simple synth I wrote some years ago. https://github.com/rikusalminen/jamtoysynth/blob/master/src/...

It was originally intended for a 4k intro (ie. demoscene) which I never finished. The synth was written in x86 assembler using 16.16 fixed point algebra because the instruction encoding for grabbing the lower 16 bit part (AX) of a 32 bit register (EAX) uses very short instruction encoding. The old assembler synth was under 1k in size, uncompressed.

This version is written with floats and is written in easy-to-read C code, but it's essentially the same logic.

I also enjoy using the keyboard as a piano-like control device, like tracker software back in the day. Here's an excellent example of playing music using the qwerty keyboard: https://www.youtube.com/watch?v=3JQkW6BgUYU

3 comments

To teach mysefl a bit more about x86 assembly I once wrote a speaker-clicking loop. It was very educational: when I first played A440, a person in the room spoke up and said "I have perfect pitch. That's 438Hz".

he was right. I had a delay bug.

That's crazy, can someone with perfect pitch really be that accurate?
Actually, it might not be as difficult as you think. Someone with a good knowledge of music theory and some ability with perfect pitch may well be able to recognize the difference with current A440 tuning and A435. Given that ability being able to recognize that it is between either and then guessing 438hz (and being lucky) doesn't seem too hard to believe to me. That said, I'm sure I couldn't manage to even guess within 100hz.
Yes. I later tested and he had 1hz resolution in that range(!!!)
That's about four cents, or a twenty-fifth of a semitone. I don't think I can even distinguish relative pitch at that level (although 15 cents I can do easily -- roughly the difference between a just major third and an equal-tempered one).
A MOD player was my first ever real x86 asm program - I remember discovering that trick too - store the 16.16 value rotated by 16 bits, then use ADD and ADC to increment it according to frequency. Good times!
Not remotely as cool, but I was working on a modular synthesizer lib [1] based on the js node audio API.

There's a small demo [2], based on an older version of the lib, which can be played using the keyboard.

[1]: https://github.com/zenoamaro/audiokit [2]: http://zenoamaro.github.io/audiokit/