/*
 * This program is intended to demonstrate reading of .wav files;
 * the output is an ascii list of the numeric samples.

 * This may only work with the "basic" wav format, to which there are extensions.

 * Usage: reader foo.wav
 */

import java.lang.*;
import java.io.*;
import javax.sound.sampled.*;

class reader {

    public static void main(String[] args) {
		if (args.length == 0) {
			System.err.println("usage: reader foo.wav");
			return;
		}
		String infilename = args[0];
		// check that it has .wav extension
		if (! (infilename.toLowerCase().endsWith(".wav"))) {
			System.err.println("must use a .wav file!");
			return;
		}
		FileInputStream fis;
		try {
			fis = new FileInputStream(infilename);
		} catch (IOException ioe) {
			System.err.println("file not found??");
			return;
		}

		WavReader wr = new WavReader(fis);

		for (int i=0; i< wr.getNumSamples(); i++) {
			int sample;
			//int valuesize = wr.getSampleSize()/wr.getChannels();
			try {
				sample = wr.readValue();
			} catch (IOException ioe) {
				System.err.println("read failure at sample # " + i);
				return;
			}
			System.out.println(sample);
		}

	}


}
