Mercurial > audio-send
view 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 source
1 #+title: The EARS!2 #+author: Robert McIntyre3 #+email: rlm@mit.edu4 #+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 yes7 #+INCLUDE: ../aurellem/src/templates/level-0.org8 #+description: Simulating multiple listeners and the sense of hearing in uMonkeyEngine313 * Ears!15 I want to be able to place ears in a similiar manner to how I place16 the eyes. I want to be able to place ears in a unique spatial17 position, and recieve as output at every tick the FFT of whatever18 signals are happening at that point.20 #+srcname: ear-header21 #+begin_src clojure22 (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_src46 JMonkeyEngine3's audio system works as follows:47 first, an appropiate audio renderer is created during initialization48 and depending on the context. On my computer, this is the49 LwjglAudioRenderer.51 The LwjglAudioRenderer sets a few internal state variables depending52 on what capabilities the audio system has.54 may very well need to make my own AudioRenderer56 #+srcname: ear-body-157 #+begin_src clojure :results silent58 (in-ns 'body.ear)59 (import 'com.jme3.capture.SoundProcessor)62 (defn sound-processor63 "deals with converting ByteBuffers into Arrays of bytes so that the64 continuation functions can be defined in terms of immutable stuff."65 [continuation]66 (proxy [SoundProcessor] []67 (cleanup [])68 (process69 [#^ByteBuffer audioSamples numSamples]70 (no-exceptions71 (let [byte-array (byte-array numSamples)]72 (.get audioSamples byte-array 0 numSamples)73 (continuation74 (vec byte-array)))))))77 (defn add-ear78 "add an ear to the world. The continuation function will be called79 on the FFT or the sounds which the ear hears in the given80 timeframe. Sound is 3D."81 [world listener continuation]82 (let [renderer (.getAudioRenderer world)]83 (.addListener renderer listener)84 (.registerSoundProcessor renderer listener85 (sound-processor continuation))86 listener))88 #+end_src92 #+srcname: test-hearing93 #+begin_src clojure :results silent94 (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 (do109 (.playSource (.getAudioRenderer world) node))))111 (defn test-world []112 (let [node1 (AudioNode. (asset-manager) "Sounds/pure.wav" false false)]113 (world114 (Node.)115 {"key-space" (partial play-sound node1)}116 setup-fn117 no-op118 )))121 #+end_src125 * COMMENT Code Generation127 #+begin_src clojure :tangle /home/r/cortex/src/body/ear.clj128 <<ear-header>>129 <<ear-body-1>>130 #+end_src133 #+begin_src clojure :tangle /home/r/cortex/src/test/hearing.clj134 <<test-hearing>>135 #+end_src