Mercurial > audio-send
diff src/body/ear.clj @ 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/src/body/ear.clj Tue Oct 25 13:02:31 2011 -0700 1.3 @@ -0,0 +1,53 @@ 1.4 + 1.5 +(ns body.ear) 1.6 +(use 'cortex.world) 1.7 +(use 'cortex.import) 1.8 +(use 'clojure.contrib.def) 1.9 +(cortex.import/mega-import-jme3) 1.10 +(rlm.rlm-commands/help) 1.11 +(import java.nio.ByteBuffer) 1.12 +(import java.awt.image.BufferedImage) 1.13 +(import java.awt.Color) 1.14 +(import java.awt.Dimension) 1.15 +(import java.awt.Graphics) 1.16 +(import java.awt.Graphics2D) 1.17 +(import java.awt.event.WindowAdapter) 1.18 +(import java.awt.event.WindowEvent) 1.19 +(import java.awt.image.BufferedImage) 1.20 +(import java.nio.ByteBuffer) 1.21 +(import javax.swing.JFrame) 1.22 +(import javax.swing.JPanel) 1.23 +(import javax.swing.SwingUtilities) 1.24 +(import javax.swing.ImageIcon) 1.25 +(import javax.swing.JOptionPane) 1.26 +(import java.awt.image.ImageObserver) 1.27 +(in-ns 'body.ear) 1.28 +(import 'com.jme3.capture.SoundProcessor) 1.29 + 1.30 + 1.31 +(defn sound-processor 1.32 + "deals with converting ByteBuffers into Vectors of Bytes so that the 1.33 + continuation functions can be defined in terms of immutable stuff." 1.34 + [continuation] 1.35 + (proxy [SoundProcessor] [] 1.36 + (cleanup []) 1.37 + (process 1.38 + [#^ByteBuffer audioSamples numSamples] 1.39 + 1.40 + (let [byte-array (make-array Byte numSamples)] 1.41 + (.get audioSamples byte-array 0 numSamples) 1.42 + 1.43 + (continuation 1.44 + (vec byte-array)))))) 1.45 + 1.46 + 1.47 +(defn add-ear 1.48 + "add an ear to the world. The continuation function will be called 1.49 + on the FFT or the sounds which the ear hears in the given 1.50 + timeframe. Sound is 3D." 1.51 + [world ear continuation] 1.52 + (let [listener (Listener.) 1.53 + renderer (.getAudioRenderer world)] 1.54 + (.addListener renderer listener) 1.55 + (.registerSoundProcessor renderer listener (sound-processor continuation)) 1.56 + listener))