#lang racket
(require plot
(planet clements/rsound)
(planet clements/rsound/draw))
(define envelope
(map
(lambda (x)
(vector (* 1/44100 (first x)) (/ (second x) 32767) 1.0))
'((53 13565)
(250 14172)
(488 14606)
(785 14778)
(1165 14934)
(1631 15078)
(2210 15104)
(2889 13665)
(3638 11605)
(4435 9653)
(5242 7926)
(6063 6459)
(6865 5254)
(7669 4242)
(8488 3445)
(9294 2770)
(10119 2224)
(10940 1788)
(11759 1411)
(12574 1117))))
(plot (mix (points envelope)
(line
((lambda (z a b c d)
(lambda (x) (exp (+ (* z x x x x)
(* a x x x)
(* b x x)
(* c x)
d))))
-939.9970010671246
685.4085357019798
-182.02721078280973
9.22106772821044
-0.8933256427308123)))
#:x-min 0
#:x-max 0.5
#:y-max 1.0
#:y-min 0
#:width 600)
(fit (lambda (x z a b c d) (+ (* z x x x x)
(* a x x x)
(* b x x)
(* c x)
d))
'((z -1)
(a 1)
(b -1)
(c -1)
(d -1))
envelope)
(plot (line ((lambda (k1 k2 k3 k4) (lambda (x) (+ k1 (* k2 (exp (* k3 (+ x k4)))))))
111.97512944218796
199.98814726453253
-0.8431357195542737
-99.27499367623983
))
#:x-max 3500
#:y-max 200)
(define m -48.034146022934905)
(define b 5.262685711446809)
(define (env t)
(exp (+ (* -939.9970010671246 t t t t)
(* 685.4085357019798 t t t)
(* -182.02721078280973 t t)
(* 9.22106772821044 t)
-0.8933256427308123)))
(define (bassdrum t)
(let ([t2 (* t 1/44100)])
(* (env t2)
(sin (* twopi
(+ (* 53 t2)
(* (/ 1 m)
(exp (+ (* t2 m) b)))))))))
(define bd (signal->rsound 15727 44100 bassdrum))
(rsound-draw bd)
(define bd2 (rsound-read "/Users/clements/RSound/contrib/drum-samples/bassdrum.wav"))
(rsound-write bd "/tmp/bassdrum-synth.wav")
(define bd3
(rsound-append* (list bd (make-silence 22050 44100) bd2 (make-silence 22050 44100))))