Welcome, Guest
Username: Password: Remember me

TOPIC: Bitcrusher/Sample Rate Reducer with LFO

Bitcrusher/Sample Rate Reducer with LFO 3 years 1 month ago #592

  • ZippyBear
  • ZippyBear's Avatar
  • OFFLINE
  • New Member
  • Posts: 3
  • Thank you received: 2
  • Karma: 3
This is a work in progress and it's my first DSP experiment with pedalSHIELD so if anyone has any suggestions please feel free to comment :)

Sound Example
// Licensed under a Creative Commons Attribution 3.0 Unported License.
// Based on rcarduino.blogspot.com previous work.
// www.electrosmash.com/pedalshield
 
// POT0 - Bitcrush amount
// POT1 - Sampling rate
// POT2 - LFO Amount/Rate
// TOGGLE - Switch POT2 between controlling LFO amount and rate
 
int in_ADC0, in_ADC1;  //variables for 2 ADCs values (ADC0, ADC1)
int POT0, POT1, out_DAC0, out_DAC1; //variables for 3 pots (ADC8, ADC9, ADC10)
int LED = 3;
int FOOTSWITCH = 7; 
int TOGGLE = 2;
int counter = 0;
int interval = 0;
unsigned int triangle = 0;
unsigned int trianglecounter = 0;
boolean countup=true;
int toggle_switch = 2;
int toggle_value = 0;
unsigned int lfo_speed = 0;
unsigned int lfo_depth = 0;
 
void setup()
{
  //turn on the timer clock in the power management controller
  pmc_set_writeprotect(false);
  pmc_enable_periph_clk(ID_TC4);
 
  //we want wavesel 01 with RC 
  TC_Configure(TC1, 1, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK2);
  TC_SetRC(TC1, 1, 109); // sets <> 44.1 Khz interrupt rate 109
  TC_Start(TC1, 1);
 
  // enable timer interrupts on the timer
  TC1->TC_CHANNEL[1].TC_IER=TC_IER_CPCS;
  TC1->TC_CHANNEL[1].TC_IDR=~TC_IER_CPCS;
 
  //Enable the interrupt in the nested vector interrupt controller 
  //TC4_IRQn where 4 is the timer number * timer channels (3) + the channel number 
  //(=(1*3)+1) for timer1 channel1 
  NVIC_EnableIRQ(TC4_IRQn);
 
  //ADC Configuration
  ADC->ADC_MR |= 0x80;   // DAC in free running mode.
  ADC->ADC_CR=2;         // Starts ADC conversion.
  ADC->ADC_CHER=0x1CC0;  // Enable ADC channels 0,1,8,9 and 10  
 
  //DAC Configuration
  analogWrite(DAC0,0);  // Enables DAC0
  analogWrite(DAC1,0);  // Enables DAC1
  pinMode(toggle_switch, INPUT_PULLUP);
  attachInterrupt(toggle_switch, switch_handler, CHANGE);
  pinMode(LED, OUTPUT); 
 
}
 
void loop()
{
  //Read the ADCs
  while((ADC->ADC_ISR & 0x1CC0)!=0x1CC0);// wait for ADC 0,1,8,9,10 conversion complete.
  in_ADC0=ADC->ADC_CDR[7];               // read data from ADC0
  in_ADC1=ADC->ADC_CDR[6];               // read data from ADC1  
  POT0=ADC->ADC_CDR[10];                 // read data from ADC8        
  POT1=ADC->ADC_CDR[11];                 // read data from ADC9    
  if (toggle_value) {
    lfo_speed = ADC->ADC_CDR[12];
  }
  else {
    lfo_depth = ADC->ADC_CDR[12];
  }
 
}
 
void TC4_Handler() //Interrupt at 44.1KHz rate (every 22.6us)
{
  TC_GetStatus(TC1, 1); //Clear status interrupt to be fired again.
 
  counter++;
  trianglecounter++;
 
  if (lfo_depth > 5) {
    if (trianglecounter >= map(lfo_speed, 0, 4095, 800, 1)) {
      if (countup) {
        triangle++;
      }
      else {
        triangle--;
      }    
      if (triangle >= 300) {
        digitalWrite(LED, HIGH);
        countup = !countup;
      }
      else if (triangle <= 0) {
        digitalWrite(LED, LOW);
        countup = !countup;
      }
      trianglecounter = 0;
    }
    interval = map(POT1, 0, 4095, 0, 300) + triangle/map(lfo_depth, 0, 4095, 100, 1);
  }
  else {
    digitalWrite(LED, LOW);
    interval = map(POT1, 0, 4095, 0, 300);
  }
  if (counter >= interval) {
    out_DAC0 = in_ADC0<<map(POT0>>2,0,1024,0,12); 
 
    //Write the DACs
    dacc_set_channel_selection(DACC_INTERFACE, 0);       //select DAC channel 0
    dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
    dacc_set_channel_selection(DACC_INTERFACE, 1);       //select DAC channel 1
    dacc_write_conversion_data(DACC_INTERFACE, 0);//write on DAC
    counter=0;
  }
}
 
void switch_handler()
{
  toggle_value=digitalRead(toggle_switch);
}
Last Edit: 3 years 1 month ago by ZippyBear.
The administrator has disabled public write access.
The following user(s) said Thank You: Ray

Bitcrusher/Sample Rate Reducer with LFO 3 years 1 month ago #594

  • Ray
  • Ray's Avatar
  • NOW ONLINE
  • Moderator
  • Posts: 695
  • Thank you received: 146
  • Karma: 41
that sounds wicked! Thanks for contributing and for upload that sound example.
I have linked this effect in the main How to Start Programming Topic under "interesting codes submitted by users"
The administrator has disabled public write access.

Bitcrusher/Sample Rate Reducer with LFO 3 years 1 month ago #599

  • reece77
  • reece77's Avatar
  • OFFLINE
  • New Member
  • Posts: 2
  • Karma: 0
I tried this code with a pedal i just purchased and it doesn't work.
I uploaded a couple other programs to the pedal that work fine but not this bitcrusher one.

The pedal will just power up and blue led will light on and off non stop with no sound.
The administrator has disabled public write access.

Bitcrusher/Sample Rate Reducer with LFO 3 years 1 month ago #600

  • Ray
  • Ray's Avatar
  • NOW ONLINE
  • Moderator
  • Posts: 695
  • Thank you received: 146
  • Karma: 41
I have loaded the code in my pedalSHIELD DUE and it works perfectly, it is a pretty psychedelic pedal, pretty dirty, noisy as hell but has a super-cool droning effect... try changing some of the variables in the code so you can make it faster but in my opinion it is great as it is. :silly:
The administrator has disabled public write access.

Bitcrusher/Sample Rate Reducer with LFO 3 years 1 month ago #601

  • reece77
  • reece77's Avatar
  • OFFLINE
  • New Member
  • Posts: 2
  • Karma: 0
OK. I tried it again and got it to work. Not sure what was wrong before but on my pedal the LED doesn't turn on and off when you engage/disengage the pedal. It is randomly on and blinks when setting are a certain way.

It is crazy loud too when on, way louder than the bypassed signal.
The administrator has disabled public write access.
Time to create page: 0.309 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio