well I think in some ways I am more confused now with the addition of the startAnalogRead and ReceiveAnalogRead commands.
I am just not sure where they go in relation to the setup of pins at the top of the sketch and where they go in setupAudio in relation to the
calls to get the audio into the filter.
anyway......here is what I got togther. it does not work at this stage.
actually it seemed to work a bit better before I put in the fast analog read stuff BUT probrably only because I am putting stuff in incorrectly.
BUT this is a start to hopefully get a conversation going!
thanks
CODE BELOW
Dan
/* Example of using analog pots, and an analog input with filter
* using Mozzi sonification library.
*
*
* 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 */
#include <MozziGuts.h>
#include <Oscil.h>
#include <tables/triangle_analogue512_int8.h> // wavetable
#include <tables/cos2048_int8.h> // for filter modulation
#include <tables/cos8192_int8.h> // wavetable
#include <AudioDelayFeedback.h>
#include <mozzi_analog.h>
#include <LowPassFilter.h>
#include <mozzi_analog.h>
#include <fixedMath.h> // for fractional modulation frequency
#define CONTROL_RATE 64 // powers of 2 please
unsigned char Audio; //this is where we will store our audio data
Oscil<COS2048_NUM_CELLS, CONTROL_RATE> kFilterMod(COS2048_DATA);
LowPassFilter lpf;
// Don't use the Arduino A0, A1 etc pin notation, just say 0, 1, 2...
#define CENTRE_FREQ_ANALOG_IN 0
#define MOD_SPEED_ANALOG_IN 1
#define MOD_WIDTH_ANALOG_IN 2
#define AUDIO_IN 3
void setup(){
startMozzi(CONTROL_RATE);
lpf.setResonance(200);
// initADC();
setupFastAnalogRead();
startAnalogRead( 3);
}
void updateControl(){
receiveAnalogRead();
startAnalogRead( 3) ;
unsigned char centre_freq = (unsigned char) (getSensor(CENTRE_FREQ_ANALOG_IN)>>2); // 0 to 255
Audio= (unsigned char) (getSensor(AUDIO_IN)>>3); //divide the 0-1023 down to a usable range
Q16n16 modulation_speed = ((Q16n16)getSensor(MOD_SPEED_ANALOG_IN)<<10); // range 0 to 15, Q16n16 fractional
kFilterMod.setFreq_Q16n16(modulation_speed);
unsigned char modulation_width = (unsigned char) (getSensor(MOD_WIDTH_ANALOG_IN)>>4); // 0 to 63
char modulation = ((int) kFilterMod.next() * modulation_width)>>8; // -32 to 31
// add centre_freq to modulation, and constrain into the filter range (0-255)
unsigned char cutoff_freq = constrain(centre_freq + modulation, 0, 255);
lpf.setCutoffFreq(cutoff_freq);
startRead();
}
int updateAudio(){
char asig = lpf.next(Audio);
return (int) asig;
}
void loop(){
audioHook();
}