Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

absolute shapers for slope library #68

Closed
trentgill opened this issue Feb 20, 2019 · 3 comments
Closed

absolute shapers for slope library #68

trentgill opened this issue Feb 20, 2019 · 3 comments
Assignees
Labels
Milestone

Comments

@trentgill
Copy link
Collaborator

@trentgill trentgill commented Feb 20, 2019

'absolute' shapers from readme-development

@trentgill trentgill added the feature label Feb 20, 2019
@trentgill trentgill added this to the 1 milestone Feb 20, 2019
@trentgill trentgill self-assigned this Feb 20, 2019
@trentgill trentgill modified the milestones: 1.0, 1.1 Mar 1, 2019
@trentgill
Copy link
Collaborator Author

@trentgill trentgill commented Oct 4, 2019

-- the absolute shapers are interesting though as a set of divisions
-- thinking primarily in terms of absolutely dividing up the output
-- space.
-- user provides:
--  zero point to base off (could be a 'key')
--  fold point (1V becomes 1 octave, but could be eg 1v2 for buchla)
--  either | divisions (divides fold-size into n equal steps)
--         | list (divides fold-size unequally according a list)
--
-- the natural use is to provide scales for quantizing. by using the
-- list approach, one can send arbitrary pitches, so this could be
-- tonal scales directly, rather than semitones of 'divisions'.
--
-- list can also take fractions to natively handle just intonation,
-- readily accepting a scale as a list of fractions.
--
-- a weighting mechanism could be added to give a wider window to
-- preferred values.
--
-- setting divisions to a large number, then manipulating fold will
-- essentially become a bit crusher with continuously variable bits
--

local shaper = { zero = 0
               , fold = 1  --volts
               , divs = 12 --semitones
               , list = {} --empty means nil
               }

function S_absolute( samp, divs, fold )
    div_sz  = fold / divs
    bracket = math.floor(samp / fold)
    shelf   = samp % fold
    shelf1  = shelf / fold
    div     = math.floor(0.5 + (shelf1 * divs))
    return ( div * div_sz
             + (bracket * fold)
           )
end

function S_absolute( samp, divs, fold )
    local bracket = math.floor(samp / fold)
    local shelf   = (samp % fold) / fold
    local plateau = 0
    if type(divs) == 'table' then
        if divs[1] == 'ji' then
            --TODO needs log shaping i believe
            plateau = divs[2][math.floor(1.5+(shelf * #divs[2]))] - 1
        else
            plateau = divs[2][math.floor(1.5+(shelf * #divs))] / divs[1]
        end
    else
        plateau = fold / divs * math.floor(0.5 + (shelf * divs))
    end

    --local plateau = type(divs) == 'table'
    --    and divs[math.floor(0.5 + (shelf * #divs))]
    --    or fold / divs * math.floor(0.5 + (shelf * divs))
    return plateau + bracket * fold
end

lydian = {12,{0,2,4,6,7,9,11}}
pentatonic = {12,{0,2,4,7,9}}
just_lydian = {'ji',{ 1/1, 9/8, 4/3, 11/8, 3/2, 10/7, 15/8}}
S_absolute( 0.1
          , lydian
          , 1
          )
@trentgill
Copy link
Collaborator Author

@trentgill trentgill commented Oct 4, 2019

float S_absolute( float samp
                , int   divs // 12 // must be >0
                , float fold // 1.0
                //, float zero // assume 0.0 for now
                ){
    // TODO optimize more elements into k-rate
    // k-rate
    float div_sz = fold / (float)divs; // abs size of a div
    // a-rate
    int bracket  = (int)floorf(samp / fold); // confirm this rounds to -ve
    float shelf  = samp % fold; // 0-fold range
    float shelf1 = shelf / fold; // 0-1 range within fold
    int div      = (int)(0.5 + (shelf1 * (float)divs)); // select the div
    return ( (float)div * div_sz
             + ((float)bracket * fold) // add #folds back
           );
}
@trentgill trentgill modified the milestones: 1.1, 1.2 Oct 6, 2019
@trentgill trentgill mentioned this issue Nov 13, 2019
7 of 7 tasks complete
@whimsical-sam
Copy link
Collaborator

@whimsical-sam whimsical-sam commented Nov 14, 2019

https://github.com/whimsical-sam/crow/blob/shapers/lua/shaper.lua

Check out this implementation for user-facing customizable shapers in lua

basic idea: four different domains

  • input signal --> convert to phase space based off a foldover value (e.g. 1V, or 1.2V etc.)
  • phase space (# of folds + 0-1 phase within a single cycle/octave etc. )
  • lookup table (lookup table divides 0-1 into a series of windows; window size can be affected by different weightings, boundaries may be related to the values within the lookup table, e.g. accurately spacing notes in a scale rather than equally dividing up 0-1)
  • output space (converting look up table values to output values, e.g. ratios to volts, semitones to volts, or any other custom mapping; interpolation between lookup table values is also availabile; also includes a function mode for using lookup-tables made up of functions instead of numbers)

here is a script which shows setting a few of them up - including running markov models with one shaper!

The library is mostly tested but it got too big for testing it all as a single user script upload, so I am working on finally getting a build environment set up :)

@trentgill trentgill modified the milestones: 1.0.2, 1.0.3 Nov 25, 2019
@trentgill trentgill changed the title implement different curves for slope library absolute shapers for slope library Dec 6, 2019
@trentgill trentgill modified the milestones: 1.0.3, Minor (1.1) Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants