# HG changeset patch # User kent # Date 1228802643 -32400 # Node ID 5c6db5d47717434fb65991a3fca2f9d803f627f6 first commit diff -r 000000000000 -r 5c6db5d47717 build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build.xml Tue Dec 09 15:04:03 2008 +0900 @@ -0,0 +1,52 @@ + + + show speech signal and spectrum. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r 5c6db5d47717 lib/jtransforms-2.0.jar Binary file lib/jtransforms-2.0.jar has changed diff -r 000000000000 -r 5c6db5d47717 src/AudioListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/AudioListener.java Tue Dec 09 15:04:03 2008 +0900 @@ -0,0 +1,126 @@ + +import javax.sound.sampled.*; +import java.lang.Runnable; +import java.lang.Math; +import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D; + +public class AudioListener implements Runnable { + private int frameLength; + private Plotter plotter; + private Plotter sprPlotter; + private AudioFormat format; + private boolean runnable=true; + private Thread thread; + private FloatFFT_1D fft; + private double[] window; + + public AudioListener(AudioFormat af, Plotter plotter, Plotter sprPlotter, int fps, boolean windowOn) { + assert af.getSampleRate()%fps==0; + this.frameLength = (int)af.getSampleRate()/fps; + this.plotter = plotter; + this.sprPlotter = sprPlotter; + this.format = af; + this.fft = new FloatFFT_1D(frameLength); + this.window = new double[frameLength]; + for (int i=0; i0; + + g.drawLine( (int)((i-1)*xstep), (int)prevValue, (int)((i)*xstep), (int)value); + } + } + /* + * Heigh - (value-minV)/(maxV-minV)*Height + * = (Height+/ + */ + + public void setData(byte[] data) { + this.data = data; + } +} + + + + diff -r 000000000000 -r 5c6db5d47717 src/SpectrumViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SpectrumViewer.java Tue Dec 09 15:04:03 2008 +0900 @@ -0,0 +1,113 @@ +import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.awt.event.WindowListener; +import java.awt.event.WindowEvent; +import javax.sound.sampled.*; + +public class SpectrumViewer extends Frame { + private Plotter plotter; + private Plotter sprPlotter; + private Container controler; + private AudioListener audioListener; + private Button startButton; + private Button stopButton; + + public static void main(String[] args) throws Exception{ + SpectrumViewer mw = new SpectrumViewer(); + mw.setVisible(true); + } + + public SpectrumViewer() { + super("mainwindow"); + setSize(400, 600); + //setLayout(new BorderLayout()); + setLayout(new BorderLayout()); + + /* startButton */ + startButton = new Button("Start"); + startButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + SpectrumViewer.this.startAudioListener(); + } + }); + /* stopButton */ + stopButton = new Button("Stop"); + stopButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + SpectrumViewer.this.stopAudioListener(); + } + }); + //stopButton.setVisible(false); + + /* control panel */ + controler = new Container(); + controler.setLayout(new BorderLayout()); + controler.add(startButton, BorderLayout.EAST); + controler.add(stopButton, BorderLayout.WEST); + + plotter = new Plotter(-128, 127); + sprPlotter = new Plotter(0, 127); + Container tmp = new Container(); + tmp.setLayout(new GridLayout(2,1)); + tmp.add(plotter); + tmp.add(sprPlotter); + + /* Frame set */ + //add(plotter, BorderLayout.SOUTH); + //add(sprPlotter, BorderLayout.CENTER); + //add(controler, BorderLayout.NORTH); + //add(plotter); + //add(sprPlotter); + add(tmp, BorderLayout.CENTER); + add(controler, BorderLayout.NORTH); + addWindowListener(new WindowListener() { + public void windowActivated(WindowEvent e){ } + public void windowClosed(WindowEvent e){ } + public void windowDeactivated(WindowEvent e){ } + public void windowDeiconified(WindowEvent e){ } + public void windowIconified(WindowEvent e){ } + public void windowOpened(WindowEvent e){ } + public void windowClosing(WindowEvent e){ + System.out.println("exit"); + System.exit(0); + } + }); + } + + public void startAudioListener() { + AudioFormat format; + //format = new AudioFormat(8000, 8, 1, true, true); + format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, + 16000, 8, 1, 1, 16000, true); + audioListener = new AudioListener(format, plotter, sprPlotter, 50,true); + audioListener.start(); + System.out.println("start button was clicked"); + System.out.println("frame rate: "+format.getFrameRate()); + System.out.println("frame size: "+format.getFrameSize()); + //System.out.println("property: "+format.getProperty()); + System.out.println("sample rate: "+format.getSampleRate()); + System.out.println("sample bits: "+format.getSampleSizeInBits()); + System.out.println("big endian: "+format.isBigEndian()); + //controler.remove(startButton); + //controler.add(stopButton); + } + public void stopAudioListener() { + audioListener.stop(); + audioListener=null; + System.out.println("stop button was clicked"); + //stopButton.setVisible(false); + //controler.remove(stopButton); + //controler.add(startButton); + } + /* + * AudioFormat( encoding, sampleRate, sampleSizeInBits, + * channels, frameSize, frameRate, bigEndian) + * sampleRate: 1秒間の1チャネル毎のサンプリング周波数 8000, 44100 + * sampleSizeInBits: 1サンプルのbit数 8, 16 + * channels: the number of channels 1(mono) or 2(stereo) + * frameSize: + * + */ + +}