Pages: [1]   Go Down
Author Topic: Help with Ardcore Ring Modulator code  (Read 1759 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey,

I'm working on a fairly simple bit of arduino code for my ardcore eurorack module (for those of you who don't know the module I'm talking about http://snazzyfx.com/ardcore.html with the manual here at the top of the page http://snazzyfx.com/instruction.html ) but I can't seem to get the arduino to function how I want it to.

I'm pretty new to arduino and have minimal background in C/C++. Thankfully there are a few example files and premade sketches that come with an ardcore so I've been reverse engineering those patches and trying to create one myself.

My sketch is pretty simple but I can't get it to work properly. My sketch generates a sine wave and multiplies it by the audio input to achieve a ring modulate sound. For some reason I can't get this to work... I'm probably overlooking something simple, some one help please :x


* bbArdcoreRingMod.ino (1.44 KB - downloaded 9 times.)
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think that reading a single input sample and multiplying by a bunch of different sine wave samples will get what you want.  Don't you have to read one input sample for each output sample?

Here is the existing sketch if anyone else wants to help:
Code:
//Brandon Bell
//Ardcore Ring Modulator
//8/10/12

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#ifndef M_PI
#define M_PI (3.141592654)
#endif

const int digPin[2] = {3, 4};
const int pinOffset = 5;   
int digState[2] = {HIGH, LOW};

int input;
//int samp;
int zoutput;

void setup()
{
 // Serial.begin(9600);
 // pinMode(clkIn, INPUT);
 
  for (int i=0; i<2; i++) {
    pinMode(digPin[i], OUTPUT);
    digitalWrite(digPin[i], digState[i]);
  }
 
  for (int i=0; i<8; i++) {
    pinMode(pinOffset+i, OUTPUT);
    digitalWrite(pinOffset+i, LOW);
  }
 // attachInterrupt(0, isr, RISING);
}

void loop () {
 
        int i,nsamps;
double samp;
        double samp2;
double twopi = 2.0 * M_PI;
double angleincr;
        int input = analogRead(2);

nsamps = analogRead(3)*4;
        angleincr = twopi / nsamps;
for(i=0;i < nsamps; i++){
    samp = sin(angleincr *i);
            samp2 = ((unsigned char)((samp*127.5)+127.5));
           
            zoutput = (input * samp2);
           
            dacOutput(zoutput);
  }

}

void dacOutput(int v)
{
  int tmpVal = v;
  for (int i=0; i<8; i++) {
    digitalWrite(pinOffset + i, tmpVal & 1);
    tmpVal = tmpVal >> 1;
  }
}

/*
void dacOutput(byte v)
{
  PORTB = (PORTB & B11100000) | (v >> 3);
  PORTD = (PORTD & B00011111) | ((v & B00000111) << 5);
}
*/
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2565
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The way how sketch written ,  float math and slow analogRead you can't get reading faster than 4 ksps, probably much lower, which imply 2 kHz upper limit for sound. Look here for basics of audio processing on 8-bits microcontroller:
http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm alright. I was just following examples that came with the module to see how they call up the different ports. I'll have to work on optimizing it more once I get it working.

My sketch is definitely a bit of a Frankenstein sketch but I don't quite understand why it wouldn't work. I'll keep at it and post something when I get it working.

Thanks for the help
Logged

Pages: [1]   Go Up
Jump to: