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

📄 229-236.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=229-236//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="224-229.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="236-240.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading24"></A><FONT COLOR="#000077">The [mu]-law CODEC Concept</FONT></H3>
<P>In this section we show how to use a software CODEC (coder-decoder) to decode and play a Sun AU audio file. The Java API uses a [mu]-law (pronounced &#147;mu-law&#148;) compression technique for playing audio files. The supported [mu]-law format consists of logarithmically companded, 8-kHhz sample rate, byte-quantized, voice-grade audio. The word <I>compandor</I> is a contraction of compressor and expander [BTL]. The sample time for an 8,000 samples per second system is 1/8,000 = 0.000125 second = 125 [mu]s. Such a format generates an 8,000 sample/second * 8 bits / sample = 64 kbps data stream and is common in telephony. Also, the peak bandwidth of such a compression format is as follows:</P>
<P ALIGN="CENTER"><IMG SRC="images/05-23d.jpg"></P>
<P>(5.17)
</P>
<P>The International Telecommunication Union (ITU), formerly CCITT, has created a specification called G.711. Two PCM algorithms are defined in the G.711 standard: A-Law and [mu]-law. In both the A-Law and [mu]-law format, the sample rate is 8 kHz. In a linear PCM system, there are uniform voltage quantization steps [Bates].</P>
<P>A copy of the G.711 specification is available for sale at <A HREF="http://www.itu.int/itudoc/itu-t/rec/g/g700-799/g711_27434.html">http://www.itu.int/itudoc/itu-t/rec/g/g700-799/g711_27434.html</A> (it cost 20 Swiss francs the last time we checked). The Sun reference implementation is on the accompanying CD-ROM along with a wealth of other audio information. The [mu]-law encoding formula is given by</P>
<P ALIGN="CENTER"><IMG SRC="images/05-24d.jpg"></P>
<P>(5.18)
</P>
<P>The A-Law formula is given by</P>
<P ALIGN="CENTER"><IMG SRC="images/05-25d.jpg"></P>
<P>(5.19)
</P>
<P>Typical values of the compression parameters used in Equations 5.18 and 5.19 are as follows:</P>
<P ALIGN="CENTER"><IMG SRC="images/05-26d.jpg"></P>
<P>(5.20)
</P>
<P>A graph of Equation 5.18, with <I>V</I>max =1 and [mu] = 255, is shown in Figure 5.7. The value [mu] = 255 is used for North American telephone transmission. The value <I>A</I> = 87.6 is used for European telephone transmission. The rationale for companding is that the human ear cannot differentiate between amplitudes of sound waves as the amplitude increases [Embree].</P>
<P><A NAME="Fig7"></A><A HREF="javascript:displayWindow('images/05-07.jpg',218,214 )"><IMG SRC="images/05-07t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/05-07.jpg',218,214)"><FONT COLOR="#000077"><B>Figure 5.7</B></FONT></A>&nbsp;&nbsp;Graph of the &#181;-law transfer function with &#181; = 255.</P>
<P>One metric of PCM performance is the ratio of the signal power to quantization noise power (signal-to-quantizing distortion ratio). The basic idea behind A-Law and &#181;-law companding is that a logarithmic curve can be used to improve the signal-to-quantizing distortion ratio at low signal levels.
</P>
<P>Binary PCM will have a number of quantization levels given by the following:</P>
<P ALIGN="CENTER"><IMG SRC="images/05-27d.jpg"></P>
<P>(5.21)
</P>
<P>where</P>
<!-- CODE SNIP //-->
<PRE>
     <I>N</I>q = the number of quantization levels
     <I>N</I>b = the number of bits per sample
</PRE>
<!-- END CODE SNIP //-->
<P>The signal power varies from 0 to 1, inclusive, and is given by
</P>
<P ALIGN="CENTER"><IMG SRC="images/05-28d.jpg"></P>
<P>The signal voltage, <I>x</I>, varies from</P>
<P ALIGN="CENTER"><IMG SRC="images/05-29d.jpg"></P>
<P>(5.22)
</P>
<P>For simplicity we assume that</P>
<P ALIGN="CENTER"><IMG SRC="images/05-30d.jpg"></P>
<P>(5.23)
</P>
<P>The uniform quantizer divides the signal voltage evenly among the number of quantization levels. The uniform quantizer&#146;s quantization error voltage is given by</P>
<P ALIGN="CENTER"><IMG SRC="images/05-31d.jpg"></P>
<P>(5.24)
</P>
<P>The average quantization error is 0, but the root-mean-square (RMS) value of the quantization error is the mean square quantization noise power. The term <I>root-mean-square</I> refers to the fact that the computation is performed by taking the square root of the mean of error voltage squared [Carlson and Gisser]. Recall that for a continuous probability distribution function, the expectation is taken by</P>
<P ALIGN="CENTER"><IMG SRC="images/05-32d.jpg"></P>
<P>and the variance is taken by
</P>
<P ALIGN="CENTER"><IMG SRC="images/05-33d.jpg"></P>
<P>The variance expands to
</P>
<P ALIGN="CENTER"><IMG SRC="images/05-34d.jpg"></P>
<P>Also recall that for a discrete random variable,
</P>
<P ALIGN="CENTER"><IMG SRC="images/05-35d.jpg"></P>
<P>and
</P>
<P ALIGN="CENTER"><IMG SRC="images/05-36d.jpg"></P>
<P>Thus, we compute the RMS error by integrating the square of the quantization error voltage over the range in Equation 5.24, assuming a zero mean:
</P>
<P ALIGN="CENTER"><IMG SRC="images/05-37d.jpg"></P>
<P>(5.25)
</P>
<P>When the maximum signal voltage is constrained, as in Equations 5.22 and 5.23, we compute the signal-to-quantization noise power as</P>
<P ALIGN="CENTER"><IMG SRC="images/05-38d.jpg"></P>
<P>(5.26)
</P>
<P>Where the signal power is given by <I>S<SUB>x</SUB></I>. If the signal power is equal to 1, the range on the upper bound for the signal-to-quantization noise power is</P>
<P ALIGN="CENTER"><IMG SRC="images/05-39d.jpg"></P>
<P>(5.27)
</P>
<P>With the 8-bit PCM system and uniform quantization, the best we can hope for is a SNR of 52.8 dB. Note that the SNR (in dB) falls off linearly as a function of the power in Equation 5.26. It can be shown that the companding equations of Equations 5.18 and 5.19 will provide an improvement in the SNR when the signal power falls below -20 dB.</P>
<P>For signal powers greater than -20 dB, companding degrades performance relative to uniform quantization, assuming that the PDF (probability distribution function) of a voice signal has a Laplace distribution of the form</P>
<P ALIGN="CENTER"><IMG SRC="images/05-40d.jpg"></P>
<P>[Carlson].
</P>
<P>The compression parameter values given in Equation 5.20 are based on an assumed PDF of an input signal. The PDF assumption is required for telephony applications. However, in the instance of audio files that are stored on static media (such as a CD-ROM or Web server hard drive), the PDF can be computed off-line. For such a system, the SNR is</P>
<P ALIGN="CENTER"><IMG SRC="images/05-41d.jpg"></P>
<P>(5.28)
</P>
<P>computing the derivative of Equation 5.18 with respect to <I>x</I> and substituting into Equation 5.28 yields</P>
<P ALIGN="CENTER"><IMG SRC="images/05-42d.jpg"></P>
<P>(5.29)
</P>
<P>Once the PDF, <I>p(x)</I>, is computed, the companding parameter can be precomputed using a criterion of optimality based on the bit rate budget. For example, a bit rate budget of 16 kbps might require a 4-bit sample with a 4-kHz sampling rate. Such a system might be used to stream audio (transmit in real time) via a low-data-rate phone connection. Ideally, a server should be able to resample and compand the audio before transmission in response to the bit rate budget.</P>
<H3><A NAME="Heading25"></A><FONT COLOR="#000077">The UlawCodec Class</FONT></H3>
<P>The <I>UlawCodec</I> class is a public class that resides in the <I>lyon.audio</I> package.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>CD-ROM:&nbsp;&nbsp;</B>The <I>UlawCodec</I> class performs the [mu]-law CODEC function in addition to providing file save and open services.<HR></FONT>
</BLOCKQUOTE>
<P>Java can, in principle, process any file format. The basic problem, however, is that Java&#146;s current API can play only an <I>AudioDataStream</I> that is [mu]-law -encoded. Even though Java can read, process, and write any audio data format file, an intermediary [mu]-law encoding is required to play the audio.</P>
<H4 ALIGN="LEFT"><A NAME="Heading26"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
public class UlawCodec implements Runnable {
 public UlawCodec()
 public UlawCodec(String name)
 public UlawCodec(short linearArrayOfShort[])
 public UlawCodec(double linearArrayOfDouble[])
 public UlawCodec(byte ulawArrayOfByte[])
 public void readAUFile(String fileName)
 public void readAUFile()
 public void writeAUFile(String fileName)
 public void writeAUFile()
 public void playSync()
 public void playAsync()
 public byte [] getUlawData()
 public void setUlawData(byte ulawArrayOfByte[])
 public double[] getDoubleArray()
 public int getLength()
 public double getDuration()
 public void reverseUlaw()
 public static void main(String argc[])
}
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="224-229.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="236-240.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 + -