Answered step by step
Verified Expert Solution
Question
1 Approved Answer
FIX ERROR IN CODE /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package waveedit;
FIX ERROR IN CODE
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package waveedit;
import java.io.*;
import javax.swing.*;
/**
*
* @author tbecker
*/
public final class WaveTools {
//main reading function stores file in my_wav
//and populates all the internal variables
public WaveTools(){
try
{
File inWav = select_wave();
// Open the wav file specified as the first argument
System.out.println("Attempting to read file: " + inWav);
WavFile wavFile = WavFile.openWavFile(inWav);
// Display information about the wav file
wavFile.display();
// Get the number of audio channels in the wav file
sample_rate = (int)wavFile.getSampleRate();
bit_depth = wavFile.getValidBits();
wav_name = inWav.getAbsolutePath();
// Create a buffer of 100 frames
my_wav = new double[wavFile.getNumChannels()][(int)wavFile.getNumFrames()];
//store a a double[][] 2D real-valued array
wavFile.close();
}
catch (IOException e)
{
System.err.println(e);
} catch (WavFileException e) {
System.err.println(e);
}
}
//graphical dialog box that allows user to pick the wav file
public File select_wave(){
File selected = new File("");
try{
JFileChooser chooser = new JFileChooser();
selected = chooser.getSelectedFile();
}
catch (Exception e){
System.err.println(e);
}
return selected;
}
//finds the largest absolute value in the my_wav array
//and then scales (multiplies every element in the array)
//by the inverse
public void normalize(){
//start DSP code here----------------------------------------------------------------
//find the min and maximum double values...
for (double[] my_wav1 : my_wav) {
for(int j = 0; j < my_wav[0].length; j++){
//FIND THE LARGEST PEAK
}
}
//scale the result to get the normalized version
for (double[] my_wav1 : my_wav) {
for(int j = 0; j < my_wav[0].length; j++){
//MULTIPLY THE MAKEUP GAIN
}
}
//end DSP code here----------------------------------------------------------------
}
//reverse the contents of the my_wav array
public void reverse(){
//CODE TO REVERSE ARRAY HERE...
}
//finalizes processes by writing an output wav audio file
public void write_wave(){
try{
// Create a wav file with the name specified as the first argument
int end_pos = wav_name.indexOf(".wav");
String new_wav_name = wav_name.substring(0,end_pos) + "-out.wav";
WavFile wavFile = WavFile.newWavFile(new File(new_wav_name), my_wav.length,
my_wav[0].length, bit_depth, sample_rate);
// Write the buffer
wavFile.writeFrames(my_wav, my_wav[0].length);
// Close the wavFile
wavFile.close();
}
catch (IOException e){
System.err.println(e);
} catch (WavFileException e) {
System.err.println(e);
}
}
//sample rate is the time resolution of the wave file
//a higher sample rate sounds more realistic
private int sample_rate;
//bit depth is the size of the nubers used to store the
//amplitude, thus affecting amplitude resolution and
//in turn dynamics. More bits sounds better
private int bit_depth;
//String used to find, load, and read into the
//my_wav array, also this name is appended with -out
//when the wave_write function is called
private String wav_name;
//internal 2D array used to store the wav file selected from
//the graphical chooser when the WaveTools constructor is called
private double[][] my_wav;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started