![]()
Lecture Topic:
<DT>![]()
DSP is a kind of data processing which operates on digitized signals.
2-D DSP Image processing I(X,Y)
3-D DSP Image Sequence processing I(X,Y,K)
4-D DSP Range Image Sequence processing I(X,Y,Z,K)
- Java support the playing of sound files
- These techniques extends to other Data Domains
- we can hear the results
- It is fun !
import java.awt.*;
import java.io.*;
import sun.audio.*;
import java.applet.*;
public class AudioFrame extends Frame {
private Panel readoutPanel = new Panel();
private AudioStream audioStream;
private AudioDataStream audioDataStream;
private byte ulawData[] = null;
private double doubleData[] = null;
AudioPlayer audioPlayer = AudioPlayer.player;
private String fileName;
private ObservableInt endPositionOfSamplesToGraph;
private ObservableInt startPositionOfSamplesToGraph;
private final double pi_2 = Math.PI * 2;
private final double pi = Math.PI;
private final double samplingRate = 8000.0;
private final double frequency = 440.0;
private Scrollbar horizontalScrollbar;
Menu m = new Menu("Audio Menu");
MenuItem openAu_mi = addItem("[o] Open Au");
MenuItem graph_mi = addItem("[u] ulaw graph ");
MenuItem graphSound_mi = addItem("[g] graph sound");
MenuItem decodeUlaw_mi = addItem("[d] decode ulaw ");
..... .....
public AudioFrame() {
// openAudioStream will set the fileName
// and audioStream variables.
openAudioStream();
// Init_menu requires that the fileName be set
// for the frame title.
init_menu();
endPositionOfSamplesToGraph =
new ObservableInt(audioStream.getLength());
startPositionOfSamplesToGraph =
new ObservableInt(0);
buildReadoutPanel();
}
public void openAudioStream() {
fileName = futil.openFile();
try {
audioStream = new AudioStream(new FileInputStream(fileName));
if ( audioStream.getLength() < 1 ) {
System.err.println("AudioFrame: Length negative");
return;
}
ulawData = new byte[audioStream.getLength()];
audioStream.read(ulawData, 0, audioStream.getLength()-1);
}
catch (IOException ioe)
{System.err.println(ioe);}
doubleData = Audio.decodeUlaw(ulawData);
play();
}
called ulaw.
public void play() {
audioPlayer.start(new AudioDataStream(new AudioData(ulawData)));
waitTillDone();
}
The graph of ulaw data is not meaningful !
so graph linear data ( ie decode ulaw first ! )
// Waveform display.
public void paint(Graphics g) {
doubleData = Audio.decodeUlaw(ulawData);
int limit = doubleData.length;
Dimension dim = this.size();
int height = dim.height;
int width = dim.width;
update();
// just plot first 100 points
// keep in mind that the origin is
// in the upper left corner
// and so y = height - y
// Are we having fun yet?
if (limit > width) limit = width;
int x = (width / horizontalScrollbar.getMaximum()) *
horizontalScrollbar.getValue();
int upper_limit = limit - horizontalScrollbar.getVisible();
for (int i = 0 ; i < upper_limit ; i++) {
g.drawLine(
i,
(int)(height -(doubleData[x+i] * height/4+height/2)),
i + 1,
(int)(height -(doubleData[x+i+1] * height/4+height/2)));
}
}
Last Update:
04/09/97