A Rotating Harmonic Sampling Quantizer

A Rotating Harmonic Sampling Quantizer

A quantizing sample and hold script with chord generator/arpeggiator functionality

This is a trigger based quantizer script with a few fun tricks up its sleeve and few different use cases. It is specifically designed for my setup in which I needed a simple quantizer but wanted to have the possibility of added harmonic interest and happy accidents. It has been surprisingly fun to play with so I thought I’d share.

At it’s most basic I wanted a utility quantizer to pair with the DFAM, and this is comically easy with the output scaling in the 2.0 firmware. Past that I wanted to be able to create related harmonic cv, and with 4 outputs it seemed natural to add a triad of harmonic offsets to the different outputs. And, finally, given that it is a trigger based script, I wanted something interesting to happen if the script was triggered but the voltage was unchanged, so I went with rotating the harmonic cv across the outputs to create arpeggiation that then resets if a voltage change is sampled.

This is the first code/script I’ve shared and the only coding I had done before I received the crow was on the Teletype, so happy to hear if people have better approaches to any of this.

Requirements

crow, trigger source, voltage source

Documentation

input[1] is the voltage to be sampled
input[2] is the trigger/gate in
output[1] is quantized version of the voltage sampled at input[1], unless rotation is present
output[2-4] are the harmonically related cv outs, as defined by ‘interval’, unless rotation is present

When the voltage sampled on input[1] is unchanged from the last time it was sampled, the outputs will begin to rotate, thus a straight clock source into input[2] with no voltage present on input[1] will be a 4 note arpeggio.

Once a new voltage is sampled, the rotation will revert and output[1] will once again by a chromatically quantized version of the input. Interesting things start happening when you vary your trigger & voltage sequences.

I included a couple of intervals, but is easy to add your own. Included intervals are major_9 (with major 3rd, 5th, and 9th) and minor_7 (with minor 3rd, 5th, and 7th).

script
--- rotating harmonic sampling quantizer
-- input[1] voltage to be sampled
-- input[2] trigger/gate in
-- output[1-4] chromatical cv out with rotation & harmonic relation

major_9 = { 4/12, 19/12, 26/12 }
minor_7 = { 3/12, 19/12, 22/12 }

-- set the intervals to relate to the root note
interval = minor_7

function init()
  input[2]{ mode = 'change', direction = 'rising' }

  for n=1,4 do output[n].scale( {} ) end
end

function update_buffer(root)
  local new_buffer = { root, 
                       root + interval[1], 
                       root + interval[2],
                       root + interval[3]
                     }
  return new_buffer
end

-- some default values
zero_event = true
default_value = input[1].volts
buffer = update_buffer(default_value)

function rotate_buffer(buffer)
  local new_buffer = { buffer[2], 
                       buffer[3],
                       buffer[4],
                       buffer[1]
                     }
  return new_buffer
end

function round(num, decimals)
  local mult = 10^(decimals)
  return math.floor(num * mult + 0.5) / mult
end

input[2].change = function()
  if(zero_event == true) then
    prev_sample = default_value
    zero_event = false
  end

  sample = input[1].volts

  -- remove the "noise" to accurately tell
  -- if the voltage has changed or not
  sample_r = round(sample/12, 2)
  prev_sample_r = round(prev_sample/12, 2)

  if(sample_r == prev_sample_r) then
    buffer = rotate_buffer(buffer)
  else
    buffer = update_buffer(sample)
    prev_sample = sample
  end

  output[1].volts = buffer[1]
  output[2].volts = buffer[2]
  output[3].volts = buffer[3]
  output[4].volts = buffer[4]
end
38 Likes

thanks for sharing

this looks wonderful!

thanks, crow is so ripe and powerful a platform for personal/custom quantizers. The ability to quantize input and output with whatever transforms / scaling you want , it feels like the surface is just being scratched at here.

7 Likes