added play-sample tutorial and play-note-at (not working)

This commit is contained in:
Mustafa 2014-06-12 10:26:12 -07:00
parent 55f96fbe9e
commit b8d3621d1b
2 changed files with 39 additions and 9 deletions

View file

@ -159,6 +159,32 @@ For example, if you want to control the cutoff frequency for a filter using the
When the mouse is at the left of the screen, the frequency is 200, when the mouse is at the right, the frequency is 500.
### Loading samples
The syntax is
* (load-sample file-name) ; returns a sample
* (play-sample sample rate)
`load-sample` returns a sample object which is passed to play-sample.
The `rate`, an optional parameter, controls the frequency at which the sample is played. 1 means normal frequency. 2 is an octave above, and 0.5 is an octave below.
Example:
```scheme
(define synth-hit1 (load-sample "/path/to/bass.wav"))
(play-sample synth-hit1)
(sleep 1)
(play-sample synth-hit1 2)
```
---
### Envelopes
@ -194,12 +220,6 @@ These can be used in defining instruments.
- comb
### Loading samples
* (load-sample file-name)
* (play-sample sample)

View file

@ -1,7 +1,7 @@
#lang racket
(require rsc3 "system.rkt")
(require rsc3 sosc/sosc "system.rkt")
(provide
(all-from-out rsc3))
@ -90,10 +90,11 @@
(struct note (id [freq #:mutable]) #:transparent)
(define (create-synth name play-on-start)
(define (create-synth name play-on-start [start -1])
(define node-id (gen-node-id))
(send-msg (s-new0 name node-id 1 1))
;; TODO - send in bundle. it run 0 may be sent after
; don't make sound upon creation
(if play-on-start
empty
@ -112,6 +113,14 @@
(define (make-note inst-name freq)
(make-note/option inst-name freq #f))
(define (play-note-at start dur inst-name freq)
(define node-id (gen-node-id))
(send-msg (bundle start (mcons (s-new0 inst-name node-id 1 1)
(mcons (n-set1 node-id "freq" freq) '()))))
(send-msg (bundle (+ start dur) (mcons
(n-run1 node-id 0) '())))
(void))
(define (note-on the-note)
@ -125,7 +134,7 @@
(void))
(define (delete-note the-note)
(send-msg (n-free (note-id the-note)))
(send-msg (n-free1 (note-id the-note)))
(void))
@ -137,6 +146,7 @@
(void))
(define (mouse/x start end)
(mouse-x kr start end 0 0.1))