Jump to content


Photo

Generative Sequences with the Formula device

formula generative procedural

  • Please log in to reply
13 replies to this topic

#1 portabello

portabello

    New Member

  • Normal Members
  • Pip
  • 7 posts

Posted 10 March 2018 - 23:42

Warning: This is some pretty advanced stuff and requires a bit of lua knowledge.

 

With some clever abuse of the formula device you can generate some pretty cool musical sequences in real time:

An example: Attached File  generative-acid.xrns   70.09KB   153 downloads
To start with we create an instrument and set its pitch modulation range to the maximum value of 96. Then we create a macro control for the pitch slider.
Next we create a formula device and route a rising sawtooth LFO to one its inputs.
If we do something like the following:

seq = {0, 3, 1, 6, 3, 5, 7, 8}

function playSeq()
  idx = floor(A * #seq) + 1
  pitch = seq[idx]
  return (96 + pitch) / 192 -- this bit normalizes the pitch values from semitones to macro values
end

and have our output be

y = playSeq()

We can modulate our pitch macro control with the formula output and play back arbitrary sequences. This can get particularly interesting if we generate new sequences on the fly using some sort of generative/procedural algorithm. In the attached XRNS file I'm using this code to generate the pitch data:

SCALE = {0, 1, 5, 7, 8, 12}

pitches = {}
glides = {}
shouldReset = true

glideChance = 0.25

currentPitch = 0
currentGlide = false

numOctaves = 3
numPitchSteps = 16
numGlideSteps = 32

function generatePitch()
  local idx = floor(random(1, 6))
  local octave = floor(random(0, numOctaves)) * 12

  return SCALE[idx] + octave
end

function generatePitches()
  for i = 1, numPitchSteps  do
    pitches[i] = generatePitch()
  end
end

function generateGlide()
  return random() < glideChance
end

function generateGlides()
  for i = 1, numGlideSteps do
    glides[i] = generateGlide()
  end
end

function resetData()
  generatePitches()
  generateGlides()
end

function makePitch(steps)
  return (steps + 96) / 192
end

function tick()
  if LINE == 0 or #pitches == 0 then
    if shouldReset then
      resetData()
      shouldReset = false
    end
    else
      shouldReset = true
    end

  local idx = floor(A * 32)
  local pitchIdx = mod(idx, numPitchSteps) + 1
  local glideIdx = mod(idx, numGlideSteps) + 1

  currentPitch = pitches[pitchIdx]
  currentGlide = glides[glideIdx]
  local glideRate = 1
  if currentGlide then
    glideRate = 0.2
  end


  local pitch = makePitch(currentPitch)

  return (glideRate * pitch) + ((1 - glideRate) * OUTPUT)
end

With the output being:

y = tick()

Check out the attached file to see this in action.

 

Attached Files


  • dblue, afta8, Ohrwert and 8 others like this

#2 dblue

dblue

    Dodgy Geezer

  • Admins
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5790 posts
  • Gender:Male
  • Location:Berlin
  • Interests:Code. Music. Graphics.

Posted 11 March 2018 - 00:50

Soooooooo rad!!! :D

#3 Neurogami

Neurogami

    Big Super GrandMasta Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 723 posts
  • Gender:Male
  • Location:Scottsdale AZ
  • Interests:Art, music, technology

Posted 11 March 2018 - 01:33

Oh shit!

 

Thank you.



#4 danoise

danoise

    Probably More God or Borg Than Human Member

  • Renoise Team
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 6844 posts
  • Gender:Male
  • Location:Berlin
  • Interests:wildlife + urban trekking

Posted 12 March 2018 - 19:47

Seriously, I love how it churns out a new sequence each time the pattern loops.

Could listen to this for a looong time :-)


Tracking with Stuff. API wishlist | Soundcloud


#5 gentleclockdivider

gentleclockdivider

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2811 posts
  • Gender:Male
  • Location:something like a sea or a river...just moving
  • Interests:slacking

Posted 12 March 2018 - 22:41

Nice !


THERE IS NO RELIGION SUPERIOR TO THE TRUTH


THERE IS NO TRUTH SUPERIOR TO THE ONE I CHOOSE

C'EST MIEUX D'ETRE BELLE ET REBELLE


QUE MOCHE ET REMOCHE



RUBIO RABIA

 


#6 vmuriel

