返回介绍

MonoBehaviour.OnAudioFilterRead(float[], int) 当音频过滤器读取

发布于 2019-12-18 15:38:02 字数 2633 浏览 1402 评论 0 收藏 0

JavaScript => 代码
C# =>

Parameters 参数

dataAn array of floats comprising the audio data.
包含音频数据的浮点数数组。
channelsAn int that stores the number of channels of audio data passed to this delegate.
int是传递给此委托音频数据的通道数

Description 描述

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

如果OnAudioFilterRead被执行,Unity将插入一个自定义的过滤器到音频DSP链。

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

该过滤器插入作为MonoBehaviour脚本以相同的顺序被插入显示在检视面板。

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.

OnAudioFilterRead 每次被调用是通过过滤器访问音频块(这种情况经常发生,每~20ms取决于采样频率和平台)。音频数据是范围在[-1.0f;1.0f]的浮点数数组并包含之前音频链中的过滤器或AudioSource中的AudioClip。如果是在链中的第一个过滤器并且剪辑没有附加到音频源,此过滤器将是“已播放”。这样你可以使用滤波器作为音频剪辑,程序生成音频。

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 ).

如果OnAudioFilterRead被执行,VU表将显示在检视面板,显示采样等级。过滤器的处理时间也被计算并以毫秒显示在旁边的VU表(如果过滤器占用太多时间,它会变红色,因此mixer将吃掉音频数据)。另注意,OnAudioFilterRead 不允许从主线程外调用。

See Also: Audio Filters.

JavaScript:

	// 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;			
	}

C#:

未提供代码

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文