vrotate   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/contrib/TSM_library.xtm

Implementation

;Circular shift closure
;Vector rotate named according to convention in math.xtm
(bind-func vrotate:[void,float*,i64,i64]*
  (lambda (ptr:float* buffer_size:i64 shift:i64)
    (let ((temp:float* (salloc buffer_size))
          (i:i64 0))
      (dotimes (i buffer_size) ;rotate the vector
        (pset! temp i (pref ptr (% (+ i shift) buffer_size))))
      (dotimes (i buffer_size) ;copy the vector back to original location
        (pset! ptr i (pref temp i))))))


Back to Index

Similar Entries