4 ms·
I've never used either Csound or Supercollider extensively (more of a PD guy), but having tried to write a simple oscillator in pure C, even that turns out to b
by rollcat 3y ago
I've never used either Csound or Supercollider extensively (more of a PD guy), but having tried to write a simple oscillator in pure C, even that turns out to be non-trivial. The naive approach of sin(t * pi2 * freq) produces pops when varying the frequency - you need to keep track of current phase. And from there it begins, the further you dig the more things you find you thought were trivial. I wouldn't be surprised if this or that synthesizer got something wrong.
- bmitc 3y agoDid you continue on your own writing synthesis in C? Any resources you found helpful?
- cseleborg 3y agoBack when I was writing a software synth for fun (and also for getting hired in the audio industry), I found the book DAFX to be very helpful. It describes basic algorithms for doing digital audio, though not the state of the art.
- TheOtherHobbes 3y agoThere's a ton of information on DIY VST sites like KVR. https://www.kvraudio.com/forum/viewforum.php?f=33 https://www.kvraudio.com/forum/viewforum.php?f=33 Most VSTs are written in C++ rather than pure C to be compatible with VST wrappers, and also because a bit of class management simplifies some parts of the coding. There's no particular advantage to using pure C. The basics - oscillators, filters, envelopes, and such - are all solved problems, although you'll need to get up to speed on basic DSP concepts like aliasing, IIR vs FIR filter designs, and such. More sophisticated filter types use numerical approximation to solve the filter equations. That gets a little more complicated. And of course you can look at the source code of Csound and Supercollider.
- bmitc 3y agoThanks! > The basics - oscillators, filters, envelopes, and such - are all solved problems, When you say this, are there any good reference materials (i.e., books or papers) of the algorithms?
- rollcat 3y agoReading other people's code helps a lot! Browse Github topics like "synth", "synthesizer", you can also narrow it down by language (C, C++, D, Rust, and Go are all fairly easy to translate between one another). I haven't looked at any of the theory stuff, which would've probably helped too. I kind-of abandoned the project before I could figure out what went wrong when rewriting it to keep track of the phase. I understand what needs to be done, I just have a stupid bug somewhere down there and it kinda demotivated me.
- bmitc 3y agoThanks! Part of my issue is that I cut my teeth on functional languages, so I am quite wary of C++, which makes this hard. I'm indeed looking to pick up Rust or get more practice with C, as there isn't that much choice beyond those.
- rollcat 3y agoThe hardest part is probably manual memory management, and getting used to expressing solutions using iteration rather than recursion? I don't like C++ (and have mixed feelings about Rust) because of how large and complex the entire language is. If you'd like a stopgap where you can still enjoy the functional style, and don't mind compromising on raw performance, Python is great. The operator syntax is also quite close to C, and you do get bindings to GStreamer in case you decide to take your audio project in new directions.
- bmitc 3y agoI roll with F# these days, which does imperative programming nicely and can reach out to unmanaged DLLs. I agree with not liking C++ and being hesitant about Rust, as it brings its own complexity. At least C is simple, but often too simple.
- zebproj 3y agoYou might enjoy my project called sndkit [0]. It's a collection of DSP algorithms implemented in C, written in a literate programming style, and presented inside of a static wiki. There's also a tiny TCL-like scripting language included that allows one to build up patches. This track [1] was made entirely using sndkit. 0: https://pbat.ch/sndkit/ https://pbat.ch/sndkit/ 1: https://soundcloud.com/patchlore/synthwave https://soundcloud.com/patchlore/synthwave
- chuchana 3y agoSounds interesting. I'll have a look.