diff 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
line wrap: on
line diff
     1.1 --- a/org/hearing.org	Sat Feb 04 10:00:37 2012 -0700
     1.2 +++ b/org/hearing.org	Sat Feb 04 10:13:15 2012 -0700
     1.3 @@ -760,6 +760,7 @@
     1.4    (:use (cortex world util sense))
     1.5    (:use clojure.contrib.def)
     1.6    (:import java.nio.ByteBuffer)
     1.7 +  (:import java.awt.image.BufferedImage)
     1.8    (:import org.tritonus.share.sampled.FloatSampleTools)
     1.9    (:import (com.aurellem.capture.audio
    1.10              SoundProcessor AudioSendRenderer))
    1.11 @@ -857,8 +858,28 @@
    1.12    (for [ear (ears creature)]
    1.13      (hearing-fn creature ear)))
    1.14  
    1.15 +(defn view-hearing
    1.16 +  "Creates a function which accepts a list of auditory data and
    1.17 +   display each element of the list to the screen as an image."
    1.18 +  []
    1.19 +  (view-sense
    1.20 +   (fn [[coords sensor-data]]
    1.21 +     (let [height 50
    1.22 +           image (BufferedImage. (count coords) height
    1.23 +                                 BufferedImage/TYPE_INT_RGB)]
    1.24 +       (dorun
    1.25 +        (for [x (range (count coords))]
    1.26 +          (dorun
    1.27 +           (for [y (range height)]
    1.28 +             (let [raw-sensor (sensor-data x)]
    1.29 +               (.setRGB image x y (gray raw-sensor)))))))
    1.30 +       image))))
    1.31 +
    1.32  #+end_src
    1.33  
    1.34 +#+results: ears
    1.35 +: #'cortex.hearing/hearing!
    1.36 +
    1.37  * Example
    1.38  
    1.39  #+name: test-hearing