# Audio Clip audioclip

The audio clip audioclip contains audio data that can be used by [Audio Source AudioSource] (./audioSource.md) and some configuration information for the data. [Import audio resources] (./audioImport.md) will automatically generate audioclip resources. For the supported audio file formats, please refer to here.


# Channel

The audio system supports mono, stereo and multi-channel audio resources, but does not support changing the channel settings of audio resources. Since the hardware device that ultimately processes the audio data may only support mono or stereo, it may need to be mixed. For specific mixing strategies, please refer to here


# Decoding and sampling rate

The audio files imported by the audioclip resource are compressed audio data by default, so they will be automatically decoded into PCM format data before playing. Each decoding process is completed in its own independent decoding thread, they do not affect each other, and will not block game rendering. The default sampling rate of the audio system is 48KHz, so the audio will be automatically resampled after decoding.


# Configurable properties

Select the audio file in the Project panel, and you can configure related properties in the Inpsector panel.

Properties Functions
length Audio duration, in seconds. When set to <=0, the audio duration will be retrieved automatically. This property is only useful when preloadAudioData=false and audioclip is used in Timeline System.
preloadAudioData Whether to download the audio to the local.
- true When the audioclip resource is loaded by engine.loader.load or other methods, the audio file will be downloaded to the local. When playing audio, it is actually playing a local audio file. Only when preloadAudioData=true, audioclip can be used for AudioSource. For audio files larger than 9M, only preloadAudioData=false can be set.
- false If false is set, the audioclip can only be played using Basic Audio Interface. At this time, it is downloading while playing.
loadType Set the loading method of audioclip. This property is valid only when preloadAudioData=true.
- Compressed_In_Memory After the audioclip is loaded, the audio data remains compressed in the memory and is decoded into PCM during playback. Since the audio is decoded during playback, a slight playback delay will occur. The Compressed_In_Memory option should be used as much as possible for larger audio files, because Compressed_On_Load will take up a lot of memory to decode when it is loaded.
- Decompressed_On_Load After loading audioclip, immediately decode the audio data into PCM. Since it is decoded immediately after loading, the slight playback delay caused by decoding can be reduced. However, the memory occupied by the decoded PCM data will be several times the memory occupied when the compressed state is maintained, depending on the sampling rate and compression method of the audio data. So try to use this option for smaller audio files.
点击咨询小助手