Help me get started audio programming
December 8, 2010 2:42 PM   Subscribe

I've been studying C++ for the last year and some change, and I'd like to start merging this study with my work in audio synthesis. What's a good way to get started programming audio applications?

Ideally I'd like to program this stuff for OSX (I'd be game for picking up C#). More ideally than that, I'd like to start making Audio Units or VSTs. Or iphone apps. Really though, I'd just like to get some programs making some noise, so I can start to get my head around how this stuff works. I just don't really know where to start. Any advice you can offer would be wonderful!
posted by Horizontally a Champion to Computers & Internet (11 answers total) 14 users marked this as a favorite
 
Write an Audacity plugin. Start here.
posted by blue_beetle at 2:45 PM on December 8, 2010 [1 favorite]


Apple's Audio Unit Programming Guide includes a C++-based tutorial.
posted by Blazecock Pileon at 3:12 PM on December 8, 2010


You can start off really simple: a command line app that reads and writes raw samples. You don't even have to worry about file formats, you can use other programs to take care of that, e.g.

sox somefile.mp3 -t raw -r 44100 -s -w | yourprogram | sox -t raw -r 44100 -s -w - output.wav

Now you just write 'yourprogram' to read and write raw s16le (16 bit signed integers, little endian) samples on stdin and stdout and process them however you want... no need to learn any new GUI or plugin APIs.
posted by Rhomboid at 3:20 PM on December 8, 2010 [2 favorites]


I think you might be interested in playing with something like MAX/MSP or it's free but less friendly cousin pd. These are more graphically oriented audio tools that will let you start experimenting with audio synthesis programming without having to deal with all the hard core programming and plugin interface stuff. You can just grab oscillators and filters and start connecting them together, but you can also drop code in as you go. It is programming, just a bit of a different kind than C++. If your goal is to start making noise, I'd get started with tools like these first.
posted by zachlipton at 3:24 PM on December 8, 2010


Have a poke around Music DSP, the hardcore resource for audio algorithms. Audio Units and VST are the packaging around this stuff.
posted by galaksit at 3:25 PM on December 8, 2010 [1 favorite]


Response by poster: zachlipton - I guess I should clarify; when I said 'work in audio synthesis' I meant 'work with programs like PD, Max/MSP, Supercollider et al'. My immediate goal isn't to get anything to make sound, I've been doing that for years! Really, I'd like to figure out how to incorporate my passion for audio synthesis into my study of C++.

Otherwise, the links posted so far seem like excellent resources; thanks!
posted by Horizontally a Champion at 3:55 PM on December 8, 2010


In addition to plugins, hacking on Audacity itself can be quite fun. I used to be an Audacity lead developer (no longer active). The code is very approachable C++ and you can choose to develop on Mac, Windows, or Linux. Your experience should let you do interesting things in the core audio code, but it's also a nice easy place to branch out into UI programming. The team is great (or at least, was several years ago when I was last in touch with them) but they could really use more help.
posted by mbrubeck at 4:05 PM on December 8, 2010


So, I'm a professional programmer who got bitten by the audio bug a few months ago.

I found a FANTASTIC programming language called ChucK. Now, I know you say you want to program C++ for this, but ChucK is far better suited to actually generating audio than C++ is--specifically, it handles time literally infinitely better than C++. You'd find yourself writing some sort of a framework for C++ soundgen anyway, and ChucK takes care of all the dreadfully boring IO and buffering and synchronization and tracking and sample rate/size compatibility and whatnot for you. This leaves you only having to work with the cool stuff: actually generating samples!

ChucK is written in (object-oriented) C and compiles with the C++ compiler--it crosslinks to C++ flawlessly. You can then write what are called UGens (for Unit Generators) in C++ that integrate seamlessly into the ChucK language.

This is what I wound up doing. I wrote a wavelet transform, and when I get back to it, I'll write displacement fractal synthesizer (essentially an inverse wavelet). I did this because I'm not a digital filter designer... it was easier to devise and reason about the operations in code than it was as abstract mathematical IIFs. But, I've very definitely written C++ code that generates noise. And it's fucking awesome.

Actually, if you're interested, I could throw my hacked version of the code up on GitHub and we could talk about these sorts of things. Memail me if you'd like. I definitely have a couple tricks I can show you, including a far more OO way of creating ChucK objects. I also have an OScope I hacked together, and a ruby-based meta-shell. Actually, I should put this shit up on GitHub anyway.
posted by Netzapper at 4:31 PM on December 8, 2010


Psst, this was my very first AskMe.

I cut my teeth on Perl and C++, and working in SuperCollider and ChucK is kind of a head trip for me. I find SuperCollider a little easier to work in then ChucK, as the super accurate ChucK timing combined with the way I think = pegged CPU.

I did a project using openFrameworks, sox, and GALib that was fun. OpenFrameworks is all C++ and makes dealing with video and sound files easy, but is still pretty raw in terms of code quality.
posted by mkb at 6:38 PM on December 8, 2010


Audacity uses portaudio, an audio library. I eventually wrote a couple of things using portaudio, and it's not a bad little library. Also look up libsndfile, and if need be, xiph.org has code for dealing with ogg files (tend to be used in game audio.) There's a linux audio developers mailing list (yeah, linux, but linux isn't necessarily so different from OS/X, and, the principles are the same.) that helped me a lot. One of my apps is a purely audio game (incidentally, inspired by a post here on metafilter. I'd link to my stuff, but, I'm ascared of the "no self link" rule.
posted by smcameron at 6:58 PM on December 8, 2010


Writing Supercollider UGens!
posted by phrontist at 9:40 PM on December 8, 2010


« Older Because "I just know" is not a sufficient...   |   Name that career Newer »
This thread is closed to new comments.