comparison org/hearing.org @ 189:facc2ef3fe5c

added hearing debug view.
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 10:13:15 -0700
parents 94b79c191fc7
children c5f6d880558b
comparison
equal deleted inserted replaced
188:22548d48cc85 189:facc2ef3fe5c
758 instantiates them in the world as actual ears." 758 instantiates them in the world as actual ears."
759 {:author "Robert McIntyre"} 759 {:author "Robert McIntyre"}
760 (:use (cortex world util sense)) 760 (:use (cortex world util sense))
761 (:use clojure.contrib.def) 761 (:use clojure.contrib.def)
762 (:import java.nio.ByteBuffer) 762 (:import java.nio.ByteBuffer)
763 (:import java.awt.image.BufferedImage)
763 (:import org.tritonus.share.sampled.FloatSampleTools) 764 (:import org.tritonus.share.sampled.FloatSampleTools)
764 (:import (com.aurellem.capture.audio 765 (:import (com.aurellem.capture.audio
765 SoundProcessor AudioSendRenderer)) 766 SoundProcessor AudioSendRenderer))
766 (:import javax.sound.sampled.AudioFormat) 767 (:import javax.sound.sampled.AudioFormat)
767 (:import (com.jme3.scene Spatial Node)) 768 (:import (com.jme3.scene Spatial Node))
855 which when called will return the auditory data from that ear." 856 which when called will return the auditory data from that ear."
856 [#^Node creature] 857 [#^Node creature]
857 (for [ear (ears creature)] 858 (for [ear (ears creature)]
858 (hearing-fn creature ear))) 859 (hearing-fn creature ear)))
859 860
860 #+end_src 861 (defn view-hearing
862 "Creates a function which accepts a list of auditory data and
863 display each element of the list to the screen as an image."
864 []
865 (view-sense
866 (fn [[coords sensor-data]]
867 (let [height 50
868 image (BufferedImage. (count coords) height
869 BufferedImage/TYPE_INT_RGB)]
870 (dorun
871 (for [x (range (count coords))]
872 (dorun
873 (for [y (range height)]
874 (let [raw-sensor (sensor-data x)]
875 (.setRGB image x y (gray raw-sensor)))))))
876 image))))
877
878 #+end_src
879
880 #+results: ears
881 : #'cortex.hearing/hearing!
861 882
862 * Example 883 * Example
863 884
864 #+name: test-hearing 885 #+name: test-hearing
865 #+begin_src clojure :results silent 886 #+begin_src clojure :results silent