Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: How to get started with audio programming?
358 points by Flex247A on May 25, 2021 | hide | past | favorite | 120 comments
I recently picked up 'The Audio Programming Book' [0] and so far, I am really liking it. But I am not sure which resource to pick after reading that. Can you recommend me some audio programming resources which are beginner friendly?

[0] https://mitpress.mit.edu/books/audio-programming-book

Edit: My goal is to make a mini-synth which takes input from the computer keyboard.




I’ll repost a comment I made a few years ago. Hopefully the (informative, and authoritative) reference will be useful!

——

The founder, and sole developer of Mutable Instruments (a well known modular audio/synth maker) wrote about her recommendations on how to get started in audio programming here [0]. Much recommended for the cited books, and general/business advice on making a hardware audio product.

[0] https://modwiggler.com/forum/viewtopic.php?p=2858814#p285881...

——

My own post about this was from a mini thread on HN about programming sound that may also interest you:

https://news.ycombinator.com/item?id=20491766

——

Last note! Another synth maker personally recommended the same DSP book as noted in the comment above (on Modwiggler), so it’s probably worth checking out!

Udo Zolzer's "DAFX"


> https://modwiggler.com/forum/viewtopic.php?p=2858814#2858814

Fixed link (anchor is broken!): https://modwiggler.com/forum/viewtopic.php?p=2858814#p285881...

As an EE that only became a programmer later, I would like to add that those are amazing tips.


Thanks a lot, I edited and simplified my comment, linking directly to the post!


If you're new to programming, it might also help you to get started with Max/MSP and YouTube videos that already show you how to make the mini-synth you're after (terrible as a programming environment but great as a learning/prototyping tool).

The Computer Music Tutorial by Curtis Roads is a good companion here if you want inner workings. You might be able to snag a PDF copy online to see if it's for you.

Audio Programming Book is entirely in C and can be a bit of a pain to get things working in C if you're new to programming (although highly worth the initial struggle if you're looking at it with a career in mind), although I'd still recommend stepping from Max/MSP into MATLAB/Python, which focuses on functionality rather than programming itself.

Python is also bit more beginner friendly, although C++ will probably end up being your long term bet.

I'd pick up the Pyo library for python, and/or a tutorial like this one, after dabbling with Max/MSP a bit: https://python.plainenglish.io/build-your-own-python-synthes...

Then if you want to get even deeper into the DSP, you could go with pretty much any of the other resources the others have mentioned here. My personal faves are the Steven Smith DSP book, Julius Smith's resources (with its runnable MATLAB scripts), and DAFX book by Udo Zolzer.


There are other programming toolkits for audio programming as well, like pure data and JUCE.

Idk maybe it’s just me but I’m an experienced programmer and I’ve spent hours learning max/msp and really don’t like the visual aspect. I like programming in vim normally and zipping around the file manipulating text very efficiently without ever taking my hands off the keyboard. Max/msp is the exact opposite, everything is drag and drop mouse movements, and then you can’t just insert new lines in a file to extend something you have to constantly be dragging your existing components out of the way to make room for new components. I find it way more tedious than any other programming environment I’ve used.


I find the same personally, but then I've seen people who would never consider themselves programmers fluently create things in Max, so I guess it depends on your background.

Max actually does have a Javascript API, it's a bit old fashioned and you couldn't use it for any DSP related stuff, but can be useful for some stuff. I used it to build a prototype of something that I'd have no idea how to build visually in Max (basically a macro parameter fader for Max for Live), but is fairly straightforward in code, and took some time to figure out a nice(ish) workflow for working with it with Typescript: https://github.com/tomduncalf/livefader

I wonder if you could use that plus the "gen~" object and/or dynamically generating Max objects from JS to do more advanced synthesis-type stuff. May be more trouble than it's worth though.


To your first point, this is exactly why Max was created, by Miller Puckette at IRCAM - so the artists didn't have to necessarily chase down coders to change their programs. In that respect, it's been a tremendous success.


Absolutely! I went to a workshop on step sequencers at Ableton Loop which I didn't realise was about Max step sequencers specifically, and it was really interesting - the host asked who in the room was a programmer, and just me and my friend raised our hands out of like 20-30 people. Then he started asking who had built x, y, or z musical thing and everyone else was raising their hands - I thought it was interesting that they didn't see what they were doing as programming, even though it very much is to me!


ha, great anecdote! Yes, it has been a super successful gateway drug to programming for many. :-)


I actually created Scheme for Max to address this, it enables scripting all of Max in s7 Scheme Lisp. Max is a wonderful environment, but for experienced programmers, not necessarily how you want to code. It's strength is the built in integration with stuff that is a pain to code from scratch: midid handling, GUI elements, scheduler, transport, audio controls, etc. If you're interested in using the Max environment, but writing your work in Scheme, check it out.

https://github.com/iainctduncan/scheme-for-max


you might prefer SuperCollider. the syntax and style are a bit bizzare, but the idea is basically if Max were Smalltalk — an entire self-contained audio programming environment where everything’s accessible as code.


Two books I loved during my digital signal processing studies (especially in the audio field):

