Skip to content

Instantly share code, notes, and snippets.

@jbclements
Created October 14, 2013 23:47
Show Gist options
  • Save jbclements/6984259 to your computer and use it in GitHub Desktop.
Save jbclements/6984259 to your computer and use it in GitHub Desktop.
code from class, 2013-10-14
(require rsound)
;; the sample rate
(define SR 44100)
;; a helper function to simplify specifying the number of seconds
(define (s seconds) (* seconds SR))
;; read in a clip of a sound
(define samp
(rs-read/clip "/path/to/your/sound.wav"
(s 500) (s 502)))
;; make a pstream
(define ps (make-pstream))
;; what is the current frame of the stream?
(pstream-current-frame ps)
;; queue a sound on 'ps' for playing at the specified frame:
(define (psq snd fr)
(pstream-queue ps snd fr))
;(psq samp 5000)
;(psq samp (+ 5000 (s 2)))
;; a sine tone function, playing at 250 Hz.
(define (tone f)
(* 0.1 (sin (* f 250 (/ (* 2 pi) SR)))))
;; a function to play the sample backward.
(define len (rs-frames samp))
(define (backward f)
(rs-ith/left samp (- len f 1)))
;; play the reversed sound
(play
(signal->rsound
(s 2)
(indexed-signal backward)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment