1

In essence the question I'm asking is how do I see a wav file's data when it causes clip to crash due to being a large file and then determine its amplitudes as the song plays on. Think of those oscillations in program a like winamp to visulaise music. in this case I need numeric values that form the sound wave.

I've done some mad research on stuff like sampling rates and even managed to find some code but it didn't help me in this task.

If someone where to be so kind as to provide a rough outline and some amount of code I would be grateful. Thanks

1 Answers1

2

This code is not tested but this is roughly what you should do :

File fileIn = new File("C:\\path\\to\\your\\file.wav");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(fileIn);
int size = audioInputStream.available();
byte[] b = new byte[size];
if (size == audioInputStream.read(b)) {
  // Do what you have to do
}
madgangmixers
  • 150
  • 1
  • 16
  • Hmm I've seen similar code somewhere however your code only seems to read 0s from my wav file... Interestingly when I print b.length I get 16 hence that might become useful. Thanks for providing me a great starting point. I appreciate it! – casparcedro Apr 14 '13 at 12:08
  • If there's silence in the beginning of the file, then a value of 0 is normal, did you read your file entirely ? – madgangmixers Apr 14 '13 at 12:13
  • I did. However, I believe this only reads 1 sample and a Wav file has 44100 samples per second? Alright here is some new code but I dunno what I'm doing sadly. File fileIn = new File("yolo1.wav"); AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(fileIn); int sampleSize = audioInputStream.getFormat().getSampleSizeInBits(); byte[] b = new byte[sampleSize]; long framelength = audioInputStream.getFrameLength(); int i = 0; for (i=0; i <= framelength; i++){ while (audioInputStream.read(b) != -1) { //Reads 1 sample System.out.println(i+":"+""+b[i]); – casparcedro Apr 14 '13 at 12:48
  • Ok. I see the sampleSize of the file is 16 bits, now the question is how do I read the file fully? Let me try the math, 44100 samples a second for a 5 minute 1 second file means 13274100 samples in total. Each has 16 bits correct? – casparcedro Apr 14 '13 at 13:05