Go to bottom

How to: write a soft synthesizer

category: code [glöplog]
Hi there!

I’ve been wondering for a while, how to write a soft syntesizer? I don’t mean technologies or raw code, but what are the steps? The theory? I’m looking for good references that explain how to write synthesizer (and if possible VST plugins).

I’ll likely be writing such a synthesizer in some months so… some theory is needed! :)

Any idea? Thank you!
added on the 2013-05-28 15:31:00 by phaazon phaazon
added on the 2013-05-28 15:42:49 by reed reed
added on the 2013-05-28 15:44:33 by reed reed
Start reading this -> www.dspguide.com

Don't be afraid of experiment. Have fun!
added on the 2013-05-28 15:44:34 by ham ham
added on the 2013-05-28 15:47:52 by reed reed
Thank you!
added on the 2013-05-28 15:51:05 by phaazon phaazon
added on the 2013-05-28 15:52:19 by MsK` MsK`
added on the 2013-05-28 15:59:53 by revival revival
Best advice might be:
1/ fiddle with hardware or VSTi synthesizers.
added on the 2013-05-28 16:23:55 by __ __
Also: Being a musician or at least having a musician involved during development time helps.
And for building a VST around your synth, you may want to give the JUCE framework a try.
Saga, it's actually what I meant a bit... also, becoming a jazz musician helps.
added on the 2013-05-28 17:18:14 by __ __
1. setup audio buffers
2. write efficient code for waveforms (saw wave, square wave, sine wave)
3. combine them

Step 3 is the hardest because you need experience to get it to sound good, but there are a few basic operations you can do:

start with a sine wave: sin(t*.5)*60

overlap slightly detuned waveforms (sin(t*.5)+sin(.499*t))*33

you can add harmonics, this will now sound like an organ (sin(t)+sin(t*.500)+sin(.25*t)+sin(.125*t))*23

use envelopes (sin(t)+sin(t*.500)+sin(.25*t)+sin(.125*t))*Math.pow((-t&0x7fff)/0x8000,4.0) *33

and you can also do FM envelope=Math.pow((-t&0x3ff)/0x400,3.0),fm=sin(t*.1)*t/0x2000,sin(fm+t)*enve lope*66
added on the 2013-05-28 20:11:23 by mu6k mu6k
http://www.dcs.shef.ac.uk/intranet/teaching/public/projects/archive/ug2004/pdf/u 1nh.pdf

two source code packages where you can find sources:

there was a very interesting introduction somewhere else, but I don't remember the website...
added on the 2013-05-28 20:31:47 by questor questor
for a lesson on history: lft seminar on elements of chipmusic
also what mu6k said made me think, is there material on how to you use a synth? i have seen the usual explanations of soundsynthesis quite often, fm, am, granular and all their values. but rarely anything beyond that. gargaj's maing of the chaos theory baseline was very interesting in that regard. or the modeling of a guitar string thread.
added on the 2013-05-28 20:48:53 by vectory vectory
@mu6k, that’s very interesting. But I guess it’s more complicated to make something more melodic?

Thank you guys! I hope I’ll have enough knowledge to write my soft synth and VST(i) plugin :)
added on the 2013-05-28 21:09:10 by phaazon phaazon
1. setup audio buffers

...or write it out to WAV/RAW/etc. - much easier to start with.
added on the 2013-05-28 21:39:46 by Gargaj Gargaj
@skypers, that's just an example of how to get some sounds working.

Writing a long monolithic function that generates the music isn't a very good idea. You'll get headaches and bad performance.

Here is a pseudocode of something I would do if I wanted to get a few notes working:

Code: struct note is frequecny, duration end struct function synth(time, frequency, envelope_time) : audio_sample return sin(time*frequency)/(envelope_time*.1 + 1.0); end function variable note is array of sequece <- ((C5,10000),(E5,10000),(G5,20000)) for each note in sequence do for envelope_time in range(1 to note.duration) do data <- synth(time,note.frequency,envelope_time) write(audio_buffer, data) time <- time + 1 end for end for

You can add volume information and effect parameters in your sequence and ofc multiple channels. It all depends on the choices you take when you're designing your synth. Start small. Get a few beeps working first. You can write a raw binary file and load it as an 8-bit sound sample from Open Mod Plug Tracker.
added on the 2013-05-28 22:11:14 by mu6k mu6k
Ooops, wanted to post
*variable sequence is array of note

but you should get the general idea
added on the 2013-05-28 22:13:38 by mu6k mu6k
So audio buffers are just sampled signal, but every how many ms? Is this related to the sample frequency (44100 Hz for our ears)? Thank you anyway! You help a lot :)
added on the 2013-05-28 22:38:45 by phaazon phaazon
sample frequency is exactly how much it's sampled :)

44100hz -> samples[44100] is one second of audio
added on the 2013-05-28 22:40:47 by ferris ferris
and to be correct, you really only hear stuff in the 20->20khz range or so, so 44100hz covers that spectrum pretty well (as you can only accurately represent harmonics below half the sample rate, or the nyquist frequency).
added on the 2013-05-28 22:43:57 by ferris ferris
How not to write a softsynth.
added on the 2013-05-28 22:44:13 by __ __
also, as far as starting out with synths advice goes, I second what mu6k is saying. I think Polaris had a seminar at Pilgrimage '05 or something about getting started with similar techniques, which is how I got into it.
added on the 2013-05-28 22:45:43 by ferris ferris
Read this thread, and follow all links.
Also read The Computer Music Tutorial by Curtis Roads. It is the bible.
added on the 2013-05-28 22:47:58 by numtek numtek


Go to top