Skip to content

Instantly share code, notes, and snippets.

@jbclements
Created November 24, 2012 17:10
Show Gist options
  • Select an option

  • Save jbclements/4140552 to your computer and use it in GitHub Desktop.

Select an option

Save jbclements/4140552 to your computer and use it in GitHub Desktop.
an example of using reverb... downloads new version of rsound.
#lang racket
(require (planet clements/rsound:4:4))
(require (planet clements/rsound:4:4/single-cycle))
(require (planet clements/rsound:4:4/network))
(require (planet clements/rsound:4:4/reverb-typed))
(require racket/flonum)
(define hi-tones
(for/list ([i 16])
(cond [(< (random 100) 30) #f]
[else (+ 20 (random 12))])))
(define-struct pd (pitch duration) #:prefab)
(define tones
(apply append
(for/list ([t '(60 55 56 53 55 53 51 50)])
(list (make-pd (- t 24) 3/4)
(make-pd #f 1/4))))
#;'(60
60 58 60 #f 55 #f 55
60 65 64 60 #f #f #f #f))
(define tones2
(for/list ([elt '((38 5) (#f 1)
(38 1/2) (37 1/2)
(36 1/2) (35 1/2)
(34 5) (#f 1)
(34 1/2) (35 1/2)
(36 1/2) (37 1/2))])
(make-pd (first elt) (second elt))))
(define tones3
(for/list ([elt '((33 5) (#f 1)
(33 1/2) (32 1/2)
(31 1/2) (30 1/2)
(29 5) (#f 1)
(29 1/2) (30 1/2)
(31 1/2) (32 1/2))])
(make-pd (first elt) (second elt))))
(define tones4
(for/list ([elt '((29 5) (#f 1)
(29 1/2) (28 1/2)
(27 1/2) (26 1/2)
(25 5) (#f 1)
(25 1/2) (26 1/2)
(27 1/2) (28 1/2))])
(make-pd (first elt) (second elt))))
(define BPM 120)
(define beat-secs (/ 60 BPM))
(define eighth-secs (* beat-secs 1/2))
(define sixteenth-secs (* beat-secs 1/4))
(define beat-frames (round (* 44100 beat-secs)))
(define quarter-frames beat-frames)
(define eighth-frames (round (* 44100 beat-secs 1/2)))
(define dotted-eighth-frames (round (* 44100 beat-secs 3/4)))
(define sixteenth-frames (round (* 44100 beat-secs 1/4)))
(define dotted-thirty-second-frames (round (* 44100 beat-secs 3/16)))
(define sixty-fourth-frames (round (* 44100 beat-secs 1/16)))
(define wf (synth-waveform "main" 09))
(define (make-hi-note note-num)
(cond [(number? note-num)
(rs-append
(rs-overlay (synth-note "main"
09
note-num
sixteenth-frames)
(synth-note "main"
09
(+ 0.01 note-num)
sixteenth-frames))
(silence sixteenth-frames))]
[else
(silence eighth-frames)]))
(define (make-note pd)
(cond [(number? (pd-pitch pd))
#;(synth-note "main"
09
(pd-pitch pd)
(round
(* quarter-frames
(pd-duration pd))))
(rs-overlay (synth-note "main"
09
(pd-pitch pd)
(round
(* quarter-frames
(pd-duration pd))))
(synth-note "main"
09
(+ 0.01 (pd-pitch pd))
(round
(* quarter-frames
(pd-duration pd)))))]
[else
(silence (round
(* quarter-frames
(pd-duration pd))))]))
;; random-note : make a random note.
;; -> pd
(define (random-note)
(make-pd (+ 20 (random 20))
(* 1/4 (add1 (random 4)))))
;; should produce a random note:
#;(random-note)
;; random-notes : produce a list of random notes
;; number -> list-of-pds
(define (random-notes n)
(cond [(= n 0) empty]
[else
(cons (random-note)
(random-notes (- n 1)))]))
;; should be a list of 20 random notes:
(random-notes 20)
(define song
(rs-append*
(map make-note (random-notes 8)))
#;(rs-overlay*
(list
(rs-scale 0.25 (rs-append* (map make-note tones2)))
(rs-scale 0.25 (rs-append* (map make-note tones3)))
(rs-scale 0.25 (rs-append* (map make-note tones4)))))
#;(rs-overlay
(rs-scale 0.5 (rs-append* (map make-hi-note hi-tones)))
(rs-append*
(map make-note tones))))
#;(define song2 (rs-read "wenceslas.wav"))
(define (looper sound)
(local [(define len (rs-frames sound))]
(network ()
[ctr ((loop-ctr len 1))]
[out (rs-ith/left sound ctr)])))
(define distort
(network (in)
[out (max -0.2 (min 0.2 (+ 0.1 in)))]))
(signal-play
(network ()
[s ((looper song))]
#;[d (distort s)]
#;[echo ((tap (round (* sixteenth-frames 2)) 0.0) (prev echo2 0.0))]
#;[echo2 (* 0.1 (+ s (* 0.8 echo)))]
[r (reverb s)]))
#;(sleep 60)
#;(stop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment