rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: The EARS! rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0:
rlm@0: rlm@0: rlm@0: rlm@0:
rlm@0:
rlm@0: rlm@0:
rlm@0: rlm@0:

aurellem

rlm@0: rlm@0:
rlm@0: rlm@0:

The EARS!

rlm@0:
Written by Robert McIntyre
rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0:
rlm@0:

Table of Contents

rlm@0:
rlm@0: rlm@0:
rlm@0:
rlm@0: rlm@0:
rlm@0:

1 Ears!

rlm@0:
rlm@0: rlm@0: rlm@0:

rlm@0: I want to be able to place ears in a similiar manner to how I place rlm@0: the eyes. I want to be able to place ears in a unique spatial rlm@0: position, and recieve as output at every tick the FFT of whatever rlm@0: signals are happening at that point. rlm@0:

rlm@0: rlm@0: rlm@0: rlm@0:
(ns body.ear)
rlm@0: (use 'cortex.world)
rlm@0: (use 'cortex.import)
rlm@0: (use 'clojure.contrib.def)
rlm@0: (cortex.import/mega-import-jme3)
rlm@0: (rlm.rlm-commands/help)
rlm@0: (import java.nio.ByteBuffer)
rlm@0: (import java.awt.image.BufferedImage)
rlm@0: (import java.awt.Color)
rlm@0: (import java.awt.Dimension)
rlm@0: (import java.awt.Graphics)
rlm@0: (import java.awt.Graphics2D)
rlm@0: (import java.awt.event.WindowAdapter)
rlm@0: (import java.awt.event.WindowEvent)
rlm@0: (import java.awt.image.BufferedImage)
rlm@0: (import java.nio.ByteBuffer)
rlm@0: (import javax.swing.JFrame)
rlm@0: (import javax.swing.JPanel)
rlm@0: (import javax.swing.SwingUtilities)
rlm@0: (import javax.swing.ImageIcon)
rlm@0: (import javax.swing.JOptionPane)
rlm@0: (import java.awt.image.ImageObserver)
rlm@0: 
rlm@0: rlm@0: rlm@0: rlm@0: rlm@0:

rlm@0: JMonkeyEngine3's audio system works as follows: rlm@0: first, an appropiate audio renderer is created during initialization rlm@0: and depending on the context. On my computer, this is the rlm@0: LwjglAudioRenderer. rlm@0:

rlm@0:

rlm@0: The LwjglAudioRenderer sets a few internal state variables depending rlm@0: on what capabilities the audio system has. rlm@0:

rlm@0:

rlm@0: may very well need to make my own AudioRenderer rlm@0:

rlm@0: rlm@0: rlm@0: rlm@0:
(in-ns 'body.ear)
rlm@0: (import 'com.jme3.capture.SoundProcessor)
rlm@0: 
rlm@0: 
rlm@0: (defn sound-processor
rlm@0:   "deals with converting ByteBuffers into Arrays of bytes so that the
rlm@0:   continuation functions can be defined in terms of immutable stuff."
rlm@0:   [continuation]
rlm@0:   (proxy [SoundProcessor] []
rlm@0:     (cleanup [])
rlm@0:     (process
rlm@0:       [#^ByteBuffer audioSamples numSamples]
rlm@0:       (no-exceptions
rlm@0:        (let [byte-array (byte-array numSamples)]
rlm@0:          (.get audioSamples byte-array 0 numSamples)
rlm@0:          (continuation
rlm@0:           (vec byte-array)))))))
rlm@0:          
rlm@0: 
rlm@0: (defn add-ear 
rlm@0:   "add an ear to the world.  The continuation function will be called
rlm@0:   on the FFT or the sounds which the ear hears in the given
rlm@0:   timeframe. Sound is 3D."
rlm@0:   [world listener continuation]
rlm@0:   (let [renderer (.getAudioRenderer world)]
rlm@0:     (.addListener renderer listener)
rlm@0:     (.registerSoundProcessor renderer listener
rlm@0:                              (sound-processor continuation))
rlm@0:     listener))
rlm@0: 
rlm@0: 
rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0:
(ns test.hearing)
rlm@0: (use 'cortex.world)
rlm@0: (use 'cortex.import)
rlm@0: (use 'clojure.contrib.def)
rlm@0: (use 'body.ear)
rlm@0: (cortex.import/mega-import-jme3)
rlm@0: (rlm.rlm-commands/help)
rlm@0: 
rlm@0: (defn setup-fn [world]
rlm@0:   (let [listener (Listener.)]
rlm@0:     (add-ear world listener #(println (nth % 0)))))
rlm@0:   
rlm@0: (defn play-sound [node world value]
rlm@0:   (if (not value)
rlm@0:     (do
rlm@0:       (.playSource (.getAudioRenderer world) node))))
rlm@0: 
rlm@0: (defn test-world []
rlm@0:   (let [node1 (AudioNode. (asset-manager) "Sounds/pure.wav" false false)]
rlm@0:     (world
rlm@0:      (Node.)
rlm@0:      {"key-space" (partial play-sound node1)}
rlm@0:      setup-fn
rlm@0:      no-op
rlm@0:      )))
rlm@0:     
rlm@0: 
rlm@0: 
rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0:
rlm@0:
rlm@0:
rlm@0:

Date: 2011-09-21 16:38:27 MDT

rlm@0:

Author: Robert McIntyre

rlm@0:

Org version 7.6 with Emacs version 23

rlm@0: Validate XHTML 1.0 rlm@0:
rlm@0:
rlm@0: rlm@0: