Categories: Unity, C #, VS2015
Date Created: 2016-04-05 I. INTRODUCTION
The choice of audio file resources should be based on the principle of smooth, trouble-free operation. The commonly used audio files are listed below.
. AIFF is converted to uncompressed audio when importing, which is best for short sound effects.
. WAV is converted to uncompressed audio at import, which is best suited for short sound effects.
. The MP3 is converted to Ogg Vorbis when importing, and is best suited for longer music tracks.
. OGG compressed audio format, most suitable for longer music tracks.
When you import an audio file into unity, you can select its final format and push it into a stereo channel or mono.
To access the Import settings (import Settings), select the audio clip in the project view, and then look for the audio importer in the viewer (Inspector). Here, you can compress the clip into the OGG Vorbis format and push it into mono or stereo playback, and then fine-tune other options, such as making very important decompress on load settings.
After you import the audio file, you can add the audio file to the game object (Gameobject). When you drag an audio file into the game object (Gameobject), the audio file will automatically create an audio source component ("Voice source Component"). Ii. Description of Details
When using audio files, you need to be aware of the following details.
1, native (Native) and compression (compressed)
The audio in Unity can be native (Native) or Compressed (compressed) audio. Unity supports most common formats. The default mode is native (Native), which means that when you import audio data from the original file, you do not make any changes to it. However, Unity can also compress audio data by enabling only the compression (compressed) option in the importer when importing.
The differences between native (Native) and compression (compressed) modes are as follows:
- Native (Native): native (such as. wav files,. aiff files, and so on) for short sound effects. This type of audio data is large in size, but does not need to be decoded at run time.
- Compression (compressed): The volume of audio data is small, but the data needs to be decompressed at run time, which results in processing overhead. Unity will encode the audio as Ogg Vorbis (mac/pc/console (consoles)) or MP3 (mobile platform), depending on the location.
If you want the best sound quality, provide audio in an uncompressed format, such as WAV or AIFF (including PCM data), and let Unity encode you. If you are targeting only Mac and PC platforms (both standalone and web player), importing Ogg Vorbis files will not degrade quality. However, when importing on a mobile platform, recoding the Ogg Vorbis and MP3 files to a MP3 file can have a slight effect on the sound quality.
2. Audio source
The AUD audio source plays the audio clip in the scene. If the audio clip is a three-dimensional fragment, the source plays at a given position and is attenuated with distance. Audio can be spread between speakers (Spread) and deformed between three dimensions and two-dimensional (translation level (Panlevel)). This can be controlled with a distance using the attenuation curve (falloff curve). In addition, if the listener is in one or more reverb regions (Reverb zone), the reverb is applied to the source. (Pro edition only) you can apply individual filters to each audio source for an even richer audio experience.
The following describes the properties and functions associated with an audio source.
- Audio clip: A reference to the sound clip file that will play.
- Mute (Mute): If enabled, the sound plays, but it is muted.
- Bypass effect (Bypass effects): This is a filter effect that is used to quickly "bypass" applied to the audio source. A convenient way to turn all effects off/on.
- Playback on wakeup (play on Awake): If enabled, the sound will start playing when the scene starts. If disabled, you need to use the Play () command in your script to start it.
- Loop: Enable this to enable the audio clip to loop at the end.
- Priority: Determines the priority between all audio sources that this audio source is co-existing in the scene. (priority): 0 = most important. 256 = least important. Default = 128. )。 Use 0 for music tracks to prevent it from being swapped out occasionally.
- Volume (Volume): The level of sound at a world coordinate unit (one metre) apart from the audio Listener.
- Pitch (Pitch): The amount of tonal variation that is formed as a result of the slow/accelerated audio clip. The value 1 is the normal playback speed.
- Three-dimensional sound settings (3D voice Settings): The audio clip is a three-dimensional sound when applied to the audio source settings.
- Pan level: Sets the extent to which the three-dimensional engine affects the audio source.
- Scatter (Spread): Sets the spread angle of the speaker space relative to the three-dimensional or multichannel sound.
- Doppler levels (Doppler level): Determines the amount of Doppler effect applied to this audio source (if set to 0, no effect is applied).
- Minimum distance (min Distance): Within the minimum distance (mindistance), the sound remains at the highest possible volume. At the minimum distance (mindistance), it starts to decay. Increasing the minimum distance (mindistance) of a sound makes it "louder" in three-dimensional world coordinates, reducing it to "quieter" in three-dimensional world coordinates.
- Maximum distance (max Distance): The distance at which the sound stops attenuation. Beyond this point, it remains at the maximum distance from the Listener (maxdistance) and no longer decays.
- Roll-down mode (rolloff modes): reduced speed of sound. The higher the value, the closer the listener must be before the sound is heard. (This is determined by a graph).
- Logarithmic roll-off (logarithmic rolloff): When approaching the audio source, the sound is high, but it is lowered at a very fast speed when away from the object.
- Linear roll-down (Linear rolloff): The farther away from the audio source, the less sound you can hear.
- Custom rolloff: The behavior of the sound from the audio source is determined by how you set the roll-down chart.
- Two-dimensional voice settings (2D sound Settings): The settings that are applied to the audio source when the audio clip is a two-dimensional sound.
- Two-dimensional panning (pan 2D): Sets the degree to which the engine affects the audio source.
The purpose of listing these properties is to understand the meaning of the English word attribute.
3. Audio Listener (Listener)
The audio Listener acts as a microphone-like device. It receives input from any given audio source in the scene and plays the sound through the computer speakers. For most applications, it is most interesting to attach the listener to the camera. If the audio Listener is within the reverb region (Reverb Zone) boundary, the reverb is applied to all audible sounds in the scene. (Professional Edition only) Also, the audio Effect can be applied to the listener and will be applied to all audible sounds in the scene.
There can be only one audio listener in your scene, and the listener is usually attached to the main camera (main Listener).
4. Audio clip
Audio clip contains an audio source. Unity supports mono, stereo, and multichannel audio resources (up to eight channels). The audio file formats that Unity can import include. AIF,. wav,. mp3, and. ogg. Unity can also import. XM,. MoD,. It, and. s3m format Tracker Modules (Tracker module). The Tracker module resource behaves the same as any other audio resource in Unity, but the waveform preview is not available in the Resource Import viewer.
Any audio file imported into Unity can find an instance of its audio clip in the script, which is actually a useful audio data storage tool.
- Audio format: A specific format used by the runtime for sound.
- Native (Native): This option provides high quality at the expense of a large file size, and is best suited for very short sound effects.
- Compression (compressed): Compression produces smaller files, but has a lower quality compared to native audio. This format is best for medium-length sound effects and music.
- Three-dimensional sounds (3D sound): If enabled, the sound plays in three-dimensional space. Both mono and stereo sound are available for three-dimensional playback.
- Force Mono: If enabled, the audio clip is blended into mono sound.
- Loading type (load type) Unity: The method used to load audio resources at run time.
- Load-time decompression (decompress on load): The audio file will be decompressed immediately after loading. Use this option for smaller compressed sounds to avoid the performance overhead of dynamic decompression. Note that the memory used to decompress the sound when it is loaded is about 10 times times more than keeping the sound in a compressed state, so do not use this option for large files.
- Compressed in memory: keeps the sound in a compressed state in memory and decompressed while it is playing. This option has a small amount of performance overhead (especially for ogg/vorbis compressed files), so it is only used for large files that will use too much memory to decompress when loading. Note that due to technical limitations, this option will silently switch the Ogg Vorbis resource to streaming from the disc (stream from Disc) on platforms using FMOD audio.
- Stream from CD-ROM (stream from disc): Stream audio data directly from a disc. The memory used by this option is usually a small part of the file size, so it is useful for music or other long tracks. For performance reasons, it is generally advisable to stream one or two files at a time from the disc only, but the number of streams that can be handled gracefully depends on the hardware.
- Compression (Compression): The amount of compression applied to compressed fragments. You can view statistics about the file size under the slider. A good way to adjust this value is to drag the slider to a location that keeps playback "good enough" and that the file is small enough to meet the distribution requirements.
- Hardware decoding (Hardware decoding): (iOS only) on iOS devices, you can use Apple's hardware decoder to generate a small CPU overhead during decompression. For more information, see platform-specific details.
- Seamless cycle (gapless looping): (Android/ios only) Use this option when compressing seamlessly looping audio source files (in uncompressed PCM format) to ensure perfect continuity at the docking point. The standard MPEG encoder introduces a short silent period at the loop point, which can be heard as a short "tick" or "Bang Bang" sound.
Audio clip must be used in conjunction with the audio Sources and audio Listener to generate sound. When you add a fragment to an object in the game, the audio source component is added to an object that contains many other properties, such as volume (Volume), Pitch (Pitch), and so on. When the source is playing, the audio Listener can "hear" all the sources in the range, and then combine the sources to make the sound pass through the speakers.
5. Audio Track Module
The Audio track module (Tracker Modules) file has many similarities to MIDI files. A soundtrack is a score that contains information such as when to play an instrument, pitch, and volume, and then creates the melody and beat of the original melody.
However, MIDI has a drawback that the sound quality relies on the available sound libraries in the audio hardware, so the sound quality of the MIDI music will vary depending on the computer used.
In contrast, the audio track module includes both high-quality PCM samples and unaffected by the audio hardware being used.
(1) Supported formats
Unity supports the four most common module file formats, namely Impulse Tracker (. It), Scream Tracker (. s3m), extension Module file format (. xm), and original module file formats (Original Module File Format) (. MoD).
(2) Advantages of using the Audio track module (Tracker Modules)
The audio track module files are different from the mainstream PCM format (. AIF,. wav,. mp3, and. ogg), and this file can be very small, but does not affect the sound quality. You can adjust the pitch and volume of a sound sample (and use other effects), so it's essentially an "instrument (instrument)" that plays tunes, and saves the overhead of recording a full tune. As a result, applying the audio track module to a game can help solve problems like music and downloading large files.
"Unity" 3.5 Import audio file