mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-08-30 02:43:13 +08:00
266 lines
18 KiB
HTML
266 lines
18 KiB
HTML
<div class="header">
|
||
<div class="subTitle">
|
||
javax.sound.sampled
|
||
</div>
|
||
<h2 class="title" title="Interface SourceDataLine">Interface SourceDataLine</h2>
|
||
</div><div class="contentContainer">
|
||
<div class="description">
|
||
<ul class="blockList">
|
||
<li class="blockList">
|
||
<dl>
|
||
<dt>
|
||
All Superinterfaces:
|
||
</dt>
|
||
<dd>
|
||
<span><a href="../../../java/lang/AutoCloseable.html" title="java.lang中的接口">AutoCloseable</a> , <a href="../../../javax/sound/sampled/DataLine.html" title="javax.sound.sampled中的接口">DataLine</a> , <a href="../../../javax/sound/sampled/Line.html" title="javax.sound.sampled中的接口">Line</a></span>
|
||
</dd>
|
||
</dl>
|
||
<hr/> <br/> <pre>public interface <span class="typeNameLabel">SourceDataLine</span>
|
||
extends <a href="../../../javax/sound/sampled/DataLine.html" title="interface in javax.sound.sampled">DataLine</a></pre>
|
||
<div class="block">
|
||
<span>源数据线是可以写入数据的数据线。</span>
|
||
<span>它作为混音器的源头。</span>
|
||
<span>应用程序将音频字节写入源数据线,该数据线处理字节的缓冲并将其传递到混频器。</span>
|
||
<span>混合器可以将样品与来自其他来源的样品混合,然后将混合物输送到目标,例如输出端口(其可以表示声卡上的音频输出设备)。</span>
|
||
<p> <span>请注意,此接口的命名约定反映了线路与其调音台之间的关系。</span> <span>从应用的角度来看,源数据线可以用作音频数据的目标。</span> </p>
|
||
<p> <span>可以通过调用具有适当的<code><a href="../../../javax/sound/sampled/DataLine.Info.html" title="class in javax.sound.sampled"><code>DataLine.Info</code></a></code>对象的<code>Mixer</code>的<code><a href="../../../javax/sound/sampled/Mixer.html#getLine-javax.sound.sampled.Line.Info-"><code>getLine</code></a></code>方法从混合器获得源数据线。</span> </p>
|
||
<p> <span><code>SourceDataLine</code>接口提供了一种将音频数据写入数据线的缓冲区的方法。</span> <span>播放或混合音频的应用程序应该将数据快速写入源数据行,以使缓冲区不会下溢(排空),这可能会导致音频中的不连续性被视为点击。</span> <span>应用程序可以使用<code><a href="../../../javax/sound/sampled/DataLine.html#available--"><code>available</code></a></code>中所定义的方法<code>DataLine</code>界面来确定当前在数据线的缓冲器排队的数据的量。</span> <span>可以写入缓冲区而不阻塞的数据量是缓冲区大小与排队数据量之间的差异。</span> <span>如果由于下溢导致音频输出的传送停止,则会生成<code><a href="../../../javax/sound/sampled/LineEvent.Type.html#STOP"><code>STOP</code></a></code>事件。</span> <span>音频输出恢复时会产生<code><a href="../../../javax/sound/sampled/LineEvent.Type.html#START"><code>START</code></a></code>事件。</span> </p>
|
||
</div>
|
||
<dl>
|
||
<dt>
|
||
<span class="simpleTagLabel">从以下版本开始:</span>
|
||
</dt>
|
||
<dd>
|
||
1.3
|
||
</dd>
|
||
<dt>
|
||
<span class="seeLabel">另请参见:</span>
|
||
</dt>
|
||
<dd>
|
||
<span><a href="../../../javax/sound/sampled/Mixer.html" title="javax.sound.sampled中的接口"><code>Mixer</code></a> , <a href="../../../javax/sound/sampled/DataLine.html" title="javax.sound.sampled中的接口"><code>DataLine</code></a> , <a href="../../../javax/sound/sampled/TargetDataLine.html" title="javax.sound.sampled中的接口"><code>TargetDataLine</code></a></span>
|
||
</dd>
|
||
</dl> </li>
|
||
</ul>
|
||
</div>
|
||
<div class="summary">
|
||
<ul class="blockList">
|
||
<li class="blockList">
|
||
<!-- ======== NESTED CLASS SUMMARY ======== -->
|
||
<ul class="blockList">
|
||
<li class="blockList"><a name="nested.class.summary">
|
||
<!-- --> </a> <h3>Nested Class Summary</h3>
|
||
<ul class="blockList">
|
||
<li class="blockList"><a name="nested.classes.inherited.from.class.javax.sound.sampled.DataLine">
|
||
<!-- --> </a> <h3>Nested classes/interfaces inherited from interface javax.sound.sampled.<a href="../../../javax/sound/sampled/DataLine.html" title="interface in javax.sound.sampled">DataLine</a></h3> <code><a href="../../../javax/sound/sampled/DataLine.Info.html" title="class in javax.sound.sampled">DataLine.Info</a></code></li>
|
||
</ul> </li>
|
||
</ul>
|
||
<!-- ========== METHOD SUMMARY =========== -->
|
||
<ul class="blockList">
|
||
<li class="blockList"><a name="method.summary">
|
||
<!-- --> </a> <h3>方法摘要</h3>
|
||
<table border="0" cellpadding="3" cellspacing="0" class="memberSummary" summary="Method Summary table, listing methods, and an explanation">
|
||
<caption>
|
||
<span class="activeTableTab" id="t0"><span>所有方法</span><span class="tabEnd"> </span></span>
|
||
<span class="tableTab" id="t2"><span><a href="javascript:show(2);">接口方法</a></span><span class="tabEnd"> </span></span>
|
||
<span class="tableTab" id="t3"><span><a href="javascript:show(4);">抽象方法</a></span><span class="tabEnd"> </span></span>
|
||
</caption>
|
||
<tbody>
|
||
<tr>
|
||
<th class="colFirst" scope="col">Modifier and Type</th>
|
||
<th class="colLast" scope="col">Method and Description</th>
|
||
</tr>
|
||
<tr class="altColor" id="i0">
|
||
<td class="colFirst"><code>void</code></td>
|
||
<td class="colLast"><code><span class="memberNameLink"><a href="../../../javax/sound/sampled/SourceDataLine.html#open-javax.sound.sampled.AudioFormat-">open</a></span>(<a href="../../../javax/sound/sampled/AudioFormat.html" title="class in javax.sound.sampled">AudioFormat</a> format)</code>
|
||
<div class="block">
|
||
以指定的格式打开行,使该行获取任何所需的系统资源,并可以运行。
|
||
</div> </td>
|
||
</tr>
|
||
<tr class="rowColor" id="i1">
|
||
<td class="colFirst"><code>void</code></td>
|
||
<td class="colLast"><code><span class="memberNameLink"><a href="../../../javax/sound/sampled/SourceDataLine.html#open-javax.sound.sampled.AudioFormat-int-">open</a></span>(<a href="../../../javax/sound/sampled/AudioFormat.html" title="class in javax.sound.sampled">AudioFormat</a> format, int bufferSize)</code>
|
||
<div class="block">
|
||
以指定的格式和建议的缓冲区大小打开行,使该行获取任何所需的系统资源并变为可操作。
|
||
</div> </td>
|
||
</tr>
|
||
<tr class="altColor" id="i2">
|
||
<td class="colFirst"><code>int</code></td>
|
||
<td class="colLast"><code><span class="memberNameLink"><a href="../../../javax/sound/sampled/SourceDataLine.html#write-byte:A-int-int-">write</a></span>(byte[] b, int off, int len)</code>
|
||
<div class="block">
|
||
通过该源数据线将音频数据写入混频器。
|
||
</div> </td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<ul class="blockList">
|
||
<li class="blockList"><a name="methods.inherited.from.class.javax.sound.sampled.DataLine">
|
||
<!-- --> </a> <h3>Methods inherited from interface javax.sound.sampled.<a href="../../../javax/sound/sampled/DataLine.html" title="interface in javax.sound.sampled">DataLine</a></h3> <code><a href="../../../javax/sound/sampled/DataLine.html#available--">available</a>, <a href="../../../javax/sound/sampled/DataLine.html#drain--">drain</a>, <a href="../../../javax/sound/sampled/DataLine.html#flush--">flush</a>, <a href="../../../javax/sound/sampled/DataLine.html#getBufferSize--">getBufferSize</a>, <a href="../../../javax/sound/sampled/DataLine.html#getFormat--">getFormat</a>, <a href="../../../javax/sound/sampled/DataLine.html#getFramePosition--">getFramePosition</a>, <a href="../../../javax/sound/sampled/DataLine.html#getLevel--">getLevel</a>, <a href="../../../javax/sound/sampled/DataLine.html#getLongFramePosition--">getLongFramePosition</a>, <a href="../../../javax/sound/sampled/DataLine.html#getMicrosecondPosition--">getMicrosecondPosition</a>, <a href="../../../javax/sound/sampled/DataLine.html#isActive--">isActive</a>, <a href="../../../javax/sound/sampled/DataLine.html#isRunning--">isRunning</a>, <a href="../../../javax/sound/sampled/DataLine.html#start--">start</a>, <a href="../../../javax/sound/sampled/DataLine.html#stop--">stop</a></code></li>
|
||
</ul>
|
||
<ul class="blockList">
|
||
<li class="blockList"><a name="methods.inherited.from.class.javax.sound.sampled.Line">
|
||
<!-- --> </a> <h3>Methods inherited from interface javax.sound.sampled.<a href="../../../javax/sound/sampled/Line.html" title="interface in javax.sound.sampled">Line</a></h3> <code><a href="../../../javax/sound/sampled/Line.html#addLineListener-javax.sound.sampled.LineListener-">addLineListener</a>, <a href="../../../javax/sound/sampled/Line.html#close--">close</a>, <a href="../../../javax/sound/sampled/Line.html#getControl-javax.sound.sampled.Control.Type-">getControl</a>, <a href="../../../javax/sound/sampled/Line.html#getControls--">getControls</a>, <a href="../../../javax/sound/sampled/Line.html#getLineInfo--">getLineInfo</a>, <a href="../../../javax/sound/sampled/Line.html#isControlSupported-javax.sound.sampled.Control.Type-">isControlSupported</a>, <a href="../../../javax/sound/sampled/Line.html#isOpen--">isOpen</a>, <a href="../../../javax/sound/sampled/Line.html#open--">open</a>, <a href="../../../javax/sound/sampled/Line.html#removeLineListener-javax.sound.sampled.LineListener-">removeLineListener</a></code></li>
|
||
</ul> </li>
|
||
</ul> </li>
|
||
</ul>
|
||
</div>
|
||
<div class="details">
|
||
<ul class="blockList">
|
||
<li class="blockList">
|
||
<!-- ============ METHOD DETAIL ========== -->
|
||
<ul class="blockList">
|
||
<li class="blockList"><a name="method.detail">
|
||
<!-- --> </a> <h3>方法详细信息</h3> <a name="open-javax.sound.sampled.AudioFormat-int-">
|
||
<!-- --> </a>
|
||
<ul class="blockList">
|
||
<li class="blockList"> <h4>open</h4> <pre>void open(<a href="../../../javax/sound/sampled/AudioFormat.html" title="class in javax.sound.sampled">AudioFormat</a> format,
|
||
int bufferSize)
|
||
throws <a href="../../../javax/sound/sampled/LineUnavailableException.html" title="class in javax.sound.sampled">LineUnavailableException</a></pre>
|
||
<div class="block">
|
||
<span>以指定的格式和建议的缓冲区大小打开行,使该行获取任何所需的系统资源并变为可操作。</span>
|
||
<p> <span>缓冲区大小以字节指定,但必须表示整数个采样帧。</span> <span>以不满足此要求的请求缓冲区大小调用此方法可能会导致IllegalArgumentException异常。</span> <span>开放行的实际缓冲区大小可能与请求的缓冲区大小不同。</span> <span>实际设置的值可以随后调用<code><a href="../../../javax/sound/sampled/DataLine.html#getBufferSize--"><code>DataLine.getBufferSize()</code></a></code>来查询。</span> </p>
|
||
<p> <span>如果此操作成功,该行将被标记为打开,并且<code><a href="../../../javax/sound/sampled/LineEvent.Type.html#OPEN"><code>OPEN</code></a></code>事件将调度到该行的监听器。</span> </p>
|
||
<p> <span>在已经打开的行上调用此方法是非法的,可能会导致<code>IllegalStateException</code> 。</span> </p>
|
||
<p> <span>请注意,一旦关闭,一些行不能重新打开。</span> <span>尝试重新打开此行将始终导致<code>LineUnavailableException</code> 。</span> </p>
|
||
</div>
|
||
<dl>
|
||
<dt>
|
||
<span class="paramLabel">参数</span>
|
||
</dt>
|
||
<dd>
|
||
<code>format</code> - 所需的音频格式
|
||
</dd>
|
||
<dd>
|
||
<code>bufferSize</code> - 所需的缓冲区大小
|
||
</dd>
|
||
<dt>
|
||
<span class="throwsLabel">异常</span>
|
||
</dt>
|
||
<dd>
|
||
<code><a href="../../../javax/sound/sampled/LineUnavailableException.html" title="class in javax.sound.sampled">LineUnavailableException</a></code> - 如果由于资源限制,该行无法打开
|
||
</dd>
|
||
<dd>
|
||
<code><a href="../../../java/lang/IllegalArgumentException.html" title="class in java.lang">IllegalArgumentException</a></code> - 如果缓冲区大小不表示采样帧的整数,或者
|
||
<code>format</code>未完全指定或无效
|
||
</dd>
|
||
<dd>
|
||
<code><a href="../../../java/lang/IllegalStateException.html" title="class in java.lang">IllegalStateException</a></code> - 如果该行已经打开
|
||
</dd>
|
||
<dd>
|
||
<code><a href="../../../java/lang/SecurityException.html" title="class in java.lang">SecurityException</a></code> - 如果由于安全限制,该行无法打开
|
||
</dd>
|
||
<dt>
|
||
<span class="seeLabel">另请参见:</span>
|
||
</dt>
|
||
<dd>
|
||
<span><a href="../../../javax/sound/sampled/SourceDataLine.html#open-javax.sound.sampled.AudioFormat-"><code>open(AudioFormat)</code></a> , <a href="../../../javax/sound/sampled/Line.html#open--"><code>Line.open()</code></a> , <a href="../../../javax/sound/sampled/Line.html#close--"><code>Line.close()</code></a> , <a href="../../../javax/sound/sampled/Line.html#isOpen--"><code>Line.isOpen()</code></a> , <a href="../../../javax/sound/sampled/LineEvent.html" title="javax.sound.sampled中的类"><code>LineEvent</code></a></span>
|
||
</dd>
|
||
</dl> </li>
|
||
</ul> <a name="open-javax.sound.sampled.AudioFormat-">
|
||
<!-- --> </a>
|
||
<ul class="blockList">
|
||
<li class="blockList"> <h4>open</h4> <pre>void open(<a href="../../../javax/sound/sampled/AudioFormat.html" title="class in javax.sound.sampled">AudioFormat</a> format)
|
||
throws <a href="../../../javax/sound/sampled/LineUnavailableException.html" title="class in javax.sound.sampled">LineUnavailableException</a></pre>
|
||
<div class="block">
|
||
<span>以指定的格式打开行,使该行获取任何所需的系统资源,并可以运行。</span>
|
||
<p> <span>该实现选择一个缓冲区大小,以字节为单位测量,但包含整数个采样帧。</span> <span>系统选择的缓冲区大小可以随后调用<code><a href="../../../javax/sound/sampled/DataLine.html#getBufferSize--"><code>DataLine.getBufferSize()</code></a></code>来查询。</span> </p>
|
||
<p> <span>如果此操作成功,则该行被标记为打开,并且<code><a href="../../../javax/sound/sampled/LineEvent.Type.html#OPEN"><code>OPEN</code></a></code>事件将发送到该行的监听器。</span> </p>
|
||
<p> <span>在已经打开的行上调用此方法是非法的,可能会导致<code>IllegalStateException</code> 。</span> </p>
|
||
<p> <span>请注意,一旦关闭,一些行不能重新打开。</span> <span>尝试重新打开此行将始终导致<code>LineUnavailableException</code> 。</span> </p>
|
||
</div>
|
||
<dl>
|
||
<dt>
|
||
<span class="paramLabel">参数</span>
|
||
</dt>
|
||
<dd>
|
||
<code>format</code> - 所需的音频格式
|
||
</dd>
|
||
<dt>
|
||
<span class="throwsLabel">异常</span>
|
||
</dt>
|
||
<dd>
|
||
<code><a href="../../../javax/sound/sampled/LineUnavailableException.html" title="class in javax.sound.sampled">LineUnavailableException</a></code> - 如果由于资源限制,该行无法打开
|
||
</dd>
|
||
<dd>
|
||
<code><a href="../../../java/lang/IllegalArgumentException.html" title="class in java.lang">IllegalArgumentException</a></code> - 如果
|
||
<code>format</code>未完全指定或无效
|
||
</dd>
|
||
<dd>
|
||
<code><a href="../../../java/lang/IllegalStateException.html" title="class in java.lang">IllegalStateException</a></code> - 如果该行已经打开
|
||
</dd>
|
||
<dd>
|
||
<code><a href="../../../java/lang/SecurityException.html" title="class in java.lang">SecurityException</a></code> - 如果由于安全限制,线路无法打开
|
||
</dd>
|
||
<dt>
|
||
<span class="seeLabel">另请参见:</span>
|
||
</dt>
|
||
<dd>
|
||
<span><a href="../../../javax/sound/sampled/SourceDataLine.html#open-javax.sound.sampled.AudioFormat-int-"><code>open(AudioFormat, int)</code></a> , <a href="../../../javax/sound/sampled/Line.html#open--"><code>Line.open()</code></a> , <a href="../../../javax/sound/sampled/Line.html#close--"><code>Line.close()</code></a> , <a href="../../../javax/sound/sampled/Line.html#isOpen--"><code>Line.isOpen()</code></a> , <a href="../../../javax/sound/sampled/LineEvent.html" title="javax.sound.sampled中的类"><code>LineEvent</code></a></span>
|
||
</dd>
|
||
</dl> </li>
|
||
</ul> <a name="write-byte:A-int-int-">
|
||
<!-- --> </a>
|
||
<ul class="blockListLast">
|
||
<li class="blockList"> <h4>write</h4> <pre>int write(byte[] b,
|
||
int off,
|
||
int len)</pre>
|
||
<div class="block">
|
||
<span>通过该源数据线将音频数据写入混频器。</span>
|
||
<span>从指定的数组读取所请求的数据字节数,从给定的偏移开始到数组,并写入数据行的缓冲区。</span>
|
||
<span>如果呼叫者尝试写入比当前可写入的数据更多的数据(见<code><a href="../../../javax/sound/sampled/DataLine.html#available--"><code>available</code></a></code> ),则该方法将阻塞,直到请求的数据量被写入。</span>
|
||
<span>即使要写入的数据量大于数据行的缓冲区大小,也适用。</span>
|
||
<span>但是,如果数据行在写入请求的数据量之前关闭,停止或刷新,则该方法不再阻塞,而是返回到目前为止写入的字节数。</span>
|
||
<p> <span>可以不受阻塞被写的字节数可使用被确定<code><a href="../../../javax/sound/sampled/DataLine.html#available--"><code>available</code></a></code>所述的方法<code>DataLine</code>接口。</span> <span>(虽然保证这个字节数可以写入而不阻塞,但不能保证写入附加数据的尝试将被阻止。)</span> </p>
|
||
<p> <span>要写入的字节数必须表示采样帧的整数,使得:</span> <br/></p>
|
||
<center>
|
||
<code>[ bytes written ] % [frame size in bytes ] == 0</code>
|
||
</center>
|
||
<br/>
|
||
<span>返回值将始终满足此要求。</span>
|
||
<span>写入表示非整数个采样帧的字节数的请求无法实现,可能会导致<code>IllegalArgumentException</code> 。</span>
|
||
</div>
|
||
<dl>
|
||
<dt>
|
||
<span class="paramLabel">参数</span>
|
||
</dt>
|
||
<dd>
|
||
<code>b</code> - 包含要写入数据线的数据的字节数组
|
||
</dd>
|
||
<dd>
|
||
<code>len</code> - 数组中有效数据的长度(以字节为单位)(换言之,要写入的请求数据量,以字节为单位)
|
||
</dd>
|
||
<dd>
|
||
<code>off</code> - 数组
|
||
<code>off</code>的偏移量(以字节为单位)
|
||
</dd>
|
||
<dt>
|
||
<span class="returnLabel">结果</span>
|
||
</dt>
|
||
<dd>
|
||
实际写入的字节数
|
||
</dd>
|
||
<dt>
|
||
<span class="throwsLabel">异常</span>
|
||
</dt>
|
||
<dd>
|
||
<code><a href="../../../java/lang/IllegalArgumentException.html" title="class in java.lang">IllegalArgumentException</a></code> - 如果请求的字节数不表示采样帧的整数,或者如果
|
||
<code>len</code>为负数
|
||
</dd>
|
||
<dd>
|
||
<code><a href="../../../java/lang/ArrayIndexOutOfBoundsException.html" title="class in java.lang">ArrayIndexOutOfBoundsException</a></code> - 如果
|
||
<code>off</code>为负数,或
|
||
<code>off+len</code>大于阵列长度
|
||
<code>b</code> 。
|
||
</dd>
|
||
<dt>
|
||
<span class="seeLabel">另请参见:</span>
|
||
</dt>
|
||
<dd>
|
||
<a href="../../../javax/sound/sampled/TargetDataLine.html#read-byte:A-int-int-"><code>TargetDataLine.read(byte[], int, int)</code></a> ,
|
||
<a href="../../../javax/sound/sampled/DataLine.html#available--"><code>DataLine.available()</code></a>
|
||
</dd>
|
||
</dl> </li>
|
||
</ul> </li>
|
||
</ul> </li>
|
||
</ul>
|
||
</div>
|
||
</div> |