diff src/SpectrumViewer.java @ 0:5c6db5d47717 default tip

first commit
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Tue, 09 Dec 2008 15:04:03 +0900
parents
children
line wrap: on
line diff
--- /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: 
+	 *
+	 */
+
+}