Help with audio delay program (shut up gun?)

Hello!

I'll go right out and say I have very very little experience with coding. A friend of mine did a good majority of the work in the program I'll link below, and I basically added a few things here and there and learned a bit about how it works.

IntervalTimer myTimer;     // Intervaltimer is a library that configures your hardware timers easily. Here, we create an "object" called "myTimer"


#define sample_Hz 16000   // To keep things organized, we use a compiler definition "sample_Hz". That is, every instance of "sample_Hz" will be replaced with 16000 upon compile. 
                          // sample_Hz is your sample rate. 
                     
#define bit_depth 12      // the ADC bit depth. 12 bits = 2^12 = 4096 levels

uint8_t buffer[sample_Hz] = {0}; // Create an array of size sample_Hz, and fill it with zeros
uint32_t arrayIndex, replayIndex; // Create some variables, unsigned, 32 bit. arrayIndex will hold your current "write" address, replayIndex will hold your "read" address
const int sensorPin = A1;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
int replay_delay = 0; //variable for the "delay" process

// Setup is an arduino function that runs only once

void setup(void) {
  float sample_period = 1.0/(float)sample_Hz; // Convert Hz to period, because timers require units of seconds. Typecast to (float) so the compiler knows sample_Hz should be treated as a float
    
  analogReadResolution(bit_depth); // Set analogRead resolution
  analogReadAveraging(1); // Set analogRead averaging to 1, (that is, use only 1 sample at a time). Noisy, but fast.
  
  myTimer.begin(sample, sample_period);  // call the myTimer object's begin(function, float period) function, to start your interrupt timer.
}





void loop(void) {
  //do nothing in your main loop. If you wanted to adjust delay, run an lcd screen or something, put that stuff here
    sensorValue = analogRead(sensorPin);
    replay_delay = map(sensorValue, 0, 4096, 6400, 12800);    
}





// Sample is called every sample_period microseconds by 

void sample(void) { // function that expects no arguments, and returns nothing. called by myTimer

  arrayIndex ++; // Incriment arrayIndex by one, otherwise we go nowhere
  
  if(arrayIndex >= sample_Hz){ // if arrayIndex is larger than sample_Hz (that is, you're at the end of your array)...
    arrayIndex = 0; // go back to the start. this makes a circular buffer.
  };
  
  buffer[arrayIndex] = analogRead(A0); // write an analogRead(pin) sample to your array at arrayIndex
  
  int replayIndex = arrayIndex + replay_delay; // fill replayIndex with arrayIndex + the amount of samples you wish to look at in the future
  
  if(replayIndex >= sample_Hz){ // make sure replayIndex isn't out of bounds either
    replayIndex = replayIndex - sample_Hz; 
  };
  
  analogWrite(A14, buffer[replayIndex]); // write your stored sample to the DAC pin
}

Right! So, I'm using a Teensy 3.1. From my understanding, and what my friend has described to me the program above takes a sample from an analog input, and puts it in a buffer array for a delay, and then spits it back out again through the DAC. Think of two sticks spinning in a circle, with one drawing and the other reading. There is also a sensor input (a potentiometer) to adjust the delay of the output, which uses a map function to change the value of the sensor to something more proper in terms of actual delay.

However, in practice, the program does not seem to work. I have an electret microphone with an amplifier hooked up to the analog input pin, with a simple op amplifier to help boost the voltage up a bit. When I hook the output of the DAC pin to my stereo amplifier, nothing is output. I've also read the the output with my oscilloscope, and again, still nothing.

I have no clue how to go about debugging this program, and I'd appreciate anyone's help very very very much. If you could explain what's wrong, why it's wrong and how I could fix it...

Thank you so much!

I have no clue how to go about debugging this program

Does that code even compile? I can't see how that is possible, given this:

IntervalTimer myTimer;     // Intervaltimer is a library that configures your hardware timers easily. Here, we create an "object" called "myTimer"

But we do this without bothering to #include anything. Or provide a link to the library.

#define sample_Hz 16000   // To keep things organized, we use a compiler definition "sample_Hz". That is, every instance of "sample_Hz" will be replaced with 16000 upon compile.

To keep things organized, feel free to NOT string comments out so damned far. There should not be a need to scroll back and forth to read your post or your code.