home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / audio / NativeAudioStream.java < prev   
Encoding:
Java Source  |  1997-01-27  |  2.8 KB  |  88 lines

  1. /*
  2.  * @(#)NativeAudioStream.java    1.2 95/09/02 Arthur van Hoff, Thomas Ball
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.audio;
  21.  
  22. import java.io.InputStream;
  23. import java.io.DataInputStream;
  24. import java.io.FilterInputStream;
  25. import java.io.IOException;
  26.  
  27. /**
  28.  * A Sun-specific AudioStream that supports the .au file format. 
  29.  *
  30.  * @version     1.1, 22 Aug 1995
  31.  */
  32. public
  33. class NativeAudioStream extends FilterInputStream {
  34.     private final int SUN_MAGIC  = 0x2e736e64;
  35.     private final int DEC_MAGIC  = 0x2e736400;
  36.     private final int MINHDRSIZE = 24;
  37.     private final int TYPE_ULAW  = 1;
  38.  
  39.     private int length = 0;
  40.  
  41.     /**
  42.      * Read header, only sun 8 bit, ulaw encoded, single channel,
  43.      * 8000hz is supported
  44.      */
  45.     public NativeAudioStream(InputStream in) throws IOException {
  46.     super(in);
  47.     DataInputStream data = new DataInputStream(in);
  48.     int magic = data.readInt();
  49.     if (magic != SUN_MAGIC && magic != DEC_MAGIC) {
  50.         System.out.println("NativeAudioStream: invalid file type.");
  51.         throw new InvalidAudioFormatException();
  52.     }
  53.     int hdr_size = data.readInt(); // header size
  54.     if (hdr_size < MINHDRSIZE) {
  55.         System.out.println("NativeAudioStream: wrong header size of " +
  56.                    hdr_size + ".");
  57.         throw new InvalidAudioFormatException();
  58.     }
  59.     length = data.readInt();
  60.     
  61.     int encoding = data.readInt();
  62.     if (encoding != TYPE_ULAW) {
  63.         System.out.println("NativeAudioStream: invalid audio encoding.");
  64.         throw new InvalidAudioFormatException();
  65.     }
  66.  
  67.     int sample_rate = data.readInt();
  68.     if ((sample_rate / 1000) != 8) {    // allow some slop
  69.         System.out.println("NativeAudioStream: invalid sample rate of " +
  70.                    sample_rate + ".");
  71.         throw new InvalidAudioFormatException();
  72.     }
  73.  
  74.     int channels = data.readInt();
  75.     if (channels != 1) {
  76.         System.out.println("NativeAudioStream: wrong number of channels. "
  77.                    + "(wanted 1, actual " + channels + ")");
  78.         throw new InvalidAudioFormatException();
  79.     }
  80.     
  81.     in.skip(hdr_size - MINHDRSIZE);
  82.     }
  83.  
  84.     public int getLength() {
  85.     return length;
  86.     }
  87. }
  88.