private void UpdateObservedStream() { IGATAudioThreadStream stream = null; if (observeTrack) { GATPlayer player = observedAudioStreamComp as GATPlayer; if (player == null) { Debug.LogWarning("Could not find Player to observe track " + observedAudioStreamComp.name); return; } GATTrack track = player.GetTrack(observedChannel); stream = (( IGATAudioThreadStreamOwner )track).GetAudioThreadStream(0); } else if (observedAudioStreamComp != null) { stream = observedAudioStreamComp as IGATAudioThreadStream; if (stream == null) { IGATAudioThreadStreamOwner streamOwner; streamOwner = observedAudioStreamComp as IGATAudioThreadStreamOwner; if (streamOwner != null) { stream = streamOwner.GetAudioThreadStream(0); } if (stream == null) { Debug.LogWarning("Could not find IGATAudioThreadStream or IGATAudioThreadStreamOwner on GameObject " + observedAudioStreamComp.name); observedAudioStreamComp = _cachedStreamComp; return; } } } if (_observedStream != null) { _observedStream.RemoveAudioThreadStreamClient(this); } if (stream != null) { stream.AddAudioThreadStreamClient(this); } else { _dataIsUpdated = false; _needsData = true; HandleNoMoreData(); } _observedStream = stream; _cachedStreamComp = observedAudioStreamComp; }
public void Init(GATData isample, GATTrack track, OnShouldMixSample callback, float gain = 1f) { AudioData = isample; _track = track; _onShouldMixSample = callback; _gain = gain; IsFirstChunk = true; _count = isample.Count; _fadeStart = -1; }
public void Clear() { AudioData.Release(); _onShouldMixSample = null; IsLastChunk = false; next = null; AudioData = null; shouldBeRemoved = false; PanInfo = null; NextIndex = 0; _track = null; }
/// <summary> /// Call from derived classes to attempt to /// get a valid stream from the streamComponent and /// store it in _stream. /// </summary> protected void GetStream() { if (streamComponent == null) { streamComponent = gameObject.GetComponent(typeof(IGATAudioThreadStreamOwner)); } if (streamIsTrack) { GATPlayer player = streamComponent as GATPlayer; if (player == null) { throw new GATException("Cannot find GATPlayer to observe track stream. "); } if (streamIndex >= player.NbOfTracks) { throw new GATException("Track does not exist!"); } GATTrack track = player.GetTrack(streamIndex); _stream = track.GetAudioThreadStream(0); } else { IGATAudioThreadStreamOwner owner = streamComponent as IGATAudioThreadStreamOwner; _stream = owner.GetAudioThreadStream(streamIndex); if (owner == null) { throw new GATException("Component is not a stream!"); } if (streamIndex >= owner.NbOfStreams) { throw new GATException("Requested stream index does not exist."); } } }
protected override void Start() { base.Start(); if (_stream == null) { this.enabled = false; } if (_stream.NbOfChannels != 1) { this.enabled = false; throw new GATException("Only mono streams can be routed to a track. You may use GATAudioThreadStreamSplitter to split an interleaved stream in as many mono streams."); } GATTrack track = player.GetTrack(trackNumber); _streamToTrack = new GATAudioThreadStreamToTrack(track, _stream, exclusive); _streamToTrack.Start(); }
/// <summary> /// Removes and destroys a specific track /// </summary> public void DeleteTrack(GATTrack track) { int i; int indexToRemove = -1; for (i = 0; i < _tracks.Count; i++) { if (track == _tracks[i]) { indexToRemove = i; break; } } if (indexToRemove == -1) { return; } _tracks.RemoveAt(indexToRemove); if (Application.isPlaying) { Destroy(track); } else { DestroyImmediate(track); } if (_tracks.Count > indexToRemove) { for (i = indexToRemove; i < _tracks.Count; i++) { _tracks[i].TrackNbDidChange(i); } } }
/// <summary> /// Streaming to the specified track will not begin until Start() is called. /// </summary> public GATAudioThreadStreamToTrack( GATTrack track, IGATAudioThreadStream stream, bool exclusive ) { _track = track; _stream = stream; _exclusive = exclusive; }
/// <summary> /// Streaming to the specified track will not begin until Start() is called. /// </summary> public GATAudioThreadStreamToTrack(GATTrack track, IGATAudioThreadStream stream, bool exclusive) { _track = track; _stream = stream; _exclusive = exclusive; }