public static void Init() { if (UniqueInstance != null) { Debug.LogWarning("GATInfo can only be initialized once!"); return; } int nbOfChannels; switch (AudioSettings.speakerMode) { case AudioSpeakerMode.Mono: nbOfChannels = 1; break; case AudioSpeakerMode.Stereo: nbOfChannels = 2; break; case AudioSpeakerMode.Quad: nbOfChannels = 4; break; case AudioSpeakerMode.Surround: nbOfChannels = 5; break; case AudioSpeakerMode.Mode5point1: nbOfChannels = 6; break; case AudioSpeakerMode.Mode7point1: nbOfChannels = 8; break; default: nbOfChannels = 2; break; } int bufferSize; int numBuffers; AudioSettings.GetDSPBufferSize(out bufferSize, out numBuffers); double dspBufferDuration = (( double )(bufferSize)) / AudioSettings.outputSampleRate; UniqueInstance = new GATInfo(nbOfChannels, bufferSize, dspBufferDuration); if (RequestedSampleRate != 0 && OutputSampleRate != RequestedSampleRate) { Debug.LogWarning("Requested sample rate of " + RequestedSampleRate + " is not available on this platform."); } #if GAT_DEBUG Debug.Log("Number of channels: " + nbOfChannels); Debug.Log("dsp buffer size: " + bufferSize + " duration: " + dspBufferDuration + "sample rate: " + OutputSampleRate); #endif }
void InitManager() { __uniqueInstance = this; #if !UNITY_5 if (_speakerModeInit == SpeakerModeBehaviour.Stereo) { AudioSettings.speakerMode = AudioSpeakerMode.Stereo; } else { AudioSettings.speakerMode = AudioSettings.driverCaps; } #endif if (GATInfo.UniqueInstance == null) { GATInfo.Init(); } GATInfo.UniqueInstance.SetSyncDspTime(AudioSettings.dspTime); GATInfo.UniqueInstance.SetPulseLatency(_PulseLatency); GATInfo.UniqueInstance.SetMaxIOChannels(_MaxIOChannels); if (__allocator == null) { #if UNITY_EDITOR if (Application.isPlaying) #endif { __allocator = new GATDataAllocator(_AllocatorInitSettings); } } //Static initializers GATPlayer.InitStatics(); if (_defaultPlayer == null) { GameObject go = new GameObject("DefaultPlayer"); go.transform.parent = transform; go.AddComponent <AudioSource>(); _defaultPlayer = go.AddComponent <GATPlayer>(); _defaultPlayer.AddTrack <GATTrack>(); } DefaultPlayer = _defaultPlayer; #if GAT_IOS && !UNITY_EDITOR GATiOS.InitializeNativeGAudio(GATInfo.OutputSampleRate, GATInfo.AudioBufferSizePerChannel, ( byte )GATInfo.NbOfChannels); #endif }
void Awake() { if (__uniqueInstance != null) { Debug.LogError("Only one GATAudioInit should exist!"); Destroy(this); return; } __uniqueInstance = this; RuntimePlatform currentPlatform = Application.platform; PlatformSettings currentSettings = null; foreach (PlatformSettings settings in platformSettings) { if (settings.platform == currentPlatform) { currentSettings = settings; break; } } if (currentSettings == null) { #if GAT_DEBUG Debug.LogWarning("GATAudioInit not configured for current platform: " + currentPlatform.ToString()); #endif return; } if (AudioSettings.outputSampleRate != currentSettings.sampleRate) { #if UNITY_5 Debug.LogWarning("GATAudioInit's sample rate setting is obsolete in Unity 5. Target platform samplerate can be configured in project settings."); #else AudioSettings.outputSampleRate = currentSettings.sampleRate; GATInfo.SetRequestedSampleRate(currentSettings.sampleRate); #endif } Application.targetFrameRate = currentSettings.targetFrameRate; }