[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

CREATING A JAVA PROGRAM TO VIEW WAVE FILES

Asked by peaches4416 in Multimedia Programming, New to Java Programming

Tags: java, file, wav, wave

I am in a Data structures class and am working on a project which requires the information below.
PROBLEM;
Develop a working Java program that opens DSCLIP.WAV file, and displays the file header content, searches the data area for the minimum (most negative) and maximum (most positive) samples, and then displays the results. The hexadecimal address of the sample within the WAV file must also be displayed, as in this example (not actual) result:

The maximum value 7F hex is located at address 1E7A hex within the file.

So far i only have come up with the following code; PLEASE HELP!!!! My course book is really bad and does me no good. I know there are experts here that can help please help me.

CODE;


import java.io.File;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;




/* Play a *.wav or *.au file */

public class test
{
/*Play a *.wav or *.au file
@param args args[0] on command line is name of file to play
*/
static int frameSample;
static int timeofFrame;
static int N;
static int runTimes;
static int bps;
static int channels;
static double times;
static int bufSize;
static int frameSize;
static int frameRate;
static long length;

public static void main(String[] args)
{
try
{
AudioInputStream ais = AudioSystem.getAudioInputStream(new File(args[0]));
AudioInputStream a;

File file = new File(args[0]); /*To get the file size*/
length = file.length();
System.out.println("File size : " + length);

AudioFormat af = ais.getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, af);

if (!AudioSystem.isLineSupported(info))
{
System.out.println("unsupported line");
System.exit(0);
}

frameRate = (int)af.getFrameRate();
System.out.println("Frame Rate: " + frameRate);

frameSize = af.getFrameSize();
System.out.println("Frame Size: " + frameSize);

bufSize = frameRate * frameSize / 10;
System.out.println("Buffer Size: " + bufSize);

channels = af.getChannels();
System.out.println("Channels : " + channels);

bps = af.getSampleSizeInBits();
System.out.println("Bits per sample : " + bps);

times = (double)(length / (frameRate * channels * bps / 8));
System.out.println("Duration of the songs : " + times +" seconds");

byte[] data2 = new byte[bufSize];
int bytesRead2;
timeofFrame = 20; //20ms
frameSample = (timeofFrame * frameRate) / 1000;
N = frameSample;
runTimes = (int) (times * 1000) / 20;


byte[] data = new byte[bufSize];
int bytesRead;
/*SourceDataLine line = (SourceDataLine)
AudioSystem.getLine(info);
line.open(af, bufSize);
line.start();

while ((bytesRead = ais.read(data, 0, data.length)) != -1)
line.write(data, 0, bytesRead);

line.drain();
line.stop();

long time = line.getMicrosecondPosition();
System.out.println("time by playing " + time);
line.close();*/


int[][] freq = new int[runTimes][N];

int temp=0;


/* Want to read the data of the wav and do the DFT later, but i don't know how to read data and save it correctly?"
for (int i = 0; i < runTimes; i++)
//for(int j=0;j<N;j++)
{
a.read(freq[i], j, N);
j = N;
}


*/

FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;


fis = new FileInputStream(file);

// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);

// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {

// this statement reads the line from the file and print it to the console.
for (int i = 0; i < 1; i++)
for(int j=0;j<N;j++)
{
freq[i][j] = (int)dis.readByte();

}
}
System.out.println(freq[0][0]);

// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();

}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
/*for (int i = 0; i < 10; i++)
//for(int j=0;j<N;j++)
{
freq[i] = a.read(file);
//j = N;
}
System.out.println(freq[0]);
*/

catch (Exception e)
{
System.out.println(e.toString());
}
System.exit(0);
}
}
[+][-]10/08/07 02:09 AM, ID: 20032822Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Multimedia Programming, New to Java Programming
Tags: java, file, wav, wave
Sign Up Now!
Solution Provided By: Merete
Participating Experts: 2
Solution Grade: B
 
[+][-]10/08/07 05:09 AM, ID: 20033398Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 / EE_QW_1_20070628