SynthMaker

Coding mono oscillators

Archive · 2005 8 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

galaa ·

As I am fairly new to DSP stuff I'd thought I'd ask for a bit of advice. In a post about portamento stefan gave me some code to create a mono sine oscillator. 🙂

monoin freq; monoout output; float cnt;

cnt = cnt + freq; cnt = cnt - ((cnt >= 1.0) & 1.0); output = sin1(cnt);

If I wanted to create other mono oscillators whats the best way of going about it. Can I create lots of separate sine waves and add them togther additive synth style or is there a more effecient way of creating such a thing using code. I want to be able to create the common waveforms (saw/square/tri/etc) and once I've got the hang of these I'll create others.

stefan ·

if you'd just change the output = sin1(cnt); to output = cnt; you'd get an aliasing sawtooth.

another way to do different waveforms is to use phase feedback within the oscillator, for instance like this:

monoin freq; monoout output; float cnt; float feedback; feedback = 0.2;

cnt = cnt + freq; cnt = cnt - ((cnt >= 1.0) & 1.0); output = sin1(cnt + output * feedback);

By adjusting the feedback you can "morph" the waveform between a sine and a saw. If you instead do a feedback with the phase "squared" you'll get a pulse waveform, like this:

output = sin1(cnt + output * output * feedback);

Too high feedback rates will introduce an instability that is undesired, so keep away from doing that.

You can also create pulsewaveforms by mixing sawtooths (invert one of them and you'll get a pulse with variable pulse width by moving the phase of one of the oscillators)

galaa ·

🙂 🙂 🙂 🙂 where have you been all my life!!!!

Fantastic. Thanks a lot for your help.

Now all I've got to do is pick the code apart and try and figure out what its doing. Can you recommend any textbooks/websites/etc where a DSP newbie can learn all about this kind of thing

stefan ·

Recently this huge gem was posted on kvr http://math.uga.edu/~djb/html/music.pdf

it's an awesome resource and getting updated when needed etc. great book. for free, whic is totally "wtf".

galaa ·

Thanks I've downloaded it. It's massive!!! Gonna take a while to read through that!!!! 😀

galaa ·

stefancrs wrote: You can also create pulsewaveforms by mixing sawtooths (invert one of them and you'll get a pulse with variable pulse width by moving the phase of one of the oscillators)

How would I create a piece of code that enabled me to vary the phase of one of the sawtooths. I am using the following code you posted:

monoin freq; monoout output; float cnt; float feedback; feedback = 0.2;

cnt = cnt + freq; cnt = cnt - ((cnt >= 1.0) & 1.0); output = sin1(cnt + output * feedback);

I am just guessing, but would I define the 'cnt' variable as having a non-zero starting value.

stefan ·

galaa wrote: stefancrs wrote: You can also create pulsewaveforms by mixing sawtooths (invert one of them and you'll get a pulse with variable pulse width by moving the phase of one of the oscillators)

How would I create a piece of code that enabled me to vary the phase of one of the sawtooths. I am using the following code you posted:

monoin freq; monoout output; float cnt; float feedback; feedback = 0.2;

cnt = cnt + freq; cnt = cnt - ((cnt >= 1.0) & 1.0); output = sin1(cnt + output * feedback);

I am just guessing, but would I define the 'cnt' variable as having a non-zero starting value.

just do it like this:

monoin freq; monoin phase; monoout output; float cnt; float feedback; feedback = 0.2;

cnt = cnt + freq; cnt = cnt - ((cnt >= 1.0) & 1.0); output = sin1(cnt + phase + output * feedback);

you can also use the phase input as a fm input.

galaa ·

Ah of course much simpler and you can have control over the phase value. Thanks you're a great help

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.