Java Sound API是javaSE平台提供底层的(low-level)处理声音接口。
例外,java也提供了简单的实用的高层媒体接口(higher-level) - JMF(Java Media Framework)。
Java Sound API 将需要处理的数字音频分为:simpled-audio和midi,
分别提供Package来处理它们:
javax.sound.simpled
javax.sound.midi
同时SOUND API还提供了第三方的扩展接口:
javax.sound.simpled.spi
javax.sound.midi.spi
*注:spi : service provider interface
Sampled Audio
采样音频(simpled-audio)不仅包含从模拟信号采样来的数字音频,还包括电脑合成的。
称作digital-audio更为合适。
为了能够让设备播放采样声音,程序需要处理 audio input, output device, audio data buffers。
还有混音处理(mix multiple streams of audio into one stream)。
SOUND API 可以使用3种方式传输声音数据:stream, buffered fashion, in-memory unbuffered fashion。
第三种方式适合数据量不大,能够一次载入的所有数据的情形。这样,声音的响应较快,循环和随机定位也会很简单。
使用SOUND API播放声音至少需要3样东西:
lformatted audio data,
la mixer,
la line.
Mixer
调音台
technically the Mixer itself is also a kind of Line
Line
音频数据管道。
Clip extends Line
将需要播放的音频数据装载进来。
preloads audio data from a sound file into clips
A Clip is a data line into which audio data can be loaded prior to playback. Because the data is
pre-loaded rather than streamed, the clip‘s duration is known before playback, and you can choose any
starting position in the media. Clips can be looped, meaning that upon playback, all the data between two
specified loop points will repeat a specified number of times, or indefinitely.
SourceDataLine extends Line
accept real-time stream of audio data
feed audio to the Mixer
A SourceDataLine receives audio data for playback. It provides methods for writing data to the
source data line‘s buffer for playback, and for determining how much data the line is prepared to receive
without blocking.
TargetDataLine
A TargetDataLine receives audio data from a mixer. Commonly, the mixer has captured audio data
from a port such as a microphone; it might process or mix this captured audio before placing the data in
the target data line‘s buffer. The Target