I am pretty excited. its a little hissy, but this works! watch your input level.
I have a knob on A1 and an audioin on A3
and it filters the audio.
It does not sound as good using the PWM out but I had to call that using the Arduino call as I could not remember how to use a single out.
It sounds pretty good with the DAC.
what would be great is if somebody could figure out how to completly get rid of the ANALOGREADS and instead use the low-level code for reading the ADC.
I tried with getSensor and setupFastAnalogRead and had no luck
thanks
/* Example of filtering a wave,
* using Mozzi sonification library.
*
* Demonstrates LowPassFilter().
*
* Circuit: Audio output on digital pin 9 (on a Uno or similar), 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.
* This example code is in the public domain.
*/
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#include <mozzi_analog.h>
#include <LowPassFilter.h>
const int digPin[2] = {3, 4}; // the digital output pins
const int pinOffset = 5; // the first DAC pin (from 5-12)
#define AUDIO_PIN A2
LowPassFilter lpf; //named in CLASS in .h
void setup(){
// set up the digital outputs
for (int i=0; i<2; i++) {
pinMode(digPin[i], OUTPUT);
digitalWrite(digPin[i], LOW);
}
// set up the 8-bit DAC output pins
for (int i=0; i<8; i++) {
pinMode(pinOffset+i, OUTPUT);
digitalWrite(pinOffset+i, LOW);
// set the ADC to a higher prescale factor
sbi(ADCSRA,ADPS2);
cbi(ADCSRA,ADPS1);
cbi(ADCSRA,ADPS0);
//pinMode(AUDIO_PIN,INPUT);
//setupFastAnalogRead();
lpf.setResonance(200); // void setResonance(unsigned char resonance)
// initADC();
}
}
void loop(){
lpf.setCutoffFreq(analogRead(1)>>4); //void setCutoffFreq(unsigned char cutoff)
int asig = lpf.next(analogRead(2)>>4); //int next(int in) return buf1;
//return (int) asig;
// output the value
dacOutput(asig); //USE THIS FOR BETTER AUDIO
// analogWrite(3, asig); //USE THIS IF NO DAC...sounds worse
}
void dacOutput(byte v)
{
PORTB = (PORTB & B11100000) | (v >> 3);
PORTD = (PORTD & B00011111) | ((v & B00000111) << 5);
}