- "Introduction to Computer Music"[0] by Nick Collins: very focused on audio programming for musical applications but you can easily extrapolate for other domains. Lots of pseudo-code algorithms are provided.

- "The Scientist and Engineer's Guide to Digital Signal Processing"[1] by Steven W. Smith: the bread and butter for everything concept related to DSP. Everything is explained in a crystal-clear fashion, lots of sample code to get you started with digital filters and analysis (although written in BASIC but easily translatable to C/C++ or even Python).

Also there is this one article "Real-time audio programming 101: time waits for nothing"[2] by Ross Bencina (creator of AudioMulch, Portaudio, etc.) about the basics concepts of real-time audio programming

[0] https://www.wiley.com/en-gb/Introduction+to+Computer+Music-p...

[1] https://www.dspguide.com/

[2] http://www.rossbencina.com/code/real-time-audio-programming-...


Thank you so much!


Shameless plug but I put together some Jupyter notebooks that walk through several of the fantastic books recommended in this thread: https://github.com/khiner/notebooks

I wanted to help myself and other folks develop better intuitions around the material, particularly focusing on short animations to develop better visual intuition along with working code examples of the material in the books.

Books covered (with a notebook for each chapter):

* Musimathics volumes 1 & 2 by Gareth Loy

* Introduction to the DFT by Julius Smith

* Introduction to Digital Filters by Julius Smith

* Physical Audio Signal Processing by Julius Smith

also a couple not directly about audio but helpful for the domain:

* Coding the Matrix by Philip Klein

* Accelerated C++ by Andrew Koenig and Barbara Moo

Hope someone gets some value from these - have fun!


I've been getting into this over the past couple of years too and I feel like I sort of hit a wall.

