I grabbed the minim library for better sound control in PROCESSING from compartmental.net, installed and eventually got it running. Pretty easy to play a sound from .mp3 or .wav file – in fact playing three at once sounds really cool. So I jumped onto the freesound project and grabbed three random cricket sounds which I turned into crickets1, 2 and 3 .wav. After fiddling about starting and stopping the sounds under keyboard control [AudioPlayMinim02_Feckabout.pde] I decided to find a way to control the sounds by SoundPressureLevel readings from my Arduino.
A quick munge of my earlier ARDUINO <-> PROCESSING serial ‘ASCII call / response’ code for running a dot on the screen by model aeroplane TX / RX remote controls did the trick:
- MultiSensorsSerialCallResponse_Crickets.ino – reads SPL from freetronics MIC sound input into Analog pin 8 of my Arduino & writes the value (0-1023) as the first of four (channel) Comma Separated Values to the serial port (every time an “A” is read from the serial port).
- SerialCallResponseASCII_Crickets02.pde – reads the 4 value parameter CSV from Serial port and does all the logic to figure out how much noise is coming in (on the first parameter) and what to do about it. The basic idea is to react to noise by setting a ‘fear’ string to the values: calm, alert or panic depending on the SPL level coming in. It then decays gradually from panic through alert to calm when all is quiet. Various cricket noises play depending on the state of fear: all three crickets.wav files play simultaneously when all is calm, only one when alert and immediately stop playing all sounds when in panic. I also threw in 4 keyboard controllable ‘seasons’ morn, noon, eve, night to toggle the mix of creatures making noise by typing 1, 2, 3 or 4. This is in preparation for time / light control.
- code.compartmental.net/tools/minim/ – looks a bit neater and possibly simpler. Let’s start here.
- crickets1 crickets.wav http://www.freesound.org/people/Christoff45/sounds/106019/
- crickets2 crickets_creek.wav http://www.freesound.org/people/rhapsodize/sounds/171823/
- crickets3 http://www.freesound.org/people/Tito%20Lahaye/sounds/83270/ [cc:by, NC and too loud, find another cc:by replacement]