private void CreateAudioPrefab(int levelSize, AudioBus bus) { GameObject go = new GameObject(); Manager.AudioTree = AudioNodeWorker.CreateTree(go, levelSize, bus); SaveAndLoad.CreateAudioNodeRootPrefab(go); }
public static void UpdateDirtyBusses(AudioBus bus) { if (bus.Dirty) { bus.RuntimeVolume = bus.RuntimeTargetVolume * bus.CombinedVolume; var nodes = bus.GetRuntimePlayers(); for (int i = 0; i < nodes.Count; ++i) { if (nodes[i] != null) { nodes[i].UpdateBusVolume(bus.RuntimeVolume); } else { nodes.SwapRemoveAt(i); } } } for (int i = 0; i < bus.Children.Count; ++i) { if (bus.Dirty) { bus.Children[i].Dirty = true; } UpdateDirtyBusses(bus.Children[i]); } }
private static void GetBussesToDelete(HashSet <AudioBus> toDelete, AudioBus bus) { toDelete.Add(bus); for (int i = 0; i < bus.Children.Count; ++i) { GetBussesToDelete(toDelete, bus.Children[i]); } }
private static AudioBus CreateBus(GameObject go, AudioBus parent, int guid) { var node = go.AddComponent <AudioBus>(); node.GUID = guid; node.AssignParent(parent); return(node); }
/// <summary> /// Finds children for the specified Audio Bus in the current hierarchy. /// </summary> /// <param name="audioBus">The Audio Bus to find children for.</param> private void FindChildren(AudioBus audioBus) { foreach (var bus in _buses[audioBus.Id]) { bus.SetParent(audioBus); FindChildren(bus); } }
public void ResetSource() { bus = AudioBus.LowPriority; source.loop = false; SetParent(AudioManagerMk2.Instance.transform); SetAudioClipInfo(new AudioClipInfoClass()); gameObject.SetActive(false); }
private static void ActualDelete(AudioBus bus) { for (int i = 0; i < bus.Children.Count; ++i) { ActualDelete(bus.Children[i]); } bus.Parent.Children.Remove(bus); Object.DestroyImmediate(bus, true); }
public virtual void run() { int samplesToRec = SAMPLING_RATE / 100; int samplesRead = 0; try { android.os.Process.ThreadPriority = android.os.Process.THREAD_PRIORITY_URGENT_AUDIO; } catch (Exception e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } while (!outerInstance.m_shutdownCaptureThread) { outerInstance.m_captureLock.@lock(); try { if (!outerInstance.m_isCapturing) { outerInstance.m_captureEvent.@await(); continue; } else { if (outerInstance.m_audioRecord == null) { continue; } int lengthInBytes = (samplesToRec << 1) * NUM_CHANNELS_CAPTURING; int readBytes = outerInstance.m_audioRecord.read(outerInstance.m_tempBufRec, 0, lengthInBytes); outerInstance.m_recBuffer.rewind(); outerInstance.m_recBuffer.put(outerInstance.m_tempBufRec); samplesRead = (readBytes >> 1) / NUM_CHANNELS_CAPTURING; } } catch (Exception e) { Log.e(LOG_TAG, "RecordAudio try failed: " + e.Message); continue; } finally { // Ensure we always unlock outerInstance.m_captureLock.unlock(); } AudioBus.writeCaptureData(outerInstance.m_recBuffer, samplesRead); outerInstance.m_estimatedCaptureDelay = samplesRead * 1000 / SAMPLING_RATE; } }
public static AudioBus CreateNode(AudioBus parent) { var child = CreateBus(parent.gameObject, parent, GUIDCreator.Create()); child.FoldedOut = true; child.Name = "Name"; return(child); }
public static AudioNode CreateTree(GameObject go, int numberOfChildren, AudioBus bus) { var Tree = CreateRoot(go, GUIDCreator.Create()); Tree.Bus = bus; for (int i = 0; i < numberOfChildren; ++i) { CreateNode(go, Tree, GUIDCreator.Create(), AudioNodeType.Folder); } return(Tree); }
void CreateSource(AudioSourceType type, AudioBus bus) { ManagedAudioSource tempSource; tempSource = Instantiate(sourceObjectPrefab, transform).GetComponent <ManagedAudioSource>(); tempSource.type = type; tempSource.bus = bus; tempSource.SetParent(transform); tempSource.gameObject.SetActive(false); sources.Add(tempSource); }
static void checkMouse(AudioBus bus) { Event e = Event.current; if (e.button == 0 && e.isMouse) { Undo.SetSnapshotTarget(bus, "Changed Slider"); Undo.CreateSnapshot(); Undo.RegisterSnapshot(); } }
//TODO Move this to another class private static void StopAllNodeInBus(AudioBus bus) { var players = bus.GetRuntimePlayers(); for (int i = 0; i < players.Count; i++) { players[i].Stop(); } for (int i = 0; i < bus.Children.Count; i++) { StopAllNodeInBus(bus.Children[i]); } }
public static void SetTargetVolume(AudioBus bus, float volume, EventBusAction.VolumeSetMode setMode) { if (setMode == EventBusAction.VolumeSetMode.Absolute) { bus.RuntimeTargetVolume = volume; bus.Dirty = true; } else { bus.RuntimeTargetVolume = Mathf.Clamp(bus.RuntimeTargetVolume + volume, 0.0f, 1.0f); bus.Dirty = true; } }
public void Load(bool forceReload = false) { if (AudioRoot == null || BankLinkRoot == null || BusRoot == null || EventRoot == null || forceReload) { Component[] audioData; Component[] eventData; Component[] busData; Component[] bankLinkData; HDRAudio.SaveAndLoad.LoadManagerData(out audioData, out eventData, out busData, out bankLinkData); BusRoot = CheckData<AudioBus>(busData); AudioRoot = CheckData<AudioNode>(audioData); EventRoot = CheckData<AudioEvent>(eventData); BankLinkTree = CheckData<AudioBankLink>(bankLinkData); } }
private static void SetBusVolumes(AudioBus bus, float volume) { float newVolume = bus.Volume * volume; if (newVolume != bus.Volume) { bus.Dirty = true; //Non serialized, so will only stick while playing, will then get updated by the runtime system } bus.CombinedVolume = newVolume; for (int i = 0; i < bus.Children.Count; i++) { SetBusVolumes(bus.Children[i], bus.CombinedVolume); } }
/// <summary> /// Rebuilds the hierarchy with the specified collection of buses. /// </summary> /// <param name="buses">The collection of buses.</param> /// <exception cref="InvalidOperationException"> /// Thrown when the hierarchy is already loaded.</exception> public void AddBuses(IEnumerable <AudioBus> buses) { if (_loaded) { throw new InvalidOperationException("The hierarchy is already loaded."); } _buses = buses.ToLookup(bus => bus.ParentId, bus => bus); MasterAudioBus = _buses[0].Single(bus => bus.Id == MasterAudioBusId); MasterSecondaryBus = _buses[0].Single(bus => bus.Id == MasterSecondaryBusId); FindChildren(MasterAudioBus); FindChildren(MasterSecondaryBus); _buses = null; _loaded = true; }
public static void DeleteBus(AudioBus bus, AudioNode root) { HashSet <AudioBus> toDelete = new HashSet <AudioBus>(); GetBussesToDelete(toDelete, bus); List <AudioNode> affectedNodes = new List <AudioNode>(); NodeWorker.FindAllNodes(root, node => toDelete.Contains(node.Bus), affectedNodes); for (int i = 0; i < affectedNodes.Count; ++i) { affectedNodes[i].Bus = bus.Parent; } ActualDelete(bus); }
public static void Draw(AudioBus node) { checkMouse(node); EditorGUILayout.BeginVertical(); node.Name = EditorGUILayout.TextField("Name", node.Name); Undo.ClearSnapshotTarget(); checkMouse(node); //In AuxWindow, update all bus volumes node.Volume = EditorGUILayout.Slider("Volume", node.Volume, 0.0f, 1.0f); Undo.ClearSnapshotTarget(); GUI.enabled = false; checkMouse(node); EditorGUILayout.Slider("Combined Volume", node.CombinedVolume, 0, 1.0f); GUI.enabled = true; EditorGUILayout.EndVertical(); //Undo.ClearSnapshotTarget(); }
ManagedAudioSource GetFreeSource(AudioBus priority, AudioSourceType sourceType) { ManagedAudioSource source = sources.Where(r => !r.gameObject.activeInHierarchy && r.type == sourceType).FirstOrDefault(); if (source == null) { source = sources.Where(r => r.bus < priority && r.type == sourceType).FirstOrDefault(); } if (source == null) { source = sources.Where(r => !r.gameObject.activeInHierarchy && r.bus != AudioBus.Music).FirstOrDefault(); source.type = sourceType; } if (source == null) { Debug.LogError("Insufficient Sources"); } return(source); }
public void Reset() { _volume = 1f; _pitch = 1f; _priority = 128; _panLevel = 1f; _spreadLevel = 0f; _dopplerLevel = 1f; _minDistance = 1f; _reverbZoneMix = 1f; _rolloffMode = AudioRolloffMode.Linear; _bypassEffects = false; _bypassListenerEffects = false; _bypassReverbZones = false; _fadeParameter = 1f; _isDirty = false; _depth = 0; _audioMixerGroup = null; _audioBus = null; _spatialize = false; _customCurves = null; }
void UpdateBuses() { BusDict = new Dictionary <string, AudioBus>(); List <AudioBus> audioBuses = new List <AudioBus>(); if (AudioPlayerOld.Instance != null) { if (AudioPlayerOld.Instance.buses != null) { if (buses == null) { buses = new AudioBus[0]; } for (int i = 0; i < AudioPlayerOld.Instance.buses.Length; i++) { if (i < buses.Length) { buses[i].name = AudioPlayerOld.Instance.buses[i].name; audioBuses.Add(buses[i]); } else { AudioBus newBus = new AudioBus(); newBus.name = AudioPlayerOld.Instance.buses[i].name; audioBuses.Add(newBus); } } buses = audioBuses.ToArray(); foreach (AudioBus bus in buses) { BusDict[bus.name] = bus; } } } }
public ManagedAudioSource PlaySound(AudioSourceType sourceType, AudioClipInfoClass clipInfo, AudioBus priority, Transform sourceOrigin = null, bool loop = false) { if (ClipPlayedThisFrame(clipInfo.Clip)) { return(null); } ManagedAudioSource source = GetFreeSource(priority, sourceType); source.gameObject.SetActive(true); if (sourceOrigin != null) { source.SetParent(sourceOrigin); } source.SetAudioClipInfo(clipInfo); source.bus = priority; source.PlaySound(loop); AddClipPlayedLastFrame(clipInfo.Clip); UpdateActiveAudioVolumes(); return(source); }
public float GetDampener(AudioSourceType type, AudioBus priorityToCompare) { return(sources.Where(r => r.bus == AudioBus.HighPriority && r.type == type && priorityToCompare != AudioBus.HighPriority).FirstOrDefault() == null ? 1f : 0.5f); }
public void FindBus(AudioBus bus) { selectedToolbar = 0; busGUI.Find(bus); }
public virtual void run() { int samplesToPlay = SAMPLING_RATE / 100; try { android.os.Process.ThreadPriority = android.os.Process.THREAD_PRIORITY_URGENT_AUDIO; } catch (Exception e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } while (!outerInstance.m_shutdownRenderThread) { outerInstance.m_rendererLock.@lock(); try { if (!outerInstance.m_isRendering) { outerInstance.m_renderEvent.@await(); continue; } else { outerInstance.m_rendererLock.unlock(); // Don't lock on audioBus calls outerInstance.m_playBuffer.clear(); int samplesRead = AudioBus.readRenderData(outerInstance.m_playBuffer, samplesToPlay); // Log.d(LOG_TAG, "Samples read: " + samplesRead); outerInstance.m_rendererLock.@lock(); // After acquiring the lock again // we must check if we are still playing if (outerInstance.m_audioTrack == null || !outerInstance.m_isRendering) { continue; } int bytesRead = (samplesRead << 1) * NUM_CHANNELS_RENDERING; outerInstance.m_playBuffer.get(outerInstance.m_tempBufPlay, 0, bytesRead); int bytesWritten = outerInstance.m_audioTrack.write(outerInstance.m_tempBufPlay, 0, bytesRead); // increase by number of written samples outerInstance.m_bufferedPlaySamples += (bytesWritten >> 1) / NUM_CHANNELS_RENDERING; // decrease by number of played samples int pos = outerInstance.m_audioTrack.PlaybackHeadPosition; if (pos < outerInstance.m_playPosition) { // wrap or reset by driver outerInstance.m_playPosition = 0; } outerInstance.m_bufferedPlaySamples -= (pos - outerInstance.m_playPosition); outerInstance.m_playPosition = pos; // we calculate the estimated delay based on the // buffered samples outerInstance.m_estimatedRenderDelay = outerInstance.m_bufferedPlaySamples * 1000 / SAMPLING_RATE; } } catch (Exception e) { Log.e(LOG_TAG, "Exception: " + e.Message); Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } finally { outerInstance.m_rendererLock.unlock(); } } }
public HIRCObject(BNK mainBnk, BinaryReader br) { Bnk = mainBnk; if (!hircError.errorOccured) { int type = br.ReadByte(); LastPos = br.BaseStream.Position; switch (type) { case 1: SettingsObject = new Settings(br, type); break; case 2: SoundSFXObject = new SoundSFX(this, br, type); break; case 3: EventAction = new EventAction(this, br, type); break; case 4: Event = new Event(this, br, type); break; case 5: RandomContainer = new RandomContainer(this, br, type); break; case 6: SwitchContainer = new SwitchContainer(this, br, type); break; case 7: ActorMixer = new ActorMixer(this, br, type); break; case 8: AudioBus = new AudioBus(this, br, type); break; case 9: BlendContainer = new BlendContainer(this, br, type); break; case 10: MusicSegment = new MusicSegment(this, br, type); break; case 11: MusicTrack = new MusicTrack(this, br, type); break; case 12: MusicSwitchContainer = new MusicSwitchContainer(this, br, type); break; case 13: MusicSequence = new MusicSequence(this, br, type); break; case 14: Attenuation = new Attenuation(br, type); break; case 16: FeedbackBus = new FeedbackBus(this, br, type); break; case 17: FeedbackNode = new FeedbackNode(this, br, type); break; case 18: FxShareSet = new FxShareSet(this, br, type); break; case 19: FxCustom = new FxCustom(this, br, type); break; case 20: AuxiliaryBus = new AuxiliaryBus(this, br, type); break; case 21: LFO = new LFO(br, type); break; case 22: Envelope = new Envelope(br, type); break; default: int length = br.ReadInt32(); br.BaseStream.Position -= 5; Data = br.ReadBytes(length + 5); System.Windows.MessageBox.Show("Detected unkown HIRC Object type at: " + (LastPos - 1).ToString("X"), "Toolkit"); break; } } }
public int GetLength() { int length = 5; if (SettingsObject != null) { length += SettingsObject.GetLength(); } else if (SoundSFXObject != null) { length += SoundSFXObject.GetLength(); } else if (EventAction != null) { length += EventAction.GetLength(); } else if (Event != null) { length += Event.GetLength(); } else if (RandomContainer != null) { length += RandomContainer.GetLength(); } else if (SwitchContainer != null) { length += SwitchContainer.GetLength(); } else if (ActorMixer != null) { length += ActorMixer.GetLength(); } else if (AudioBus != null) { length += AudioBus.GetLength(); } else if (BlendContainer != null) { length += BlendContainer.GetLength(); } else if (MusicSegment != null) { length += MusicSegment.GetLength(); } else if (MusicTrack != null) { length += MusicTrack.GetLength(); } else if (MusicSwitchContainer != null) { length += MusicSwitchContainer.GetLength(); } else if (MusicSequence != null) { length += MusicSequence.GetLength(); } else if (Attenuation != null) { length += Attenuation.GetLength(); } else if (FeedbackNode != null) { length += FeedbackNode.GetLength(); } else if (FxShareSet != null) { length += FxShareSet.GetLength(); } else if (FxCustom != null) { length += FxCustom.GetLength(); } else if (AuxiliaryBus != null) { length += AuxiliaryBus.GetLength(); } else if (LFO != null) { length += LFO.GetLength(); } else if (Envelope != null) { length += Envelope.GetLength(); } else if (FeedbackBus != null) { length += FeedbackBus.GetLength(); } else { if (Data != null) { length += Data.Length; } else { length = -1; } } return(length); }
private static bool DrawContent(AudioEvent audioevent, Rect area) { Rect selectedBackground = drawArea; selectedBackground.y += 2; DrawBackground(selectedBackground); GUI.skin.label.alignment = TextAnchor.MiddleCenter; bool repaint = false; EditorGUILayout.BeginVertical(); for (int i = 0; i < audioevent.ActionList.Count; ++i) { var currentAction = audioevent.ActionList[i]; Rect lastArea = EditorGUILayout.BeginHorizontal(GUILayout.Height(20)); if (i == 0) { Rect actionArea = lastArea; actionArea.width = 100; actionArea.height = 20; actionArea.y -= 20; EditorGUI.LabelField(actionArea, "Action", EditorStyles.boldLabel); } if (currentAction != null) { if (GUILayout.Button( Enum.GetName(typeof(EventActionTypes), (int)currentAction.EventActionType) .AddSpacesToSentence(), GUILayout.Width(110))) { ShowChangeContext(audioevent, currentAction); Event.current.Use(); } } else { EditorGUILayout.LabelField("Missing"); GUI.enabled = false; } EditorGUILayout.BeginVertical(GUILayout.Height(20)); GUILayout.Label("", GUILayout.Height(0)); //Aligns it to the center by creating a small vertical offset, by setting the height to zero if (currentAction != null && currentAction.EventActionType != EventActionTypes.StopAll) { EditorGUILayout.LabelField(currentAction.ObjectName); } EditorGUILayout.EndHorizontal(); Rect dragArea = GUILayoutUtility.GetLastRect(); if (i == 0) { Rect actionArea = dragArea; actionArea.width = 100; actionArea.height = 20; actionArea.y -= 20; EditorGUI.LabelField(actionArea, "Data", EditorStyles.boldLabel); } if (currentAction is EventAudioAction) { AudioNode dragged = OnDragging.DraggingObject <AudioNode>(dragArea, node => node.IsPlayable); if (dragged != null) { (currentAction as EventAudioAction).Node = dragged; } } else if (currentAction is EventBankAction) { AudioBankLink dragged = OnDragging.DraggingObject <AudioBankLink>(dragArea, bank => bank.Type == AudioBankTypes.Link); if (dragged != null) { (currentAction as EventBankAction).BankLink = dragged; } } else if (currentAction is EventBusAction) { AudioBus dragged = OnDragging.DraggingObject <AudioBus>(dragArea, bus => true); if (dragged != null) { (currentAction as EventBusAction).Bus = dragged; } } EditorGUILayout.Separator(); EditorGUILayout.Separator(); Rect rightArea = EditorGUILayout.BeginHorizontal(GUILayout.Width(area.width - 100)); rightArea.x -= 150; rightArea.y += 3; rightArea.width = 80; //rightARea.height -= 6; if (GUI.Button(rightArea, "Find")) { SearchHelper.SearchFor(currentAction); } rightArea.x += 90; rightArea.width = 30; if (GUI.Button(rightArea, "X")) { if (audioevent.ActionList[i] != null) { AudioEventWorker.DeleteActionAtIndex(audioevent, i); } else { audioevent.ActionList.SwapRemoveAt(i); --i; } } if (Event.current.ClickedWithin(lastArea)) { drawArea = lastArea; audioEventAction = currentAction; Event.current.Use(); } //if (audioEventAction == null || ( Event.current.type == EventType.MouseDown && lastArea.Contains(Event.current.mousePosition))) //{ // drawArea = lastArea; // audioEventAction = currentAction; //} GUILayout.Label(""); //EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal(); GUI.enabled = true; } EditorGUILayout.EndVertical(); return(repaint); }
public static void SetBusVolumes(AudioBus bus) { SetBusVolumes(bus, 1.0f); }