diff clojure/com/aurellem/run/music.clj @ 461:a2ae4213deb7

implemented adjustable wave-duty for the two pitch channels.
author Robert McIntyre <rlm@mit.edu>
date Fri, 04 May 2012 03:01:28 -0500
parents 9c192737034d
children 32375de697e5
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/music.clj	Fri May 04 02:41:45 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/music.clj	Fri May 04 03:01:28 2012 -0500
     1.3 @@ -177,8 +177,9 @@
     1.4    "Read the message which starts at the current value of HL and do
     1.5     what it says. Duration is left in A, and HL is advanced
     1.6     appropraitely."
     1.7 -  ([] (do-message 0x16))
     1.8 -  ([sound-base-address]
     1.9 +  ([] (do-message 0x16 1))
    1.10 +  ([sound-base-address wave-duty]
    1.11 +     (assert (<= 0 wave-duty 3))
    1.12       (let [switch
    1.13             [0x2A ;; load message code into A, increment HL
    1.14              
    1.15 @@ -190,7 +191,11 @@
    1.16              :note-length]
    1.17  
    1.18             play-note
    1.19 -           [0x2A   ;; load volume/frequency-high info
    1.20 +           [0x3E ;; set wave-duty
    1.21 +            (bit-shift-left wave-duty 6)
    1.22 +            0xE0
    1.23 +            sound-base-address
    1.24 +            0x2A   ;; load volume/frequency-high info
    1.25              0xF5   ;; push A
    1.26              0xE6
    1.27              (Integer/parseInt "11110000" 2) ;; volume mask
    1.28 @@ -233,7 +238,7 @@
    1.29  ;;    0x2A   ;; load duration
    1.30  ;;    ]) 
    1.31  
    1.32 -(defn music-step [sound-base-address]
    1.33 +(defn music-step [sound-base-address wave-duty]
    1.34    ;; C == current-ticks
    1.35    ;; A == desired-ticks
    1.36    
    1.37 @@ -262,9 +267,9 @@
    1.38      ;;   go to next note ; set current set ticks to 0.
    1.39  
    1.40      0x20
    1.41 -    (+ (count (do-message 0)) 2)
    1.42 +    (+ (count (do-message 0 0)) 2)
    1.43  
    1.44 -    (do-message sound-base-address)
    1.45 +    (do-message sound-base-address wave-duty)
    1.46      
    1.47      0x0E
    1.48      0x00 ;; 0->C (current-ticks)
    1.49 @@ -280,7 +285,7 @@
    1.50  (def music-1 0x11)
    1.51  (def music-2 0x16)
    1.52  
    1.53 -(defn music-kernel []
    1.54 +(defn music-kernel [wave-duty-1 wave-duty-2]
    1.55    (flatten
    1.56     [;; global initilization section
    1.57      (clear-music-registers)
    1.58 @@ -324,19 +329,19 @@
    1.59  
    1.60      0xE8 ;; SP + 6; activate frame 1
    1.61      6
    1.62 -    (music-step music-1)
    1.63 +    (music-step music-1 wave-duty-1)
    1.64      ;;(repeat (count (music-step music-1)) 0x00)
    1.65      
    1.66      0xE8 ;; SP - 6; activate frame 2
    1.67      (->signed-8-bit -6)
    1.68      ;;(repeat (count (music-step music-2)) 0x00)
    1.69 -    (music-step music-2)
    1.70 +    (music-step music-2 wave-duty-2)
    1.71      
    1.72  
    1.73      0x18
    1.74      (->signed-8-bit (+
    1.75                       ;; two music-steps
    1.76 -                     (- (* 2 (count (music-step 0))))
    1.77 +                     (- (* 2 (count (music-step 0 0))))
    1.78                       -2 ;; this jump instruction
    1.79                       -2 ;; activate frame 1
    1.80                       -2 ;; activate frame 2
    1.81 @@ -468,14 +473,19 @@
    1.82          track-2-target 0xB000
    1.83          program-target 0xC000
    1.84          mini-midi (midi->mini-midi midi-file)
    1.85 -        long-silence (flatten (note-codes 20 0 9001))]
    1.86 +        long-silence (flatten (note-codes 20 0 9001))
    1.87 +        wave-duty-1 2
    1.88 +        wave-duty-2 2
    1.89 +        ]
    1.90      
    1.91      (-> (second (music-base))
    1.92          (set-memory-range track-1-target long-silence)
    1.93          (set-memory-range track-2-target long-silence)
    1.94          (set-memory-range track-1-target (:track-1 mini-midi))
    1.95          (set-memory-range track-2-target (:track-2 mini-midi))
    1.96 -        (set-memory-range program-target (music-kernel))
    1.97 +        (set-memory-range
    1.98 +         program-target
    1.99 +         (music-kernel wave-duty-1 wave-duty-2))
   1.100          (PC! program-target))))
   1.101  
   1.102  (def C4 (partial note-codes 261.63))