Mercurial > cortex
changeset 221:7c374c6cfe17
hearing.org rough draft is ready
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 11 Feb 2012 12:15:07 -0700 |
parents | c5f6d880558b |
children | 49d0a545a872 |
files | assets/Models/test-creature/worm.blend images/worm-with-ear.png org/hearing.org org/sense.org |
diffstat | 4 files changed, 153 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
1.1 Binary file assets/Models/test-creature/worm.blend has changed
2.1 Binary file images/worm-with-ear.png has changed
3.1 --- a/org/hearing.org Sat Feb 11 07:08:38 2012 -0700 3.2 +++ b/org/hearing.org Sat Feb 11 12:15:07 2012 -0700 3.3 @@ -788,7 +788,7 @@ 3.4 rarefaction of the air while 1.0 represents maximum compression of the 3.5 air at a given instant. 3.6 3.7 -#+name: ears 3.8 +#+name: hearing-pipeline 3.9 #+begin_src clojure 3.10 (in-ns 'cortex.hearing) 3.11 3.12 @@ -832,6 +832,7 @@ 3.13 listeners, =(update-listener-velocity!)= ensures that this velocity 3.14 information is always up-to-date. 3.15 3.16 +#+name: hearing-ears 3.17 #+begin_src clojure 3.18 (defvar 3.19 ^{:arglists '([creature])} 3.20 @@ -874,6 +875,7 @@ 3.21 3.22 ** Ear Creation 3.23 3.24 +#+name: hearing-kernel 3.25 #+begin_src clojure 3.26 (defn hearing-kernel 3.27 "Returns a functon which returns auditory sensory data when called 3.28 @@ -920,7 +922,10 @@ 3.29 [-1.0, 1.0] to the range [0 255], converts to integer, and displays 3.30 the number as a greyscale pixel. 3.31 3.32 +#+name: hearing-display 3.33 #+begin_src clojure 3.34 +(in-ns 'cortex.hearing) 3.35 + 3.36 (defn view-hearing 3.37 "Creates a function which accepts a list of auditory data and 3.38 display each element of the list to the screen as an image." 3.39 @@ -933,7 +938,7 @@ 3.40 #(rem (int (* 255 (/ (+ 1 %) 2))) 256) 3.41 sensor-data)) 3.42 height 50 3.43 - image (BufferedImage. (count coords) height 3.44 + image (BufferedImage. (max 1 (count coords)) height 3.45 BufferedImage/TYPE_INT_RGB)] 3.46 (dorun 3.47 (for [x (range (count coords))] 3.48 @@ -968,7 +973,6 @@ 3.49 detects sound which is louder than a certain threshold. As the blue 3.50 sphere travels along the path, it excites each of the cubes in turn.</p> 3.51 </div> 3.52 - 3.53 #+end_html 3.54 3.55 #+include "../../jmeCapture/src/com/aurellem/capture/examples/Advanced.java" src java 3.56 @@ -976,7 +980,7 @@ 3.57 Here is a small clojure program to drive the java program and make it 3.58 available as part of my test suite. 3.59 3.60 -#+name: test-hearing 3.61 +#+name: test-hearing-1 3.62 #+begin_src clojure 3.63 (in-ns 'cortex.test.hearing) 3.64 3.65 @@ -994,9 +998,139 @@ 3.66 (.setPauseOnLostFocus false))) 3.67 #+end_src 3.68 3.69 + 3.70 + 3.71 + 3.72 ** Adding Hearing to the Worm 3.73 3.74 +To the worm, I add a new node called "ears" with one child which 3.75 +represents the worm's single ear. 3.76 3.77 +#+attr_html: width=755 3.78 +#+caption: The Worm with a newly added nodes describing an ear. 3.79 +[[../images/worm-with-ear.png]] 3.80 + 3.81 +The node highlighted in yellow it the top-level "ears" node. It's 3.82 +child, highlighted in orange, represents a the single ear the creature 3.83 +has. The ear will be localized right above the curved part of the 3.84 +worm's lower hemispherical region opposite the eye. 3.85 + 3.86 +The other empty nodes represent the worm's single joint and eye and are 3.87 +described in [[./body.org][body]] and [[./vision.org][vision]]. 3.88 + 3.89 +#+name: test-hearing-2 3.90 +#+begin_src clojure 3.91 +(in-ns 'cortex.test.hearing) 3.92 + 3.93 +(cortex.import/mega-import-jme3) 3.94 +(import java.io.File) 3.95 + 3.96 +(use 'cortex.body) 3.97 + 3.98 +(defn test-worm-hearing [] 3.99 + (let [the-worm (doto (worm) (body!)) 3.100 + hearing (hearing! the-worm) 3.101 + hearing-display (view-hearing) 3.102 + 3.103 + tone (AudioNode. (asset-manager) 3.104 + "Sounds/pure.wav" false) 3.105 + 3.106 + hymn (AudioNode. (asset-manager) 3.107 + "Sounds/ear-and-eye.wav" false)] 3.108 + (world 3.109 + (nodify [the-worm (floor)]) 3.110 + (merge standard-debug-controls 3.111 + {"key-return" 3.112 + (fn [_ value] 3.113 + (if value (.play tone))) 3.114 + "key-l" 3.115 + (fn [_ value] 3.116 + (if value (.play hymn)))}) 3.117 + (fn [world] 3.118 + (light-up-everything world) 3.119 + (com.aurellem.capture.Capture/captureVideo 3.120 + world 3.121 + (File."/home/r/proj/cortex/render/worm-audio/frames")) 3.122 + (com.aurellem.capture.Capture/captureAudio 3.123 + world 3.124 + (File."/home/r/proj/cortex/render/worm-audio/audio.wav"))) 3.125 + 3.126 + (fn [world tpf] 3.127 + (hearing-display 3.128 + (map #(% world) hearing) 3.129 + (File. "/home/r/proj/cortex/render/worm-audio/hearing-data")))))) 3.130 +#+end_src 3.131 + 3.132 +In this test, I load the worm with its newly formed ear and let it 3.133 +hear sounds. The sound the worm is hearing is localized to the origin 3.134 +of the world, and you can see that as the worm moves farther away from 3.135 +the origin when it is hit by balls, it hears the sound less intensely. 3.136 + 3.137 +The sound you hear in the video is from the worm's perspective. Notice 3.138 +how the pure tone becomes fainter and the visual display of the 3.139 +auditory data becomes less pronounced as the worm falls farther away 3.140 +from the source of the sound. 3.141 + 3.142 +#+begin_html 3.143 +<div class="figure"> 3.144 +<center> 3.145 +<video controls="controls" width="600"> 3.146 + <source src="../video/worm-hearing.ogg" type="video/ogg" 3.147 + preload="none" poster="../images/aurellem-1280x480.png" /> 3.148 +</video> 3.149 +</center> 3.150 +<p>The worm can now hear the sound pulses produced from the 3.151 + hymn. Notice the strikingly different pattern that human speech 3.152 + makes compared to the insturments. Once the worm is pushed off the 3.153 + floor, the sound it hears is attenuated, and the display of the 3.154 + sound it hears beomes fainter. This shows the 3D localization of 3.155 + sound in this world.</p> 3.156 +</div> 3.157 + 3.158 +#+end_html 3.159 + 3.160 +*** Creating the Ear Video 3.161 +#+name: magick-3 3.162 +#+begin_src clojure 3.163 +(ns cortex.video.magick3 3.164 + (:import java.io.File) 3.165 + (:use clojure.contrib.shell-out)) 3.166 + 3.167 +(defn images [path] 3.168 + (sort (rest (file-seq (File. path))))) 3.169 + 3.170 +(def base "/home/r/proj/cortex/render/worm-audio/") 3.171 + 3.172 +(defn pics [file] 3.173 + (images (str base file))) 3.174 + 3.175 +(defn combine-images [] 3.176 + (let [main-view (pics "frames") 3.177 + hearing (pics "hearing-data") 3.178 + background (repeat 9001 (File. (str base "background.png"))) 3.179 + targets (map 3.180 + #(File. (str base "out/" (format "%07d.png" %))) 3.181 + (range 0 (count main-view)))] 3.182 + (dorun 3.183 + (pmap 3.184 + (comp 3.185 + (fn [[background main-view hearing target]] 3.186 + (println target) 3.187 + (sh "convert" 3.188 + background 3.189 + main-view "-geometry" "+66+21" "-composite" 3.190 + hearing "-geometry" "+21+526" "-composite" 3.191 + target)) 3.192 + (fn [& args] (map #(.getCanonicalPath %) args))) 3.193 + background main-view hearing targets)))) 3.194 +#+end_src 3.195 + 3.196 +#+begin_src sh 3.197 +cd /home/r/proj/cortex/render/worm-audio 3.198 +ffmpeg -r 60 -i out/%07d.png -i audio.wav \ 3.199 + -b:a 128k -b:v 9001k \ 3.200 + -acodec libvorbis -vcodec libtheora worm-hearing.ogg 3.201 +#+end_src 3.202 3.203 * Headers 3.204 3.205 @@ -1006,7 +1140,7 @@ 3.206 "Simulate the sense of hearing in jMonkeyEngine3. Enables multiple 3.207 listeners at different positions in the same world. Automatically 3.208 reads ear-nodes from specially prepared blender files and 3.209 - instantiates them in the world as actual ears." 3.210 + instantiates them in the world as simulated ears." 3.211 {:author "Robert McIntyre"} 3.212 (:use (cortex world util sense)) 3.213 (:use clojure.contrib.def) 3.214 @@ -1022,9 +1156,11 @@ 3.215 (:import com.jme3.scene.control.AbstractControl)) 3.216 #+end_src 3.217 3.218 +#+name: test-header 3.219 #+begin_src clojure 3.220 (ns cortex.test.hearing 3.221 (:use (cortex world util hearing)) 3.222 + (:use cortex.test.body) 3.223 (:import (com.jme3.audio AudioNode Listener)) 3.224 (:import com.jme3.scene.Node 3.225 com.jme3.system.AppSettings)) 3.226 @@ -1042,11 +1178,20 @@ 3.227 3.228 #+begin_src clojure :tangle ../src/cortex/hearing.clj 3.229 <<hearing-header>> 3.230 -<<ears>> 3.231 +<<hearing-pipeline>> 3.232 +<<hearing-ears>> 3.233 +<<hearing-kernel>> 3.234 +<<hearing-display>> 3.235 #+end_src 3.236 3.237 #+begin_src clojure :tangle ../src/cortex/test/hearing.clj 3.238 -<<test-hearing>> 3.239 +<<test-header>> 3.240 +<<test-hearing-1>> 3.241 +<<test-hearing-2>> 3.242 +#+end_src 3.243 + 3.244 +#+begin_src clojure :tangle ../src/cortex/video/magick3.clj 3.245 +<<magick-3>> 3.246 #+end_src 3.247 3.248 #+begin_src C :tangle ../../audio-send/Alc/backends/send.c
4.1 --- a/org/sense.org Sat Feb 11 07:08:38 2012 -0700 4.2 +++ b/org/sense.org Sat Feb 11 12:15:07 2012 -0700 4.3 @@ -511,7 +511,7 @@ 4.4 4.5 #+begin_src sh :results silent 4.6 cd /home/r/proj/cortex/render/ 4.7 -ffmpeg -r 60 -b 9000k -i bind-sense/%07d.png bind-sense.ogg 4.8 +ffmpeg -r 30 -i bind-sense/%07d.png -b:v 9000k -vcodec libtheora bind-sense.ogg 4.9 #+end_src 4.10 4.11 * Headers