Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Main program provided here: public class HW4a { // add functions here public static double[] overdrive(double [] x, double clip) { double y[] = new

image text in transcribed

Main program provided here:

public class HW4a { // add functions here public static double[] overdrive(double [] x, double clip) { double y[] = new double[x.length]; for(int i = 0; i

public static void main(String [] args){ // usage: java HW4a

// add test code here double[] result = overdrive(data,3.5); StdOut.println("overdrive of data array with clip 3.5 is "); StdArrayIO.print(result); //result = echo(data,lag); StdOut.println("echo of data with lag length of 3 is "); StdArrayIO.print(result); } } }

Next implement another array processing function that will be used to provide an echo (also known as a reverb). This approach will average the current array value with a value from a fixed number of step in front of it. When applied to the audio signal, this will give an echoing sound. In HW4a.java, add a function with the signature public static double [] echo (double [] x, double [] lag)1 The array x is the original audio signal. At the beginning of the array, the echo would be from the previous note played. The lag array is used to pass that in. At the beginning of the function, declare a double array y and create it with the same length as x. This array will hold the results of the echo and will be returned from the function. Now create a for loop that iterates over every element of x. At index i if index i is less than lag.length then set y to the average of x and the lag, that is, y[i]-(x[i]+lag[i])/2.0; else we have used all of the lag, so x can refer back to itself. Set y to the average of x and:x from lag.length earlier in the array. That is. [1] (x[i] + x [1-1ag.length])/2.0; The array y is now filled. The lag array needs to be updated so that it can be used for the next note. Basically, the tail of x is copied into lag. The code also needs to handle the situation in which x is shorter than the lag (a very short note is being played and the echo spans multiple notes). The following code is an example of conducting the lag array update int shift - x.length - lag.length for(int i-0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions