comparison ear.html @ 0:f9476ff7637e

initial forking of open-al to create multiple listeners
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 13:02:31 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f9476ff7637e
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml"
5 lang="en" xml:lang="en">
6 <head>
7 <title>The EARS!</title>
8 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
9 <meta name="generator" content="Org-mode"/>
10 <meta name="generated" content="2011-09-21 16:38:27 MDT"/>
11 <meta name="author" content="Robert McIntyre"/>
12 <meta name="description" content="Simulating multiple listeners and the sense of hearing in uMonkeyEngine3"/>
13 <meta name="keywords" content=""/>
14 <style type="text/css">
15 <!--/*--><![CDATA[/*><!--*/
16 html { font-family: Times, serif; font-size: 12pt; }
17 .title { text-align: center; }
18 .todo { color: red; }
19 .done { color: green; }
20 .tag { background-color: #add8e6; font-weight:normal }
21 .target { }
22 .timestamp { color: #bebebe; }
23 .timestamp-kwd { color: #5f9ea0; }
24 .right {margin-left:auto; margin-right:0px; text-align:right;}
25 .left {margin-left:0px; margin-right:auto; text-align:left;}
26 .center {margin-left:auto; margin-right:auto; text-align:center;}
27 p.verse { margin-left: 3% }
28 pre {
29 border: 1pt solid #AEBDCC;
30 background-color: #F3F5F7;
31 padding: 5pt;
32 font-family: courier, monospace;
33 font-size: 90%;
34 overflow:auto;
35 }
36 table { border-collapse: collapse; }
37 td, th { vertical-align: top; }
38 th.right { text-align:center; }
39 th.left { text-align:center; }
40 th.center { text-align:center; }
41 td.right { text-align:right; }
42 td.left { text-align:left; }
43 td.center { text-align:center; }
44 dt { font-weight: bold; }
45 div.figure { padding: 0.5em; }
46 div.figure p { text-align: center; }
47 textarea { overflow-x: auto; }
48 .linenr { font-size:smaller }
49 .code-highlighted {background-color:#ffff00;}
50 .org-info-js_info-navigation { border-style:none; }
51 #org-info-js_console-label { font-size:10px; font-weight:bold;
52 white-space:nowrap; }
53 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
54 font-weight:bold; }
55 /*]]>*/-->
56 </style>
57 <link rel="stylesheet" type="text/css" href="../aurellem/src/css/aurellem.css"/>
58 <script type="text/javascript">
59 <!--/*--><![CDATA[/*><!--*/
60 function CodeHighlightOn(elem, id)
61 {
62 var target = document.getElementById(id);
63 if(null != target) {
64 elem.cacheClassElem = elem.className;
65 elem.cacheClassTarget = target.className;
66 target.className = "code-highlighted";
67 elem.className = "code-highlighted";
68 }
69 }
70 function CodeHighlightOff(elem, id)
71 {
72 var target = document.getElementById(id);
73 if(elem.cacheClassElem)
74 elem.className = elem.cacheClassElem;
75 if(elem.cacheClassTarget)
76 target.className = elem.cacheClassTarget;
77 }
78 /*]]>*///-->
79 </script>
80
81 </head>
82 <body>
83
84 <div id="content">
85
86
87
88 <div class="header">
89 <div class="float-right">
90 <!--
91 <form>
92 <input type="text"/><input type="submit" value="search the blog &raquo;"/>
93 </form>
94 -->
95 </div>
96
97 <h1>aurellem <em>&#x2609;</em></h1>
98 <ul class="nav">
99 <li><a href="/">read the blog &raquo;</a></li>
100 <!-- li><a href="#">learn about us &raquo;</a></li-->
101 </ul>
102 </div>
103
104 <h1 class="title">The EARS!</h1>
105 <div class="author">Written by <author>Robert McIntyre</author></div>
106
107
108
109
110
111
112
113
114
115
116 <div id="table-of-contents">
117 <h2>Table of Contents</h2>
118 <div id="text-table-of-contents">
119 <ul>
120 <li><a href="#sec-1">1 Ears! </a></li>
121 </ul>
122 </div>
123 </div>
124
125 <div id="outline-container-1" class="outline-2">
126 <h2 id="sec-1"><span class="section-number-2">1</span> Ears! </h2>
127 <div class="outline-text-2" id="text-1">
128
129
130 <p>
131 I want to be able to place ears in a similiar manner to how I place
132 the eyes. I want to be able to place ears in a unique spatial
133 position, and recieve as output at every tick the FFT of whatever
134 signals are happening at that point.
135 </p>
136
137
138
139 <pre class="src src-clojure">(<span style="color: #9b30ff;">ns</span> body.ear)
140 (<span style="color: #da70d6;">use</span> 'cortex.world)
141 (<span style="color: #da70d6;">use</span> 'cortex.import)
142 (<span style="color: #da70d6;">use</span> 'clojure.contrib.def)
143 (cortex.import/mega-import-jme3)
144 (rlm.rlm-commands/help)
145 (<span style="color: #9b30ff;">import</span> java.nio.ByteBuffer)
146 (<span style="color: #9b30ff;">import</span> java.awt.image.BufferedImage)
147 (<span style="color: #9b30ff;">import</span> java.awt.Color)
148 (<span style="color: #9b30ff;">import</span> java.awt.Dimension)
149 (<span style="color: #9b30ff;">import</span> java.awt.Graphics)
150 (<span style="color: #9b30ff;">import</span> java.awt.Graphics2D)
151 (<span style="color: #9b30ff;">import</span> java.awt.event.WindowAdapter)
152 (<span style="color: #9b30ff;">import</span> java.awt.event.WindowEvent)
153 (<span style="color: #9b30ff;">import</span> java.awt.image.BufferedImage)
154 (<span style="color: #9b30ff;">import</span> java.nio.ByteBuffer)
155 (<span style="color: #9b30ff;">import</span> javax.swing.JFrame)
156 (<span style="color: #9b30ff;">import</span> javax.swing.JPanel)
157 (<span style="color: #9b30ff;">import</span> javax.swing.SwingUtilities)
158 (<span style="color: #9b30ff;">import</span> javax.swing.ImageIcon)
159 (<span style="color: #9b30ff;">import</span> javax.swing.JOptionPane)
160 (<span style="color: #9b30ff;">import</span> java.awt.image.ImageObserver)
161 </pre>
162
163
164
165
166 <p>
167 JMonkeyEngine3's audio system works as follows:
168 first, an appropiate audio renderer is created during initialization
169 and depending on the context. On my computer, this is the
170 LwjglAudioRenderer.
171 </p>
172 <p>
173 The LwjglAudioRenderer sets a few internal state variables depending
174 on what capabilities the audio system has.
175 </p>
176 <p>
177 may very well need to make my own AudioRenderer
178 </p>
179
180
181
182 <pre class="src src-clojure">(<span style="color: #9b30ff;">in-ns</span> 'body.ear)
183 (<span style="color: #9b30ff;">import</span> 'com.jme3.capture.SoundProcessor)
184
185
186 (<span style="color: #9b30ff;">defn</span> <span style="color: #0000ff;">sound-processor</span>
187 <span style="color: #EB4264;">"deals with converting ByteBuffers into Arrays of bytes so that the</span>
188 <span style="color: #EB4264;"> continuation functions can be defined in terms of immutable stuff."</span>
189 [continuation]
190 (<span style="color: #da70d6;">proxy</span> [SoundProcessor] []
191 (cleanup [])
192 (process
193 [<span style="color: #228b22;">#^ByteBuffer</span> audioSamples numSamples]
194 (no-exceptions
195 (<span style="color: #9b30ff;">let</span> [byte-array (<span style="color: #da70d6;">byte-array</span> numSamples)]
196 (.get audioSamples byte-array 0 numSamples)
197 (continuation
198 (<span style="color: #da70d6;">vec</span> byte-array)))))))
199
200
201 (<span style="color: #9b30ff;">defn</span> <span style="color: #0000ff;">add-ear</span>
202 <span style="color: #EB4264;">"add an ear to the world. The continuation function will be called</span>
203 <span style="color: #EB4264;"> on the FFT or the sounds which the ear hears in the given</span>
204 <span style="color: #EB4264;"> timeframe. Sound is 3D."</span>
205 [world listener continuation]
206 (<span style="color: #9b30ff;">let</span> [renderer (.getAudioRenderer world)]
207 (.addListener renderer listener)
208 (.registerSoundProcessor renderer listener
209 (sound-processor continuation))
210 listener))
211
212 </pre>
213
214
215
216
217
218
219
220 <pre class="src src-clojure">(<span style="color: #9b30ff;">ns</span> test.hearing)
221 (<span style="color: #da70d6;">use</span> 'cortex.world)
222 (<span style="color: #da70d6;">use</span> 'cortex.import)
223 (<span style="color: #da70d6;">use</span> 'clojure.contrib.def)
224 (<span style="color: #da70d6;">use</span> 'body.ear)
225 (cortex.import/mega-import-jme3)
226 (rlm.rlm-commands/help)
227
228 (<span style="color: #9b30ff;">defn</span> <span style="color: #0000ff;">setup-fn</span> [world]
229 (<span style="color: #9b30ff;">let</span> [listener (Listener.)]
230 (add-ear world listener #(<span style="color: #da70d6;">println</span> (<span style="color: #da70d6;">nth</span> % 0)))))
231
232 (<span style="color: #9b30ff;">defn</span> <span style="color: #0000ff;">play-sound</span> [node world value]
233 (<span style="color: #9b30ff;">if</span> (<span style="color: #da70d6;">not</span> value)
234 (<span style="color: #9b30ff;">do</span>
235 (.playSource (.getAudioRenderer world) node))))
236
237 (<span style="color: #9b30ff;">defn</span> <span style="color: #0000ff;">test-world</span> []
238 (<span style="color: #9b30ff;">let</span> [node1 (AudioNode. (asset-manager) <span style="color: #3AA221;">"Sounds/pure.wav"</span> false false)]
239 (world
240 (Node.)
241 {<span style="color: #3AA221;">"key-space"</span> (<span style="color: #da70d6;">partial</span> play-sound node1)}
242 setup-fn
243 no-op
244 )))
245
246
247 </pre>
248
249
250
251
252
253
254
255
256 </div>
257 </div>
258 <div id="postamble">
259 <p class="date">Date: 2011-09-21 16:38:27 MDT</p>
260 <p class="author">Author: Robert McIntyre</p>
261 <p class="creator">Org version 7.6 with Emacs version 23</p>
262 <a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a>
263 </div>
264 </div>
265 </body>
266 </html>