Sound — An API for playing sound data from applications.

https://docs.oracle.com/javase/tutorial/sound/index.html

 

The Java Sound API is a low-level API for effecting and controlling the input and output of sound media, including both audio and Musical Instrument Digital Interface (MIDI) data. The Java Sound API provides explicit control over the capabilities normally required for sound input and output, in a framework that promotes extensibility and flexibility.

Java Sound API是一个底层API,用于实现和控制声音媒体的输入和输出,包括音频和乐器数字接口(MIDI)数据。 Java Sound API在一个促进可扩展性和灵活性的框架中提供对声音输入和输出通常所需功能的显式控制。

 

The Java Sound API fulfills the needs of a wide range of application developers. Potential application areas include:

  • Communication frameworks, such as conferencing and telephony
  • End-user content delivery systems, such as media players and music using streamed content
  • Interactive application programs, such as games and Web sites that use dynamic content
  • Content creation and editing
  • Tools, toolkits, and utilities

Java Sound API满足了各种应用程序开发人员的需求。 潜在的应用领域包括:

  • 通信框架,例如会议和电话
  • 最终用户内容传送系统,例如媒体播放器和使用流内容的音乐
  • 交互式应用程序,例如使用动态内容的游戏和网站
  • 内容创建和编辑
  • 工具,工具包和实用程序

 

The Java Sound API provides the lowest level of sound support on the Java platform. It provides application programs with a great amount of control over sound operations, and it is extensible. For example, the Java Sound API supplies mechanisms for installing, accessing, and manipulating system resources such as audio mixers, MIDI synthesizers, other audio or MIDI devices, file readers and writers, and sound format converters. The Java Sound API does not include sophisticated sound editors or graphical tools, but it provides capabilities upon which such programs can be built. It emphasizes low-level control beyond that commonly expected by the end user.

Java Sound API在Java平台上提供最低级别的声音支持。 它为应用程序提供了对声音操作的大量控制,并且是可扩展的。 例如,Java Sound API提供了安装,访问和操作系统资源的机制,如音频混合器,MIDI合成器,其他音频或MIDI设备,文件读取器和写入器以及声音格式转换器。 Java Sound API不包含复杂的声音编辑器或图形工具,但它提供了构建此类程序的功能。 它强调低级控制,超出最终用户通常期望的控制。

 

The Java Sound API includes support for both digital audio and MIDI data. These two major modules of functionality are provided in separate packages:

  • javax.sound.sampled – This package specifies interfaces for capture, mixing, and playback of digital (sampled) audio.
  • javax.sound.midi – This package provides interfaces for MIDI synthesis, sequencing, and event transport.

Java Sound API包括对数字音频和MIDI数据的支持。 这两个主要功能模块在单独的包中提供:

  • javax.sound.sampled - 此包指定用于捕获,混合和回放数字(采样)音频的接口。
  • javax.sound.midi - 此包提供MIDI合成,排序和事件传输的接口。

 

Two other packages permit service providers (as opposed to application developers) to create custom software components that extend the capabilities of an implementation of the Java Sound API:

另外两个包允许服务提供者(而不是应用程序开发人员)创建自定义软件组件,以扩展Java Sound API实现的功能:

  • javax.sound.sampled.spi
  • javax.sound.midi.spi

 

This page introduces the sampled-audio system, the MIDI system, and the SPI packages. Each package is then discussed in greater detail later in the tutorial.

本页介绍了采样音频系统,MIDI系统和SPI包。 然后在本教程的后面更详细地讨论每个包。

 


Note: 

There are other Java platform APIs that also have sound-related elements. The Java Media Framework API (JMF) is a higher-level API that is currently available as a Standard Extension to the Java platform. JMF specifies a unified architecture, messaging protocol, and programming interface for capturing and playing back time-based media. JMF provides a simpler solution for basic media-player application programs, and it enables synchronization between different media types, such as audio and video. On the other hand, programs that focus on sound can benefit from the Java Sound API, especially if they require more advanced features, such as the ability to carefully control buffered audio playback or directly manipulate a MIDI synthesizer. Other Java APIs with sound aspects include Java 3D and APIs for telephony and speech. An implementation of any of these APIs might use an implementation of the Java Sound API internally, but is not required to do so.

注意:

