synthesizer

11ivan11
Posts: 15
Joined: Mon Apr 26, 2021 10:55 am

synthesizer

Post by 11ivan11 »

Hi, how to make knob that changes oscillator wave-form?
User avatar
utdgrant
Posts: 625
Joined: Wed Apr 07, 2021 8:58 am
Location: Scotland
Contact:

Re: synthesizer

Post by utdgrant »

11ivan11 wrote: Sat Oct 12, 2024 3:55 pm Hi, how to make knob that changes oscillator wave-form?
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?
KnobSmoothWaveform.jpg
KnobSmoothWaveform.jpg (11.33 KiB) Viewed 1178 times
Or a Minimoog with a discrete selection of switched waveforms?
KnobSwitchedWaveform.jpg
KnobSwitchedWaveform.jpg (14.81 KiB) Viewed 1178 times
______________________
Dome Music Technologies
User avatar
Waverley Instruments
Posts: 147
Joined: Thu May 05, 2022 2:10 pm

Re: synthesizer

Post by Waverley Instruments »

Or you could get real fancy... :)
Attachments
wav-knob.gif
wav-knob.gif (573.94 KiB) Viewed 1050 times
User avatar
resoluxe
Posts: 17
Joined: Wed Jul 20, 2022 10:23 am

Re: synthesizer

Post by resoluxe »

Now that is fancy - love it!
11ivan11
Posts: 15
Joined: Mon Apr 26, 2021 10:55 am

Re: synthesizer

Post by 11ivan11 »

like Minimoog with a discrete selection of switched waveforms
User avatar
utdgrant
Posts: 625
Joined: Wed Apr 07, 2021 8:58 am
Location: Scotland
Contact:

Re: synthesizer

Post by utdgrant »

11ivan11 wrote: Wed Nov 06, 2024 10:26 am like Minimoog with a discrete selection of switched waveforms
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
User avatar
utdgrant
Posts: 625
Joined: Wed Apr 07, 2021 8:58 am
Location: Scotland
Contact:

Re: synthesizer

Post by utdgrant »

11ivan11 wrote: Wed Nov 06, 2024 10:26 am like Minimoog with a discrete selection of switched waveforms
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.
PinkFlightWaveSwitch.PNG
PinkFlightWaveSwitch.PNG (94.95 KiB) Viewed 561 times
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
User avatar
utdgrant
Posts: 625
Joined: Wed Apr 07, 2021 8:58 am
Location: Scotland
Contact:

Re: synthesizer

Post by utdgrant »

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.
SwitchedAnalogueOscillator.jpg
SwitchedAnalogueOscillator.jpg (26.35 KiB) Viewed 516 times
YouTube Demo: Basic Switched Waveform Analogue Oscillator for Voltage Modular

The waveform selector knob is limited to four discrete steps.
WaveformKnob.jpg
WaveformKnob.jpg (72.17 KiB) Viewed 516 times
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();
This is the initialisation code:

Code: Select all

public void Initialize()
{
   // add your own code here

   previousPitchIn = -1000.0f;   // Force recalculate on first ProcessSample
This is the ProcessSample code:

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
11ivan11
Posts: 15
Joined: Mon Apr 26, 2021 10:55 am

Re: synthesizer

Post by 11ivan11 »

thank you but, my oscillators will go through mixer, that mixes signals as in korg ms-20
User avatar
utdgrant
Posts: 625
Joined: Wed Apr 07, 2021 8:58 am
Location: Scotland
Contact:

Re: synthesizer

Post by utdgrant »

11ivan11 wrote: Sat Nov 09, 2024 1:38 pm thank you but, my oscillators will go through mixer, that mixes signals as in korg ms-20
That's simple.

Add a new knob for output level.
VCOOutputLevelKnob.jpg
VCOOutputLevelKnob.jpg (70.45 KiB) Viewed 459 times
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 ***
Add these lines to the Knob_Changed event in Notify():

Code: Select all

      case Knob_Changed:   // doubleValue is the new VoltageKnob value
      {
         if (component == knobOutputLevel)
         {
            smoothVolume.SetValue(doubleValue);
         }
      }
      break;
Add this line to Initialize():

Code: Select all

   previousPitchIn = -1000.0f;   // Force recalculate on first ProcessSample
   smoothVolume.SetValue(knobOutputLevel.GetValue());    // NEW LINE***
Add this line to ProcessSample():

Code: Select all


      default:
      {
         outputValue = mainOscillator.GetPureSineValue();
      }
      break;
      
   }
   
   outputValue *= smoothVolume.GetSmoothValue();    // NEW LINE ***
   
   outputJack.SetValue(outputValue);
   

And you're good to go.
______________________
Dome Music Technologies
Post Reply

Return to “Module Designer”