I am comfortable writing low level efficient real-time code in C (I'm an ex game dev). I understand most synthesis techniques in pretty good detail. I could probably write a book on subtractive synthesis, and I have implemented a complete functioning FM synth.

I get the fundamental concepts around DSP: Nyquist, sampling, Fourier analysis, etc.

But when it comes to sitting down and, say, designing and implementing a filter from scratch, I'm pretty well stuck. Part of it is that most of the material I've found either goes straight to heavy calculus (which I can kind of hack but am pretty rusty on) or to MATLAB (which I don't have).

Likewise, implementing a simple digital sawtooth or square oscillator analytically is trivial. Sample playback is also a piece of cake. But doing those without aliasing seems to jump from super-easy mode all the way to hardcore nightmare. All of a sudden I'm trying to understand what minBLEPs are and other stuff that feels over my head.

Any recommendations on how to get over this hump? Should I get MATLAB?


Have you tried GNU Octave? It seems to be a replacement for MATLAB.


I have not, that's a good pointer. Thanks!


As an alternative to MATLAB/Octave, may I suggest using Python with Jupyter Notebooks?

For exploratory/analysis/prototyping work, I have not found a better platform and ecosystem. These notebooks are really powerful feature-wise, you can mix Markdown notes/documentation with code blocks with data visualization natively, which is a no brainer when doing your research work.


How does Jupyter compare with an environment like Spyder, which basically mimics the MATLAB approach? Can I inspect variables, run arbitrary commands against them in a REPL?


I don't think it's an issue of having some general language for doing math work. My understanding is that MATLAB specifically has a ton of built in functionality for filter design and coefficient calculation.


I'd suggest looking at code for how people have done it other projects, there are some really good open source implementations of those sorts of things in languages like Csound, PureData, Faust, SuperCollider, etc. Csound is old school, but the band limited VCO is brilliant (the vco2 opcode)


I manage a team in this field presently; the answer to your question depends on whether you want to be gainfully employed doing so, or not.

Web Audio API and JUCE are the modern building blocks for mostly everything out there; if you're familiar with these, that's a really good place to start.

If you're looking for something accessible, SOUL is an excellent domain-specific scripting language that leverages JUCE underneath; see https://github.com/julianstorer for more context.

I'm not as sold on Max/MSP or Pd, though they're fun to play with for a brief moment.


I'm super interested in SOUL. I noticed the keynote was two years ago and it's still being developed, makes me hopeful for its future.


What is the Web Audio API used for?



Games mostly, but there exist web-based digital audio workstations as well:

https://filmora.wondershare.com/audio/best-free-daw-online.h...


Here are four videos on the subject from my absolute favorite Yotuber, One Lone Coder (whom, sadly, is more or less on a hiatus now after having a kid. Damn those pesky kids!!!!)

https://m.youtube.com/watch?v=tgamhuQnOkM&t=77s

https://m.youtube.com/watch?v=OSCzKOqtgcA&t=2s

https://m.youtube.com/watch?v=kDuvruJTjOs

https://m.youtube.com/watch?v=roRH3PdTajs


Hey,

I asked myself too how I should get started with Audio Programming in 2019. I ended up building my own little synth in the progress and I ended up talking to people from Ableton and even gave a talk at Native Instrument's headquarters here in Berlin.

I blogged about my experience and my product here: https://timdaub.github.io/2020/02/19/wasm-synth/


* Valhalla DSP Blog - so many good articles on the real world idea. https://valhalladsp.com/blog/

* JUCE for making VSTs. https://juce.com/

* ELK Audio for hardware / audio. https://elk.audio/

* Find open source projects that meet your needs / desires.


Not answering your question, but if you're interested in audio programming you might find Pure Data interesting, it's sort of visual audio programming. It might seem like a toy but it's actually incredibly powerful: https://puredata.info


There is a more up to date fork of it called Purr Data https://www.purrdata.net/


Purr Data is not really more “up to date“, it is rather Pd vanilla with batteries included + a nicer UI. Both are actively developed. Note, however, that they are not 100% compatible: both have features that the other one is (still) missing.


Second for puredata. It's pretty different from other options but very powerful. It's also quite visual and uses the same kind of design concepts involved in setting up a traditional modular synth.


If you are on macOS, AudioKit is a nice simplified layer on top of CoreAudio and CoreMidi: https://github.com/AudioKit/AudioKit

It ccomes with many Xcode playgrounds for interactive exploration of the SDK.


Designing Audio Effect Plugins - https://www.routledge.com/Designing-Audio-Effect-Plugins-in-...

This book teaches you DSP and also how to apply those DSP algorithms by employing them inside an audio plugin.


Hi,

I started with Csound and Cabbage framework[1] which I used to create some VST plugins.

Then I moved to javascript lands (as everyone already has runtime called web browser) and I am creating sort of DAW using webaudio. I used Tone.js, but it was somewhat confusing, so I started my own library[2].

It's not finished yet but I have already nice and usable demo - comb organ playable with computer or MIDI keyboard with built-in "tape recorder"[3]. Good news is that is open source so you can actually stole some ideas from me.

[1]: https://cabbageaudio.com/

[2]: https://github.com/severak/cyber-music-studio/blob/main/js/h...

[3]: https://severak.github.io/cyber-music-studio/regenschori.htm...


In your demo, if you are not using <button> for buttons, please at least set css "user-select: none" so that when I move mouse 1px after clicking it still works as button.


Cabbage has some great testimonials!

> My music used to make children cry. But since using Cabbage the children laugh and dance with joy.

> Julie, Montreal


also:

> No vegetables were harmed in the making of this software


Implement a MIDI 1.0 sequencer and get it to play back SMF files with a sine wave synth - you can have it output a WAV file, or learn an API to do realtime rendering. It's not a large spec, there are lots of old documents on how the protocol functions in practice, and then once you start getting it working you'll get results instantly(lots of SMF files around to test with) but will want more features, better synthesis; complications start to arise and you will then pick up a lot of knowledge by doing.


Depends on what audio programming do you want to do really. If you are interested in the audio side, I would recommend https://puredata.info/ (it has tutorial on synthesis and everything). If you want to explorer the programming side, I would just go picking apart small synths: https://github.com/grumdrig/jsfxr http://www.pouet.net/prod.php?which=20656 (click on source, there's a mini synth there in that demo).


Only related if you just read the title and ignore the rest, but I loved this article: https://zserge.com/posts/etude-in-c/

Covered on HN late last year https://news.ycombinator.com/item?id=24940624 ("How to create minimal music with code in any programming language")

Also related to bytebeats: https://soundcloud.com/robertskmiles/bitshift-variations-in-...


Haven't read that book so I'm not familiar with the contents, but if you're interested in creating VST plugins you might want to check out some frameworks out there like JUCE: https://juce.com/

I don't know if you're a musician yourself but I'd highly recommend downloading a DAW and playing around with the plugins to get a sense of common audio processing modules, you can perhaps make it a near-term goal to create an EQ or filter plugin that you can install and use in the DAW. IIRC I think Ableton Lite should have a free demo, Reaper is another well-regarded free DAW from what I've heard


I watched CppCon 2015: Timur Doumler “C++ in the Audio Industry” https://m.youtube.com/watch?v=boPEO2auJj4 not long ago and enjoyed it. He was a developer at Roli working on synths and he goes through real time strategies to keep the response time under around 30ms IIRC


The Will Pirkle books are excellent, and he did a new edition of the synthesizer one. "Designing Software Synthesizer Plugins in C++: With Audio DSP"

Also, you can learn a ton by looking at various other higher level languages do it: Csound, SuperCollider, PureData are all open source.

Oli Larkin made a brilliant page of resources on github: https://github.com/olilarkin/awesome-musicdsp


Since we are all here, I have a question. I personally am much more interested in audio sample triggering and/or loop based production in this context than synthesis/wave generation -- and it seems like the overwhelming majority of tools are focused on the latter.

In my head, I'm imagining a more programmatic approach to "arrangement of samples and loops," as in, instead of, or perhaps complementing, the classic "grid" or "buttons" view -- something like,e.g.:

- Specify 4/4 @ 95bpm for the piece

- Sample 1, a drum loop stretched/and or pitched

- Sample 2, a hit on the 2nd beat of each interval

- Sample 3, a simple electric piano melody, repeating over X intervals.

- Sample 4, a pad with an echo/reverb

etc. Now, what should be easy to do is to switch out, e.g. which drum loop, or change your piano to a trumpet. I get that MIDI is okay for this -- but is of course better for the latter situation and not great for effects and audio samples.

Your Abletons and so forth are not bad at this, of course, but - and maybe this what I'm describing -- Ableton's features -- but doable in vim, perhaps with the ability to create functions et al on the fly, which strikes me as a potentially powerful way to "group" musical sounds/ideas/intervals/melodies/chords/effects etc etc


Sounds like you might be more interested in live coding. Overtone [1] can do what I think you are describing, and more--it's a frontend to SuperCollider, which has all the audio synthesis stuff you aren't interested in, but it can trigger samples fine. Of course, if Clojure isn't your thing, there are other live coding tools out there. I'm partial to Orca [2] myself.

[1] https://github.com/overtone/overtone

[2] https://github.com/hundredrabbits/Orca


Echoing a lot of sentiment here, you can do pretty much all of these things with SuperCollider. I'd go straight to SuperCollider rather than a "frontend" like Overtone/SonicPi. Not that these frontends are bad, but SuperCollider also has a nice frontend - the IDE works great with builtin doc searching, autocompletion, etc.

Sample wrangling becomes pretty thorny quickly as if you are triggering samples you want to make sure they don't "clip"/"pop" when you change them (due to discontinuities between the abrupt stop and the new start). I wrote a SuperCollider tutorial that demo's how to make a really high-quality sample player that takes care of these kinds of things plus gives you lots of control over rates, looping, etc. [1] That was my main hurdle with SuperCollider as that it has surprisingly few tutorials for such a long-running and deep program. Hopefully that helps :)

[1] https://schollz.com/blog/sampler/


This looks cool! I haven't played around with these sorts of things in a long time, but yes, it's always felt like "samples" have been a second class citizen in these deals -- but of course, ought to be able to be abstracted away with functional programming.


You can do all that in any of the major music programming languages. Max, Pure Data, Csound, Supercollider, all have tons of facilities for this kind of thing.

The Cipriani & Giri books for Max cover working with samples and loops in great detail and are fantastic books.


Awesome discussion in here, I'm happy to see it!

I thought I might throw my hat in the ring of shameless self promotion since you might be interested:

I'm working on a project called Elementary Audio, which is a brand new javascript runtime and framework for writing native audio applications– meaning desktop apps, like perhaps the mini-synth you're hoping to make, as well as audio plugins (VST, AU, AAX, etc) and even embedded hardware, all in JavaScript.

The project is still in an early stage (and macOS only right now). I'm planning to share it more widely here on HN once it's ready for beta, but I thought this thread might be interested in it before then.

Website: https://www.elementary.audio/

And here's an example MIDI Synth: https://github.com/nick-thompson/elementary/blob/master/exam...

You could even spin up an Electron frontend to take input from your computer keyboard and send those over to Elementary to render the synth sounds. It's actually an example project I was considering doing myself but you might beat me to it at this point!

Lastly, I'll say briefly that there are a lot of tools out there (as we're seeing in these comments), different things work for different people, and there's no single "right" way to start audio programming– find the path that makes it fun for you, because it's such an awesome field to get into.


