Mozzi  version 2015-05-11-20:23
sound synthesis library for Arduino
 All Classes Functions Typedefs Groups
10.Audio_Filters/LowPassFilter/LowPassFilter.ino

This example demonstrates the LowPassFilter class.

/* Example of filtering a wave,
using Mozzi sonification library.
Demonstrates LowPassFilter().
Circuit: Audio output on digital pin 9 on a Uno or similar, or
DAC/A14 on Teensy 3.1, or
check the README or http://sensorium.github.com/Mozzi/
Mozzi help/discussion/announcements:
https://groups.google.com/forum/#!forum/mozzi-users
Tim Barrass 2012, CC by-nc-sa.
*/
//#include <ADC.h> // Teensy 3.1 uncomment this line and install http://github.com/pedvide/ADC
#include <MozziGuts.h>
#include <Oscil.h>
#include <tables/chum9_int8.h> // recorded audio wavetable
#include <tables/cos2048_int8.h> // for filter modulation
#include <LowPassFilter.h>
#include <mozzi_rand.h>
#define CONTROL_RATE 64 // powers of 2 please
Oscil<CHUM9_NUM_CELLS, AUDIO_RATE> aCrunchySound(CHUM9_DATA);
Oscil<COS2048_NUM_CELLS, CONTROL_RATE> kFilterMod(COS2048_DATA);
void setup(){
aCrunchySound.setFreq(2.f);
kFilterMod.setFreq(1.3f);
lpf.setResonance(200);
}
void loop(){
}
if (rand(CONTROL_RATE/2) == 0){ // about once every half second
kFilterMod.setFreq((float)rand(255)/64); // choose a new modulation frequency
}
// map the modulation into the filter range (0-255)
byte cutoff_freq = 100 + kFilterMod.next()/2;
lpf.setCutoffFreq(cutoff_freq);
}
char asig = lpf.next(aCrunchySound.next());
return (int) asig;
}