LOW PASS FILTER WORKS ON AUDIO

436 views
Skip to first unread message

loss1234

unread,
Mar 29, 2013, 1:29:50 PM3/29/13
to mozzi...@googlegroups.com
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);
}


Mr Sensorium

unread,
Mar 30, 2013, 6:02:45 AM3/30/13
to mozzi...@googlegroups.com
Hi Dan,
if your code does what you need, that's great.  It doesn't actually use any of the Mozzi architecture, only the filter class, so that offers you freedom if it fits the other work you do.

In response to your postings in this direction (and as I mentioned in our email), the next Mozzi update will have buffered audio input sampled in the background in step with the defined audio rate.  It seems to be working, but it's part of the guts.  For the sake of efficiency, I'm shuffling things around to make it a configuration option.
Anyway, if there's any advantage for you in using Mozzi's framework with the separate timed control and audio interrupts, buffering etc., the feature you've been interested in will be included soon.  Of course, everything takes longer than expected!

Tim

loss1234

unread,
Mar 30, 2013, 8:56:18 AM3/30/13
to mozzi...@googlegroups.com
sadly so far I could not get it to work with the MOZZIGUTS.h

I am hoping I can find a way to read the analog inputs more quickly so I can go back to using the Mozziguts

I CANT WAIT FOR THE NEXT UPDATE!!! woo hoo

thanks for all your hard work

dan
Reply all
Reply to author
Forward
0 new messages