# HG changeset patch # User Robert McIntyre # Date 1335192011 18000 # Node ID a69c4d0c1a3b5a22f7c7224a56c1123d77323041 # Parent 476f7da175a4ad6adb2dc9bcd0561092e9e87c1f investigating infinite loop in note-codes. diff -r 476f7da175a4 -r a69c4d0c1a3b clojure/com/aurellem/run/music.clj --- a/clojure/com/aurellem/run/music.clj Mon Apr 23 09:22:07 2012 -0500 +++ b/clojure/com/aurellem/run/music.clj Mon Apr 23 09:40:11 2012 -0500 @@ -308,18 +308,24 @@ (defn note-codes [frequency volume duration] (assert (<= 0 volume 0xF)) - (assert (<= 0 duration 0xFF)) - (let [frequency-code - (frequency->frequency-code frequency) - volume&high-frequency - (+ (bit-shift-left volume 4) - (bit-shift-right frequency-code 8)) - low-frequency - (bit-and 0xFF frequency-code)] - [note-code - volume&high-frequency - low-frequency - duration])) + (loop [current-duration duration + notes []] + + (if (<= 0 duration 0xFF) + (let [frequency-code + (frequency->frequency-code frequency) + volume&high-frequency + (+ (bit-shift-left volume 4) + (bit-shift-right frequency-code 8)) + low-frequency + (bit-and 0xFF frequency-code)] + [note-code + volume&high-frequency + low-frequency + duration]) + (recur (- current-duration 0xFF) + (conj notes (note-codes frequency volume 0xFF)))))) + (defn midi-code->frequency [midi-code] @@ -396,16 +402,6 @@ notes-with-silence))) - - - - - - - - - - (def C4 (partial note-codes 261.63)) (def D4 (partial note-codes 293.66)) (def E4 (partial note-codes 329.63)) @@ -415,16 +411,16 @@ (def B4 (partial note-codes 493.88)) (def C5 (partial note-codes 523.3)) -(def scale - (flatten - [(C4 0xF 0x40) - (D4 0xF 0x40) - (E4 0xF 0x40) - (F4 0xF 0x40) - (G4 0xF 0x40) - (A4 0xF 0x40) - (B4 0xF 0x40) - (C5 0xF 0x40)])) +;; (def scale +;; (flatten +;; [(C4 0xF 0x40) +;; (D4 0xF 0x40) +;; (E4 0xF 0x40) +;; (F4 0xF 0x40) +;; (G4 0xF 0x40) +;; (A4 0xF 0x40) +;; (B4 0xF 0x40) +;; (C5 0xF 0x40)])) (defn play-music [music-bytes] (let [program-target 0xC000