Formula DSP: Global Variables Static?

Global variables that are defined in formula, are they treated statically or dynamically? Want to create a LFO that runs independent from Renoise BPM.

I think accessing variables directly changes the global value. Then when passing to function, some simple types are passed as copy on the stack (i.e. numbers), while others get handed over as reference (arrays) that will mess with the global copy of the data.

I have made a formula to set the Renoise LFO device frequency to Hz values that will be kept at constant speed when LPB or BPM change: Add Line, Beats and Hz mode to LFO device - #2 by OopsIFly

Maybe it helps you saving some time :smiley:

1 Like

I see.
The thing I want to avoid is using the LFO’s Frequency variable. Instead I’ll stick the LFO to INF and latch the formula output to LFO’s reset. May have to figure a way to use the SAMPLECOUNTER to achieve such thing.

Think I know where to go from here.
local timer = ((SAMPLECOUNTER)%SRATE) / SRATE

clock_generator

This generates I believe approximately a 60HZ clock signal, though I do have to check other parameters to verify this. But I think I got what I’m looking for.

1 Like

Very well done, proper way to get a high resolution clock in the formula device!

I have played around a little, and created an LFO based on it, it can do sine, saw, tri and sq. Maybe you find it interesting for you project, so here I share, copy&paste the text to renoise dsp panel:

copy&paste formula device preset
<?xml version="1.0" encoding="UTF-8"?>
<FilterDeviceClipboard doc_version="0">
  <DeviceSlot type="FormulaMetaDevice">
    <IsMaximized>true</IsMaximized>
    <IsSelected>true</IsSelected>
    <SelectedPresetName>SRATELFO</SelectedPresetName>
    <SelectedPresetLibrary>User Library</SelectedPresetLibrary>
    <SelectedPresetIsModified>false</SelectedPresetIsModified>
    <IsActive>
      <Value>1.0</Value>
      <Visualization>Device only</Visualization>
    </IsActive>
    <FormulaParagraphs>
      <FormulaParagraph>LFO(A,B,C)</FormulaParagraph>
    </FormulaParagraphs>
    <FunctionsParagraphs>
      <FunctionsParagraph>maxhz = 5.0</FunctionsParagraph>
      <FunctionsParagraph/>
      <FunctionsParagraph>local phase = 0.0</FunctionsParagraph>
      <FunctionsParagraph>local lasttime = -1.0</FunctionsParagraph>
      <FunctionsParagraph>local lastreset = -1.0</FunctionsParagraph>
      <FunctionsParagraph>function LFO(speed,mode,reset)</FunctionsParagraph>
      <FunctionsParagraph>  t=SAMPLECOUNTER</FunctionsParagraph>
      <FunctionsParagraph>  adv=0</FunctionsParagraph>
      <FunctionsParagraph>  if reset ~= lastreset and reset ~= 1.0 then</FunctionsParagraph>
      <FunctionsParagraph>    phase = reset</FunctionsParagraph>
      <FunctionsParagraph>    lastreset = reset</FunctionsParagraph>
      <FunctionsParagraph>  end</FunctionsParagraph>
      <FunctionsParagraph>  if t&gt;lasttime then</FunctionsParagraph>
      <FunctionsParagraph>    adv = t-lasttime</FunctionsParagraph>
      <FunctionsParagraph>    lasttime = t</FunctionsParagraph>
      <FunctionsParagraph>    phinc = (maxhz*speed*adv%SRATE)/SRATE</FunctionsParagraph>
      <FunctionsParagraph>    phase = (phase+phinc)%1.0</FunctionsParagraph>
      <FunctionsParagraph>  end</FunctionsParagraph>
      <FunctionsParagraph>  mode = floor(mode*3+1.5)</FunctionsParagraph>
      <FunctionsParagraph>  return lfo_modes[mode](phase)</FunctionsParagraph>
      <FunctionsParagraph>end</FunctionsParagraph>
      <FunctionsParagraph/>
      <FunctionsParagraph/>
      <FunctionsParagraph>function sinlfo(x)</FunctionsParagraph>
      <FunctionsParagraph>  return sin(x*TWOPI)*0.5+0.5</FunctionsParagraph>
      <FunctionsParagraph>end</FunctionsParagraph>
      <FunctionsParagraph/>
      <FunctionsParagraph>function sawlfo(x)</FunctionsParagraph>
      <FunctionsParagraph>  return x</FunctionsParagraph>
      <FunctionsParagraph>end</FunctionsParagraph>
      <FunctionsParagraph/>
      <FunctionsParagraph>function trilfo(x)</FunctionsParagraph>
      <FunctionsParagraph>  return abs(x-0.5)*2</FunctionsParagraph>
      <FunctionsParagraph>end</FunctionsParagraph>
      <FunctionsParagraph/>
      <FunctionsParagraph>function sqlfo(x)</FunctionsParagraph>
      <FunctionsParagraph>  return floor(x+0.5)</FunctionsParagraph>
      <FunctionsParagraph>end</FunctionsParagraph>
      <FunctionsParagraph/>
      <FunctionsParagraph>lfo_modes = {}</FunctionsParagraph>
      <FunctionsParagraph>lfo_modes[1] = sinlfo</FunctionsParagraph>
      <FunctionsParagraph>lfo_modes[2] = sawlfo</FunctionsParagraph>
      <FunctionsParagraph>lfo_modes[3] = trilfo</FunctionsParagraph>
      <FunctionsParagraph>lfo_modes[4] = sqlfo</FunctionsParagraph>
      <FunctionsParagraph/>
    </FunctionsParagraphs>
    <InputNameA>Hz*5</InputNameA>
    <InputNameB>mode</InputNameB>
    <InputNameC>reset</InputNameC>
    <EditorVisible>true</EditorVisible>
    <InputA>
      <Value>0.200000003</Value>
      <Visualization>Device only</Visualization>
    </InputA>
    <InputB>
      <Value>0.0</Value>
      <Visualization>Device only</Visualization>
    </InputB>
    <InputC>
      <Value>0.0</Value>
      <Visualization>Device only</Visualization>
    </InputC>
    <DestTrack>
      <Value>-1</Value>
      <Visualization>Device only</Visualization>
    </DestTrack>
    <DestEffect>
      <Value>-1</Value>
      <Visualization>Device only</Visualization>
    </DestEffect>
    <DestParameter>
      <Value>-1</Value>
      <Visualization>Device only</Visualization>
    </DestParameter>
  </DeviceSlot>
</FilterDeviceClipboard>
1 Like

Excellent stuff, made some adjustments to your code for solely being an independent clock but also allow the user to adjust the MaxHZ value between 1-10Hz.
INDEPENDENT LFO CLOCK.xrdp (2.8 KB)

We’re already beyond the discussion of this topic, I’ll deem this specific post as the solution and leave the topic as be. Also keep making stupid mistakes, sorry for the edited post.

1 Like

Yes very nice. With the “saw” mode or your version you can drive the reset of a standstill LFO, which is nice because it allows to use the custom graphical curve.

If you need more resolution to do high frequencies, you cantry tp push up bpm, lpb and alsouse high tpl. Then you can even use the formula device as kind of dirty low quality oscillator. But it has the drawback that the pattern data will fly through much too fast, also it uses a lot of cpu

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.