还有其他Java平台API也具有与声音相关的元素。 Java Media Framework API(JMF)是一种更高级别的API,目前可用作Java平台的标准扩展。 JMF指定用于捕获和回放基于时间的媒体的统一架构,消息传递协议和编程接口。 JMF为基本的媒体播放器应用程序提供了一种更简单的解决方案,它可以实现不同媒体类型(如音频和视频)之间的同步。 另一方面,专注于声音的程序可以从Java Sound API中受益,特别是如果它们需要更高级的功能,例如能够仔细控制缓冲的音频播放或直接操作MIDI合成器。 其他具有声音方面的Java API包括用于电话和语音的Java 3D和API。 任何这些API的实现都可能在内部使用Java Sound API的实现,但不是必须这样做。


 

What is Sampled Audio?

The javax.sound.sampled package handles digital audio data, which the Java Sound API refers to as sampled audio. Samples are successive snapshots of a signal. In the case of audio, the signal is a sound wave. A microphone converts the acoustic signal into a corresponding analog electrical signal, and an analog-to-digital converter transforms that analog signal into a sampled digital form. The following figure shows a brief moment in a sound recording.

什么是Sampled Audio?

javax.sound.sampled包处理数字音频数据,Java Sound API将其称为采样音频。 样本是信号的连续快照。 在音频的情况下,信号是声波。 麦克风将声学信号转换为相应的模拟电信号,并且模拟 - 数字转换器将该模拟信号转换为采样的数字形式。 下图显示了录音中的短暂时刻。

 

This graph plots sound pressure (amplitude) on the vertical axis, and time on the horizontal axis. The amplitude of the analog sound wave is measured periodically at a certain rate, resulting in the discrete samples (the red data points in the figure) that comprise the digital audio signal. The center horizontal line indicates zero amplitude; points above the line are positive-valued samples, and points below are negative. The accuracy of the digital approximation of the analog signal depends on its resolution in time (the sampling rate) and its quantization, or resolution in amplitude (the number of bits used to represent each sample). As a point of reference, the audio recorded for storage on compact discs is sampled 44,100 times per second and represented with 16 bits per sample.

该图描绘了垂直轴上的声压(振幅)和水平轴上的时间。 以一定速率周期性地测量模拟声波的幅度,从而产生包括数字音频信号的离散样本(图中的红色数据点)。 中心水平线表示零幅度; 线上方的点是正值样本,下面的点是负数。 模拟信号的数字近似的精确度取决于其在时间上的分辨率(采样率)及其量化,或幅度分辨率(用于表示每个样本的比特数)。 作为参考,记录存储在光盘上的音频每秒采样44,100次,每个采样16位。

 

The term "sampled audio" is used here slightly loosely. A sound wave could be sampled at discrete intervals while being left in an analog form. For purposes of the Java Sound API, however, "sampled audio" is equivalent to "digital audio."

这里使用术语“采样音频”略微松散。 可以以离散的间隔对声波进行采样,同时保持模拟形式。 但是,出于Java Sound API的目的,“采样音频”等同于“数字音频”。

 

Typically, sampled audio on a computer comes from a sound recording, but the sound could instead be synthetically generated (for example, to create the sounds of a touch-tone telephone). The term "sampled audio" refers to the type of data, not its origin.

通常,计算机上的采样音频来自录音,但声音可以通过合成生成(例如,创建按键式电话的声音)。 术语“采样音频”是指数据的类型,而不是其来源。

 

The Java Sound API does not assume a specific audio hardware configuration; it is designed to allow different sorts of audio components to be installed on a system and accessed by the API. The Java Sound API supports common functionality such as input and output from a sound card (for example, for recording and playback of sound files) as well as mixing of multiple streams of audio. Here is one example of a typical audio architecture:

Java Sound API不承担特定的音频硬件配置; 它旨在允许在系统上安装不同种类的音频组件并由API访问。 Java Sound API支持常见功能,例如声卡的输入和输出(例如,用于录制和回放声音文件)以及混合多个音频流。 以下是典型音频架构的一个示例:

 

In this example, a device such as a sound card has various input and output ports, and mixing is provided in the software. The mixer might receive data that has been read from a file, streamed from a network, generated on the fly by an application program, or produced by a MIDI synthesizer. The mixer combines all its audio inputs into a single stream, which can be sent to an output device for rendering.

在该示例中,诸如声卡的设备具有各种输入和输出端口,并且在软件中提供混合。 混音器可能接收从文件读取,从网络流式传输,应用程序即时生成或由MIDI合成器生成的数据。 混音器将其所有音频输入组合成单个流,可以将其发送到输出设备进行渲染。

 

