synthesizer
synthesizer
Hi, how to make knob that changes oscillator wave-form?
Re: synthesizer
It depends on whether you want to smoothly morph between waveforms, or use the knob as a rotary selector switch.
Are you thinking along the lines of the RSF Kobol, with its continuously variable morph knob?
Or a Minimoog with a discrete selection of switched waveforms?
______________________
Dome Music Technologies
Dome Music Technologies
- Waverley Instruments
- Posts: 147
- Joined: Thu May 05, 2022 2:10 pm
Re: synthesizer
Or you could get real fancy...
- Attachments
-
- wav-knob.gif (573.94 KiB) Viewed 1013 times
Re: synthesizer
Now that is fancy - love it!
Re: synthesizer
like Minimoog with a discrete selection of switched waveforms
Re: synthesizer
Firstly, select the style of knob you would like from the selection available in VMD.
Decide how many different waveforms you want to switch between. Make this a constant called NUMBER_OF_WAVEFORMS.
In the knob parameters, set min range to 1.0 and max range to NUMBER_OF_WAVEFORMS. Set the number of discrete steps to NUMBER_OF_WAVEFORMS.
Try this out in the debugger to get a feel for how this looks and feels.
If you want to read some similar code, download the Dome Music Technologies source code zip file, and open up one of the Drawbar Mixer projects. This turns a VoltageSlider control into a 9-position (0 for off and volumes 1 to 8) vertical switch.
______________________
Dome Music Technologies
Dome Music Technologies
Re: synthesizer
If you want an example of how to generate switched waveforms in ProcessSample, you can check out the source code for the Pink Flight Divide-Down Oscillator. This has a three-position switch to choose between Sawtooth, Pulse and Triangle waveforms, but you can just as easily use a knob with discrete steps as described in my previous post.
The wave selection and generation logic is contained in these lines of code:
Code: Select all
switch (currentWaveform)
{
case PULSE:
{
channelOscillator[i].SetPulseWidth(pulseWidth);
oscillatorOutput = channelOscillator[i].GetPulseValue();
}
break;
case TRIANGLE:
{
oscillatorOutput = channelOscillator[i].GetTriangleValue();
}
break;
default:
{
oscillatorOutput = channelOscillator[i].GetSawtoothValue();
}
break;
}
______________________
Dome Music Technologies
Dome Music Technologies
Re: synthesizer
I threw this one together in about an hour tonight. It's not the clearest of code, or the most efficient, but it gets the job done.
YouTube Demo: Basic Switched Waveform Analogue Oscillator for Voltage Modular
The waveform selector knob is limited to four discrete steps.
This is the User Variable code:
This is the initialisation code:
This is the ProcessSample code:
YouTube Demo: Basic Switched Waveform Analogue Oscillator for Voltage Modular
The waveform selector knob is limited to four discrete steps.
This is the User Variable code:
Code: Select all
// Add your own variables and functions here
private final float BASE_FREQUENCY = 65.4f;
private float previousPitchIn;
private AnalogOscillator mainOscillator = new AnalogOscillator();
Code: Select all
public void Initialize()
{
// add your own code here
previousPitchIn = -1000.0f; // Force recalculate on first ProcessSample
Code: Select all
public void ProcessSample()
{
// add your own code here
float tempFloat;
float pitchIn;
double tempDouble;
double pulseWidthIn;
double pulseWidth;
double outputValue;
int waveformNumber;
pitchIn = (float) inputJackPitch.GetValue();
if (pitchIn != previousPitchIn)
{
// Recalculate exponential frequency
tempFloat = BASE_FREQUENCY * Values.FastTwoToTheX(pitchIn);
mainOscillator.SetFrequency(tempFloat);
}
waveformNumber = (int) knobWaveform.GetValue();
if (waveformNumber == 2) // Pulse
{
pulseWidth = knobPulseWidth.GetValue();
if (inputJackPWM.IsConnected())
{
tempDouble = inputJackPWM.GetValue() *
knobPWM.GetValue() *
0.2;
pulseWidth += tempDouble;
}
mainOscillator.SetPulseWidth (pulseWidth);
}
mainOscillator.AdvanceSample();
switch (waveformNumber)
{
case 1:
{
outputValue = mainOscillator.GetSawtoothValue();
}
break;
case 2:
{
outputValue = mainOscillator.GetPulseValue();
}
break;
case 3:
{
outputValue = mainOscillator.GetTriangleValue();
}
break;
default:
{
outputValue = mainOscillator.GetPureSineValue();
}
break;
}
outputJack.SetValue(outputValue);
}
______________________
Dome Music Technologies
Dome Music Technologies
Re: synthesizer
thank you but, my oscillators will go through mixer, that mixes signals as in korg ms-20
Re: synthesizer
That's simple.
Add a new knob for output level.
YouTube demo: Adding Level Knob to Switched Oscillator
Add a SmoothValue object to the User Variables area:
Code: Select all
private final float BASE_FREQUENCY = 65.4f;
private float previousPitchIn;
private AnalogOscillator mainOscillator = new AnalogOscillator();
private SmoothValue smoothVolume = new SmoothValue(); // NEW LINE ***
Code: Select all
case Knob_Changed: // doubleValue is the new VoltageKnob value
{
if (component == knobOutputLevel)
{
smoothVolume.SetValue(doubleValue);
}
}
break;
Code: Select all
previousPitchIn = -1000.0f; // Force recalculate on first ProcessSample
smoothVolume.SetValue(knobOutputLevel.GetValue()); // NEW LINE***
Code: Select all
default:
{
outputValue = mainOscillator.GetPureSineValue();
}
break;
}
outputValue *= smoothVolume.GetSmoothValue(); // NEW LINE ***
outputJack.SetValue(outputValue);
______________________
Dome Music Technologies
Dome Music Technologies