2014-05-20 18:04:42 +00:00
|
|
|
#lang racket
|
|
|
|
|
|
|
|
(require rsc3 rhs/rhs)
|
|
|
|
|
|
|
|
|
2014-06-13 23:41:36 +00:00
|
|
|
(provide load-sample
|
|
|
|
play-sample)
|
2014-05-20 18:04:42 +00:00
|
|
|
|
2014-06-12 05:12:51 +00:00
|
|
|
|
|
|
|
(struct sample (buf len))
|
|
|
|
|
|
|
|
(define current-buf-id 10)
|
|
|
|
(define (gen-buf-id)
|
|
|
|
(set! current-buf-id (add1 current-buf-id))
|
|
|
|
(sub1 current-buf-id))
|
|
|
|
|
|
|
|
;; path -> sample
|
|
|
|
(define (load-sample path)
|
|
|
|
(if (not (file-exists? path))
|
|
|
|
(display (format "Error: The file \"~a\" does not exist\n" path))
|
|
|
|
(let ([id (gen-buf-id)])
|
|
|
|
(send-async-msg (b-alloc-read id path 0 0))
|
|
|
|
(sample id 0))))
|
|
|
|
|
|
|
|
|
|
|
|
(define sample-player-ugen
|
|
|
|
(letc ([buf 0]
|
|
|
|
[bus 0]
|
|
|
|
[rate 1])
|
|
|
|
(out bus (play-buf 2 buf rate 1 0 0))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (play-sample smpl [rate 1])
|
|
|
|
(send-msg (s-new2 "sample-player" -1 1 1
|
|
|
|
"buf" (sample-buf smpl)
|
|
|
|
"rate" rate)))
|
|
|
|
|
2014-06-13 23:41:36 +00:00
|
|
|
;; send sample-player synthdef
|
2014-06-12 05:12:51 +00:00
|
|
|
(with-sc3 (lambda (fd)
|
|
|
|
(send-synth fd "sample-player" sample-player-ugen)))
|
|
|
|
|
2014-05-20 18:04:42 +00:00
|
|
|
|
|
|
|
|
2014-06-12 05:12:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|