/*
*
*
*
*
*/
package horcher.sound;
import horcher.Fehler;
import horcher.Main;
import horcher.maths2.ComplexD;
import horcher.maths2.NotComplexD;
import horcher.maths2.Signal;
import java.io.File;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
public class FileInput implements Input {
class WaveFilter extends FileFilter {
@Override
public boolean accept(final File f) {
if (f == null)
return false;
if (f.isDirectory())
return true;
return f.getName().toLowerCase().endsWith(".wav");
}
@Override
public String getDescription() {
return "Unkompremierte 4-Kanal PCM Wave Audiodatei ";
}
}
private File ort;
private final WaveFileInputStream[] in;
public final int N_KANALE;
public FileInput() throws Fehler, IOException {
final JFileChooser fc = new JFileChooser();
fc.setFileFilter(new WaveFilter());
fc
.setSelectedFile(new File(
"K:/Dokumente und Einstellungen/YAK/Eigene Dateien/Programieren/Java/JavaProjekte/Horcher/Windows Pop-up Blocked.wav"));
final int status = fc.showOpenDialog(null);
if (status == JFileChooser.APPROVE_OPTION){
this.ort = fc.getSelectedFile();
final WaveFileInputStream tmp = new WaveFileInputStream(this.ort, 0);
this.N_KANALE = tmp.kanalanzahl;
if (this.N_KANALE != Main.N_Kanale)
throw new Fehler("fKanalzahl");
this.in = new WaveFileInputStream[this.N_KANALE];
this.in[0] = tmp;
for (int i = 1; i < this.N_KANALE; i++)
this.in[i] = new WaveFileInputStream(this.ort, i);
}else{
this.N_KANALE = 0;
in=null;
}
}
public void close() throws Fehler, IOException {
for (int i = 1; i < this.in.length; i++)
this.in[i].close();
}
public String getSourceName() {
return this.ort.getName();
}
public Signal input(final int kanal, final long lange) throws Fehler,
IOException {
final Signal signal = new Signal(this.in[kanal].samplerate);
ComplexD tmp;
for (int i = 0; i < lange; i++) {
tmp = new NotComplexD(this.in[kanal].read());
signal.add(tmp);
}
return signal;
}
}