# HG changeset patch # User Robert McIntyre # Date 1328276476 25200 # Node ID 75b6c2ebbf8e64fb7ec5ed9210e80d0082773f6b # Parent 811127d79d24b9637d2311fedf9c41e5f05d7be6 refactored audio code diff -r 811127d79d24 -r 75b6c2ebbf8e org/test-creature.org --- a/org/test-creature.org Fri Feb 03 06:33:37 2012 -0700 +++ b/org/test-creature.org Fri Feb 03 06:41:16 2012 -0700 @@ -259,94 +259,6 @@ -;; Ears work the same way as vision. - -;; (hearing creature) will return [init-functions -;; sensor-functions]. The init functions each take the world and -;; register a SoundProcessor that does foureier transforms on the -;; incommong sound data, making it available to each sensor function. - -(defn creature-ears - "Return the children of the creature's \"ears\" node." - ;;dylan - ;;"The ear nodes which are children of the \"ears\" node in the - ;;creature." - [#^Node creature] - (if-let [ear-node (.getChild creature "ears")] - (seq (.getChildren ear-node)) - (do (println-repl "could not find ears node") []))) - - -;;dylan (defn follow-sense, adjoin-sense, attach-stimuli, -;;anchor-qualia, augment-organ, with-organ - - -(defn update-listener-velocity - "Update the listener's velocity every update loop." - [#^Spatial obj #^Listener lis] - (let [old-position (atom (.getLocation lis))] - (.addControl - obj - (proxy [AbstractControl] [] - (controlUpdate [tpf] - (let [new-position (.getLocation lis)] - (.setVelocity - lis - (.mult (.subtract new-position @old-position) - (float (/ tpf)))) - (reset! old-position new-position))) - (controlRender [_ _]))))) - -(import com.aurellem.capture.audio.AudioSendRenderer) - -(defn attach-ear - [#^Application world #^Node creature #^Spatial ear continuation] - (let [target (closest-node creature ear) - lis (Listener.) - audio-renderer (.getAudioRenderer world) - sp (sound-processor continuation)] - (.setLocation lis (.getWorldTranslation ear)) - (.setRotation lis (.getWorldRotation ear)) - (bind-sense target lis) - (update-listener-velocity target lis) - (.addListener audio-renderer lis) - (.registerSoundProcessor audio-renderer lis sp))) - -(defn enable-hearing - [#^Node creature #^Spatial ear] - (let [hearing-data (atom [])] - [(fn [world] - (attach-ear world creature ear - (fn [data] - (reset! hearing-data (vec data))))) - [(fn [] - (let [data @hearing-data - topology - (vec (map #(vector % 0) (range 0 (count data)))) - scaled-data - (vec - (map - #(rem (int (* 255 (/ (+ 1 %) 2))) 256) - data))] - [topology scaled-data])) - ]])) - -(defn hearing - [#^Node creature] - (reduce - (fn [[init-a senses-a] - [init-b senses-b]] - [(conj init-a init-b) - (into senses-a senses-b)]) - [[][]] - (for [ear (creature-ears creature)] - (enable-hearing creature ear)))) - - - - - - ;; lower level --- nodes ;; closest-node "parse/compile-x" -> makes organ, which is spatial, fn pair @@ -415,14 +327,6 @@ (vi image))))) - - -;;(defn test-touch [world creature] - - - - - (defn test-creature [thing] (let [x-axis (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red)