User Tools

Site Tools


vividshaper_reference_manual

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
vividshaper_reference_manual [2023/10/25 08:38] larsvividshaper_reference_manual [2024/03/30 10:02] (current) lars
Line 21: Line 21:
  
 ===== A simple example ===== ===== A simple example =====
 +In this example, we'll demonstrate how to create a basic patch using VividShaper's Lua API.
 +
 <code Lua> <code Lua>
 -- Patch: A simple example -- Patch: A simple example
Line 27: Line 29:
 </code> </code>
  
-The above example will create Triangle wave at the base frequency 1 Hz, meaning it will oscillate one time over the wavetable. The volume will then be set to an exponential volume ADSR envelope, with attack=1 sec, decay=1 sec, sustain=0.8, release=3 sec, startlevel=0. The name of the wave table will be "A simple example".+This example encapsulates the fundamental process of generating wave and setting its volume envelope in VividShaper. The line **wave[1] = VSTriangle(1,0)** creates a triangle wave at the base frequency of 1 Hz and phase of 0 degrees (between 0-360 degrees). You need to provide both arguments even if you are not phase shifting the wave. The frequency here refers to the number of complete cycles of the Triangle wave form that fits within the sample (consisting of 128 sample points). A frequency of 1 Hz means one complete cycle of the triangle fits within the 128 samples. 
 + 
 +This is not the playback frequency of the note (i.e. which note that is being played). The speed of the 128 samples is determined by note[1] for oscillator 1. We don't have to set note[1] explicitly, it is already set by the note you are playing on the keyboard. However, if we do wish to change it, for instance transposing one octave, we can do so by setting: **note[1] = notein+12**. Alternatively, if we wish to set it to a constant value, making it play back the same note even if play another note, we could do that as well: **note[1] = 40**. 
 + 
 +The volume will then be set to an exponential volume ADSR envelope, with attack=1 sec, decay=1 sec, sustain=0.8, release=3 sec, startlevel=0. The name of the wave table will be "A simple example".
  
 This is all it takes to generate a simple wave. This will then be played back at different speeds, depending on the note being played. This is all it takes to generate a simple wave. This will then be played back at different speeds, depending on the note being played.
Line 46: Line 52:
 gatetimeon     -- Time in seconds for how long the key was pressed. gatetimeon     -- Time in seconds for how long the key was pressed.
 gatetimeoff    -- Time in seconds since the key was released. gatetimeoff    -- Time in seconds since the key was released.
 +timeon         -- The number of seconds since the generator was turned on. Resets after parse.
 +gtimeon        -- Global time. The number of seconds since the first generator was turned on. Resets after parse.
 tick           -- The number of times the Lua code has been called since initiation (when tick=0). tick           -- The number of times the Lua code has been called since initiation (when tick=0).
 cc[x]          -- Value of CC message x (between 0 to 127). cc[x]          -- Value of CC message x (between 0 to 127).
Line 55: Line 63:
  
 -- Output information -- Output information
-wave[x]        -- Wave array x (one array for each oscillator x).+wave[x]        -- Wave array x (one array for each oscillator x, 128 elements).
 panning[x]     -- Panning for oscillator x (between 0 - 1; 0 = left, 0.5 = middle, 1= right). panning[x]     -- Panning for oscillator x (between 0 - 1; 0 = left, 0.5 = middle, 1= right).
 note[x]        -- Note output for oscillator x (default value is the same as note). note[x]        -- Note output for oscillator x (default value is the same as note).
 vol[x]         -- Volume for oscillator x. Default is 0. vol[x]         -- Volume for oscillator x. Default is 0.
 +ring[x]=y      -- Oscillator x should be ring moduled by oscillator y (coming in next version)
 +sync[x]=y      -- Oscillator x should be synced by oscillator y       (coming in next version)
 gvol           -- Global volume, default = 1. Multiplied on the output to amplify or limit the audio. gvol           -- Global volume, default = 1. Multiplied on the output to amplify or limit the audio.
 updatefreq     -- Update frequency: 128, 256, 512, 1024, 2048, or 4096. Tells how many frames to wait before running Lua. updatefreq     -- Update frequency: 128, 256, 512, 1024, 2048, or 4096. Tells how many frames to wait before running Lua.
