The sound can create an artistic conception, triggering delusions, when combined with the virtual image, more enabled the entire world full of illusion. The sound is the foundation of multimedia technology. This is why SUN's Java Media Technology Development Team is busy preparing Java Sound 1.0 API and is included in the next version of the Java development tool library. Before the Java2 platform appears, the Java language can only handle the sound of the phone sound quality, stored as the μ-Law Au file with the sampling frequency of mono 8kHz. The Java2 platform adds support for AIFF, WAV, and three MIDI file types. The three MIDI file formats support are MIDI file type 0, MIDI file type 1, and RMF. Application Interface API1.0 provides an easy-to-use toolset that allows programmers to access the underlying synthetic and playing engine to extend the application of Java sound. Two of these important areas are to create digitized audio and musical instrument command digitization interface MIDI. Since a large number of underlying support functions are provided, the programmer can enter the output sound, control the MIDI device, and can query the system operation. Sound file type Introduction The main sound file type is as follows: AU - (Extension is AU or SND) Suitable for short sound files, the general file format for Solaris and next generation machines, is also the standard audio format of the Java platform. The three typical audio formats used by the AU type file are: 8-bit μ-Law type (usually sampling frequency is 8kHz), 8-bit linear type, and 16-bit linear type. WAV - (extension WAV) is developed by Microsoft and IBM, and support for WAV has been added to Windows 95 and extends to Windows 98. WAV files can store various formats including μ-Law, A-Law and PCM ( Linear) data. They can be played by all Windows applications that support sound. AIFF - (Extension AIF or IEF) Audio Interchange File Format is a standard audio file format shared for Macintosh Computers and Silicon Graphics (SGI) computers. AIFF and AIFF-C are almost the same, except for the latter to support, for example, μ-Law and IMA ADPCM type compression. MIDI - (Extension MID) Musical instrument digital interface MIDI is a standard recognized for music manufacturing, primarily to control equipment such as synthesizer and sound card. The MIDI file does not contain digital audio sampling, but includes a series of instructions that control the synthesis of the musical sequence from different instruments. Some MIDI files contain additional instructions to program a variety of synthetic settings. Most synthesizers support MIDI standards, so music created on a synthesizer can play on another. Computers with MIDI interfaces can manipulate MIDI data to generate new music or sound effects. For example, a complete music work can be converted into a new form via a software-driven command. The Java Sound Engine supports two MIDI file types: MIDI type 0 file - contains only one sequence, all related instrument parts are included on the same logic "track". MIDI Type 1 File - Contains multiple "track" such that different instruments are logically separated, so that the operation and reunion of the sound is easier. The RMF - (extension is RMF) Mixed music format is a hybrid file type designed by Beatnik, and MIDI and audio sampling are packaged together by interactive settings. RMF is like a container of all music related files. RMF also includes support for detailed file instructions on copyright. The RMF file can contain multiple works that are stored as MIDI types or audio sampling types by different artists, each with associated copyright information.
The selection of sound engines In 1997, Sun's Java Media Development Group tried to find a way to enhance sound processing capabilities and provide a solid platform for future. According to the Java Media Development Group, Michael Bundschuh said, "We want a very high quality play engine to handle all the operations from the eight μ-Law level until the CD quality sound. We want to easily cross all platforms, such as Solaris platform, Windows, Mac, and others. We also want to be highly developed with MIDI capabilities that can span different platforms. For the above purposes, reasonable choice is Beatnik's audio engine (since the time is headspace.) "SUN gets the audio of Beatnik The engine uses the license as the basis of the Java sound application interface API. Thomas Dolby Robertson-Beatnik Introduction Before the 1990s, Thomas Dolby Robertson's career is fully in music. "She uses science to illuminate me" in 1982, it is an early MTV masterpiece. In the 1980s, he continued to compose and recording, using a non-structured music production software. But at 1990, he started thinking to do some work ability to improve the music production capacity by demonstrating the virtual reality of the Guggenheim Museum. "I was in the shoulder of the C programmer, and I suddenly realized that I made a lot of work for doing records, but I didn't do anything for the interaction of performance." With this idea, Robertson was established in 1992. HEADSPACE, hire the moonlight composition to help achieve his views. Headspace became the company in 1996, now known as Beatnik. The Java Sound Audio Engine Java sound engine creates multimedia, considering the game design and releases Web content. With standard MIDI files, RMF files, and / or sampling from any source, the engine will play music or manufacturing sound effects while using CPUs as little as possible. It provides complete playback control, with the ability to mix the sound and respond to the user's input in real time. The Java sound engine is a software MIDI synthesizer, sampling player, and a 16-bit stereo hybrid. It supports mixing until 64-bit stereo MIDI sound and audio sampling. It directly supports MIDI type 0 and type 1 files and synthesis from 8-bit devices to 16-bit instruments. The engine supports all universal MIDI controllers and includes features such as echo processing, LFO (control filters or stereo devices), as well as ADSR envelopes (shaping samples when playing). That is, the Java sound engine also takes no more than 30% of the CPU time on a 90MHz Pentium computer. It can also make it more efficient by selectively disabling unwanted features. In addition, it released the rich content stored in the compressed RMF music file. Thomas Dolby Robertson "She illuminates me", a 7-minute 21 second song, such as the file for the CD sound quality occupies 70M byte space. If it is stored in RMF format only about 636 kB, it is reduced by 120: 1, and does not tender quality. For more information about Beatnik, see Beatnik's Web Site.
The Java platform sound is in JDK 1.0.x and JDK 1.1.x, the AUDIOCLIP interface provides the following functions: l AudioClip interface playback loop stop recovery and play the simpler method to play the sound of the APPLET class. Method. Calling the Play () method has the following two ways: play () - with a parameter, a URL object, loading and playing the sound piece stored at the URL. Play () - With two parameters, basic URLs and folder path names, load and play sound files. The first parameter is often a call to getCodeBase () or getDocumentBase (). The following code segmentation example illustrates the method of directly playing Hello.au.au. The AU file is located in the same folder or directory. Play (GetCodeBase (), "Hello.au"); Play () Once you are called immediately start recovery and play sound. If the sound file cannot be found, there will be no error information, just silence. Start and stop the sound file, or loop play, you must load it into the AudioClip object with the Applet's GetAudioClip method, similar to the parameters of the above () method, the GetAudioclip method uses one or two parameters as the indication of the playback. The first or unique parameter is the URL parameter, used to indicate the location of the sound file, the second parameter is the folder path pointer. The following code line example will now describe the loading sound file into the cliphedu: audioclip co = getAudioClip (getcodebase (), "horns.wav"); getaudioclip () method can only be called within the applet. As Java2 introduces, the application can also load the sound file with the Newaudioclip method of the Applet class. The former example can rewrite the following for Java applications: audioclip co = newaudioclip ("HORns.wav"); after you have created an AudioClip object, you can call Play (), loop (), and stop () method. If the getaudioclip or newaudioclip method does not find the specified sound file, the value of the Audioclip object will be empty. Trying to play an empty object will result in an error, so the standard process is first detected. Next is a complete programming example, the program will generate an applet, which will play Flute HRN MRMBA.Au music sample when the mouse is pressed within the applet range. This Au sample file is in the same directory or folder.
import java.applet *;. import java.awt.event *;. public class PlayAudio extends Applet implements MouseListener {AudioClip audio; public void init () {audio = getAudioClip (getDocumentBase (), "flute hrn mrmba.au" ); addMouseListener (this);!} public void mousePressed (MouseEvent evt) {if (audio = null) audio.play ();} public void mouseEntered (MouseEvent me) {} public void mouseExited (MouseEvent me) {} public void MouseClicked (MouseEvent Me) {} PUBLIC VOID MOUSERELEASED (MouseEvent Me) {}} Note: MouseDown () method is indeed part of the Java 1.0 event model in many Java2 technology books. This method is used to have a certain risk because the method may not be supported in the future. Combining MouseListener and MousePressed in Java2 platform is preferred. API 1.0-Quality Leap Note: The following note is based on the earlier version 0.86 of Java API. Although most of the objects and concepts discussed here are consistent with the past, some changes may exist because the API version has terminated. Java Sound 1.0 API defines a complete set of basic underlying audio processing functions for the Java platform. It provides the following interfaces to: audio capture and play IDi synthesis and serialization These two main functional modules are provided in their respective packages. Javax.media.sound.sampled-This package explicitly illustrates the interface of capture, mix, and playback digital sampling audio. Javax.media.sound.midi- This package provides interfaces that MIDI synthesis, serialization, and event transfer. The Java 1.0 API has the following features: Digital audio frequency capture - data capture from the input source such as the microphone. Tone and replay - mix the sound of various input sources and replay. System and Coding - Adjusting Gain, Positioning, Echo Processing, etc., and format conversion. State and its prompt - When replay start and end, the device is opened or closed and other related events will receive events. Synthesis for MIDI's support MIDI message-switched message (open note, shutting down note, etc.) - loaded from MIDI data and generates sound. Serialization - Load a MIDI sequence, start and stop playback, and adjust the rhythm. Toolware Input Output - Read and write universal audio files such as WAV, AIFF and MIDI - Query systems to get information about components and devices; install or cancel coding, file analyzers, and devices.
Digital Audio Channel Kara Kytle, Java Sound API Director Engineer and System Designer said: "Channel is the basic functional component in the audio pipe." Implementing the class of the Channel interface represents an element of the "pipe", such as a hardware device, a sound synthesizer, or a single audio stream. InputChannel and OutputChannel inherit the Channel, which is used to read the captured data and to write data. The sub-interface CLIP supports cyclic play and repositioning of pre-installed audio data. Device represents any hardware or software devices for capture, play or mix audio. When a Channel is turned on, it retains system resources for yourself, and when it ends, these resources are released to other applications and objects. Use the isopen () method to query Channel whether it is open or off. The processing of data is typically started by sub-interface methods such as a READ () method, which is described in the INPUTCHANNEL interface description (see the Java Sound API manual). The processing method makes the Channel are in the state where the audio data is entered or output. Use the isactive method to identify if the Channel is in this state. By calling the PAUSE () method, the channel can be paused, this state can be discriminated by the ispaused () method. When the channel is suspended, there are three options: retention data (default), discard the data in the inner buffer with a flush () method, or use the DRAIN () method to make the data in the internal cache immediately processed. Objects can be registered in advance, so that it can receive advertisement information whenever the channel state changes. The registration object must implement the Channel.Listener interface, which contains only one method update (). This method will be called when Channel opens, ends, start, and stops. START or STOP events will be generated when Channel starts or stops activity and starting or stopping capturing data. Input Channel INPUTCHANNEL is the source of the captured audio data. This interface provides a method to read the captured data from the InputChannel buffer, and determine the currently readable amount of data. If the application tries to read too much data, the reading method is blocked until the required read data is reached. Output channel OutputChannel receives audio data for playback. This interface provides a method that writes the data to be played into the buffer of OutputChannel, and can determine the amount of data that the channel is uninterruptible. If the application tries to write excessive data, the reading method blocks until there is enough data. The clip CLIP interface represents a special channel that can be loaded into audio data before playing. Since the data is pre-installed, the Clip can support continuous queries, loop play, and reposition playback.
The device DEVICE interface is a class that represents the audio device. The audio device can be shared or exclusive system resources, which can be hardware, or software, but also based on both. It can be repeatedly opened and closed, which can often explain its intrinsic characteristics and supported audio formats. At the same time, it also provides an information object to describe the device. Java Sound API further describes three devices sub-interfaces: The InputDevice InputDevice interface provides a method GetInputChannel to get an InputChannel object, capture readable audio data from it. The OutputDevice OutputDevice interface provides a method GetputPutChannel to get an OutputChannel object, and audio data can be written to the output channel and play it. Mixer Mixer supports multiple InputChannel and / or CLIPs. In addition, it provides a query method that can be obtained from the number of channels it supports, which also provides a method of supporting synchronous pause and awakening multiple channel playback. Control channels and audio ports (such as speakers and microphones) typically support a set of controls such as gain and positioning. By passing it as a parameter to getControl () method, the channel object and port object of Java Sound API can get a special control. Encoder CODECs can encode and decode audio data, allow conversion between different formats and codes. The Java Sound API provides advanced interfaces for these conversions through the Audiosystem class. If a special audio stream is given, the application queries the audio system to find the corresponding conversion, resulting in an audio stream in the specified format. File and streaming streams are input streams associated with audio data format and data length, and the file stream is an input stream associated with file type and data length. The Java Sound API provides an interface between the conversion between the audio file and the audio stream in the Audiosystem class. Query and Access the Installation Components Audiosystem class acts as a role of the sampling audio system resource entry. This class allows programmers to query and access input devices, output devices, and installed mixers. In addition, AUDIOSYSTEM contains many methods of conversion between different audio data formats. It also provides some methods such that the input channel or output channel is directly obtained without the direct operation of the device. System Configuration - Service Provider Interface (SPI) The configuration of the sampling audio system is done by javax.media.sound.sampled.spi package. Through the AudioConfig class, you can install or uninstall the device in the system, and the default state can be established. Service providers can want to provide and install their own encoders and analyzers. This package provides a mechanism to complete this function. Midi javax.media.sound.midi package describes the MIDI event transfer, synthesis, and serialization interface. The main concepts used in the package are described below. Transfer the basic MIDI transfer interface is MIDIDEVICE. All devices provide a method for the pre-supporting mode and query the current mode. The device supports the listener, you can listen to various events such as opening and closing the event, and there is an information object to describe the device status. Typically, the device is one of the transmitters or receivers of the MIDI event. The transmitter interface provides some ways to set and query the receiver, which receives the MIDI event transmitted by the transmitter. The receiver provides a method for receiving the MIDI event. The basic MIDIEVENT object is an event type, data length, and status through a message. It also provides accurate timing signals for devices involving MIDI timing, such as sequencer.
The synthesizer synthesizer interface is a special type of receiver that generates sound. It also provides some ways to manage sound libraries and instruments. In addition, the synthesizer can support a set of global non-MIDI controls such as gain and positioning. It also provides access to a group of MIDI channels, in fact, the sound is generated by these channels. The Midichannel interface provides a set of methods to express public MIDI sound messages such as Noteon, Noteoff, and ControlChange. Also supports queries for current channel status. The serialization Sequencer interface inherits MIDIDEVICE, which provides a method of completing basic MIDI serialization operations. The sequencer can load and play a sequence, query, and set the rhythm, and control the master from synchronization. An application can also notify yourself by registering that you will notify yourself when processing device units and controller events. Files and serialized sequences represent a MIDI sequence from one or more tracks and related timing information. A track object contains a series of plus time tagged MIDI events. Java Sound API provides advanced interfaces for transitions between MIDI files and serialized objects in the MIDISystem class. Query and access the installed component MIDISystem class act as the role of the MIDI music system entry. It provides information about related devices and access it, including transmitters, receivers, synthesizers, and sequencers. It also provides access to the SoundBank object. System Configuration - Service Provider Interface (SPI) MIDI system is completed by javax.media.sound.midi.spi package. With the MIDICONFIG class, the device can be installed in the system or uninstall it from it, and the default state can be established. Service providers can want to provide and install their own files and sound library analyzers. The SPI package includes the mechanism of completing this function. Let us now see what can do with these classes and methods. Please check it carefully. The TOYSYNTH application TOYSYNTH application tests the way to access the Java sound API, mainly by providing a range of device settings, including MIDI channel selection, volume control, stereo positioning, echo processing, and other options. You can play the song using the specified device by tapping the keyboard, and these devices are all achieved through the Java sound engine. Complete ToySynth.java code sample. Downloading the Java Sound API can get an exemplary application and its source code.