Mercurial > audio-send
diff 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 |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ear.html Tue Oct 25 13:02:31 2011 -0700 1.3 @@ -0,0 +1,266 @@ 1.4 +<?xml version="1.0" encoding="utf-8"?> 1.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 1.6 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 1.7 +<html xmlns="http://www.w3.org/1999/xhtml" 1.8 +lang="en" xml:lang="en"> 1.9 +<head> 1.10 +<title>The EARS!</title> 1.11 +<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> 1.12 +<meta name="generator" content="Org-mode"/> 1.13 +<meta name="generated" content="2011-09-21 16:38:27 MDT"/> 1.14 +<meta name="author" content="Robert McIntyre"/> 1.15 +<meta name="description" content="Simulating multiple listeners and the sense of hearing in uMonkeyEngine3"/> 1.16 +<meta name="keywords" content=""/> 1.17 +<style type="text/css"> 1.18 + <!--/*--><![CDATA[/*><!--*/ 1.19 + html { font-family: Times, serif; font-size: 12pt; } 1.20 + .title { text-align: center; } 1.21 + .todo { color: red; } 1.22 + .done { color: green; } 1.23 + .tag { background-color: #add8e6; font-weight:normal } 1.24 + .target { } 1.25 + .timestamp { color: #bebebe; } 1.26 + .timestamp-kwd { color: #5f9ea0; } 1.27 + .right {margin-left:auto; margin-right:0px; text-align:right;} 1.28 + .left {margin-left:0px; margin-right:auto; text-align:left;} 1.29 + .center {margin-left:auto; margin-right:auto; text-align:center;} 1.30 + p.verse { margin-left: 3% } 1.31 + pre { 1.32 + border: 1pt solid #AEBDCC; 1.33 + background-color: #F3F5F7; 1.34 + padding: 5pt; 1.35 + font-family: courier, monospace; 1.36 + font-size: 90%; 1.37 + overflow:auto; 1.38 + } 1.39 + table { border-collapse: collapse; } 1.40 + td, th { vertical-align: top; } 1.41 + th.right { text-align:center; } 1.42 + th.left { text-align:center; } 1.43 + th.center { text-align:center; } 1.44 + td.right { text-align:right; } 1.45 + td.left { text-align:left; } 1.46 + td.center { text-align:center; } 1.47 + dt { font-weight: bold; } 1.48 + div.figure { padding: 0.5em; } 1.49 + div.figure p { text-align: center; } 1.50 + textarea { overflow-x: auto; } 1.51 + .linenr { font-size:smaller } 1.52 + .code-highlighted {background-color:#ffff00;} 1.53 + .org-info-js_info-navigation { border-style:none; } 1.54 + #org-info-js_console-label { font-size:10px; font-weight:bold; 1.55 + white-space:nowrap; } 1.56 + .org-info-js_search-highlight {background-color:#ffff00; color:#000000; 1.57 + font-weight:bold; } 1.58 + /*]]>*/--> 1.59 +</style> 1.60 +<link rel="stylesheet" type="text/css" href="../aurellem/src/css/aurellem.css"/> 1.61 +<script type="text/javascript"> 1.62 +<!--/*--><![CDATA[/*><!--*/ 1.63 + function CodeHighlightOn(elem, id) 1.64 + { 1.65 + var target = document.getElementById(id); 1.66 + if(null != target) { 1.67 + elem.cacheClassElem = elem.className; 1.68 + elem.cacheClassTarget = target.className; 1.69 + target.className = "code-highlighted"; 1.70 + elem.className = "code-highlighted"; 1.71 + } 1.72 + } 1.73 + function CodeHighlightOff(elem, id) 1.74 + { 1.75 + var target = document.getElementById(id); 1.76 + if(elem.cacheClassElem) 1.77 + elem.className = elem.cacheClassElem; 1.78 + if(elem.cacheClassTarget) 1.79 + target.className = elem.cacheClassTarget; 1.80 + } 1.81 +/*]]>*///--> 1.82 +</script> 1.83 + 1.84 +</head> 1.85 +<body> 1.86 + 1.87 +<div id="content"> 1.88 + 1.89 + 1.90 + 1.91 +<div class="header"> 1.92 + <div class="float-right"> 1.93 + <!-- 1.94 + <form> 1.95 + <input type="text"/><input type="submit" value="search the blog »"/> 1.96 + </form> 1.97 + --> 1.98 + </div> 1.99 + 1.100 + <h1>aurellem <em>☉</em></h1> 1.101 + <ul class="nav"> 1.102 + <li><a href="/">read the blog »</a></li> 1.103 + <!-- li><a href="#">learn about us »</a></li--> 1.104 + </ul> 1.105 +</div> 1.106 + 1.107 +<h1 class="title">The EARS!</h1> 1.108 +<div class="author">Written by <author>Robert McIntyre</author></div> 1.109 + 1.110 + 1.111 + 1.112 + 1.113 + 1.114 + 1.115 + 1.116 + 1.117 + 1.118 + 1.119 +<div id="table-of-contents"> 1.120 +<h2>Table of Contents</h2> 1.121 +<div id="text-table-of-contents"> 1.122 +<ul> 1.123 +<li><a href="#sec-1">1 Ears! </a></li> 1.124 +</ul> 1.125 +</div> 1.126 +</div> 1.127 + 1.128 +<div id="outline-container-1" class="outline-2"> 1.129 +<h2 id="sec-1"><span class="section-number-2">1</span> Ears! </h2> 1.130 +<div class="outline-text-2" id="text-1"> 1.131 + 1.132 + 1.133 +<p> 1.134 +I want to be able to place ears in a similiar manner to how I place 1.135 +the eyes. I want to be able to place ears in a unique spatial 1.136 +position, and recieve as output at every tick the FFT of whatever 1.137 +signals are happening at that point. 1.138 +</p> 1.139 + 1.140 + 1.141 + 1.142 +<pre class="src src-clojure">(<span style="color: #9b30ff;">ns</span> body.ear) 1.143 +(<span style="color: #da70d6;">use</span> 'cortex.world) 1.144 +(<span style="color: #da70d6;">use</span> 'cortex.import) 1.145 +(<span style="color: #da70d6;">use</span> 'clojure.contrib.def) 1.146 +(cortex.import/mega-import-jme3) 1.147 +(rlm.rlm-commands/help) 1.148 +(<span style="color: #9b30ff;">import</span> java.nio.ByteBuffer) 1.149 +(<span style="color: #9b30ff;">import</span> java.awt.image.BufferedImage) 1.150 +(<span style="color: #9b30ff;">import</span> java.awt.Color) 1.151 +(<span style="color: #9b30ff;">import</span> java.awt.Dimension) 1.152 +(<span style="color: #9b30ff;">import</span> java.awt.Graphics) 1.153 +(<span style="color: #9b30ff;">import</span> java.awt.Graphics2D) 1.154 +(<span style="color: #9b30ff;">import</span> java.awt.event.WindowAdapter) 1.155 +(<span style="color: #9b30ff;">import</span> java.awt.event.WindowEvent) 1.156 +(<span style="color: #9b30ff;">import</span> java.awt.image.BufferedImage) 1.157 +(<span style="color: #9b30ff;">import</span> java.nio.ByteBuffer) 1.158 +(<span style="color: #9b30ff;">import</span> javax.swing.JFrame) 1.159 +(<span style="color: #9b30ff;">import</span> javax.swing.JPanel) 1.160 +(<span style="color: #9b30ff;">import</span> javax.swing.SwingUtilities) 1.161 +(<span style="color: #9b30ff;">import</span> javax.swing.ImageIcon) 1.162 +(<span style="color: #9b30ff;">import</span> javax.swing.JOptionPane) 1.163 +(<span style="color: #9b30ff;">import</span> java.awt.image.ImageObserver) 1.164 +</pre> 1.165 + 1.166 + 1.167 + 1.168 + 1.169 +<p> 1.170 +JMonkeyEngine3's audio system works as follows: 1.171 +first, an appropiate audio renderer is created during initialization 1.172 +and depending on the context. On my computer, this is the 1.173 +LwjglAudioRenderer. 1.174 +</p> 1.175 +<p> 1.176 +The LwjglAudioRenderer sets a few internal state variables depending 1.177 +on what capabilities the audio system has. 1.178 +</p> 1.179 +<p> 1.180 +may very well need to make my own AudioRenderer 1.181 +</p> 1.182 + 1.183 + 1.184 + 1.185 +<pre class="src src-clojure">(<span style="color: #9b30ff;">in-ns</span> 'body.ear) 1.186 +(<span style="color: #9b30ff;">import</span> 'com.jme3.capture.SoundProcessor) 1.187 + 1.188 + 1.189 +(<span style="color: #9b30ff;">defn</span> <span style="color: #0000ff;">sound-processor</span> 1.190 + <span style="color: #EB4264;">"deals with converting ByteBuffers into Arrays of bytes so that the</span> 1.191 +<span style="color: #EB4264;"> continuation functions can be defined in terms of immutable stuff."</span> 1.192 + [continuation] 1.193 + (<span style="color: #da70d6;">proxy</span> [SoundProcessor] [] 1.194 + (cleanup []) 1.195 + (process 1.196 + [<span style="color: #228b22;">#^ByteBuffer</span> audioSamples numSamples] 1.197 + (no-exceptions 1.198 + (<span style="color: #9b30ff;">let</span> [byte-array (<span style="color: #da70d6;">byte-array</span> numSamples)] 1.199 + (.get audioSamples byte-array 0 numSamples) 1.200 + (continuation 1.201 + (<span style="color: #da70d6;">vec</span> byte-array))))))) 1.202 + 1.203 + 1.204 +(<span style="color: #9b30ff;">defn</span> <span style="color: #0000ff;">add-ear</span> 1.205 + <span style="color: #EB4264;">"add an ear to the world. The continuation function will be called</span> 1.206 +<span style="color: #EB4264;"> on the FFT or the sounds which the ear hears in the given</span> 1.207 +<span style="color: #EB4264;"> timeframe. Sound is 3D."</span> 1.208 + [world listener continuation] 1.209 + (<span style="color: #9b30ff;">let</span> [renderer (.getAudioRenderer world)] 1.210 + (.addListener renderer listener) 1.211 + (.registerSoundProcessor renderer listener 1.212 + (sound-processor continuation)) 1.213 + listener)) 1.214 + 1.215 +</pre> 1.216 + 1.217 + 1.218 + 1.219 + 1.220 + 1.221 + 1.222 + 1.223 +<pre class="src src-clojure">(<span style="color: #9b30ff;">ns</span> test.hearing) 1.224 +(<span style="color: #da70d6;">use</span> 'cortex.world) 1.225 +(<span style="color: #da70d6;">use</span> 'cortex.import) 1.226 +(<span style="color: #da70d6;">use</span> 'clojure.contrib.def) 1.227 +(<span style="color: #da70d6;">use</span> 'body.ear) 1.228 +(cortex.import/mega-import-jme3) 1.229 +(rlm.rlm-commands/help) 1.230 + 1.231 +(<span style="color: #9b30ff;">defn</span> <span style="color: #0000ff;">setup-fn</span> [world] 1.232 + (<span style="color: #9b30ff;">let</span> [listener (Listener.)] 1.233 + (add-ear world listener #(<span style="color: #da70d6;">println</span> (<span style="color: #da70d6;">nth</span> % 0))))) 1.234 + 1.235 +(<span style="color: #9b30ff;">defn</span> <span style="color: #0000ff;">play-sound</span> [node world value] 1.236 + (<span style="color: #9b30ff;">if</span> (<span style="color: #da70d6;">not</span> value) 1.237 + (<span style="color: #9b30ff;">do</span> 1.238 + (.playSource (.getAudioRenderer world) node)))) 1.239 + 1.240 +(<span style="color: #9b30ff;">defn</span> <span style="color: #0000ff;">test-world</span> [] 1.241 + (<span style="color: #9b30ff;">let</span> [node1 (AudioNode. (asset-manager) <span style="color: #3AA221;">"Sounds/pure.wav"</span> false false)] 1.242 + (world 1.243 + (Node.) 1.244 + {<span style="color: #3AA221;">"key-space"</span> (<span style="color: #da70d6;">partial</span> play-sound node1)} 1.245 + setup-fn 1.246 + no-op 1.247 + ))) 1.248 + 1.249 + 1.250 +</pre> 1.251 + 1.252 + 1.253 + 1.254 + 1.255 + 1.256 + 1.257 + 1.258 + 1.259 +</div> 1.260 +</div> 1.261 +<div id="postamble"> 1.262 +<p class="date">Date: 2011-09-21 16:38:27 MDT</p> 1.263 +<p class="author">Author: Robert McIntyre</p> 1.264 +<p class="creator">Org version 7.6 with Emacs version 23</p> 1.265 +<a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a> 1.266 +</div> 1.267 +</div> 1.268 +</body> 1.269 +</html>