vmuriel

    Member

  • Normal Members
  • PipPip
  • 19 posts
  • Gender:Male

Posted 13 March 2018 - 00:41

So cool, thanks for sharing.

Any way to edit the lua code in a external editor while renoise is running ?



#7 Zer0 Fly

Zer0 Fly

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1197 posts
  • Gender:Male
  • Location:Oops
  • Interests:Flying

Posted 13 March 2018 - 01:04

I usually just copy&pase formula device code to a text editor program.



#8 portabello

portabello

    New Member

  • Normal Members
  • Pip
  • 7 posts

Posted 13 March 2018 - 07:03

I wrote my initial version in vim then debugged everything in the formula edit window . Not a great user experience but neither is copying and pasting whenever I need to change something. I would love to be able to have it do some sort of file-watching and just let me edit externally. Even being able to load in a lua file at all would be nice. Also, as long as I'm wishing for things: I would looooove an audio-rate formula device! I tried to implement audio rate FM but it seems that the formula device only updates every tick so my sinusoids were aliasing like I've never seen before sad.png


Edited by portabello, 13 March 2018 - 07:04.

  • vmuriel and Neurogami like this

#9 vmuriel

vmuriel

    Member

  • Normal Members
  • PipPip
  • 19 posts
  • Gender:Male

Posted 13 March 2018 - 10:19

Lua is not fast enough to run at sample rate speed.

File-watching + 1.

 

Would be nice a formula device using c language with some kind of jit compilation.

Compile externally and load as a library.

Or use something like Tiny C https://github.com/TinyCC/tinycc

LuaJit http://luajit.org/luajit.html

 

Just dreaming.



#10 boonier

boonier

    Super Advanced Member

  • Normal Members
  • PipPipPipPip
  • 141 posts

Posted 23 March 2018 - 09:28

This is great btw, inspired

 

Re JIT something like this http://www.osar.fr/protoplug/ but native?



#11 afta8

afta8

    Big Super GrandMasta Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 751 posts
  • Gender:Male
  • Location:London

Posted 24 March 2018 - 12:26

Love this, having great fun hacking the code, thanks for showing us how :D



#12 ΔBįSƧȔš ṼØȊÐƎ

ΔBįSƧȔš ṼØȊÐƎ

    Big Masta Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPip
  • 513 posts
  • Gender:Male
  • Location:Terror Australis

Posted 07 April 2018 - 23:41

Yes! Much thx. Will have a crack at this asap. Very much getting into generative art/music making. So far have only implemented it via phrase editor and Y command. This looks intriguing thx!


┷┯┷┯┷┷┗┯┷┯┷┗┯┷ Ŧh̢ƏRę̡ I̕§ ̛B̢ë̕ΔÜt¥ i̷Й͟ ͘È̷ЯRØŔ̵ ͠ ä₦Ð MɐĢ͟iƆ !Ṇ͢ ӍΔLℲuИ¢Ț̡ï̸Ѻп ┯┷┯┯┷┷┯┷┷┗┷┷┯  

┷┷┗┯┷┯┷┷┗┯┷┯┷┯┷┗┷┯┷┷┷┷┗┯┷┯┯┷┷┯┷┗┷┗vaeprism.com┷┷┗┯┷┯┷┷┗┯┷┯┷┯┷┗┷┯┷┗┷┗┷┯┷┷┗┷┯┷┗┯


#13 The_Traveler

The_Traveler

    Super Advanced Member

  • Normal Members
  • PipPipPipPip
  • 173 posts
  • Gender:Male
  • Interests:Exploring timbrality ...

Posted 20 April 2018 - 03:03

Thanks for much for sharing this! +1

 

I never thought about using the formula device to solve a problem I'm having. It might just work ... :)

 

Cheers


Edited by The_Traveler, 20 April 2018 - 03:04.


#14 Psynapsex

Psynapsex

    Super Advanced Member

  • Normal Members
  • PipPipPipPip
  • 146 posts
  • Gender:Male
  • Interests:Synthesis, Electronics, & Day Trading (I'm a noob)

    I'm a big fan of Venetian Snares, Psykovsky, Richard Devine, and The Advent.

    I've been using Reaktor 5 since 2008, and love the thought of a real analog modular synth.

Posted 03 June 2018 - 19:57

Is there a resource on the web that hosts a variety of formulas?





Also tagged with one or more of these keywords: formula, generative, procedural