[CM] make-sampler vs. open
bil at ccrma.Stanford.EDU
bil at ccrma.Stanford.EDU
Thu Dec 7 13:01:27 PST 2023
I'd need to see you sampler code to see what the problem
is, but this sequence works:
;; write a square-wave to test.snd
(with-sound (:output "test.snd" :to-snd #f)
(let ((g (make-square-wave 440.0)))
(do ((i 0 (+ i 1)))
((= i 44100))
(outa i (square-wave g)))))
;; read it using a sampler
(let* ((snd (open-sound "test.snd"))
(sampler (make-sampler 0 snd 0)))
(with-sound (:output "test1.snd")
(do ((i 0 (+ i 1)))
((= i 44100))
(outa i (read-sample sampler)))))
;; filter it using fft-filtering
(let* ((len (mus-sound-framples "test1.snd"))
(fsize (expt 2 (ceiling (log len 2))))
(rdata (make-float-vector fsize))
(idata (make-float-vector fsize)))
(file->array "test1.snd" 0 0 len rdata)
(mus-fft rdata idata fsize 1)
(let ((fsize2 (/ fsize 2))
(cutoff (round (/ fsize 10))))
(do ((i cutoff (+ i 1))
(j (- fsize 1) (- j 1)))
((= i fsize2))
(set! (rdata i) 0.0)
(set! (idata i) 0.0)
(set! (rdata j) 0.0)
(set! (idata j) 0.0)))
(mus-fft rdata idata fsize -1)
(array->file "test2.snd"
(float-vector-scale! rdata (/ 1.0 fsize))
len
44100 ;(srate "oboe.snd")
1)
(open-sound "test2.snd"))
load this into snd and you should see the 3 files. If they
appear to be all ones, move the graph slider to show a
smaller portion of the file. File:Open is probably
showing only a small portion of the file in its initial
window -- I think the variable that sets that is initial-dur
which defaults to .1 seconds.
More information about the Cmdist
mailing list