I second the recommendation of Steven W. Smith's dspguide.com, which will get you from (I think) zero to a profound understanding of DSP. I've also learned a lot from Julius O. Smith's Physical Audio Signal Processing, which I see a couple of other people have also recommended: https://ccrma.stanford.edu/~jos/pasp/

But if you're using an existing computer music programming environment like Csound (used in The Audio Programming Book), SuperCollider, or PureData, you can make a mini-synth which takes input from the computer keyboard without any of that stuff! (Stay away from Max/MSP; it's proprietary.)

The most fun I've had with audio programming has been bytebeat, though: http://canonical.org/~kragen/bytebeat. I didn't invent bytebeat but I did write that page about it.

Also, there are a lot of the hassles involved in audio latency on CTSS-derived OSes like MacOS, Linux (especially Android), or Microsoft Windows; it's easy to end up with 100+ ms of latency, and hard to do better than 10 ms, and either of those is a super shitty musician experience. If you do your stuff on an Arduino or similar microcontroller instead, those problems evaporate, and your computer music system will fit into an effects pedal. You need a DAC and, if you're taking audio input, an ADC; the built-in PWM and ADC in a standard AVR may not be sufficient. (And, beware, a 31.25 kHz PWM carrier can go right through a stereo system and burn out your venue's tweeters if it's turned up high enough. Filtering is required.)


Short answer: Just do it.

Now that you've read a book, pick an extremely simple task and just do it. For example, maybe try writing a command-line program that will just play a square wave through the speakers. Then, build up your skills by making options for sawtooth, triangle, and sine waves. Finally, in the callback from the audio API, poll the keyboard to decide what tones to play. ;)

