Stomp shield Octaver.

Stomp shield Octaver.

Postby Arduinoob » Tue Apr 15, 2014 7:32 am

Hi,
Im trying to build an Octave effect using the stomp shield but im running into some basic problems with the code. (It's not my strong point!) In order to build the Octave effect I need to full rectify a sine wave. I have altered the bitcrush effect as a start off point. In the code at the bottom, I have managed to half rectify a wave but Im running into problems with the code that is performing the full rectification. Can anyone help with this or just give me the pointers to head in the right direction? Also, when I tested a sine wave in an oscilloscope I was getting the reverse of what I expected with the half rectified wave. The wave was like a half rectified wave but upside down. Anyway, here is the code and thanks for any help in advance.



THe input signal is represented as a signed 16-bit integer. This means that its values can vary between
-32768 up to 32767.


*/
#include "StompShield.h"

int counter; // bit mask
byte button; // button checking timer
byte last_state; // last rotary encoder state
int output;

void setup() {
counter = 0xffff;
StompShield_init(); // setup the arduino for the shield
}

void loop() {
}

ISR(TIMER1_OVF_vect) {

// get ADC data
byte temp1 = ADCL; // you need to fetch the low byte first
byte temp2 = ADCH; // yes it needs to be done this way
int input = ((temp2 << 8) | temp1) + 0x8000; // make a signed 16b value

button--; // check buttons every so often
if (button == 0) {

// controlling what the encoder is doing
byte temp3 = (PIND & 0x94); // mask off and invert
if (((last_state | temp3) & 0x10) == 0) { // falling edge
if (temp3 & 0x04) {
if ((counter & 0x7fff) == 0) counter = 0x8000;
else counter <<= 1;
}
else counter >>= 1;
}
last_state = (temp3 ^ 0x94);
button = 0x20; // reset counter
}

//altering the input signal - half wave rectification
// if (input<=0) {
// output = input;
// } else {
// output=0;
// }

if (input<=0) {
output = input;
} else {
output=input*(-1);
}


// output data
OCR1AL = ((output + 0x8000) >> 8); // convert to unsigned and output high byte
OCR1BL = output; // output the low byte
}
Arduinoob
 
Posts: 4
Joined: Tue Apr 15, 2014 6:46 am

Re: Stomp shield Octaver.

Postby guest » Wed Apr 16, 2014 1:04 am

you are almost there. all you have to do is reset the bias point (and invert it, if thats what you want). so, after you fullwave rectify, your signal is only positive values. so this only takes up half the range (0 - 32k). so you need to multiply everything by 2, to get the full range. but, this makes it 0 - 64k, so you also need to subtract 32k to get it to go from -32k - 32k. also, i cut out all the other code that wasnt doing anything. also, in your code you were inverting the positive values, so it was all coming out negative.

Code: Select all
#include "StompShield.h"

int output;

void setup() {
StompShield_init(); // setup the arduino for the shield
}

void loop() {
}

ISR(TIMER1_OVF_vect) {

// get ADC data
byte temp1 = ADCL; // you need to fetch the low byte first
byte temp2 = ADCH; // yes it needs to be done this way
int input = ((temp2 << 8) | temp1) + 0x8000; // make a signed 16b value

if (input < 0) { // if number is negative
output = 0 - input; // output = -input (adding takes less time than multiplying)
} // otherwise dont do anything for positive values

output = input - 0x4000; // shift everything down by 16k, so we now have -16k -> +16k range
output <<= 1; // fast way to multiply by 2 - shift everything to the left 1 bit.

// output data
OCR1AL = ((output + 0x8000) >> 8); // convert to unsigned and output high byte
OCR1BL = output; // output the low byte
}
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Stomp shield Octaver.

Postby Arduinoob » Mon Apr 28, 2014 10:20 am

Thanks very much for the reply! You helped me out a lot.
Arduinoob
 
Posts: 4
Joined: Tue Apr 15, 2014 6:46 am

Re: Stomp shield Octaver.

Postby digithree » Mon Apr 28, 2014 11:10 am

You made a small error there guest in your response. The lines
Code: Select all
if (input < 0) { // if number is negative
output = 0 - input; // output = -input (adding takes less time than multiplying)
} // otherwise dont do anything for positive values

should be
Code: Select all
if (input < 0) { // if number is negative
input = 0 - input; // output = -input (adding takes less time than multiplying)
} // otherwise dont do anything for positive values

otherwise the next line
Code: Select all
output = input - 0x4000;

makes the condition redundant if the input is less than zero
digithree
 
Posts: 1
Joined: Mon Apr 28, 2014 11:05 am

Re: Stomp shield Octaver.

Postby guest » Mon Apr 28, 2014 9:20 pm

good catch!
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Stomp shield Octaver.

Postby hello_kitty » Mon May 12, 2014 5:27 am

small mistake but very siginificant.
hello_kitty
 
Posts: 3
Joined: Mon May 12, 2014 4:16 am


Return to Stomp Shield

Who is online

Users browsing this forum: No registered users and 1 guest


cron