-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathecho.lisp
48 lines (41 loc) · 1.43 KB
/
echo.lisp
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
(in-package "ACL2")
(defun multiply-list (val xs)
(if (consp xs)
(cons (* (car xs) val)
(multiply-list val (cdr xs)))
nil))
(defun get-slice (x length xs)
(multiply-list x (take length xs)))
;ys is the data
(defun add-lists-echo (xs ys)
(if (and (consp xs)
(consp ys))
(cons (+ (car xs) (car ys))
(add-lists-echo (cdr xs) (cdr ys)))
ys))
(defun echo-helper (slice val xs n)
(if (zp n)
nil
(let* ((length (if (> (len xs) (len slice))
(len slice)
(len xs)))
(modifiable-part (take length xs))
(rest (nthcdr length xs))
(new-slice (multiply-list val modifiable-part))
)
(append (add-lists-echo slice modifiable-part)
(echo-helper new-slice
val
rest
(- n 1))))))
(defun echo-handler (length val xs)
(let ((slice (get-slice val length xs))
(rest (nthcdr length xs))
(run-time (floor (len xs) length)))
(append slice
(echo-helper slice
val
rest
run-time))))
(defun echo (time val wav)
(modify-data wav (echo-handler (floor (* (* (wav-file-sample-rate wav) (wav-file-num-channels wav)) time) 1) val (wav-file-data wav))))