comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:5c6db5d47717
1 import java.awt.*;
2 import java.awt.event.ActionListener;
3 import java.awt.event.ActionEvent;
4 import java.awt.event.WindowListener;
5 import java.awt.event.WindowEvent;
6 import javax.sound.sampled.*;
7
8 public class SpectrumViewer extends Frame {
9 private Plotter plotter;
10 private Plotter sprPlotter;
11 private Container controler;
12 private AudioListener audioListener;
13 private Button startButton;
14 private Button stopButton;
15
16 public static void main(String[] args) throws Exception{
17 SpectrumViewer mw = new SpectrumViewer();
18 mw.setVisible(true);
19 }
20
21 public SpectrumViewer() {
22 super("mainwindow");
23 setSize(400, 600);
24 //setLayout(new BorderLayout());
25 setLayout(new BorderLayout());
26
27 /* startButton */
28 startButton = new Button("Start");
29 startButton.addActionListener(new ActionListener() {
30 public void actionPerformed(ActionEvent e) {
31 SpectrumViewer.this.startAudioListener();
32 }
33 });
34 /* stopButton */
35 stopButton = new Button("Stop");
36 stopButton.addActionListener(new ActionListener() {
37 public void actionPerformed(ActionEvent e) {
38 SpectrumViewer.this.stopAudioListener();
39 }
40 });
41 //stopButton.setVisible(false);
42
43 /* control panel */
44 controler = new Container();
45 controler.setLayout(new BorderLayout());
46 controler.add(startButton, BorderLayout.EAST);
47 controler.add(stopButton, BorderLayout.WEST);
48
49 plotter = new Plotter(-128, 127);
50 sprPlotter = new Plotter(0, 127);
51 Container tmp = new Container();
52 tmp.setLayout(new GridLayout(2,1));
53 tmp.add(plotter);
54 tmp.add(sprPlotter);
55
56 /* Frame set */
57 //add(plotter, BorderLayout.SOUTH);
58 //add(sprPlotter, BorderLayout.CENTER);
59 //add(controler, BorderLayout.NORTH);
60 //add(plotter);
61 //add(sprPlotter);
62 add(tmp, BorderLayout.CENTER);
63 add(controler, BorderLayout.NORTH);
64 addWindowListener(new WindowListener() {
65 public void windowActivated(WindowEvent e){ }
66 public void windowClosed(WindowEvent e){ }
67 public void windowDeactivated(WindowEvent e){ }
68 public void windowDeiconified(WindowEvent e){ }
69 public void windowIconified(WindowEvent e){ }
70 public void windowOpened(WindowEvent e){ }
71 public void windowClosing(WindowEvent e){
72 System.out.println("exit");
73 System.exit(0);
74 }
75 });
76 }
77
78 public void startAudioListener() {
79 AudioFormat format;
80 //format = new AudioFormat(8000, 8, 1, true, true);
81 format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
82 16000, 8, 1, 1, 16000, true);
83 audioListener = new AudioListener(format, plotter, sprPlotter, 50,true);
84 audioListener.start();
85 System.out.println("start button was clicked");
86 System.out.println("frame rate: "+format.getFrameRate());
87 System.out.println("frame size: "+format.getFrameSize());
88 //System.out.println("property: "+format.getProperty());
89 System.out.println("sample rate: "+format.getSampleRate());
90 System.out.println("sample bits: "+format.getSampleSizeInBits());
91 System.out.println("big endian: "+format.isBigEndian());
92 //controler.remove(startButton);
93 //controler.add(stopButton);
94 }
95 public void stopAudioListener() {
96 audioListener.stop();
97 audioListener=null;
98 System.out.println("stop button was clicked");
99 //stopButton.setVisible(false);
100 //controler.remove(stopButton);
101 //controler.add(startButton);
102 }
103 /*
104 * AudioFormat( encoding, sampleRate, sampleSizeInBits,
105 * channels, frameSize, frameRate, bigEndian)
106 * sampleRate: 1秒間の1チャネル毎のサンプリング周波数 8000, 44100
107 * sampleSizeInBits: 1サンプルのbit数 8, 16
108 * channels: the number of channels 1(mono) or 2(stereo)
109 * frameSize:
110 *
111 */
112
113 }