Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

MonoBehaviour.OnAudioFilterRead(float[], int)

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual

Parámetros

data An array of floats comprising the audio data.
channels An int that stores the number of channels of audio data passed to this delegate.

Descripción

If OnAudioFilterRead is implemented, Unity will insert a custom filter into the audio DSP chain.

The filter is inserted in the same order as the MonoBehaviour script is shown in the inspector.

OnAudioFilterRead is called everytime a chunk of audio is routed through the filter (this happens frequently, every ~20ms depending on the samplerate and platform). The audio data is an array of floats ranging from [-1.0f;1.0f] and contains audio from the previous filter in the chain or the AudioClip on the AudioSource. If this is the first filter in the chain and a clip isn't attached to the audio source this filter will be 'played'. That way you can use the filter as the audio clip, procedurally generating audio.

If OnAudioFilterRead is implemented a VU meter will show up in the inspector showing the outgoing samples level. The process time of the filter is also measured and the spent milliseconds will show up next to the VU Meter (it turns red if the filter is taking up too much time, so the mixer will starv audio data). Also note, that OnAudioFilterRead is called on a different thread from the main thread (namely the audio thread) so calling into many Unity functions from this function is not allowed ( a warning will show up ).

See Also: Audio Filters.

	// This custom filter controls the gain by filtering the samples by multiplying each sample with a <i>gain</i> parameter.  

public var gain : float;

function OnAudioFilterRead(var data:float[], var channels:int) { for (var i = 0; i < data.Length; ++i) data[i] = data[i] * gain; }