FWIW: A few years ago I wrote a functional keyboard and mouse synth program that just did sine, triangle, square waves and harmonics. It sounded a lot like an organ. (I later lost interest.) What helped was that I found a wrapper for MacOS CoreAudio that dramatically simplified the API so all I needed to do was provide a stream of floats. (I don't remember the name.)

Don't fall under the illusion that you can just read books and at the end you'll know how to do this. You'll need to work through simplified tasks to build your skills and understanding before you can write your mini-synth.


"Richard Boulanger" is the C-Sound [0] guy. I mention that because anyone interested in audio programming might want to be familiar with C-sound first. Programming audio in C is way more complex than programming audio in C-sound. Starting from scratch might not be preferable to using a toolkit that's been developed for 35 years! [1]

A book I thought was great has no code in it, but is FULL of very useful info about audio and computing it. Computer Music by Dodge and Jerse, ISBN 0028646827 (1997) ... a little pricey, might be hard to find, but very hard to beat.

[0] https://csound.com/

[1] I haven't seen Richard's book (I'm sure it's great - and I will see it, thanks for the tip) ... he just might be pitching this idea in there!


Another nice thing about Csound is that if you want to start doing C level dsp in baby steps, extending Csound is very straightforward. MUCH easier than adding objects in Max or PD for example. Max and PD externals require a ton of platform specific boilerplate.


Cycling 74's Max is a really good way to get into audio (and visual) programming. It introduces the concepts of programming and DSP whilst still keeping things beginner friendly. It's a lot more beginner friendly that something like JUCE which, while super powerful, has a much steeper learning curve and requires you to know C++. Major downside is that it's not suitable for making full audio plugin products, rather I would use it to prototype a plugin, the DSP logic and even the UI before writing any text-based code for a VST/AU.

You can absolutely make a nice synth that takes input from pretty much anything you can attach to a computer.

And as everyone else has said - theAudioProgrammer is good too.

(Edit) - Pure Data (PD) is an open source alternative to Max which is free. I've heard people recommend it but never used it myself.


I've been working on a little synthesizer as a means of learning rust. https://github.com/jimktrains/synth

Sound on sound has a series on synthesizer concepts. https://www.soundonsound.com/series/synth-secrets

Dsp guide is a great resource. http://dspguide.com/

Music dsp also has some good information and implementations. https://www.musicdsp.org/en/latest/index.html


My advice would be to start with JUCE. It's a great framework for audio development, and has a lot of example projects for making plugins and hosts. Audio programming is definitely tricky and something of a black art. Even making a simple square wave synth that doesn't sound crap is surprisingly difficult, because of unintuitive artefacts engendered by the sampling theorem. (In a nutshell you have to make the square waves wiggle a bit for them to sound good, otherwise you get lots of high frequency garbage which sounds metallic and ugly.)

Ross Bencina also has some good articles about the realtime aspect. Basically, you shouldn't use locks and should become intimately familiar with ring buffers :)


One other comment. There are two rates: audio rate and control rate. Audio rate is "for each sample". Control rate is roughly "once per frame" i.e. once per buffer.

If you want to do anything useful you'll need a GUI which can control the parameters of the audio plugin. The GUI will communicate with the audio thread at control rate. The audio thread will usually pick up messages from the GUI via a ring buffer. And by the way, this can happen in reverse, e.g. for level meters, where you do a moving average of squared amplitude (RMS), and output this as a control rate. You can use ring buffers for this, but another approach is to use atomic variables. And in x86 architectures you can actually even use just regular variables because of its strong memory architecture.


Most of the good resources where already mentioned, but these are some I missed:

- Musimathics Vol I & II: This will teach you the basics of Music and DSP in a very approachable way. I wish I had these when I started writing audio software.

- The Art of VA Filter Design: https://www.native-instruments.com/fileadmin/ni_media/downlo...

If you are programming in C, these libraries are very useful:

- PortAudio: Cross platform audio playback

- libsndfile: Easy and cross platform sound file io

- ladspa: Really simple plugin API, useful if you want to make or use audio plugins without all the boilerplate of vst or lv2


If you don't mind, what music software did you start writing?


It might not be inline with your exact goals, but I've really been enjoying doing audio visualization lately.

I'm using the Unity game engine, and am leaning heavily on already-implemented FFT algorithms available on the Unity AudioSource component, but the fun part is taking the spectrum data, dividing it up into bands, and doing visuals with those.

Here is a short video showing a simple audio visualization demo I created: https://www.youtube.com/watch?v=kYt0dcUY3i8

It led me down a bit of a rabbit hole with watching videos about Fast Fourier Transforms, and learning more about audio specific programming.


Have any resource recommendations? I have a future project lined up for audio visualization on a custom LED array.


Take a look at the source code of the Pink Thrombone, there are some interesting link in the comments of the source: https://dood.al/pinktrombone/


It depends on what you're trying to achieve. I'd say pick a project you want to work on and go from there, resources on JUCE/C++ aren't always going to be helpful if you don't want to write plugins.


This is a topic close to my heart as I've always been very into music production and programming, and have dabbled with a few things over the years, but have only started working professionally with audio software in the last few years.

What is your background, and which parts of audio programming would you like to focus on? e.g. are you interested in writing your own low-level DSP code, or more interested in hooking together higher-level blocks?

If you're from a web programming background, you can have a lot of fun with the WebAudio API [1]. It provides high level building blocks like oscillators, filters, effects, etc., which you can hook together. It has some rough edges but it's a great starting point.

Tone.js [2] is a great way to get started with WebAudio, it provides some useful abstractions that let you build fun things quickly, and there are some great examples of WebAudio creativity out there e.g. Blokdust [3]. If you want to go lower level, all major browsers now support the AudioWorklet API [4], which lets you write your own custom DSP algorithms and have them run efficiently within WebAudio.

However, WebAudio has limitations in terms of performance, and you can't use a WebAudio synth as a plugin in your music production software of choice (well, you might be able to get a browser which runs as a plugin, but it's not going to be ideal!).

