📄 219-224.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=219-224//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="213-219.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="224-229.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading5"></A><FONT COLOR="#000077">What Does Sampling Do to the Spectrum of a Signal?</FONT></H3>
<P>The digitization process, as depicted in Figure 5.1, starts with the process of sampling. The sampling-reconstruction process need not perform digitization and yet is responsible for the introduction of additional harmonic content into the reconstructed signal. The sampling-reconstruction process is shown in Figure 5.5.
</P>
<P><A NAME="Fig5"></A><A HREF="javascript:displayWindow('images/05-05.jpg',482,76 )"><IMG SRC="images/05-05t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/05-05.jpg',482,76)"><FONT COLOR="#000077"><B>Figure 5.5</B></FONT></A> The sampling-reconstruction process.</P>
<P>Figure 5.5 shows a continuous signal, <I>v(t)</I> , being sampled at a rate of <I>fs</I> using an electronically controlled switch. The output of the switch is fed into an amplifier that has a gain of <I>R</I>. Mathematically, the sampling function can be expressed in terms of a Dirac delta function multiplied by <I>v(t)</I> in the time domain. The Dirac delta function, <I>(</I>(<I>t</I>), is a generalized function that is defined by</P>
<P ALIGN="CENTER"><IMG SRC="images/05-16d.jpg"></P>
<P>(5.10)
</P>
<P>Where <I>(</I> is arbitrarily small. Thus, the Dirac delta function is a unit impulse that occurs at time <I>t</I> = 0. We can make the Dirac delta function fire at any time, <I>t<SUB>d</SUB></I>, by using the form</P>
<P ALIGN="CENTER"><IMG SRC="images/05-17d.jpg"></P>
<P>(5.11)
</P>
<P>Furthermore, we can model the sampling function as an infinite sum of Dirac delta functions:</P>
<P ALIGN="CENTER"><IMG SRC="images/05-18d.jpg"></P>
<P>(5.12)
</P>
<P>The switching function multiplies <I>s(t)</I> by <I>v(t)</I>. The sampled function is represented by</P>
<P ALIGN="CENTER"><IMG SRC="images/05-19d.jpg"></P>
<P>(5.13)
</P>
<P>Recall that multiplication in the time domain is convolution in the frequency domain:</P>
<P ALIGN="CENTER"><IMG SRC="images/05-20d.jpg"></P>
<P>(5.14)
</P>
<P>The Fourier transform of an impulse train is also an impulse train.</P>
<P ALIGN="CENTER"><IMG SRC="images/05-21d.jpg"></P>
<P>(5.15)
</P>
<P>Finally, we see that sampling a signal at a rate of <I>fs</I> causes the spectrum to be reproduced at <I>f<SUB>s</SUB></I> intervals.</P>
<P ALIGN="CENTER"><IMG SRC="images/05-22d.jpg"></P>
<P>(5.16)
</P>
<P>A sample of this spectrum replication is shown in Figure 5.6.</P>
<P><A NAME="Fig6"></A><A HREF="javascript:displayWindow('images/05-06.jpg',368,130 )"><IMG SRC="images/05-06t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/05-06.jpg',368,130)"><FONT COLOR="#000077"><B>Figure 5.6</B></FONT></A> Spectrum replication due to sampling.</P>
<P>Equation 5.16 is called the aliasing formula.
</P>
<H3><A NAME="Heading6"></A><FONT COLOR="#000077">Audio Files</FONT></H3>
<P>In this section we describe how to read, play, graph, and write audio files. The current Java API can open and play an audio file but not decode it. The code we present in this chapter extends and builds on the existing Java API.
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>CD-ROM: </B>You will find a collection of sound utilities for the Mac at <A HREF="http://wwwhost.ots.utexas.edu/mac/pub-mac-sound.html">http://wwwhost.ots.utexas.edu/mac/pub-mac-sound.html</A>. The book’s CD-ROM has a collection of sound utilities that are useful for recording and resampling audio files.<HR></FONT>
</BLOCKQUOTE>
<H3><A NAME="Heading7"></A><FONT COLOR="#000077">The sun.audio Package</FONT></H3>
<P><I>AudioData</I>, <I>AudioDataStream</I>, <I>AudioPlayer</I>, <I>AudioStream</I>, <I>AudioStream-Sequence</I>, and <I>ContinuousAudioDataStream</I> are public classes that reside in the <I>sun.audio</I> package.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>WARNING: </B>Code that uses classes in the Java <I>sun.audio</I> package does so in an undocumented and unsupported way. When the package changes, code that depends on its classes may not work.<HR></FONT>
</BLOCKQUOTE>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>A trick of the Java trade is to unzip a library of files (such as the <B>classes.zip</B> file that comes with some applet viewers. Unzipping creates a large number of class files (446 for JDK 1.0.2), and it is a good idea to perform this operation on a copy of the file (don’t break your applet viewer!). Using a class browser (such as the <I>class dumper</I> included with DiffCAD), you can list the fields of the class.<HR></FONT>
</BLOCKQUOTE>
<P>A clip of audio data contains [mu]-law-encoded, 8-bit, 8,000-Hz sample rate data. This data can be used to construct an <I>AudioDataStream</I> instance. The <I>getAudioData</I> method gets an audio clip from the cache. <I>AudioStream</I> is an input stream used to play <I>AudioData</I>. For more documentation on the <I>sun.audio</I> package, see <A HREF="http://www.cdt.luth.se/java/doc/sun/shared/package-sun.audio.html">http://www.cdt.luth.se/java/doc/sun/shared/Package-sun.audio.html</A>.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>Current implementations have been tested with the book software on the MacOS System 7.5x, Windows 95/NT, and Sun Solaris operating systems. The sound player software cannot make audio output on a Wintel platform that lacks a sound card. Furthermore, some sound cards do not get driven properly by the current Java sound drivers. Soundblaster-compatible cards seem to work with this book’s software.<HR></FONT>
</BLOCKQUOTE>
<P>We can only guess how classes in the <I>sun.audio</I> package might work. There is no documentation on which to base a solid code foundation. However, the code that we present in the following section works for now.</P>
<H3><A NAME="Heading8"></A><FONT COLOR="#000077">The AudioStream Class</FONT></H3>
<P>The <I>AudioStream</I> class resides in the <I>sun.audio</I> package. It is used to convert an <I>InputStream</I> to an <I>AudioStream</I>. The <I>AudioStream</I> class extends the <I>FilterInputStream</I> class. As a subclass of <I>FilterInputStream</I>, the <I>AudioStream</I> class inherits all the methods and attributes of <I>FilterInputStream</I>.</P>
<H4 ALIGN="LEFT"><A NAME="Heading9"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<P>We cannot reverse-engineer the software that makes up <I>AudioStream</I>, so we reproduce the raw class dumper output from the DiffCAD program:</P>
<!-- CODE //-->
<PRE>
package sun.audio
import java.lang.Thread;
import java.io.IOException;
/*
* This class has 1 optional class attributes.
* These attributes are:
* Attribute 1 is of type SourceFile
* SourceFile : AudioStream.java
*/
public class AudioStream extends FilterInputStream {
public void AudioStream(java.io.InputStream a);
public int read(byte a[], int b, int c);
public sun.audio.AudioData getData();
public int getLength();
}
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading10"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>Suppose the following variables are predefined:
</P>
<!-- CODE SNIP //-->
<PRE>
InputStream is;
int position, length;
byte bytes[];
AudioData ad;
</PRE>
<!-- END CODE SNIP //-->
<P>To construct an instance of the <I>AudioStream</I> class (throws <I>IOException</I>), use this code:</P>
<!-- CODE SNIP //-->
<PRE>
AudioStream as = new AudioStream(is);
</PRE>
<!-- END CODE SNIP //-->
<P>To construct an instance of an <I>AudioStream</I> from a URL:</P>
<!-- CODE SNIP //-->
<PRE>
AudioStream as = new AudioStream(url.openStream());
</PRE>
<!-- END CODE SNIP //-->
<P>To read an array of bytes from the input stream starting at <I>position</I> and proceeding for <I>length</I> bytes (throws <I>IOException</I>):</P>
<!-- CODE SNIP //-->
<PRE>
as.read(bytes, position, length);
</PRE>
<!-- END CODE SNIP //-->
<P>To find the length of the <I>AudioStream</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
length = as.getLength();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the <I>AudioData</I> from an <I>AudioStream</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
ad = as.getData();
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="213-219.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="224-229.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright © <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 + -