sketch: a simple comb filter for Maple

sketch: a simple comb filter for Maple

Postby okie » Tue Aug 23, 2011 10:23 pm

Code: Select all
#define SAMPLE_RATE 44
#define ADCS 2

#include <AudioCodec_Maple.h>

int16 left_in = 0;
int16 right_in = 0;
int16 left_out = 0;
int16 right_out = 0;

uint16 mod0_value = 0;
uint16 mod1_value = 0;

#define MOD_RANGE 65536
#define BUFFER_SIZE 4096
int16 buffer[BUFFER_SIZE];
uint16 location = 0;

void setup() {
  SerialUSB.end();
  AudioCodec_init();
}

void loop() {
  while (1);
}

void AudioCodec_interrupt() {
  AudioCodec_data(&left_in, &right_in, left_out, right_out);
  AudioCodec_ADC(&mod0_value, &mod1_value);
  buffer[location] = (left_in - buffer[(location + mod0_value/(MOD_RANGE/BUFFER_SIZE))%BUFFER_SIZE]*31)/2/32;
  left_out = 4*buffer[location]; //multiply by 4 because it's too quiet
  right_out = left_out;
  location = (location + 1)%BUFFER_SIZE;
}
okie
 
Posts: 1
Joined: Tue Aug 23, 2011 10:21 pm

Re: sketch: a simple comb filter for Maple

Postby guest » Wed Aug 24, 2011 10:16 pm

ill give it a try
looks good

why do you think the volume is low from memory
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: sketch: a simple comb filter for Maple

Postby loss1234 » Sun Apr 01, 2012 8:18 am

Any chance of this getting converted to arduino??
loss1234
 
Posts: 10
Joined: Sun Apr 01, 2012 1:39 am

Re: sketch: a simple comb filter for Maple

Postby guest » Sun Apr 01, 2012 10:38 pm

not too much needs to change

first the correct header file needs to be included
so change
#include <AudioCodec_Maple.h>
to
#include <AudioCodec.h>

also since there is only one mod being used
#define ADCS 2
should be
#define ADCS 1
and
AudioCodec_ADC(&mod0_value, &mod1_value);
should be
AudioCodec_ADC(&mod0_value);

and the memory is smaller so
#define BUFFER_SIZE 4096
becomes
#define BUFFER_SIZE 800

and you dont need this
SerialUSB.end();

that takes care of all basic maple vs arduino differences
now the processing speed differences
there is no hardware divide on arduino
so you can not use divide in any of the functions
unless you are dividing by a factor of 2
so the interrupt loop will look something like this

Code: Select all
ISR(TIMER1_COMPA_vect, ISR_NAKED) {
  AudioCodec_data(&left_in, &right_in, left_out, right_out);
  uint temp1 = location + (mod0>>6);
  if (temp >= BUFFER_SIZE) {
    temp -= BUFFER_SIZE; // reset location
  }
  int temp2 = buffer[temp1];
  buffer[location] = (left_in >> 5) - temp2;
  right_out = left_out;
  location++; // increment locations
  if (location >= BUFFER_SIZE) {
    location = 0; // reset location
  }
  AudioCodec_ADC(&mod0_value); 
  reti();
}


note the use of ISR instead of AudioCodec_interrupt
and the addition of reti(); at the end to return from the interrupt
i also got rid of the volume adjustment
that can easily be added back in if its not loud enough
and changed the rollover function for BUFER_SIZE
modulo takes forever to run
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: sketch: a simple comb filter for Maple

Postby guest » Sun Apr 01, 2012 11:08 pm

this is a basic version works
Code: Select all
/*
comb_filter.pde
guest openmusiclabs 4.1.12
*/


// setup codec parameters
// must be done before #includes
// see readme file in libraries folder for explanations
#define SAMPLE_RATE 44 // 44.1Khz
#define ADCS 1 // no ADCs are being used

// include necessary libraries
#include <Wire.h>
#include <SPI.h>
#include <AudioCodec.h>

// create data variables for audio transfer
int left_in = 0x0000;
int left_out = 0x0000;
int right_in = 0x0000;
int right_out = 0x0000;

unsigned int mod0_value = 0x0000;

// create a delay buffer in memory
#define SIZE 800 // buffer size is limited by microcontroller SRAM size
int buffer[SIZE]; // 800 positions x 2 bytes = 1600 bytes of SRAM
unsigned int location = 0; // buffer location to read/write from

void setup() {
  AudioCodec_init(); // setup codec registers
  // call this last if setting up other parts
}

void loop() {
  while (1); // reduces clock jitter
}

// timer1 interrupt routine - all data processed here
ISR(TIMER1_COMPA_vect, ISR_NAKED) {
  AudioCodec_data(&left_in, &right_in, left_out, right_out);
  int temp1 = location + (mod0_value>>6);
  if (temp1 >= SIZE) {
    temp1 -= SIZE; // reset location
  }
  int temp2 = buffer[temp1];
  left_out = ((left_in >> 3) - temp2);
  buffer[location] = left_out >> 1;
  right_out = left_in;
  location++; // increment locations
  if (location >= SIZE) {
    location = 0; // reset location
  }
  AudioCodec_ADC(&mod0_value);
  reti();
}
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm


Return to Audio Codec Shield

Who is online

Users browsing this forum: Bing [Bot] and 1 guest


cron