comparison clojure/com/aurellem/run/music.clj @ 468:85d9fa354f0b

got drums to work.
author Robert McIntyre <rlm@mit.edu>
date Fri, 04 May 2012 06:12:59 -0500
parents ac0ed5c1a1c4
children f28a3baa4c56
comparison
equal deleted inserted replaced
467:ac0ed5c1a1c4 468:85d9fa354f0b
14 (def pony 14 (def pony
15 (File. "/home/r/proj/vba-clojure/music/pony-title.mid")) 15 (File. "/home/r/proj/vba-clojure/music/pony-title.mid"))
16 16
17 (def sync-test 17 (def sync-test
18 (File. "/home/r/proj/vba-clojure/music/sync-test.mid")) 18 (File. "/home/r/proj/vba-clojure/music/sync-test.mid"))
19
20 (def drum-test
21 (File. "/home/r/proj/vba-clojure/music/drum-test.mid"))
19 22
20 23
21 (defn raw-midi-text [#^File midi-file] 24 (defn raw-midi-text [#^File midi-file]
22 (:out 25 (:out
23 (clojure.java.shell/sh 26 (clojure.java.shell/sh
518 (note-codes (:frequency note-event) 521 (note-codes (:frequency note-event)
519 (:volume note-event) 522 (:volume note-event)
520 (int (* (:duration note-event) 0x100)))) 523 (int (* (:duration note-event) 0x100))))
521 abstract-mini-midi))) 524 abstract-mini-midi)))
522 525
526 (def midi-code->gb-noise-code
527 {nil 0xFF
528 35 87
529 38 20
530 39 0
531 })
532
533
523 (defn noise-codes [code volume duration] 534 (defn noise-codes [code volume duration]
524 (assert (<= 0 volume 0xF)) 535 (assert (<= 0 volume 0xF))
525 (if (<= duration 0xFF) 536 (if (<= duration 0xFF)
526 [(if (nil? code) 0xFF code) 537 [(midi-code->gb-noise-code code code)
527 (bit-shift-left volume 4) 538 (bit-shift-left volume 4)
528 duration] 539 duration]
529 (vec 540 (vec
530 (flatten 541 (flatten
531 [(noise-codes code volume 0xFF) 542 [(noise-codes code volume 0xFF)
581 (set-memory-range 592 (set-memory-range
582 program-target 593 program-target
583 (music-kernel wave-duty-1 wave-duty-2)) 594 (music-kernel wave-duty-1 wave-duty-2))
584 (PC! program-target)))) 595 (PC! program-target))))
585 596
586
587 (defn test-noise [] 597 (defn test-noise []
588 (let [noise-pattern 598 (let [noise-pattern
589 (concat (interleave (range 0x100) (repeat 0xF0) (repeat 255)) 599 (concat (interleave (range 0x100) (repeat 0xF0) (repeat 255))
590 (interleave (range 10) (repeat 0x00) (repeat 255)))] 600 (interleave (range 10) (repeat 0x00) (repeat 255)))]
591 601
593 (set-memory-range 0xA900 (flatten noise-pattern)) 603 (set-memory-range 0xA900 (flatten noise-pattern))
594 (set-memory-range 0xC000 (music-kernel 0 0)) 604 (set-memory-range 0xC000 (music-kernel 0 0))
595 (PC! 0xC000)))) 605 (PC! 0xC000))))
596 606
597 (defn test-play-noise [noise-code] 607 (defn test-play-noise [noise-code]
598 (println "playing-noise" noise-code) 608 (Thread/sleep 300)
609 (println "playing noise:" noise-code)
599 (run-moves 610 (run-moves
600 (let [noise-pattern 611 (let [noise-pattern
601 (interleave (repeat 10 noise-code) (repeat 0xF0) (repeat 255))] 612 (interleave (repeat 10 noise-code) (repeat 0xF0) (repeat 255))]
602 (-> (second (music-base)) 613 (-> (second (music-base))
603 (set-memory-range 0xA900 (flatten noise-pattern)) 614 (set-memory-range 0xA900 (flatten noise-pattern))
604 (set-memory-range 0xC000 (music-kernel 0 0)) 615 (set-memory-range 0xC000 (music-kernel 0 0))
605 (PC! 0xC000))) 616 (PC! 0xC000)))
606 (repeat 128 []))) 617 (repeat 20 [])))
607 618
608 (defn test-all-noises [] 619 (defn test-all-noises []
609 (dorun (map test-play-noise (range 0x100)))) 620 (dorun (map test-play-noise (range 0x100))))
610
611
612 621
613 (def C4 (partial note-codes 261.63)) 622 (def C4 (partial note-codes 261.63))
614 (def D4 (partial note-codes 293.66)) 623 (def D4 (partial note-codes 293.66))
615 (def E4 (partial note-codes 329.63)) 624 (def E4 (partial note-codes 329.63))
616 (def F4 (partial note-codes 349.23)) 625 (def F4 (partial note-codes 349.23))