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!
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!
Start reading this -> www.dspguide.com
Don't be afraid of experiment. Have fun!
Don't be afraid of experiment. Have fun!
Thank you!
Best advice might be:
1/ fiddle with hardware or VSTi synthesizers.
1/ fiddle with hardware or VSTi synthesizers.
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.
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.
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)*envelope*66
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)*envelope*66
http://www.dcs.shef.ac.uk/intranet/teaching/public/projects/archive/ug2004/pdf/u1nh.pdf
two source code packages where you can find sources:
http://pouet.net/prod.php?which=52834
http://pouet.net/prod.php?which=59335
there was a very interesting introduction somewhere else, but I don't remember the website...
two source code packages where you can find sources:
http://pouet.net/prod.php?which=52834
http://pouet.net/prod.php?which=59335
there was a very interesting introduction somewhere else, but I don't remember the website...
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.
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.
@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 :)
Thank you guys! I hope I’ll have enough knowledge to write my soft synth and VST(i) plugin :)
Quote:
1. setup audio buffers
...or write it out to WAV/RAW/etc. - much easier to start with.
@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:
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.
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.
Ooops, wanted to post
*variable sequence is array of note
but you should get the general idea
*variable sequence is array of note
but you should get the general idea
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 :)
sample frequency is exactly how much it's sampled :)
44100hz -> samples[44100] is one second of audio
44100hz -> samples[44100] is one second of audio
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).
How not to write a softsynth.
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.
Read this thread, and follow all links.
Also read The Computer Music Tutorial by Curtis Roads. It is the bible.
Also read The Computer Music Tutorial by Curtis Roads. It is the bible.