# HG changeset patch # User Robert McIntyre # Date 1336122793 18000 # Node ID b31cd66513753cb3d51db18b877fc7776666f7e7 # Parent 34bf4b64d9d179224e6d5cf759166c95b4a3e24b working on noise. diff -r 34bf4b64d9d1 -r b31cd6651375 clojure/com/aurellem/run/music.clj --- a/clojure/com/aurellem/run/music.clj Fri May 04 03:55:00 2012 -0500 +++ b/clojure/com/aurellem/run/music.clj Fri May 04 04:13:13 2012 -0500 @@ -215,6 +215,17 @@ {:note-length (count play-note)} (concat switch play-note))))) +(defn play-noise + "read [noise-code, duration] and play the noise. Duration is left in + A, and HL is advanced appropraitely." + ([] + [0x2A ;; load noise-code into A + 0xE0 + 0x22 ;; write noise-code + 0x2A] ;; load duration into A + )) + + ;; (defn play-note ;; "Play the note referenced by HL in the appropiate channel. ;; Leaves desired-duration in A." @@ -238,7 +249,7 @@ ;; 0x2A ;; load duration ;; ]) -(defn music-step [sound-base-address wave-duty] +(defn music-step [sound-base-address wave-duty noise?] ;; C == current-ticks ;; A == desired-ticks @@ -266,10 +277,14 @@ ;; if desired-ticks = current ticks ;; go to next note ; set current set ticks to 0. - 0x20 - (+ (count (do-message 0 0)) 2) - - (do-message sound-base-address wave-duty) + (if noise? + [0x20 + (+ 2 (count (play-noise))) + (play-noise)] + + [0x20 + (+ (count (do-message 0 0)) 2) + (do-message sound-base-address wave-duty)]) 0x0E 0x00 ;; 0->C (current-ticks) @@ -325,26 +340,38 @@ 0xE5 ;; push HL + ;; initialize frame 3 (noise) + 0x21 + 0x00 + 0xA9 ;; 0xA9OO -> HL + + 0xF5 ;; push AF + 0xC5 ;; push CB + 0xE5 ;; push HL + ;; main music loop - 0xE8 ;; SP + 6; activate frame 1 - 6 - (music-step music-1 wave-duty-1) - ;;(repeat (count (music-step music-1)) 0x00) + 0xE8 ;; SP + 12; activate frame 1 + 12 + (music-step music-1 wave-duty-1 false) 0xE8 ;; SP - 6; activate frame 2 (->signed-8-bit -6) - ;;(repeat (count (music-step music-2)) 0x00) - (music-step music-2 wave-duty-2) - + (music-step music-2 wave-duty-2 false) + + 0xE8 ;; SP - 6; activate frame 3 + (->signed-8-bit -6) + (music-step nil nil true) 0x18 (->signed-8-bit (+ ;; two music-steps - (- (* 2 (count (music-step 0 0)))) + (- (* 2 (count (music-step 0 0 false)))) + (- (count (music-step nil nil true))) -2 ;; this jump instruction -2 ;; activate frame 1 -2 ;; activate frame 2 + -2 ;; activate frame 3 ))])) (defn frequency-code->frequency @@ -402,6 +429,11 @@ :duration length :volume 0}) +(defn commands + "return all events where #(= (:command %) command)" + [command s] + (filter #(= command (:command %)) s)) + (defn track-info [#^File midi-file] (let [events (parse-midi midi-file) track-titles (commands :Title_t events) @@ -420,11 +452,6 @@ (vals track-data)) channel-nums (map (comp :channel track-order) (range 3))] channel-nums)) - -(defn commands - "return all events where #(= (:command %) command)" - [command s] - (filter #(= command (:command %)) s)) (defn midi-track->mini-midi [#^File midi-file track-num] (let [midi-events (parse-midi midi-file) @@ -508,6 +535,8 @@ voice-2 (flatten (:voice-2 mini-midi)) wave-duty-2 ((:duty mini-midi) 1 0) + + noise (flatten (:noise mini-midi)) ] (-> (second (music-base))