comparison utils/utils.lisp @ 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 90abdf9adb60
children df1482ef96fe
comparison
equal deleted inserted replaced
46:34fb42cba5b9 47:e3d86a0f25b3
358 (if (and (> total 0) 358 (if (and (> total 0)
359 (>= (/ overs total) 359 (>= (/ overs total)
360 1/4)) 360 1/4))
361 'T 361 'T
362 'nil)))) 362 'nil))))
363
364 (defgeneric inter-onset-intervals (composition &key rounding-divisor))
365 (defmethod inter-onset-intervals ((composition composition) &key (rounding-divisor 1/4))
366 ;; returns values - list inter-onset intervals in beats, modal i-o-i
367 ;; and i-o-is in seconds.
368 ;; ** Only makes sense for monodic music
369 ;; FIXME: Should this keep in objects or am I right to make numbers
370 ;; here?
371 ;; FIXME: Should I (do I) filter out 0s?
372 (let ((i-o-i-list) (i-o-i-secs-list) (prev)
373 (hits (make-array (/ 32 rounding-divisor))))
374 (loop for event being the elements of composition
375 do (progn
376 (when prev
377 (let* ((i-o-i-period (inter-onset-interval prev event))
378 (i-o-i (duration i-o-i-period))
379 (i-o-i-secs (amuse-utils:beats-to-seconds i-o-i-period composition)))
380 (when (= i-o-i-secs 0)
381 (format t "~D, ~D -- " (timepoint prev) (timepoint event)))
382 (push i-o-i i-o-i-list)
383 (push i-o-i-secs i-o-i-secs-list)
384 (when (< i-o-i 32)
385 ;; Not really interested in very long results for the
386 ;; modal value anyway.
387 (incf (aref hits (round i-o-i rounding-divisor))))))
388 (setf prev event)))
389 (let ((mode '(0 0)))
390 ;; we want the position of the highest mode
391 (loop for i downfrom (1- (length hits)) to 0
392 when (> (aref hits i) (car mode))
393 do (setf mode (list (aref hits i) i)))
394 (values (reverse i-o-i-list)
395 (* (cadr mode) rounding-divisor)
396 (reverse i-o-i-secs-list)))))
397
398 (defun pitch-interval-list (composition)
399 (let ((intervals)
400 (previous-event))
401 (sequence:dosequence (event composition (reverse intervals))
402 (when previous-event
403 (push (span (pitch- event previous-event))
404 intervals))
405 (setf previous-event event))))