[Nyquist-users] Simple function to reverse a sound
Nyquist is a language for sound synthesis and music composition.
Brought to you by:
rbd
|
From: <dav...@sy...> - 2005-03-19 12:25:37
|
Hi!
I wrote a very simple function to "reverse" a sound in time=2E It doesn't
run very quickly, but it might be useful for short sounds=2E I couldn't
think of any way to do it except extract all the samples to an array,
reverse the array, and convert it back to a sound=2E If there's a more
efficient way (other than writing it in C), please let me know=2E
If you think it might be useful, please feel free to add it to the
next release=2E It uses a "helper" function, 'array-reverse', since=20
there doesn't seem to be any function in Xlisp to do this=2E
David=2E
(defun array-reverse (a length)
;; Note: this function updates the input parameter
;; in place=2E If you don't want this, copy the array
;; to another variable first=2E
(prog* ((mid (/ length 2)) (tmp nil))
(if (equal (type-of a) 'ARRAY)
(do ((n1 0) (n2 (1- length)))
((>=3D n1 mid) a)
(setf tmp (aref a n1))
(setf (aref a n1) (aref a n2))
(setf (aref a n2) tmp)
(setf n1 (1+ n1))
(setf n2 (1- n2))
)
(return a)
)
)
)
(defun snd-reverse (s)
;; returns time-reversed sound (preserving sample rate and start=20
;; time), but doesn't operate on multi-channel sounds
(if (soundp s)
(prog* ((len (snd-length s NY:ALL)) (a (snd-samples s len)))
(array-reverse a len)
(return (snd-from-array (snd-t0 s) (snd-srate s) a))
)
)
)
--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web=2Ecom/ =2E
|