Page 1 of 1

Beginner question

Posted: Fri Jan 08, 2021 5:30 pm
by aintteyen
So i recently started using Module Designer and so far i have built my first LFO and oscillator, however i really need some help on how to implement v/oct input.

Re: Beginner question

Posted: Mon Jan 11, 2021 11:11 am
by ColinP
This is one of those things that I would have thought was super easy to find sample code for but a quick google reveals nothing very useful. And I must confess that this is something I've never coded myself but kind of just assumed was simple.

Someone else here can probably come up with better advice but I think you could start with the Java.lang.Math pow() method to convert voltage to frequency.

Something like frequency = pow( 2.0, voltage ).

This produces the 1 V/Octave curve so 0 V = 1 Hz, 1 V = 2 Hz, 2 V = 4 Hz, 3 V = 8 Hz and so on. Then you'd scale it so that the frequencies were in the range you wanted. Unfortunately there's no accepted standard for what pitch 0 V represents but most people choose either C0 or C2.

On modern CPUs pow() might not be as expensive as it used to be but one simple optimisation would be to only call pow() when the voltage changes rather than every sample.

As I said, I've never done this and am kind of surprised that it's not well documented. I don't have the time to look at this in more depth but hopefully another developer has already done this and can chip in with wiser words and maybe a snippet of source code.

Re: Beginner question

Posted: Mon Jan 11, 2021 9:55 pm
by aintteyen
ColinP wrote:
Mon Jan 11, 2021 11:11 am
This is one of those things that I would have thought was super easy to find sample code for but a quick google reveals nothing very useful. And I must confess that this is something I've never coded myself but kind of just assumed was simple.

Someone else here can probably come up with better advice but I think you could start with the Java.lang.Math pow() method to convert voltage to frequency.

Something like frequency = pow( 2.0, voltage ).

This produces the 1 V/Octave curve so 0 V = 1 Hz, 1 V = 2 Hz, 2 V = 4 Hz, 3 V = 8 Hz and so on. Then you'd scale it so that the frequencies were in the range you wanted. Unfortunately there's no accepted standard for what pitch 0 V represents but most people choose either C0 or C2.

On modern CPUs pow() might not be as expensive as it used to be but one simple optimisation would be to only call pow() when the voltage changes rather than every sample.

As I said, I've never done this and am kind of surprised that it's not well documented. I don't have the time to look at this in more depth but hopefully another developer has already done this and can chip in with wiser words and maybe a snippet of source code.
Basically the converting voltage to frequency was the thing that got me stumped. Thank you, I will try this.

Re: Beginner question

Posted: Tue Jan 12, 2021 2:58 pm
by honki-bobo
Check out this thread:
viewtopic.php?f=8&t=974#p3753

Re: Beginner question

Posted: Tue Jan 12, 2021 4:26 pm
by ColinP
That thread actually confused me.

I can see that 55.0 * 2.0 ^ ( x + 0.25 ) produces, as shown in the screenshot, C5 with x = 3 but it took me several minutes to figure it out.

F = FZ * 2 ^ V

or

frequency = frequencyAtZeroVolts * pow( 2.0, voltage );

seems far easier to understand.