Clicking (clipping?) with lpf

195 views
Skip to first unread message

nrb...@nyu.edu

unread,
Oct 5, 2014, 12:14:36 PM10/5/14
to mozzi...@googlegroups.com
Hi all,

I made a group of oscillators with the code found below ( I also attached the sketch mozzi_trial3.ino). I am trying to use a low pass filter on the group of oscillators called "out." In updateControl(), when I replace the last line with the second to last line (replace return (int) out; with return (int) lpf.next(out); I don't hear the oscillators being passed through a low pass filter, but rather a series of clicks on top of the unfiltered sound. I've attached two (my apologies: due to weird circumstances I had to record the audio with a field recorder listening to laptop speakers) audio clips showing what I hear, so you don't have to build the circuit. The circuit is simply the arduino pin9 running to a headphone jack's hot pin and the jack's pin grounded to the arduino. Thank you in advance for any assistance/advice! It's much appreciated. -Nick 

The code:

//drone in F minor

#include <MozziGuts.h>
#include <Oscil.h>
#include <tables/sin2048_int8.h>
#include <LowPassFilter.h>
#include <ReverbTank.h>
#define CONTROL_RATE 128

Oscil<2048, AUDIO_RATE> aSin1(SIN2048_DATA);
Oscil<2048, AUDIO_RATE> aSin2(SIN2048_DATA);
Oscil<2048, AUDIO_RATE> aSin3(SIN2048_DATA);
Oscil<2048, AUDIO_RATE> aSin4(SIN2048_DATA);
Oscil<2048, AUDIO_RATE> aSin5(SIN2048_DATA);
Oscil<2048, AUDIO_RATE> aSin6(SIN2048_DATA);
Oscil<2048, AUDIO_RATE> aSin7(SIN2048_DATA);
Oscil<2048, AUDIO_RATE> aSin0(SIN2048_DATA);

Oscil<2048, CONTROL_RATE> kVol1(SIN2048_DATA);
Oscil<2048, CONTROL_RATE> kVol2(SIN2048_DATA);
Oscil<2048, CONTROL_RATE> kVol3(SIN2048_DATA);
Oscil<2048, CONTROL_RATE> kVol4(SIN2048_DATA);
Oscil<2048, CONTROL_RATE> kVol5(SIN2048_DATA);
Oscil<2048, CONTROL_RATE> kVol6(SIN2048_DATA);
Oscil<2048, CONTROL_RATE> kVol7(SIN2048_DATA);
Oscil<2048, CONTROL_RATE> kVol0(SIN2048_DATA);

Oscil<2048, CONTROL_RATE> kFilterMod(SIN2048_DATA);

char v1,v2,v3,v4,v5,v6,v7,v0;
LowPassFilter lpf;

void setup() {
  
  lpf.setResonance(1);
  byte cutoff_freq = 80;
  lpf.setCutoffFreq(cutoff_freq);
  
  aSin1.setFreq(174.61f); // F3
  aSin2.setFreq(196.0f); // G3
  aSin3.setFreq(207.65f); // Ab3
  aSin4.setFreq(233.08f); // Bb3
  aSin5.setFreq(261.63f); // C4
  aSin6.setFreq(277.18f); // Db
  aSin7.setFreq(311.13f); // Eb
  aSin0.setFreq(349.23f); // F4
  
  kVol1.setFreq(4.43f);
  kVol2.setFreq(0.0245f);
  kVol3.setFreq(0.019f);
  kVol4.setFreq(0.07f);
  kVol5.setFreq(0.047f);
  kVol6.setFreq(0.031f);
  kVol7.setFreq(0.0717f);
  kVol0.setFreq(0.041f);

  v1=v2=v3=v4=v5=v6=v7=v0=127;
  
  startMozzi(CONTROL_RATE);
}

void updateControl(){
   v1 = kVol1.next()>>1; // going at a higher freq, this creates zipper noise, so reduce the gain
   v2 = kVol2.next();
   v3 = kVol3.next();
   v4 = kVol4.next();
   v5 = kVol5.next();
   v6 = kVol6.next();
   v7 = kVol7.next();
   v0 = kVol0.next();
}

int updateAudio(){
  long out =
      (long)
      aSin1.next()*v1 +
      aSin2.next()*v2 +
      aSin3.next()*v3 +
      aSin4.next()*v4 +
      aSin5.next()*v5 +
      aSin6.next()*v6 +
      aSin7.next()*v7 +
      aSin0.next()*v0;
      out >>= 9;
  //return (int) lpf.next(out);
  return (int) out;
}

void loop() {
  audioHook();
}
withoutLPF.m4a
withLPF.m4a
mozzi_trial3.ino

Tim Barrass

unread,
Oct 5, 2014, 7:25:05 PM10/5/14
to mozzi...@googlegroups.com
Hi nrb338,

it sounds like the processor can't keep up - have you tried reducing the number of oscillators?

Also, the filter resonance increases from 0 (none) to 255 (maximum).  This is not clearly documented (thanks for drawing my attention to it), but the examples have it around 200.  Your setting of 1 probably won't do much - also, the oscillators in the sketch aren't producing very high frequencies, so the filter might not be very dramatic even with higher resonances.

Tim

--
You received this message because you are subscribed to the Google Groups "Mozzi-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozzi-users...@googlegroups.com.
To post to this group, send email to mozzi...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/bc1c53d4-8245-4f7b-91d4-db513c0e7035%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages