Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello!! I just need help on this question. Here is my code so far but it is not

ID: 3722277 • Letter: H

Question

Hello!! I just need help on this question. Here is my code so far but it is not fully working. Thank you in advance!

void add_echo(int array[], int length, int rate, double d){

int p = rate*d;
int arrayTwo[length];
for (int i = 0; i < length; i++){
arrayTwo[i]=array[i]+array[i-p];
}
for (int i = 0; i < length; i++){   
array[i]=arrayTwo[i];
}

Question 2 Write a function add_echo that adds an echo to the samples array. Your function should take four parameters: the samples array, the size of the samples array, the sampling rate (as an int), and the delay d in seconds (as a double), in this order The function will not return any values. When testing the audio files provided, use the sample rate variable initialized in main. How to add an echo: For each sample in the samples array, add the value from d seconds ago. If there is not a sample at exactly d seconds ago, add the value from the sample at the closest sampling time greater than d. Examples: Let the sampling rate be 10 and the delay be 0.25 seconds. Since we have 10 samples a second, we have one sample every 1/10 seconds (0.1 seconds) //time (in seconds) 234 int samples1, 4,2, 5, 10 Let's say we are currently trying to add an echo with a delay d-0.25 seconds to just samples[4]. samples [4]is taken at t-0.4, and the desired delay is 0.25 seconds, so we want to get the value at: time .4-8.25 = .15 seconds However, there is no sample at t 15, so we add the value from the closest sampling time after t . 15, which is t 2 at samples [2] in this case. = / / time = 01 .2 .34

Explanation / Answer

Given below is the modified code. You will need #include <math.h> if its C program, or #include <cmath> if its C++. Hope it helps.

void add_echo(int array[], int length, int rate, double d){

double interval = 1.0 / rate; // time interval between samples  
int index;
double t1, t2;

//start from the last entry
for (int i = lenght-1; i > 0; i--){
t1 = i * interval;
t2 = t1 - d;
if(t2 > 0){
index = ceil( t2 / interval); //calculate the index for the corresponding time t2
array[i]=array[i]+array[index];
}   
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote