karplus strong?

karplus strong?

Postby loss1234 » Tue Apr 03, 2012 8:01 pm

does anyone know if this might be possible with the audio codec shield on arduino?

i played around with a really dirty KS sketch with an 8 bit DAC and while it did sound metallic, it didnt sound very HI-FI...the shield could take care of the fidelity but I am not sure if there is enough buffer to do it or not


but it might be possible!
loss1234
 
Posts: 10
Joined: Sun Apr 01, 2012 1:39 am

Re: karplus strong?

Postby guest » Tue Apr 03, 2012 8:41 pm

a friend of mine introduced me to karplus-strong on sunday
they look really cool
and are not computationally expensive
although i will have to see how much ram they require
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: karplus strong?

Postby guest » Tue Apr 03, 2012 9:32 pm

this stuff is pretty amazing
it basically takes no time to process

Code: Select all
/*
karplus.pde
guest openmusiclabs 4.3.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;
int last_value = 0x0000;
int curr_value = 0x0000;
unsigned int decay = 0x0000;
#define DECAY 65000
unsigned int mod0_value =0;

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

void setup() {
 
  for (int i = 0; i < SIZE; i++) {
    delaymem[i] = random(65535);
  }
 
  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) { // dont store any registers

  // &'s are necessary on data_in variables
  AudioCodec_data(&left_in, &right_in, left_out, right_out);
 
   // & is required before adc variable
  AudioCodec_ADC(&mod0_value);
 
  if (decay++ < DECAY) {
 
    delaymem[location++] = left_out;
    // check if location has gotten bigger than buffer size
    if (location >= boundary) {
      location = 0; // reset location
    }
    curr_value = delaymem[location];
    left_out = (last_value>>1) + (curr_value>>1);
    last_value = curr_value;
    }
  else {
    for (int i = 0; i < SIZE; i++) {
      delaymem[i] = random(65535);
    }
    decay = 0;
   
    unsigned int scale = SIZE;
    MultiU16X16toH16(boundary, mod0_value, scale);
  }
  // dont forget to return from interrupt
  reti();
}
Last edited by guest on Tue Apr 03, 2012 10:10 pm, edited 2 times in total.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: karplus strong?

Postby guest » Tue Apr 03, 2012 9:37 pm

oh yeah
DECAY sets the note repeat time
and MOD0 sets the note frequency

it is a tad metallic
but i think starting with a different lookup table
would cure that problem
i have a lookup table generator for Pure Data
thats linked off the mixtape_alpha wiki page
a bandpass filtered noise source would be good
this could be stored in flash
and then reloaded to create each note

but it is still monophonic
and the ram limits this
going down to 22k
and lmiting the lowest note to 100hz
could give 4 note polyphony
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: karplus strong?

Postby loss1234 » Thu Apr 05, 2012 6:39 am

thanks for this!!!
trying it out right now
loss1234
 
Posts: 10
Joined: Sun Apr 01, 2012 1:39 am

Re: karplus strong?

Postby loss1234 » Thu Apr 05, 2012 6:46 am

it sounds great!
loss1234
 
Posts: 10
Joined: Sun Apr 01, 2012 1:39 am

Re: karplus strong?

Postby JLS » Mon Aug 27, 2012 5:09 am

Very interesting for me.

Many thanks
JLS
 
Posts: 2
Joined: Mon Aug 27, 2012 5:08 am

Re: karplus strong?

Postby donal » Fri Aug 31, 2012 7:40 am

I changed :
#define DECAY 10000
unsigned int mod0_value =0;

// create a delay buffer in memory
#define SIZE 10 /

Sounds lovely! Nice percussive stuff.
donal
 
Posts: 1
Joined: Fri Aug 31, 2012 7:36 am

Re: karplus strong?

Postby guest » Fri Aug 31, 2012 12:27 pm

its good to hear it works well with small SIZE
that means you can setup a bunch of buffers
and have some polyphony going
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