changeset 159:75b6c2ebbf8e

refactored audio code
author Robert McIntyre <rlm@mit.edu>
date Fri, 03 Feb 2012 06:41:16 -0700
parents 811127d79d24
children 33278bf028e7
files org/test-creature.org
diffstat 1 files changed, 0 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/test-creature.org	Fri Feb 03 06:33:37 2012 -0700
     1.2 +++ b/org/test-creature.org	Fri Feb 03 06:41:16 2012 -0700
     1.3 @@ -259,94 +259,6 @@
     1.4  
     1.5  
     1.6  
     1.7 -;; Ears work the same way as vision.
     1.8 -
     1.9 -;; (hearing creature) will return [init-functions
    1.10 -;; sensor-functions]. The init functions each take the world and
    1.11 -;; register a SoundProcessor that does foureier transforms on the
    1.12 -;; incommong sound data, making it available to each sensor function.
    1.13 -
    1.14 -(defn creature-ears
    1.15 -  "Return the children of the creature's \"ears\" node."
    1.16 -  ;;dylan
    1.17 -  ;;"The ear nodes which are children of the \"ears\" node in the
    1.18 -  ;;creature."
    1.19 -  [#^Node creature]
    1.20 -  (if-let [ear-node (.getChild creature "ears")]
    1.21 -    (seq (.getChildren ear-node))
    1.22 -    (do (println-repl "could not find ears node") [])))
    1.23 -
    1.24 -
    1.25 -;;dylan (defn follow-sense, adjoin-sense, attach-stimuli,
    1.26 -;;anchor-qualia, augment-organ, with-organ
    1.27 -
    1.28 -
    1.29 -(defn update-listener-velocity
    1.30 -  "Update the listener's velocity every update loop."
    1.31 -  [#^Spatial obj #^Listener lis]
    1.32 -  (let [old-position (atom (.getLocation lis))]
    1.33 -    (.addControl
    1.34 -     obj
    1.35 -     (proxy [AbstractControl] []
    1.36 -       (controlUpdate [tpf]
    1.37 -         (let [new-position (.getLocation lis)]
    1.38 -           (.setVelocity
    1.39 -            lis 
    1.40 -            (.mult (.subtract new-position @old-position)
    1.41 -                   (float (/ tpf))))
    1.42 -           (reset! old-position new-position)))
    1.43 -       (controlRender [_ _])))))
    1.44 -
    1.45 -(import com.aurellem.capture.audio.AudioSendRenderer)
    1.46 -
    1.47 -(defn attach-ear
    1.48 -  [#^Application world #^Node creature #^Spatial ear continuation]
    1.49 -  (let [target (closest-node creature ear)
    1.50 -        lis (Listener.)
    1.51 -        audio-renderer (.getAudioRenderer world)
    1.52 -        sp (sound-processor continuation)]
    1.53 -    (.setLocation lis (.getWorldTranslation ear))
    1.54 -    (.setRotation lis (.getWorldRotation ear))
    1.55 -    (bind-sense target lis)
    1.56 -    (update-listener-velocity target lis)
    1.57 -    (.addListener audio-renderer lis)
    1.58 -    (.registerSoundProcessor audio-renderer lis sp)))
    1.59 -
    1.60 -(defn enable-hearing
    1.61 -  [#^Node creature #^Spatial ear]
    1.62 -  (let [hearing-data (atom [])]
    1.63 -    [(fn [world]
    1.64 -       (attach-ear world creature ear
    1.65 -                   (fn [data]
    1.66 -                     (reset! hearing-data (vec data)))))
    1.67 -     [(fn []
    1.68 -        (let [data @hearing-data
    1.69 -              topology              
    1.70 -              (vec (map #(vector % 0) (range 0 (count data))))
    1.71 -              scaled-data
    1.72 -              (vec
    1.73 -               (map
    1.74 -                #(rem (int (* 255 (/ (+ 1 %) 2)))  256)
    1.75 -                   data))]
    1.76 -          [topology scaled-data]))
    1.77 -        ]]))
    1.78 -
    1.79 -(defn hearing
    1.80 -  [#^Node creature]
    1.81 -  (reduce
    1.82 -   (fn [[init-a senses-a]
    1.83 -        [init-b senses-b]]
    1.84 -     [(conj init-a init-b)
    1.85 -      (into senses-a senses-b)])
    1.86 -   [[][]]      
    1.87 -   (for [ear (creature-ears creature)]
    1.88 -     (enable-hearing creature ear))))
    1.89 -
    1.90 -
    1.91 -
    1.92 -
    1.93 -
    1.94 -
    1.95  ;; lower level --- nodes
    1.96  ;; closest-node "parse/compile-x" -> makes organ, which is spatial, fn pair
    1.97  
    1.98 @@ -415,14 +327,6 @@
    1.99  
   1.100          (vi image)))))
   1.101          
   1.102 -         
   1.103 -
   1.104 -;;(defn test-touch [world creature]
   1.105 -
   1.106 -
   1.107 -
   1.108 -
   1.109 -
   1.110  (defn test-creature [thing]
   1.111    (let [x-axis
   1.112          (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red)