File: trigger.lsp

package info (click to toggle)
nyquist 3.23%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 58,064 kB
  • sloc: ansic: 74,758; lisp: 18,104; java: 10,719; cpp: 6,688; sh: 171; xml: 58; makefile: 40; python: 15
file content (105 lines) | stat: -rw-r--r-- 3,267 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'(print
  (control-srate-abs 20
    (snd-samples 
      (snd-trigger (lfo 2) '(lambda (t0) (at-abs t0 (const 0.5 0.2))))
      100)))

'(print
  (control-srate-abs 20
    (snd-samples 
      (trigger (lfo 2) (const 0.5 0.2))
      100)))

(defmacro trigger (input beh)
  `(let* ((nyq%environment (nyq:the-environment))
          (s%rate *sound-srate*))
     (snd-trigger (force-srate *sound-srate* ,input)
                  #'(lambda (t0) (eval-seq-behavior ,beh "TRIGGER")))))

(setf *gc-flag* t)
(setf *breakenable* t)

(autonorm-off)

(pprint (macroexpand '(trigger (snd-offset (sound-srate-abs 20 (noise dur))
                                           -0.9)
                               (pluck (+ 48 (random 24))))))


(setf pitch-pat (make-heap '(60 62 65 67 70 72 74 77 79 82 84)))

;; make a big sound with trigger so we can see if there is
;; retention in memory
'(defun trigger-test (dur)
  (play (scale 0.25 (trigger (snd-offset (sound-srate-abs 40 (noise dur))
                                        -0.9)
                            (scale (+ 0.1 (rrandom))
                                   (pluck (next pitch-pat)))))))

'(defun trigger-test (dur)
  (play (trigger  (pwl 1 0 2 1 3 0 4 1 5) (pluck c4))))

(defun make-trigger-input ()
 (force-srate *sound-srate*
  (vector (snd-offset (sound-srate-abs 40 (noise 600)) -0.9)
          (snd-offset (sound-srate-abs 40 (noise 600)) -0.9))))

(defun trigger-snd (input)
  (trigger input (pluck c4)))

'(trigger-test 20)
;; Legacy version:
(defun multichan-expand-old (fn &rest args)
  (let (len newlen result) ; len is a flag as well as a count
    (dolist (a args)
        (cond ((arrayp a)
           (setf newlen (length a))
           (cond ((and len (/= len newlen))
              (error (format nil "In ~A, two arguments are vectors of differing length." fn))))
           (setf len newlen))))
    (cond (len
       (setf result (make-array len))
       ; for each channel, call fn with args
       (dotimes (i len)
           (setf (aref result i)
             (apply fn
            (mapcar
                #'(lambda (a)
                ; take i'th entry or replicate:
                (cond ((arrayp a) (aref a i))
                      (t a)))
                args))))
       result)
      (t
       (apply fn args)))))

(defmacro audacity (snd)
  `(s-save (let ((s ,snd)) (setf *track* nil) s) ny:all "temp.wav"))

(setf *track* (make-trigger-input))

'(print (macroexpand '(multichan-expand-old #'trigger-snd *track*)))

'(audacity (multichan-expand-old #'trigger-snd *track*))

'(s-save (multichan-expand "test" #'trigger-snd '(((sound) "input"))
                          (make-trigger-input))
        ny:all "temp.wav")

;; this is what steve says works with stereo:
(defmacro with%environment-hack (env &rest expr)
  `(progv ',*environment-variables* ,env ,@expr))
 
(defmacro trigger2 (input beh)
  `(let ((nyq%environment (nyq:the-environment)))
     (snd-trigger ,input #'(lambda (t0) (with%environment-hack nyq%environment
                                                (at-abs t0 ,beh))))))

;; my guess at getting it to work with stereo
(defun test (snd) (trigger2 snd (stretch-abs 1 (pluck c4))))

(audacity (multichan-expand-old #'test *track*))


(defun re () (load "trigger"))