What is MIDI?

The javax.sound.midi package contains APIs for transporting and sequencing MIDI events, and for synthesizing sound from those events.

什么是MIDI?

javax.sound.midi包中包含用于传输和排序MIDI事件以及合成来自这些事件的声音的API。

 

Whereas sampled audio is a direct representation of a sound itself, MIDI data can be thought of as a recipe for creating a sound, especially a musical sound. MIDI data, unlike audio data, does not describe sound directly. Instead, it describes events that affect the sounds (or actions) performed by a MIDI-enabled device or instrument, such as a synthesizer. MIDI data is analogous to a graphical user interface's keyboard and mouse events. In the case of MIDI, the events can be thought of as actions upon a musical keyboard, along with actions on various pedals, sliders, switches, and knobs on that musical instrument. These events need not actually originate with a hardware musical instrument; they can be simulated in software, and they can be stored in MIDI files. A program that can create, edit, and perform these files is called a sequencer. Many computer sound cards include MIDI-controllable music synthesizer chips to which sequencers can send their MIDI events. Synthesizers can also be implemented entirely in software. The synthesizers interpret the MIDI events that they receive and produce audio output. Usually the sound synthesized from MIDI data is musical sound (as opposed to speech, for example). MIDI synthesizers are also capable of generating various kinds of sound effects.

虽然采样音频是声音本身的直接表示,但MIDI数据可以被认为是用于创建声音的配方,尤其是音乐声音。与音频数据不同,MIDI数据不直接描述声音。相反,它描述了影响由启用MIDI的设备或乐器(例如合成器)执行的声音(或动作)的事件。 MIDI数据类似于图形用户界面的键盘和鼠标事件。在MIDI的情况下,事件可以被认为是对音乐键盘的动作,以及对该乐器上的各种踏板,滑块,开关和旋钮的动作。这些事件实际上不需要硬件乐器;它们可以用软件模拟,也可以存储在MIDI文件中。可以创建,编辑和执行这些文件的程序称为顺控程序。许多计算机声卡包括MIDI可控音乐合成器芯片,音序器可以向其发送其MIDI事件。合成器也可以完全用软件实现。合成器解释它们接收的MIDI事件并产生音频输出。通常,从MIDI数据合成的声音是音乐声音(例如,与语音相反)。 MIDI合成器还能够产生各种声音效果。

 

Some sound cards include MIDI input and output ports to which external MIDI hardware devices (such as keyboard synthesizers or other instruments) can be connected. From a MIDI input port, an application program can receive events generated by an external MIDI-equipped musical instrument. The program might play the musical performance using the computer's internal synthesizer, save it to disk as a MIDI file, or render it into musical notation. A program might use a MIDI output port to play an external instrument, or to control other external devices such as recording equipment.

某些声卡包括MIDI输入和输出端口,可以连接外部MIDI硬件设备(如键盘合成器或其他乐器)。 从MIDI输入端口,应用程序可以接收由配备有外部MIDI的乐器生成的事件。 该程序可以使用计算机的内部合成器播放音乐表演,将其作为MIDI文件保存到磁盘,或将其呈现为乐谱。 程序可能使用MIDI输出端口播放外部乐器,或控制其他外部设备,如录音设备。

 

The following diagram illustrates the functional relationships between the major components in a possible MIDI configuration based on the Java Sound API. (As with audio, the Java Sound API permits a variety of MIDI software devices to be installed and interconnected. The system shown here is just one potential scenario.) The flow of data between components is indicated by arrows. The data can be in a standard file format, or (as indicated by the key in the lower right corner of the diagram), it can be audio, raw MIDI bytes, or time-tagged MIDI messages.

下图说明了基于Java Sound API的可能MIDI配置中主要组件之间的功能关系。 (与音频一样,Java Sound API允许安装和连接各种MIDI软件设备。此处显示的系统只是一种可能的情况。)组件之间的数据流用箭头表示。 数据可以采用标准文件格式,或者(如图中右下角的键所示),可以是音频,原始MIDI字节或带时间标记的MIDI信息。

 

