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: (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 Vectors 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: rlm@0: (let [byte-array (make-array Byte numSamples)] rlm@0: (.get audioSamples byte-array 0 numSamples) rlm@0: 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 ear continuation] rlm@0: (let [listener (Listener.) rlm@0: renderer (.getAudioRenderer world)] rlm@0: (.addListener renderer listener) rlm@0: (.registerSoundProcessor renderer listener (sound-processor continuation)) rlm@0: listener))