view org/ear.org @ 4:ed256a687dfe

removed very old crufty java program
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 13:17:37 -0700
parents c41d773a85fb
children 19ff95c69cf5
line wrap: on
line source
1 #+title: The EARS!
2 #+author: Robert McIntyre
3 #+email: rlm@mit.edu
4 #+MATHJAX: align:"left" mathml:t path:"../aurellem/src/MathJax/MathJax.js"
5 #+STYLE: <link rel="stylesheet" type="text/css" href="../aurellem/src/css/aurellem.css"/>
6 #+BABEL: :exports both :noweb yes :cache no :mkdirp yes
7 #+INCLUDE: ../aurellem/src/templates/level-0.org
8 #+description: Simulating multiple listeners and the sense of hearing in uMonkeyEngine3
13 * Ears!
15 I want to be able to place ears in a similiar manner to how I place
16 the eyes. I want to be able to place ears in a unique spatial
17 position, and recieve as output at every tick the FFT of whatever
18 signals are happening at that point.
20 #+srcname: ear-header
21 #+begin_src clojure
22 (ns body.ear)
23 (use 'cortex.world)
24 (use 'cortex.import)
25 (use 'clojure.contrib.def)
26 (cortex.import/mega-import-jme3)
27 (rlm.rlm-commands/help)
28 (import java.nio.ByteBuffer)
29 (import java.awt.image.BufferedImage)
30 (import java.awt.Color)
31 (import java.awt.Dimension)
32 (import java.awt.Graphics)
33 (import java.awt.Graphics2D)
34 (import java.awt.event.WindowAdapter)
35 (import java.awt.event.WindowEvent)
36 (import java.awt.image.BufferedImage)
37 (import java.nio.ByteBuffer)
38 (import javax.swing.JFrame)
39 (import javax.swing.JPanel)
40 (import javax.swing.SwingUtilities)
41 (import javax.swing.ImageIcon)
42 (import javax.swing.JOptionPane)
43 (import java.awt.image.ImageObserver)
44 #+end_src
46 JMonkeyEngine3's audio system works as follows:
47 first, an appropiate audio renderer is created during initialization
48 and depending on the context. On my computer, this is the
49 LwjglAudioRenderer.
51 The LwjglAudioRenderer sets a few internal state variables depending
52 on what capabilities the audio system has.
54 may very well need to make my own AudioRenderer
56 #+srcname: ear-body-1
57 #+begin_src clojure :results silent
58 (in-ns 'body.ear)
59 (import 'com.jme3.capture.SoundProcessor)
62 (defn sound-processor
63 "deals with converting ByteBuffers into Arrays of bytes so that the
64 continuation functions can be defined in terms of immutable stuff."
65 [continuation]
66 (proxy [SoundProcessor] []
67 (cleanup [])
68 (process
69 [#^ByteBuffer audioSamples numSamples]
70 (no-exceptions
71 (let [byte-array (byte-array numSamples)]
72 (.get audioSamples byte-array 0 numSamples)
73 (continuation
74 (vec byte-array)))))))
77 (defn add-ear
78 "add an ear to the world. The continuation function will be called
79 on the FFT or the sounds which the ear hears in the given
80 timeframe. Sound is 3D."
81 [world listener continuation]
82 (let [renderer (.getAudioRenderer world)]
83 (.addListener renderer listener)
84 (.registerSoundProcessor renderer listener
85 (sound-processor continuation))
86 listener))
88 #+end_src
92 #+srcname: test-hearing
93 #+begin_src clojure :results silent
94 (ns test.hearing)
95 (use 'cortex.world)
96 (use 'cortex.import)
97 (use 'clojure.contrib.def)
98 (use 'body.ear)
99 (cortex.import/mega-import-jme3)
100 (rlm.rlm-commands/help)
102 (defn setup-fn [world]
103 (let [listener (Listener.)]
104 (add-ear world listener #(println (nth % 0)))))
106 (defn play-sound [node world value]
107 (if (not value)
108 (do
109 (.playSource (.getAudioRenderer world) node))))
111 (defn test-world []
112 (let [node1 (AudioNode. (asset-manager) "Sounds/pure.wav" false false)]
113 (world
114 (Node.)
115 {"key-space" (partial play-sound node1)}
116 setup-fn
117 no-op
118 )))
121 #+end_src
125 * COMMENT Code Generation
127 #+begin_src clojure :tangle /home/r/cortex/src/body/ear.clj
128 <<ear-header>>
129 <<ear-body-1>>
130 #+end_src
133 #+begin_src clojure :tangle /home/r/cortex/src/test/hearing.clj
134 <<test-hearing>>
135 #+end_src