First time here? Check out the FAQ!
x

SmallTalk arrays question

0 votes
850 views

I was working on some SmallTalk array sorting functions  ( heartSmallTalk)

I'd like to make something that stretches out a few values to fill a longer Array which will then be converted to Audio data by SyntheticSpectrumFromArray Class.
 


| shuffleWithSeed repeat stretch retro |


"#####################################"

shuffleWithSeed := [ :arrayIn :seedIn |

    |  r result  r2 range |
    result := arrayIn reverse.
    r := Random new seed: seedIn.
    r2 := Random new seed: (seedIn/2).
    range := arrayIn size.
    arrayIn size timesRepeat:  
        [
            result swap: (r next abs * range) ceiling with: ((r2 next abs * range) ceiling).
        ].
result.
].

"######################################"

repeat := [ :arrayIn :frameLength |
     
    | result rem |
    result := arrayIn.
    rem :=  ?frameLength \\ arrayIn size.
      
    "test if the array does not fit in the Framelength then build a result that adds enough extra
    elements to repeat in sync with the FrameLength.  FrameLength will be also redefined
    to match the result length in next ArrayRewriter script"
    (rem > 0) ifTrue: [

    result :=  (0 to: ?frameLength-1) collect: [:i | ((i mod: arrayIn size) of: arrayIn) ].    
    ].
    result
].

 

"######################################"

stretch := [ :arrayIn :frameLength |
    | spreadFactor result |
    spreadFactor := (frameLength // (arrayIn size)).
    result := OrderedCollection new.
    
    arrayIn do: [:e | (0 to: spreadFactor) do: [:f | result add: e ]].
    
    result.
].

 


"######################################"

retro := [ :arrayIn |
    arrayIn reverse
].


(inputs at: 1)
start: 0 s
shuffle: shuffleWithSeed repeat: repeat stretch: stretch retro: retro

 

 

in the 'Stretch' algorithm, I want to try and hold the same element and repeat it so that for example, 4 Capytalk functions fill a FrameLength of 128 samples evenly.

Its kind of working, except that a repeated element that is for exmaple, a RandomWalk, is not a duplicate (exact copy) but has its own different seed and walks independently. I was wondering if there was a SmallTalk command like 'clone' or 'duplicate' which would simple make an exact copy of the Event Value?

I know this is obscure and probably not much use to anybody else, but I'm enjoying the intellectual excercise ;)

 

 

asked Jul 3, 2017 in Capytalk & Smalltalk by cristian-vogel (Master) (8,440 points)

1 Answer

0 votes
I already found out what was happening and updated my code. Its more to do with Capytalk/AudioRate sync related issues I think
answered Jul 3, 2017 by cristian-vogel (Master) (8,440 points)
...