Line 89: Line 99:
 wave[x] = VSWaveFold(wave[x],amplify)         -- Wave will be folded outside the range [-1, 1]. wave[x] = VSWaveFold(wave[x],amplify)         -- Wave will be folded outside the range [-1, 1].
 wave[x] = VSNorm(wave[x],threshold,normvalue) -- Normalise the waveform to normval if max amplitude is above threshold wave[x] = VSNorm(wave[x],threshold,normvalue) -- Normalise the waveform to normval if max amplitude is above threshold
 +wave[x] = VSAbs(wave[x])                      -- Return absolute values of the input wave.
  
 -- Wave math operators - arguments can be either arrays or scalar factors -- Wave math operators - arguments can be either arrays or scalar factors
Line 96: Line 107:
 wave[x] = VSAdd(wave1,wave2) -- Add element wise wave1 with wave2 wave[x] = VSAdd(wave1,wave2) -- Add element wise wave1 with wave2
 wave[x] = VSSub(wave1,wave2) -- Subtract element wise wave1 with wave2 wave[x] = VSSub(wave1,wave2) -- Subtract element wise wave1 with wave2
 +
 +-- LFOs (Low Frequency Operators): Coming in the next version (v1.2)
 +-- These LFO functions take time as input. They are similar to the wave generators in how they
 +-- operate, but they only return a scalar value.
 +lfo = VSLFOSin(frequency,phase,time)          -- phase is in degrees
 +lfo = VSLFOTriangle(frequency,phase,time) 
 +lfo = VSLFOSaw(frequency,phase,time)
 +lfo = VSLFOSquare(frequency,phase,width,time) -- width is between 0 to 1
 +
 +-- Helper function to remove negative values
 +output = VSRect(input)  -- Input is a scalar value
 +wave[x] = VSRect(wave[x]) -- Input is a wave array
  
 -- Envelopes -- Envelopes
Line 102: Line 125:
 vol[x] = VSADSR(attack,decay,sustain,release,initlevel,timeOn,timeOff) -- initlevel is initial volume vol[x] = VSADSR(attack,decay,sustain,release,initlevel,timeOn,timeOff) -- initlevel is initial volume
 vol[x] = VSADSRE(attack,decay,sustain,release,initlevel,timeOn,timeOff) -- Exponential release vol[x] = VSADSRE(attack,decay,sustain,release,initlevel,timeOn,timeOff) -- Exponential release
 +
  
 -- Filters (x = oscillator) -- Filters (x = oscillator)
Line 113: Line 137:
 biquadcoeff = VSBandpass(cutoffFreq,resonance,notein) -- Helper function to set the quadfilter values biquadcoeff = VSBandpass(cutoffFreq,resonance,notein) -- Helper function to set the quadfilter values
 biquadcoeff = VSHighpass(cutoffFreq,resonance,notein) -- Helper function to set the quadfilter values biquadcoeff = VSHighpass(cutoffFreq,resonance,notein) -- Helper function to set the quadfilter values
-wave[x] = VSBiquad(wave[x],biquadcoeff)                  -- Apply filter on wave using quadfilter settings+wave[x] = VSBiquad(wave[x],biquadcoeff)               -- Apply filter on wave using quadfilter settings
  
--- MIDI output+-- MIDI output (coming soon - not available in this version!)
 -- VSTick is a help function to determine if the beat position crosses a certain time interval. -- VSTick is a help function to determine if the beat position crosses a certain time interval.
 -- For instance, if length=1/4 (corresponding to a quarter note), VSTick will return true every time -- For instance, if length=1/4 (corresponding to a quarter note), VSTick will return true every time
vividshaper_reference_manual.1698215906.txt.gz · Last modified: 2023/10/25 08:38 by lars