Feeding delayed output back into input.

Re: Feeding delayed output back into input.

Postby ArcAttack » Sat Nov 17, 2012 4:47 pm

Yeah
void loop() {
if (Serial.available() > 0) {
Serial.println(88);
Serial.println(serial_out);
}}


Still no luck :-/ Even tried different baud rates.


Code: Select all

#include <mult16x16.h>
#include <mult16x8.h>
#include <mult32x16.h>

/*
variable_delay.pde
guest openmusiclabs 6.22.11
this program takes input from the left channel, and delays it
by a variable amount, set by the MOD0 knob.  it then presents
this delayed data on the left channel, with the non-delayed
data coming out of the right channel.
*/

// setup codec parameters
// must be done before #includes
// see readme file in libraries folder for explanations
#define SAMPLE_RATE 44 // 44.1kHz sample rate
#define ADCS 2 // only 1 ADC used here -> MOD0
#define LINVOL 22
//#define RHPVOL 127
//#define LHPVOL 127
// include necessary libraries
#include <Wire.h>
#include <SPI.h>
#include <AudioCodec.h>

// create data variables for audio transfer
// even though the function is mono, the codec requires stereo data
int left_in = 0; // in from codec (LINE_IN)
int right_in = 0;
int left_out = 0; // out to codec (HP_OUT)
int right_out = 0;

// create variable for ADC result
// it only has positive values -> unsigned
unsigned int mod0_value =0;
unsigned int mod1_value =0;
//int vol = 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 = 0; // end of buffer position

void setup() {
  // call this last if you are setting up other things
 
  Serial.begin(1200);
  Serial.println(88);
  AudioCodec_init(); // setup codec and microcontroller registers
}

volatile unsigned int serial_out = 0;

void loop() {
  if (Serial.available() > 0) {
    Serial.println(88);
    Serial.println(serial_out);
   }}



// timer1 interrupt routine - all data processed here
ISR(TIMER1_COMPA_vect){//, ISR_NAKED) { // dont store any registers
  serial_out = mod0_value;
  // &'s are necessary on data_in variables
  AudioCodec_data(&left_in, &right_in, left_out, right_out);
  unsigned int vol;
  unsigned int off = 1;
  // pass left input to right output
  right_out = left_out;
 
     
  //Serial.println(sensorValue);
  //fetch data from buffer and put it into output register
  left_out = delaymem[location];
  // put new data in same location for maximal delay time

  MultiSU16X16toH16(vol, left_out, mod1_value);
  delaymem[location++] = (left_in + (vol))*off; // post increment location to go to next memory location
  // check if location has gotten bigger than buffer size
  //left_in = left_out;
  if (location >= boundary) {
    location = 0; // reset location
  }

             
  // & is required before adc variable
  AudioCodec_ADC(&mod0_value,&mod1_value);
 
  if (mod1_value < 60000) {
         off = 1;
          }
          else
          {
          off = 0;
          }
  // scale ADC value to match buffer size
  // note the use of the fancy fast math function
  // you can read about these in the readme file
  unsigned int scale = SIZE;
  unsigned int newmod;
 
  if (mod0_value > 30000)
      {
        if (mod0_value < 60000)
        {
      newmod = 11000;
        }
        else
        {
      newmod = 8250;
        } 
    }
  if (mod0_value < 30000)
    {
     if (mod0_value > 10000)
         {
      newmod = 16500;//low?
         }
         else
         {
      newmod = 22000;}
     
    }
     
 // if (mod0_value < 1)
   //  {newmod = 44000;}
  MultiU16X16toH16(boundary, newmod, scale);

  //reti(); // dont forget to return from the interrupt
}
ArcAttack
 
Posts: 9
Joined: Fri Nov 16, 2012 4:55 pm

Re: Feeding delayed output back into input.

Postby guest » Sat Nov 17, 2012 5:33 pm

i just ran your code, and it worked. i had to comment out the #include <mult>'s a the top, and im not sure why. i think it has to do with the library structure on my computer.

im using an Duelimanove and arduino-00022. i will try it with arduino1.0, and see if i can round up an UNO to try it with as well. what platforms are you using?
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Feeding delayed output back into input.

Postby guest » Sat Nov 17, 2012 5:44 pm

ok, so it doesnt work with arduino1.0. i will figure out why. i never transitioned to 1.0 because it was more bloated and buggy than 0022.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Feeding delayed output back into input.

Postby guest » Sat Nov 17, 2012 6:06 pm

the problem is somehwere in serial.available(). if you get rid of the serial.available() line and just send the data out, then it should work. the arduino1.0 serial code uses interrupts, and blocks the codecshield, so the audio quality drops. i will look into why serial.available() messes with it. there are work arounds for the audio quality if you need that as a permanent feature, but if youre just using it for debugging, then its probably not worth it.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Feeding delayed output back into input.

Postby guest » Sat Nov 17, 2012 6:24 pm

very strange. i put a serial.read() command into the loop, and then it worked. i think serial.avaialble() doesnt do anything unless there is something setup to read the data bytes. serial.available() is a function which returns the number of bytes waiting on the incoming receive buffer. so perhaps the receive buffer isnt bothered with if there isnt anything to read the data, and therefore it always returns 0.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Feeding delayed output back into input.

Postby ArcAttack » Sun Nov 18, 2012 2:13 am

well, after futzing about it for a while, i got the codec shield working with the mega, and with your tweaks the usb serial monitor works fine. Thanks again for all your help!


P.S.

do you know a guy named Chris Hatfield?
ArcAttack
 
Posts: 9
Joined: Fri Nov 16, 2012 4:55 pm

Re: Feeding delayed output back into input.

Postby guest » Sun Nov 18, 2012 11:46 am

wow, congrats on getting it working with the mega. was there anything extra you had to do, that isnt documented in the mega thread? it would be good info for others.

i dont think i know chris hatfield.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Feeding delayed output back into input.

Postby ArcAttack » Sun Nov 18, 2012 2:12 pm

Yeah, there was a little. I'm taking photos and documenting it to explain how I did it. I was planning on making a new thread to explain what we did.

Thanks again for all your help!

wow, congrats on getting it working with the mega. was there anything extra you had to do, that isnt documented in the mega thread? it would be good info for others.

i dont think i know chris hatfield.
ArcAttack
 
Posts: 9
Joined: Fri Nov 16, 2012 4:55 pm

Re: Feeding delayed output back into input.

Postby ArcAttack » Sun Nov 18, 2012 4:29 pm

Hey guest! do you think we could chat on IM. I wanna make sure that my arduino mega fix makes sense and had some questions about the audiocodec.h

guest wrote:wow, congrats on getting it working with the mega. was there anything extra you had to do, that isnt documented in the mega thread? it would be good info for others.

i dont think i know chris hatfield.
ArcAttack
 
Posts: 9
Joined: Fri Nov 16, 2012 4:55 pm

Re: Feeding delayed output back into input.

Postby guest » Mon Nov 19, 2012 10:25 am

it doesnt seem like our forums have a pm system. if you want, i can set aside a time where we both can post at the same time to the forums. the delay should be pretty small.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

PreviousNext

Return to Audio Codec Shield

Who is online

Users browsing this forum: No registered users and 1 guest


cron