If you want to write professional audio code, you can't really avoid working with C++ - it's the industry standard approach. This is largely because C++ allows programmers to very carefully design the performance characteristics of their code - specifically, you can avoid doing anything which might take an unknown amount of time (e.g. allocating new memory, locking) while processing on your audio thread - audio is realtime and very low latency, so you need to be sure your code is going to run in the amount of time you think it will.

Personally, I think JUCE [5] is a great starting point. It abstracts away some of the complexities of both C++ and audio APIs, allowing you to build cross platform audio apps and plugins without having to worry about platform-specific quirks. They have a pretty good selection of tutorials too [6]. An alternative you could look into is iPlug2 [7]. There are a couple of books by Will Pirkle on the topic of programming audio effects and synths with C++ - the author uses his own framework, but the same principles apply to other frameworks. Make sure you get the new editions if you do get these.

You'll probably want to take time to learn some C++ basics first if you don't already know it, it's a hard language to master! I'm actually working on an integration right now to allow you to build web UIs for JUCE apps, which takes away the complexity of also building the UI in C++ - I'll hopefully have something to share in the next few weeks.

If you want something a bit more straightforward and you're happy just supporting MacOS and iOS, AudioKit [8] is worth a look. It's kind of in between WebAudio and JUCE in terms of complexity I'd say - you write your code in Swift and it provides a load of high level building blocks, but you can drop down to a lower level if you need to write your own stuff in C++. Also the CoreAudio/CoreMIDI APIs on Apple platforms are very powerful, though I've struggled to find great documentation.

One other option you could look at are specialist audio languages like Supercollider [9] and Faust [10], or visual programming tools like Max [11] or Pure Data [12]. I'm not very well versed in any of these, but I've heard good things about Supercollider especially.

Phew, hope that helps! As you can probably tell, I'm really interested in this stuff so please give me a shout with any questions!

Edit: one more resource I remembered, there's a Youtube channel dedicated to learning audio programming, mostly using JUCE, called The Audio Programmer [13]. I haven't actually watched much content so can't say too much about that, but I know the guy behind it and he's great, and also runs a great community for people interested in audio programming [14].

[1] https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_A...

[2] https://tonejs.github.io/

[3] https://blokdust.com/

[4] https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkle...

[5] https://juce.com

[6] https://juce.com/learn/tutorials

[7] https://github.com/iPlug2/iPlug2

[8] https://audiokit.io/

[9] https://supercollider.github.io/

[10] https://faust.grame.fr/

[11] https://cycling74.com/

[12] https://puredata.info/

[13] https://www.youtube.com/channel/UCpKb02FsH4WH4X_2xhIoJ1A

[14] https://theaudioprogrammer.com/community/


> JUCE

I would add to that VCV Rack [1] is another great starting point.

Very low barrier to entry, see developer manual [2], hundreds open source modules to learn from. [3]

[1] https://vcvrack.com

[2] https://vcvrack.com/manual/PluginDevelopmentTutorial

[3] https://github.com/search?o=desc&q=vcv&s=&type=Repositories


Nice, I hadn’t looked into building VCV Rack modules but it’s a super fun piece of software - there’s also an iOS port called MiRack, personally I love making music on the iPad so I use that more.

I saw this the other day that lets reuse gen~ code from Max as a VCV module: https://github.com/isabelgk/gen-rack


Thanks for this answer!

I don't know much about audio programming, but here's a question.

When emulating sounds from physical instruments, can you get close by using only code without using audio samples? If yes, is it harder/easier?


It's not something I know a lot about (I'm more interested in synthesised sounds!) but I believe you can create pretty impressive emulations of physical instruments using techniques like physical modelling. Not sure if it's comparable to a well recorded sample though.

I believe Audio Modelling are one of the leaders in this field: https://audiomodeling.com/

In terms of harder/easier... I'd guess it's a lot harder to code, but easier in terms of not having to sample thousands of different articulations for each instrument! Judging by the huge selection of sampled physical instruments and the small amount of synthesised ones, I guess overall harder. Would be interesting to hear from someone who knows more though!


> I'm actually working on an integration right now to allow you to build web UIs for JUCE apps, which takes away the complexity of also building the UI in C++

I assume you've seen the Blueprint project for building React UIs on top of JUCE? Very interested to hear more details about what you've been working on whenever you have something ready to share!


I have indeed, it's great.

My primary motivations for doing something different was that Blueprint currently doesn't work on mobile (and I'm not sure it could ship on the iOS app store currently, with it using Duktape), and I wanted to get away from writing any C++ at all for the UI – and also that I love playing with this kind of stuff, heh. The app that I work on is built using React Native and JUCE (and Unity), so it's an area I have a lot of thoughts about!

