;;; -*- logo -*-
;; This is offered as part of the sound API.
;;
;; copyright University of Victoria, 2005


to upsample :iarray :inc
  local [ oarray i rise next factor df ]

  if less? inc 2 [ output iarray ]
  make "df round inc
  make "df 1/df

  make "oarray (array (count iarray)*inc 0)

  make "i 1
  make "j 1
  setitem 0 oarray item 0 iarray

  repeat (count iarray)-1 [

    setitem j oarray item i iarray
    if less? i (count iarray) - 1 [
      make "rise (item (i+1) iarray) - (item i iarray)

      make "factor df
      repeat inc [
        make "j j+1
        make "next (item i iarray) + rise * factor
        make "factor factor + df 
        setitem j oarray next

      ]
    ] 
    make "i i+1
  ]  

  output oarray
end

bury [ upsample ]

