You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
966B

  1. // Voltage-controlled oscillator example
  2. // by Andrew Belt
  3. // adapted for SC by Brian Heim
  4. ~vcv_frameDivider = 1;
  5. ~vcv_bufferSize = 32;
  6. ~phase = 0;
  7. ~vcv_process = { |block|
  8. var pitch, freq, deltaPhase;
  9. // Knob ranges from -5 to 5 octaves
  10. pitch = block.knobs[0] * 10 - 5;
  11. // Input follows 1V/oct standard
  12. // Take the first input's first buffer value
  13. pitch = pitch + block.inputs[0][0];
  14. // The relationship between 1V/oct pitch and frequency is `freq = 2^pitch`.
  15. // Default frequency is middle C (C4) in Hz.
  16. // https://vcvrack.com/manual/VoltageStandards.html#pitch-and-frequencies
  17. freq = 261.6256 * pow(2, pitch);
  18. postf("Freq: % Hz", freq);
  19. deltaPhase = ~vcv_frameDivider * block.sampleTime * freq;
  20. // Set all samples in output buffer
  21. block.bufferSize.do { |i|
  22. // Accumulate phase & wrap around range [0, 1]
  23. ~phase = (~phase + deltaPhase) % 1.0;
  24. // Convert phase to sine output
  25. block.outputs[0][i] = sin(2pi * ~phase) * 5;
  26. };
  27. block
  28. }