diff org/ear.org @ 1:c41d773a85fb

moved org files, ignored html files
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 13:03:35 -0700
parents ear.org@f9476ff7637e
children 19ff95c69cf5
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/org/ear.org	Tue Oct 25 13:03:35 2011 -0700
     1.3 @@ -0,0 +1,137 @@
     1.4 +#+title: The EARS!
     1.5 +#+author: Robert McIntyre
     1.6 +#+email: rlm@mit.edu
     1.7 +#+MATHJAX: align:"left" mathml:t path:"../aurellem/src/MathJax/MathJax.js"
     1.8 +#+STYLE: <link rel="stylesheet" type="text/css" href="../aurellem/src/css/aurellem.css"/>
     1.9 +#+BABEL: :exports both :noweb yes :cache no :mkdirp yes
    1.10 +#+INCLUDE: ../aurellem/src/templates/level-0.org
    1.11 +#+description: Simulating multiple listeners and the sense of hearing in uMonkeyEngine3
    1.12 +
    1.13 +
    1.14 +
    1.15 +
    1.16 +* Ears!
    1.17 +
    1.18 +I want to be able to place ears in a similiar manner to how I place
    1.19 +the eyes.  I want to be able to place ears in a unique spatial
    1.20 +position, and recieve as output at every tick the FFT of whatever
    1.21 +signals are happening at that point.
    1.22 +
    1.23 +#+srcname: ear-header
    1.24 +#+begin_src clojure
    1.25 +(ns body.ear)
    1.26 +(use 'cortex.world)
    1.27 +(use 'cortex.import)
    1.28 +(use 'clojure.contrib.def)
    1.29 +(cortex.import/mega-import-jme3)
    1.30 +(rlm.rlm-commands/help)
    1.31 +(import java.nio.ByteBuffer)
    1.32 +(import java.awt.image.BufferedImage)
    1.33 +(import java.awt.Color)
    1.34 +(import java.awt.Dimension)
    1.35 +(import java.awt.Graphics)
    1.36 +(import java.awt.Graphics2D)
    1.37 +(import java.awt.event.WindowAdapter)
    1.38 +(import java.awt.event.WindowEvent)
    1.39 +(import java.awt.image.BufferedImage)
    1.40 +(import java.nio.ByteBuffer)
    1.41 +(import javax.swing.JFrame)
    1.42 +(import javax.swing.JPanel)
    1.43 +(import javax.swing.SwingUtilities)
    1.44 +(import javax.swing.ImageIcon)
    1.45 +(import javax.swing.JOptionPane)
    1.46 +(import java.awt.image.ImageObserver)
    1.47 +#+end_src
    1.48 +
    1.49 +JMonkeyEngine3's audio system works as follows:
    1.50 +first, an appropiate audio renderer is created during initialization
    1.51 +and depending on the context.  On my computer, this is the
    1.52 +LwjglAudioRenderer. 
    1.53 +
    1.54 +The LwjglAudioRenderer sets a few internal state variables depending
    1.55 +on what capabilities the audio system has.
    1.56 +
    1.57 +may very well need to make my own AudioRenderer
    1.58 +
    1.59 +#+srcname: ear-body-1
    1.60 +#+begin_src clojure :results silent
    1.61 +(in-ns 'body.ear)
    1.62 +(import 'com.jme3.capture.SoundProcessor)
    1.63 +
    1.64 +
    1.65 +(defn sound-processor
    1.66 +  "deals with converting ByteBuffers into Arrays of bytes so that the
    1.67 +  continuation functions can be defined in terms of immutable stuff."
    1.68 +  [continuation]
    1.69 +  (proxy [SoundProcessor] []
    1.70 +    (cleanup [])
    1.71 +    (process
    1.72 +      [#^ByteBuffer audioSamples numSamples]
    1.73 +      (no-exceptions
    1.74 +       (let [byte-array (byte-array numSamples)]
    1.75 +	 (.get audioSamples byte-array 0 numSamples)
    1.76 +	 (continuation
    1.77 +	  (vec byte-array)))))))
    1.78 +	 
    1.79 +
    1.80 +(defn add-ear 
    1.81 +  "add an ear to the world.  The continuation function will be called
    1.82 +  on the FFT or the sounds which the ear hears in the given
    1.83 +  timeframe. Sound is 3D."
    1.84 +  [world listener continuation]
    1.85 +  (let [renderer (.getAudioRenderer world)]
    1.86 +    (.addListener renderer listener)
    1.87 +    (.registerSoundProcessor renderer listener
    1.88 +			     (sound-processor continuation))
    1.89 +    listener))
    1.90 +
    1.91 +#+end_src
    1.92 +
    1.93 +
    1.94 +
    1.95 +#+srcname: test-hearing
    1.96 +#+begin_src clojure :results silent
    1.97 +(ns test.hearing)
    1.98 +(use 'cortex.world)
    1.99 +(use 'cortex.import)
   1.100 +(use 'clojure.contrib.def)
   1.101 +(use 'body.ear)
   1.102 +(cortex.import/mega-import-jme3)
   1.103 +(rlm.rlm-commands/help)
   1.104 +
   1.105 +(defn setup-fn [world]
   1.106 +  (let [listener (Listener.)]
   1.107 +    (add-ear world listener #(println (nth % 0)))))
   1.108 +  
   1.109 +(defn play-sound [node world value]
   1.110 +  (if (not value)
   1.111 +    (do
   1.112 +      (.playSource (.getAudioRenderer world) node))))
   1.113 +
   1.114 +(defn test-world []
   1.115 +  (let [node1 (AudioNode. (asset-manager) "Sounds/pure.wav" false false)]
   1.116 +    (world
   1.117 +     (Node.)
   1.118 +     {"key-space" (partial play-sound node1)}
   1.119 +     setup-fn
   1.120 +     no-op
   1.121 +     )))
   1.122 +    
   1.123 +
   1.124 +#+end_src
   1.125 +
   1.126 +
   1.127 +
   1.128 +* COMMENT Code Generation
   1.129 +
   1.130 +#+begin_src clojure :tangle /home/r/cortex/src/body/ear.clj
   1.131 +<<ear-header>>
   1.132 +<<ear-body-1>>
   1.133 +#+end_src
   1.134 +
   1.135 +
   1.136 +#+begin_src clojure :tangle /home/r/cortex/src/test/hearing.clj
   1.137 +<<test-hearing>>
   1.138 +#+end_src
   1.139 +
   1.140 +