view src/body/ear.clj @ 4:ed256a687dfe

removed very old crufty java program
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 13:17:37 -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-processor
29 "deals with converting ByteBuffers into Vectors of Bytes so that the
30 continuation functions can be defined in terms of immutable stuff."
31 [continuation]
32 (proxy [SoundProcessor] []
33 (cleanup [])
34 (process
35 [#^ByteBuffer audioSamples numSamples]
37 (let [byte-array (make-array Byte numSamples)]
38 (.get audioSamples byte-array 0 numSamples)
40 (continuation
41 (vec byte-array))))))
44 (defn add-ear
45 "add an ear to the world. The continuation function will be called
46 on the FFT or the sounds which the ear hears in the given
47 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))