comparison org/ear.org @ 163:985c73659923

renamed functions in ear.org
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 02:15:32 -0700
parents 2cbdd7034c6c
children c33a8e5fe7bc
comparison
equal deleted inserted replaced
162:2cbdd7034c6c 163:985c73659923
781 (FloatSampleTools/byte2floatInterleaved 781 (FloatSampleTools/byte2floatInterleaved
782 bytes 0 floats 0 num-floats audioFormat) 782 bytes 0 floats 0 num-floats audioFormat)
783 (continuation 783 (continuation
784 (vec floats)))))) 784 (vec floats))))))
785 785
786 786 (defn ears
787
788
789 ;; Ears work the same way as vision.
790
791 ;; (hearing creature) will return [init-functions
792 ;; sensor-functions]. The init functions each take the world and
793 ;; register a SoundProcessor that does foureier transforms on the
794 ;; incommong sound data, making it available to each sensor function.
795
796 (defn creature-ears
797 "Return the children of the creature's \"ears\" node." 787 "Return the children of the creature's \"ears\" node."
798 ;;dylan
799 ;;"The ear nodes which are children of the \"ears\" node in the
800 ;;creature."
801 [#^Node creature] 788 [#^Node creature]
802 (if-let [ear-node (.getChild creature "ears")] 789 (if-let [ear-node (.getChild creature "ears")]
803 (seq (.getChildren ear-node)) 790 (seq (.getChildren ear-node))
804 (do (println-repl "could not find ears node") []))) 791 (do (println-repl "could not find ears node") [])))
805 792
806 793 (defn update-listener-velocity!
807 ;;dylan (defn follow-sense, adjoin-sense, attach-stimuli,
808 ;;anchor-qualia, augment-organ, with-organ
809
810
811 (defn update-listener-velocity
812 "Update the listener's velocity every update loop." 794 "Update the listener's velocity every update loop."
813 [#^Spatial obj #^Listener lis] 795 [#^Spatial obj #^Listener lis]
814 (let [old-position (atom (.getLocation lis))] 796 (let [old-position (atom (.getLocation lis))]
815 (.addControl 797 (.addControl
816 obj 798 obj
824 (reset! old-position new-position))) 806 (reset! old-position new-position)))
825 (controlRender [_ _]))))) 807 (controlRender [_ _])))))
826 808
827 (import com.aurellem.capture.audio.AudioSendRenderer) 809 (import com.aurellem.capture.audio.AudioSendRenderer)
828 810
829 (defn attach-ear 811 (defn create-listener!
830 [#^Application world #^Node creature #^Spatial ear continuation] 812 [#^Application world #^Node creature #^Spatial ear continuation]
831 (let [target (closest-node creature ear) 813 (let [target (closest-node creature ear)
832 lis (Listener.) 814 lis (Listener.)
833 audio-renderer (.getAudioRenderer world) 815 audio-renderer (.getAudioRenderer world)
834 sp (sound-processor continuation)] 816 sp (sound-processor continuation)]
835 (.setLocation lis (.getWorldTranslation ear)) 817 (.setLocation lis (.getWorldTranslation ear))
836 (.setRotation lis (.getWorldRotation ear)) 818 (.setRotation lis (.getWorldRotation ear))
837 (bind-sense target lis) 819 (bind-sense target lis)
838 (update-listener-velocity target lis) 820 (update-listener-velocity! target lis)
839 (.addListener audio-renderer lis) 821 (.addListener audio-renderer lis)
840 (.registerSoundProcessor audio-renderer lis sp))) 822 (.registerSoundProcessor audio-renderer lis sp)))
841 823
842 (defn enable-hearing 824 (defn hearing-fn
843 [#^Node creature #^Spatial ear] 825 [#^Node creature #^Spatial ear]
844 (let [hearing-data (atom [])] 826 (let [hearing-data (atom [])]
845 [(fn [world] 827 [(fn [world]
846 (attach-ear world creature ear 828 (create-listener! world creature ear
847 (fn [data] 829 (fn [data]
848 (reset! hearing-data (vec data))))) 830 (reset! hearing-data (vec data)))))
849 [(fn [] 831 [(fn []
850 (let [data @hearing-data 832 (let [data @hearing-data
851 topology 833 topology
856 #(rem (int (* 255 (/ (+ 1 %) 2))) 256) 838 #(rem (int (* 255 (/ (+ 1 %) 2))) 256)
857 data))] 839 data))]
858 [topology scaled-data])) 840 [topology scaled-data]))
859 ]])) 841 ]]))
860 842
861 (defn hearing 843 (defn hearing!
862 [#^Node creature] 844 [#^Node creature]
863 (reduce 845 (reduce
864 (fn [[init-a senses-a] 846 (fn [[init-a senses-a]
865 [init-b senses-b]] 847 [init-b senses-b]]
866 [(conj init-a init-b) 848 [(conj init-a init-b)
867 (into senses-a senses-b)]) 849 (into senses-a senses-b)])
868 [[][]] 850 [[][]]
869 (for [ear (creature-ears creature)] 851 (for [ear (ears creature)]
870 (enable-hearing creature ear)))) 852 (hearing-fn creature ear))))
871 853
872 854
873 #+end_src 855 #+end_src
874 856
875 * Example 857 * Example
923 in demos and the like. 905 in demos and the like.
924 906
925 907
926 * COMMENT Code Generation 908 * COMMENT Code Generation
927 909
928 #+begin_src clojure :tangle ../cortex/src/cortex/hearing.clj 910 #+begin_src clojure :tangle ../src/cortex/hearing.clj
929 <<ears>> 911 <<ears>>
930 #+end_src 912 #+end_src
931 913
932 #+begin_src clojure :tangle ../src/cortex/test/hearing.clj 914 #+begin_src clojure :tangle ../src/cortex/test/hearing.clj
933 <<test-hearing>> 915 <<test-hearing>>