返回介绍

AudioSettings.Reset 重设

发布于 2019-12-18 15:37:23 字数 7656 浏览 1161 评论 0 收藏 0

JavaScript => public static function Reset(config: AudioConfiguration): bool;
C# => public static bool Reset(AudioConfiguration config);

Parameters 参数

configThe new configuration to be used.
使用新的配置。

Returns 返回

bool True if all settings could be successfully applied.

如果所有的设置成功应用,返回true。

Description 描述

Performs a change of the device configuration. In response to this the AudioSettings.OnAudioConfigurationChanged delegate is invoked with the argument deviceWasChanged=false. It cannot be guaranteed that the exact settings specified can be used, but the an attempt is made to use the closest match supported by the system.

执行修改设备配置。针对AudioSettings.OnAudioConfigurationChanged委托参数deviceWasChanged=false被调用。它不能保证所指定的设置可以使用,但尝试使用系统支持的最接近的值。

JavaScript:

#pragma strict
public class TestAudioConfiguration extends MonoBehaviour {
	function Start() {
		AudioSettings.OnAudioConfigurationChanged += OnAudioConfigurationChanged;
	}
	function OnAudioConfigurationChanged(deviceWasChanged: boolean) {
		Debug.Log(deviceWasChanged ? "Device was changed" : "Reset was called");
		if (deviceWasChanged) {
			var config: var = AudioSettings.GetConfiguration();
			config.dspBufferSize = 64;
			AudioSettings.Reset(config);
		}
		GetComponent.<AudioSource>().Play();
	}
	static var validSpeakerModes: int[] = [intAudioSpeakerMode.Mono, intAudioSpeakerMode.Stereo, intAudioSpeakerMode.Quad, intAudioSpeakerMode.Surround, intAudioSpeakerMode.Mode5point1, intAudioSpeakerMode.Mode7point1];
	static var validDSPBufferSizes: int[] = [32, 64, 128, 256, 340, 480, 512, 1024, 2048, 4096, 8192];
	static var validSampleRates: int[] = [11025, 22050, 44100, 48000, 88200, 96000];
	static var validNumRealVoices: int[] = [1, 2, 4, 8, 16, 32, 50, 64, 100, 128, 256, 512];
	static var validNumVirtualVoices: int[] = [1, 2, 4, 8, 16, 32, 50, 64, 100, 128, 256, 512];
	function GUIRow(name: String, valid: int[], value: int, modified: boolean) {
		GUILayout.BeginHorizontal();
		GUILayout.Button(name + "=" + value);
		for (var i: int = 0; i < valid.Length; i++) {
			var s: String = valid[i].ToString();
			if (valid[i] == value)
				s = "[" + s + "]";
			if (GUILayout.Button(s)) {
				value = valid[i];
				modified = true;
			}
		}
		GUILayout.EndHorizontal();
		return value;
	}
	function OnGUI() {
		var source: var = GetComponent.<AudioSource>();
		var modified: boolean = false;
		var config: AudioConfiguration = AudioSettings.GetConfiguration();
		config.speakerMode = AudioSpeakerModeGUIRow("speakerMode", validSpeakerModes, intconfig.speakerMode, modified);
		config.dspBufferSize = GUIRow("dspBufferSize", validDSPBufferSizes, config.dspBufferSize, modified);
		config.sampleRate = GUIRow("sampleRate", validSampleRates, config.sampleRate, modified);
		config.numRealVoices = GUIRow("RealVoices", validNumRealVoices, config.numRealVoices, modified);
		config.numVirtualVoices = GUIRow("numVirtualVoices", validNumVirtualVoices, config.numVirtualVoices, modified);
		if (modified)
			AudioSettings.Reset(config);
		if (GUILayout.Button("Start"))
			source.Play();
		if (GUILayout.Button("Stop"))
			source.Stop();
	}
}

C#:

using UnityEngine;
using System.Collections;
 
public class TestAudioConfiguration : MonoBehaviour
{
	void Start ()
	{
		AudioSettings.OnAudioConfigurationChanged += OnAudioConfigurationChanged;
	}
 
	void OnAudioConfigurationChanged(bool deviceWasChanged)
	{
		Debug.Log(deviceWasChanged ? "Device was changed" : "Reset was called");
		if (deviceWasChanged)
		{
			var config = AudioSettings.GetConfiguration ();
			config.dspBufferSize = 64;
			AudioSettings.Reset (config);
		}
		GetComponent<AudioSource>().Play ();
	}
 
	static int[] validSpeakerModes =
	{
		(int)AudioSpeakerMode.Mono,
		(int)AudioSpeakerMode.Stereo,
		(int)AudioSpeakerMode.Quad,
		(int)AudioSpeakerMode.Surround,
		(int)AudioSpeakerMode.Mode5point1,
		(int)AudioSpeakerMode.Mode7point1
	};
 
	static int[] validDSPBufferSizes =
	{
		32, 64, 128, 256, 340, 480, 512, 1024, 2048, 4096, 8192
	};
 
	static int[] validSampleRates =
	{
		11025, 22050, 44100, 48000, 88200, 96000, 
	};
 
	static int[] validNumRealVoices =
	{
		1, 2, 4, 8, 16, 32, 50, 64, 100, 128, 256, 512,
	};
 
	static int[] validNumVirtualVoices =
	{
		1, 2, 4, 8, 16, 32, 50, 64, 100, 128, 256, 512,
	};
 
	int GUIRow(string name, int[] valid, int value, ref bool modified)
	{
		GUILayout.BeginHorizontal ();
		GUILayout.Button (name + "=" + value);
		for (int i = 0; i < valid.Length; i++)
		{
			string s = valid [i].ToString ();
			if (valid [i] == value)
				s = "[" + s + "]";
			if (GUILayout.Button (s))
			{
				value = valid [i];
				modified = true;
			}
		}
		GUILayout.EndHorizontal ();
		return value;
	}
 
	void OnGUI()
	{
		var source = GetComponent<AudioSource> ();
		bool modified = false;
 
		AudioConfiguration config = AudioSettings.GetConfiguration ();
 
		config.speakerMode = (AudioSpeakerMode)GUIRow ("speakerMode", validSpeakerModes, (int)config.speakerMode, ref modified);
		config.dspBufferSize = GUIRow ("dspBufferSize", validDSPBufferSizes, config.dspBufferSize, ref modified);
		config.sampleRate = GUIRow ("sampleRate", validSampleRates, config.sampleRate, ref modified);
		config.numRealVoices = GUIRow ("RealVoices", validNumRealVoices, config.numRealVoices, ref modified);
		config.numVirtualVoices = GUIRow ("numVirtualVoices", validNumVirtualVoices, config.numVirtualVoices, ref modified);
 
		if (modified)
			AudioSettings.Reset (config);
 
		if (GUILayout.Button ("Start"))
			source.Play ();
 
		if (GUILayout.Button ("Stop"))
			source.Stop ();
	}
}

AudioSettings

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

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

发布评论

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