In this example, the application program prepares a musical performance by loading a musical score that's stored as a standard MIDI file on a disk (left side of the diagram). Standard MIDI files contain tracks, each of which is a list of time-tagged MIDI events. Most of the events represent musical notes (pitches and rhythms). This MIDI file is read and then "performed" by a software sequencer. A sequencer performs its music by sending MIDI messages to some other device, such as an internal or external synthesizer. The synthesizer itself may read a soundbank file containing instructions for emulating the sounds of certain musical instruments. If not, the synthesizer will play the notes stored in the MIDI file using whatever instrument sounds are already loaded into it.

在该示例中,应用程序通过将存储为标准MIDI文件的乐谱加载到盘(图的左侧)来准备音乐演奏。 标准MIDI文件包含轨道,每个轨道都是带时间标记的MIDI事件列表。 大多数事件代表音符(音高和节奏)。 读取该MIDI文件,然后由软件定序器“执行”。 音序器通过将MIDI消息发送到某些其他设备(例如内部或外部合成器)来执行其音乐。 合成器本身可以读取包含用于模拟某些乐器的声音的指令的音库文件。 如果没有,合成器将使用已加载到其中的任何乐器声音播放存储在MIDI文件中的音符。

 

As illustrated, the MIDI events must be translated into raw (non-time-tagged) MIDI before being sent through a MIDI output port to an external MIDI instrument. Similarly, raw MIDI data coming into the computer from an external MIDI source (a keyboard instrument, in the diagram) is translated into time-tagged MIDI messages that can control a synthesizer, or that a sequencer can store for later use.

如图所示,MIDI事件必须在通过MIDI输出端口发送到外部MIDI乐器之前转换为原始(非时间标记)MIDI。 类似地,从外部MIDI源(图中的键盘乐器)进入计算机的原始MIDI数据被转换为时间标记的MIDI消息,可以控制合成器,或者音序器可以存储以供以后使用。

 

Service Provider Interfaces

The javax.sound.sampled.spi and javax.sound.midi.spi packages contain APIs that let software developers create new audio or MIDI resources that can be provided separately to the user and "plugged in" to an existing implementation of the Java Sound API. Here are some examples of services (resources) that can be added in this way:

服务提供者接口

javax.sound.sampled.spi和javax.sound.midi.spi包中包含的API允许软件开发人员创建新的音频或MIDI资源,这些资源可以单独提供给用户并“插入”Java Sound的现有实现API。 以下是可以通过这种方式添加的服务(资源)的一些示例:

 

  • An audio mixer
  • A MIDI synthesizer
  • A file parser that can read or write a new type of audio or MIDI file
  • A converter that translates between different sound data formats
  • 音频混音器
  • MIDI合成器
  • 一种文件解析器,可以读取或写入新类型的音频或MIDI文件
  • 转换器,可在不同的声音数据格式之间进行转换

 

In some cases, services are software interfaces to the capabilities of hardware devices, such as sound cards, and the service provider might be the same as the vendor of the hardware. In other cases, the services exist purely in software. For example, a synthesizer or a mixer could be an interface to a chip on a sound card, or it could be implemented without any hardware support at all.

在某些情况下,服务是硬件设备(如声卡)功能的软件接口,服务提供商可能与硬件供应商相同。 在其他情况下,服务纯粹存在于软件中。 例如,合成器或混合器可以是声卡上芯片的接口,或者可以在没有任何硬件支持的情况下实现。

 

An implementation of the Java Sound API contains a basic set of services, but the service provider interface (SPI) packages allow third parties to create new services. These third-party services are integrated into the system in the same way as the built-in services. The AudioSystem class and the MidiSystem class act as coordinators that let application programs access the services explicitly or implicitly. Often the existence of a service is completely transparent to an application program that uses it. The service-provider mechanism benefits users of application programs based on the Java Sound API, because new sound features can be added to a program without requiring a new release of the JDK or runtime environment, and, in many cases, without even requiring a new release of the application program itself.

Java Sound API的实现包含一组基本服务,但服务提供者接口(SPI)包允许第三方创建新服务。 这些第三方服务以与内置服务相同的方式集成到系统中。 AudioSystem类和MidiSystem类充当协调器,允许应用程序显式或隐式地访问服务。 通常,服务的存在对于使用它的应用程序是完全透明的。 服务提供程序机制使基于Java Sound API的应用程序用户受益,因为可以将新的声音功能添加到程序中而无需新版本的JDK或运行时环境,并且在许多情况下甚至不需要新的 发布应用程序本身。

转载于:https://my.oschina.net/u/3134761/blog/2986841

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值