;;; -*- logo -*-
;; This is offered as part of the sound API.  It's intention is to
;; draw the graph of an array of numbers, presumably corresponding
;; to audio data.
;;
;; copyright University of Victoria, 2005

to downsample :wave :factor

local [owave i j]

;; error message
make "msg [downsampling factor must be an integer greater than 1]

;; check that factor is a positive integer
if less? factor 1 [ print msg stop ]
if not equal? modulo factor 1 0 [ print msg stop ]


make "owave (array round (count wave)/factor 0)

make "i 0
make "j 0
repeat count wave [

  test equal? (modulo i factor) 0
  iftrue [
   setitem j owave (item i wave)
   make "j j+1
  ]
  make "i i+1
]

output owave

end

bury "downsample 
