Mercurial > audio-send
view src/body/ear.clj @ 20:e8ae40c9848c
fixed 1,000,000 spelling errors
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 03 Nov 2011 15:02:18 -0700 |
parents | f9476ff7637e |
children |
line wrap: on
line source
2 (ns body.ear)3 (use 'cortex.world)4 (use 'cortex.import)5 (use 'clojure.contrib.def)6 (cortex.import/mega-import-jme3)7 (rlm.rlm-commands/help)8 (import java.nio.ByteBuffer)9 (import java.awt.image.BufferedImage)10 (import java.awt.Color)11 (import java.awt.Dimension)12 (import java.awt.Graphics)13 (import java.awt.Graphics2D)14 (import java.awt.event.WindowAdapter)15 (import java.awt.event.WindowEvent)16 (import java.awt.image.BufferedImage)17 (import java.nio.ByteBuffer)18 (import javax.swing.JFrame)19 (import javax.swing.JPanel)20 (import javax.swing.SwingUtilities)21 (import javax.swing.ImageIcon)22 (import javax.swing.JOptionPane)23 (import java.awt.image.ImageObserver)24 (in-ns 'body.ear)25 (import 'com.jme3.capture.SoundProcessor)28 (defn sound-processor29 "deals with converting ByteBuffers into Vectors of Bytes so that the30 continuation functions can be defined in terms of immutable stuff."31 [continuation]32 (proxy [SoundProcessor] []33 (cleanup [])34 (process35 [#^ByteBuffer audioSamples numSamples]37 (let [byte-array (make-array Byte numSamples)]38 (.get audioSamples byte-array 0 numSamples)40 (continuation41 (vec byte-array))))))44 (defn add-ear45 "add an ear to the world. The continuation function will be called46 on the FFT or the sounds which the ear hears in the given47 timeframe. Sound is 3D."48 [world ear continuation]49 (let [listener (Listener.)50 renderer (.getAudioRenderer world)]51 (.addListener renderer listener)52 (.registerSoundProcessor renderer listener (sound-processor continuation))53 listener))