TBH the web stuff started out as an experiment, but I'm actually pretty impressed by how practical web is for building UIs – I've got some nice integration going on to make it pretty natural to write plugin UIs. I'll post it on here when it's ready, but if you have a Twitter/email/whatever you'd like to share or can contact me via mine in my profile, I'd be happy to share with you in advance – I'd love to get feedback from people interested in this area.


Thank you so much for your detailed comment! I am mostly interested in writing professional audio code, so I am learning C++ at the moment. Also, do you think Rust is a good alternative to C++ for writing high performance code? I am thinking of learning Rust too, but I am not sure whether Rust audio programming is popular or not.


My pleasure!

My understanding of Rust audio programming is that it is possible, but still fairly early days... something like JUCE provides a huge amount out of the box that you might not initially appreciate, e.g. it abstracts away the details of all the different plugin formats and all the different platform's audio APIs, and it has been around for long enough that you can be confident it does it well.

I'm really curious about Rust as it feels like a nicer language to work with than C++, but if you are serious about building professional audio software I personally don't think you can avoid C++ so you might as well embrace it.

I have a feeling that with Rust, you'd spend half your time figuring out how to do stuff that JUCE does out of the box, which is fine if you are interested in the figuring out part, but ultimately it might not help you focus on the actual audio programming.

Also there are a tonne of resources on C++ and especially JUCE out there, never underestimate the power of being able to Google for your answers!

Edit: on the C++ side, I found Bjarne Stroustrup's "C++ Programming Language" book quite a good way to understand the fundamentals. To be honest, I usually learn new languages just by doing and Googling, but with C++ it quickly became apparent after the 100th mystery crash that I'd actually have to understand what was going on under the hood with memory etc!


Thank you! Looks like I might have to embrace C++ after all ;)


Haha yeah sorry about that ;) To be honest I actually found it really interesting to be exposed to lower level concerns like thinking about memory allocation, runtime complexity, locking etc. after working in higher level languages throughout my career, but there’s no doubt that it can be a frustrating language at times.

One thing to watch out for is that the language has evolved a lot recently, but a lot of code samples are still written in an old style. You want to make sure you are using “modern” C++ (e.g. post C++11) features where possible e.g. smart pointers. It can be a bit confusing as some JUCE classes have been superseded by the C++ standard library, they date back to the days before “modern C++”... but I wouldn’t stress too much, using the JUCE versions is usually equally fine.


Depending on what kind of audio programming you intend to do, it should be possible to use Rust or other alternative programming languages. Your mileage may vary, depending on the dependencies of what you intend to build. If you want to interface with your operating system's low-level audio libraries you should be able to do that from any language that can interface with C. I was able to use Ada together with ALSA on Linux in this way. In this case the code responsible for generating the sound was in Ada, and the code for interfacing with the audio hardware (via ALSA) was in C. If you intend to write audio code for bare metal, you should be able to use any programming language your target hardware's toolchain supports. I've heard of people using alternative languages to write VSTs. I'm not an expert in this area, however theoretically you should be able to do something similar to the above as long as you have a good way to interface with C/C++ code.


> If you want to write professional audio code, you can't really avoid working with C++ - it's the industry standard approach.

No, you can do with C just fine.


True, although most of the frameworks for building plugins etc. are in C++ as far as I know, so using C might be making life hard for yourself if that’s your goal.


I haven't started the course yet but I've been looking at doing this one:

Learn C++ Real-Time Audio Programming with Bela - https://hackaday.io/course/171240-learn-c-real-time-audio-pr.... The course does recommend buying the Bela development board from https://shop.bela.io/ but I don't think it's a hard requirement.


