CS411X - Lecture 4

homeContentsIndexPrevNext

Lecture Topic:

<DT>
 


Digitization:

Quantization:

In Digit Signal Processing we have broad categories. Generally by dimension

Java's API

Why 1-D DSP?

pressure, temp, speed, radiation, sound & also non-physical phenomina
Financial data, Statistical data.

How do we do it?

Restrict the domains
Deal primarily with Audio Digital Signal processing
Why ?

Audio Files :

Reading Audio files in Java :

The central class in DiffCad for processing Audio files is "AudioFrame" class.

AudioFrame.java


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();
  }

Sun uses Audio data format

ulaw data is currently 8bit-8khz

Insiders at Sun say something better is coming soon !
So do not get too hung on ulaw.

doubleData is the only Audio data format
you need for this class.

Playing the Audio :

To play the audio, 8bit ulaw data is available. (This is all Java API can play )
Once ulaw is available call play( ) method

    public void play() {
        audioPlayer.start(new AudioDataStream(new AudioData(ulawData)));
        waitTillDone();
    }

Graphing the Audio :

     // 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)));
        }
       }
 

Wavetable Generation :

A wavetable is just a series of voltages which will vary as a function of index.
vi belongs to [-1..1] and i belongs to [0..N] and i belongs to Z
where

vi is a double precision floating point.
vi is a number which has to be scaled to range between -1 & 1
The class AudioFrame stores vi in doubleData[i]
an array of double precision floats.
N = doubleData.length();

Sample Quiz

1. The Audio Data Format currently used by sun is


 
homeContentsIndexPrevNext



UBLOGOLast Update: 04/09/97
Copyright © 1997- Douglas Lyon
Lyon@cse.bridgeport.edu