Mercurial > hg > amuse
changeset 47:e3d86a0f25b3
n-gram features
darcs-hash:20070615112417-f76cc-6cc8c9b58db4f04bf1793af6521cbb037dce485f.gz
author | David Lewis <d.lewis@gold.ac.uk> |
---|---|
date | Fri, 15 Jun 2007 12:24:17 +0100 |
parents | 34fb42cba5b9 |
children | cace0cf82aee |
files | utils/package.lisp utils/utils.lisp |
diffstat | 2 files changed, 47 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/utils/package.lisp Fri Jun 15 12:12:02 2007 +0100 +++ b/utils/package.lisp Fri Jun 15 12:24:17 2007 +0100 @@ -26,5 +26,8 @@ #:levenshtein-distance #:beats-to-seconds #:get-n-grams + #:inter-onset-intervals + #:get-n-gram + #:n-gram-stats #:monodificate ))
--- a/utils/utils.lisp Fri Jun 15 12:12:02 2007 +0100 +++ b/utils/utils.lisp Fri Jun 15 12:24:17 2007 +0100 @@ -359,4 +359,47 @@ (>= (/ overs total) 1/4)) 'T - 'nil)))) \ No newline at end of file + 'nil)))) + +(defgeneric inter-onset-intervals (composition &key rounding-divisor)) +(defmethod inter-onset-intervals ((composition composition) &key (rounding-divisor 1/4)) + ;; returns values - list inter-onset intervals in beats, modal i-o-i + ;; and i-o-is in seconds. + ;; ** Only makes sense for monodic music + ;; FIXME: Should this keep in objects or am I right to make numbers + ;; here? + ;; FIXME: Should I (do I) filter out 0s? + (let ((i-o-i-list) (i-o-i-secs-list) (prev) + (hits (make-array (/ 32 rounding-divisor)))) + (loop for event being the elements of composition + do (progn + (when prev + (let* ((i-o-i-period (inter-onset-interval prev event)) + (i-o-i (duration i-o-i-period)) + (i-o-i-secs (amuse-utils:beats-to-seconds i-o-i-period composition))) + (when (= i-o-i-secs 0) + (format t "~D, ~D -- " (timepoint prev) (timepoint event))) + (push i-o-i i-o-i-list) + (push i-o-i-secs i-o-i-secs-list) + (when (< i-o-i 32) + ;; Not really interested in very long results for the + ;; modal value anyway. + (incf (aref hits (round i-o-i rounding-divisor)))))) + (setf prev event))) + (let ((mode '(0 0))) + ;; we want the position of the highest mode + (loop for i downfrom (1- (length hits)) to 0 + when (> (aref hits i) (car mode)) + do (setf mode (list (aref hits i) i))) + (values (reverse i-o-i-list) + (* (cadr mode) rounding-divisor) + (reverse i-o-i-secs-list))))) + +(defun pitch-interval-list (composition) + (let ((intervals) + (previous-event)) + (sequence:dosequence (event composition (reverse intervals)) + (when previous-event + (push (span (pitch- event previous-event)) + intervals)) + (setf previous-event event)))) \ No newline at end of file