Browsers have a very accessible API for audio programming now[0]. Comes with the benefits of being platform independent, using JS(okay, this as a benefit is arguable to some), and easily distributable(perhaps too easy since you can't hide your source code either, unless you do some form of SaaS and introduce latency).

[0] - https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_A...


It is surprisingly good, though programming per sample seemed unusable on my plenty fast enough machine.


Does anybody have a good tutorial on the Fast Fourier Transform? It always feels to be just out of my grasp and I wonder if someone has broken it down in an intuitive way.


You’re in luck. There was a thread about it 5 days ago.

https://news.ycombinator.com/item?id=27229836

My favorite was

https://youtu.be/spUNpyF58BY


Solid Gold List! I got into audio with ChucK: Strongly-timed, Concurrent, and On-the-fly Music Programming Language. Concurrency primitives are built right into the language spec, so it's easy for programmers to grok per sample digital sound. Powers laptop orchestras, but simple enough that you can build a laptop synthesizer in 100 lines of code

http://chuck.stanford.edu/


Join the Audio Programmer community: https://theaudioprogrammer.com/


is this page's discord group still active? i couldn't join


Literally go with this other project on the front page right now, it's good a good pedigree and a healthy ecosystem: https://news.ycombinator.com/item?id=27269589

If you want a really gentle start, try Sassy: https://sol-hsa.itch.io/sassy


Depends a bit on where you want to go with this.

If you want this to play nicely musically you want low latency and I'd look for programming languages made for audio. Just watch a few introductions and pick what you like best.

More professionally I'm not experienced, but maybe writing a VST MIDI instrument would make sense.

If it's just about the sound maybe you should start at the DAW end and use Bitwigs Grid or Ableton (possibly with max/msp).


I've used The Audio Programming book in conjunction with "Musimathics" http://musimathics.com/ to write many parts of GoAudio. (https://github.com/DylanMeeus/GoAudio).


Edit: My goal is to make a mini-synth which takes input from the computer keyboard.

If you are a Ruby programmer on Linux, you could use this rubygem I wrote: https://github.com/mike-bourgeous/mb-sound

A video about using that gem to make a synthesizer: https://m.youtube.com/watch?v=aS43s6TWnIY&feature=youtu.be

Part of a long-running experiment of mine to make educational videos about sound, which I hope might help you on your audio programming journey: https://www.youtube.com/playlist?list=PLpRqC8LaADXnwve3e8gI2...

There have been recent posts to HN about the difficulty of reading key-up events from the terminal. I used MIDI and a separate MIDI keyboard app for my video demo.


> My goal is to make a mini-synth which takes input from the computer keyboard.

It might be worth studying the sources of some working soft synths such as Helm, Surge or ZynAddSubFx or mixed firmware-hardware synths such as TSynth. The latter in particular is a low cost polyphonic external module built around a Teensy microcontroller, so the code base isn't that big, and it sounds great.

https://tytel.org/helm/

https://surge-synthesizer.github.io/

https://github.com/zynaddsubfx/zynaddsubfx

https://github.com/ElectroTechnique/

https://electrotechnique.cc/



It depends what you're trying to accomplish, but I found VCV Rack to be a great environment to implement synth ideas without having to worry about reinventing the wheel. Trying making a Rack module!

https://vcvrack.com/


It is even better to learn audio in its analog form first, great explanations by Moritz here https://www.youtube.com/channel/UCzfW6SlNEyxmAPtdr3n-_Og



Shameless plug for my own audio programming experiment: https://noise.sh

It's not as powerful as something like PureData but it does give you a simple and intuitive introduction to DSP and audio synthesis.


You can try to build an visual audio editor and learn everything else from there, step by step.


That is how I learned the very basics of web audio and modular synthesizers at once (here's the result https://github.com/spectrome/patchcab). Setting a clear goal makes the learning much easier.


Looks cool


I am building one currently :)


:)


Get into Zynthian:

http://zynthian.org/

Tons of great code to read and projects to understand ..

Also, the Basic Synth book is a dream:

http://basicsynth.com/


Just today there was a Audio Operating System featured on HN that looks like a great starting point for audio programming and it comes with everything you need. Unfortunately it looks like everything is out of stock, but looks interesting none the less and you can probably run it in a VM until they get the development kits in stock again.

- https://news.ycombinator.com/item?id=27269589 - Elk OS – Audio Operating System

- https://elk.audio/audio-os/


I wrote a CLI version of a sequencer (multitrack sequencing with plugins and automation where a simple xml format controls the sequencer events) a couple of years ago. I had a quite clear vision of what I wanted to achieve, and then picked C++ and JUCE and just started figuring things out.

I generally learn best by having a real thing to build; and then finding the resources I need when I get stuck.

I buy books aspirationally (I have bought the Audio Programming Book as well come to think of it) - so I often end up with many books on subjects that interests me, without learning much from them.


Long, long ago I made a simple synthesizer for windows using the CoreAudio API (there is a newer one, WASAPI, but I never got it to work well myself since it is so complicated). It's a fun project. It is also easy to add some simple filters this way.

If you don't want to do realtime synthesis, you can also dive in the (uncompressed) WAV file format and make programs that generate sound files.

Another thing that might be nice (but I personally haven't tried) is to synthesize your own drums, 808-style. Google 'kick synthesis' for example.


There is an online course in audio signal processing, FWIW. Caveat: I have not taken this course.

https://online.stanford.edu/courses/sohs-ymusic0001-audio-si...

See also this book about computational music synthesis:

https://cs.gmu.edu/~sean/book/synthesis/


If you're interested in synths, there is a new version of the Pirkle synth book coming out soon.

Also, I second the suggestion to join the Audio Programmer community.


Reading 'The Audio Programming Book' also clarified the concept of OOP for me. There was a small section where function pointers in C structs was discussed. Just after that, there was a section on struct classes in C++ which made it clear why data members should be grouped with their related functions.



I used tone.js for https://synthia.app


Have a look at Teensy microcontrollers and Audio shield available for them. https://www.pjrc.com/store/teensy3_audio.html


Think DSP is a free book on digital signal processing in Python: https://greenteapress.com/wp/think-dsp/


prof. Julius Smith has a huge amount of music dsp resources available freely [1]

1: https://ccrma.stanford.edu/~jos/sitemap.html


"listening in the ocean" by lammers can give you a resource for applications of audio programming. it's all about marine acoustics


Anyone have thoughts on JUCE vs SOUL for writing a VST?


I found writing a module for VCV rack quite accessible


A great, fun, system is CSOUND

https://csound.com/


Come hang in #lad on libera.chat


how about sharing the link to the book and asking in the comments for more resources instead of Ask HN




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

Search: