From b8d3621d1b968c2f576460ab40f68abe7817d804 Mon Sep 17 00:00:00 2001 From: Mustafa Date: Thu, 12 Jun 2014 10:26:12 -0700 Subject: [PATCH] added play-sample tutorial and play-note-at (not working) --- oregano/Tutorial.md | 32 ++++++++++++++++++++++++++------ oregano/instrument.rkt | 16 +++++++++++++--- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/oregano/Tutorial.md b/oregano/Tutorial.md index 731876a..9610ad6 100644 --- a/oregano/Tutorial.md +++ b/oregano/Tutorial.md @@ -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) - diff --git a/oregano/instrument.rkt b/oregano/instrument.rkt index e232ae0..9325c41 100644 --- a/oregano/instrument.rkt +++ b/oregano/instrument.rkt @@ -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))