⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 224-229.html

📁 dshfghfhhgsfgfghfhfghgfhfghfgh fg hfg hh ghghf hgf hghg gh fg hg hfg hfh f hg hgfh gkjh kjkh g yj f
💻 HTML
字号:
<HTML>
<HEAD>
<META name=vsisbn content="1558515682"><META name=vstitle content="Java Digital Signal Processing"><META name=vsauthor content="Douglas A. Lyon"><META name=vsimprint content="M&T Books"><META name=vspublisher content="IDG Books Worldwide, Inc."><META name=vspubdate content="11/01/97"><META name=vscategory content="Web and Software Development: Programming, Scripting, and Markup Languages: Java"><TITLE>Java Digital Signal Processing:Digital Audio Processing</TITLE>
<!-- HEADER --><STYLE type="text/css">  <!-- A:hover  { 	color : Red; } --></STYLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<!--ISBN=1558515682//-->
<!--TITLE=Java Digital Signal Processing//-->
<!--AUTHOR=Douglas A. Lyon//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=5//-->
<!--PAGES=224-229//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="219-224.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="229-236.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading11"></A><FONT COLOR="#000077">The AudioData Class</FONT></H3>
<P>The <I>AudioData</I> class resides in the <I>sun.audio</I> package. An instance of <I>AudioData</I> is often called a <I>clip</I> of audio data. The <I>AudioData</I> instance consists of 8-bit [mu]-law-encoded, 8,000-Hz sample rate data. An instance of the <I>AudioData</I> stream is used to construct an instance of an <I>AudioDataStream</I>. An instance of an <I>AudioDataStream</I> can be played to the speaker of audio-capable machines.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>WARNING:&nbsp;&nbsp;</B>Because <I>AudioData</I> is a resident of the <I>sun.audio</I> package, the interface is subject to change without notice. The class summary was derived from the DiffCAD class dumper.<HR></FONT>
</BLOCKQUOTE>
<H4 ALIGN="LEFT"><A NAME="Heading12"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE SNIP //-->
<PRE>
public class AudioData extends java.lang.Object {
public void AudioData(byte a[]);
}
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading13"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>Suppose the following variables are predefined:
</P>
<!-- CODE SNIP //-->
<PRE>
AudioStream as;
byte bytes[];
</PRE>
<!-- END CODE SNIP //-->
<P>To make an instance of the <I>AudioData</I>, use this code:</P>
<!-- CODE SNIP //-->
<PRE>
ad = new AudioData(bytes);
</PRE>
<!-- END CODE SNIP //-->
<P>To get data from an <I>AudioStream</I>:</P>
<!-- CODE SNIP //-->
<PRE>
ad = as.getData();
</PRE>
<!-- END CODE SNIP //-->
<H3><A NAME="Heading14"></A><FONT COLOR="#000077">The AudioDataStream Class</FONT></H3>
<P>The <I>AudioDataStream</I> resides in the <I>sun.audio</I> package. It extends <I>ByteArrayInputStream</I>. An <I>AudioDataStream</I> instance provides an input stream to play <I>AudioData</I>.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>WARNING:&nbsp;&nbsp;</B>Because <I>AudioDataStream</I> is a resident of the <I>sun.audio</I> package, the interface is subject to change without notice. The class summary was derived from the DiffCAD class dumper.<HR></FONT>
</BLOCKQUOTE>
<H4 ALIGN="LEFT"><A NAME="Heading15"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE SNIP //-->
<PRE>
public class AudioDataStream extends ByteArrayInputStream {
 public void AudioDataStream(sun.audio.AudioData a);
}
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading16"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P><I>AudioDataStream</I> has only one public method, its constructor.</P>
<P>Suppose the following variables are predefined:</P>
<!-- CODE SNIP //-->
<PRE>
byte ulawData[];
AudioData audioData = new AudioData ( ulawData);
</PRE>
<!-- END CODE SNIP //-->
<P>To make an instance of <I>AudioDataStream</I>, use this code:</P>
<!-- CODE SNIP //-->
<PRE>
audioDataStream = new AudioDataStream (audioData);
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading17"></A><FONT COLOR="#000077">Reading and Playing an AU File</FONT></H4>
<P>The following code fragment, from the <I>UlawCodec</I> class on the accompanying CD-ROM, shows how to read data from a Sun AU file. This code is used to make and play an <I>AudioDataStream</I> instance:</P>
<!-- CODE //-->
<PRE>
package lyon.audio;
import java.io.*;
import sun.audio.*;
import futils.Futil;
public class UlawCodec implements Runnable {
private byte ulawData[];
private double doubleArray[];
private  AudioDataStream audioDataStream = null;
private  AudioStream audioStream = null;
....
// --------------------------------
//
// public ReadAUFile(String name);
//
// This constructor can be used to acquire the audio samples
// from an AU file
//
// --------------------------------
 public void readAUFile(String fileName){
      // force recomputation
      // of the doubleArray, because it is invalid
      doubleArray = null;
  try {
   audioStream = new AudioStream(new FileInputStream(fileName));
   // AudioStream constructor expects data stream from AU file as input
   ulawData = new byte[audioStream.getLength()];
   audioStream.read(ulawData, 0, audioStream.getLength());
  } catch(Exception e){}
 }
 public void readAUFile() {
      String fileName = Futil.getReadFileName();
      readAUFile(fileName);
 }
</PRE>
<!-- END CODE //-->
<H3><A NAME="Heading18"></A><FONT COLOR="#000077">The AudioStreamSequence Class</FONT></H3>
<P>The <I>AudioStreamSequence</I> class resides in the <I>sun.audio</I> package. An instance of <I>AudioStreamSequence</I> can be used to convert a sequence of input streams into a single <I>InputStream</I>. This class is typically used to play two audio clips in sequence.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>WARNING:&nbsp;&nbsp;</B>Because <I>AudioStreamSequence</I> is a resident of the <I>sun.audio</I> package, the interface is subject to change without notice. The class summary was derived from the DiffCAD class dumper.<HR></FONT>
</BLOCKQUOTE>
<H4 ALIGN="LEFT"><A NAME="Heading19"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE SNIP //-->
<PRE>
public class AudioStreamSequence extends java.io.InputStream {
 public void AudioStreamSequence(java.util.Enumeration a);
 public int read();
 public int read(byte a[], int b, int c);
}
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading20"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>Suppose the following variables are predefined:
</P>
<!-- CODE SNIP //-->
<PRE>
AudioStream as1, as2;
Vector v = new Vector();
v.addElement(as1);
v.addElement(as2);
int lenghtRead, length, position;
byte bytes[];
</PRE>
<!-- END CODE SNIP //-->
<P>To make a new instance of the <I>AudioStreamSequence</I>, use this code:</P>
<!-- CODE SNIP //-->
<PRE>
AudioStreamSequence ass = new AudioStreamSequence(v.elements());
</PRE>
<!-- END CODE SNIP //-->
<P>To play the <I>AudioStreamSequence</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
AudioPlayer.player.start(audiostream);
</PRE>
<!-- END CODE SNIP //-->
<P>To read from an instance of <I>AudioStreamSequence</I> and flip to the next stream if an EOF is encountered (throws <I>IOException</I>):</P>
<!-- CODE SNIP //-->
<PRE>
lengthRead = ass.read(bytes, position, length);
lengthRead = ass.read();
</PRE>
<!-- END CODE SNIP //-->
<H3><A NAME="Heading21"></A><FONT COLOR="#000077">The AudioPlayer Class</FONT></H3>
<P>The <I>AudioPlayer</I> class resides in the <I>sun.audio</I> package. This class provides an interface to play an instance of <I>AudioStream</I>.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>WARNING:&nbsp;&nbsp;</B>Because <I>AudioPlayer</I> is a resident of the <I>sun.audio</I> package, the interface is subject to change without notice. The class summary was derived from the DiffCAD class dumper.<HR></FONT>
</BLOCKQUOTE>
<H4 ALIGN="LEFT"><A NAME="Heading22"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
import java.io.PrintStream;
import java.lang.System;
public class AudioPlayer extends java.lang.Thread {
public static final sun.audio.AudioPlayer player;
private void AudioPlayer();
public synchronized void start(java.io.InputStream a);
public synchronized void stop(java.io.InputStream a);
public void run();
}
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading23"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>Suppose the following variables are predefined:
</P>
<!-- CODE SNIP //-->
<PRE>
AudioStream as;
AudoData ad = as.getData();
</PRE>
<!-- END CODE SNIP //-->
<P>To play an audio stream, use this code:
</P>
<!-- CODE SNIP //-->
<PRE>
AudioPlayer.player.start(as);
</PRE>
<!-- END CODE SNIP //-->
<P>To stop playing an audio stream:
</P>
<!-- CODE SNIP //-->
<PRE>
AudioPlayer.player.stop(as);
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="219-224.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="229-236.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>

<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright &copy; <a href="/reference/idgbooks00001.html">IDG Books Worldwide, Inc.</a></font></div>
<!-- all of the reference materials (books) have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --></BODY></HTML><!-- END FOOTER -->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -