void Awake() { if (player == null) { player = GATManager.DefaultPlayer; } }
/// <summary> /// Initialize a filter parameter handler for a track filter. /// paramName should be the exact name of the property /// to tweak. If player is null, the default player is used instead. /// </summary> public GATFilterParam( int trackNb, int slotNb, string paramName, GATPlayer player = null ) { Type t; GATTrack track; if( player == null ) player = GATManager.DefaultPlayer; track = player.GetTrack( trackNb ); if( track == null ) { throw new GATException( "Track " + trackNb + " does not exist." ); } Filter = track.FiltersHandler.GetFilterAtSlot( slotNb ); if( Filter == null ) { throw new GATException( "No filter found in slot " + slotNb + " of track " + trackNb ); } t = Filter.GetType(); _propInfo = t.GetProperty( paramName, BindingFlags.Public | BindingFlags.Instance ); if( _propInfo == null ) { throw new GATException( "No such filter!" ); } }
/// <summary> /// Initializes a new instance of the <see cref="GATDynamicPanInfo"/> class. /// </summary> /// <param name='player'> /// Instances need to subscribe to GATPlayer delegates in order to /// pan multiple samples at once. /// </param> public GATDynamicPanInfo(GATPlayer player, bool startsActive = true) { channelGains = new List <GATDynamicChannelGain>(GATInfo.NbOfChannels); _indexedChannelGains = new GATDynamicChannelGain[GATInfo.NbOfChannels]; _player = player; Active = startsActive; }
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 ReleaseAllAndPool(GATPlayer parentPlayer) { while (head.next != null) { parentPlayer.PoolBufferedSample(head.next); head.next = head.next.next; } Clear(); }
/// <summary> /// Plays the sample through the specified player's track trackNb /// </summary> public void PlayScheduledThroughTrack(GATPlayer player, double dspTime, int trackNb, float gain = 1f) { if (PlayingStatus != Status.ReadyToPlay) { return; } PlayingStatus = Status.Scheduled; player.PlayDataScheduled(_dataOwner.AudioData, dspTime, trackNb, gain, PlayerWillMixSample); _endDspTime = dspTime + MaxDuration; }
protected override void Awake() { base.Awake(); _sampleCount = UpdatedSampleCount(); if (_player == null) { _player = GATManager.DefaultPlayer; } }
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 }
public virtual void InitTrack(GATPlayer parentPlayer, int trackNb) { int i; _player = parentPlayer; _trackNb = trackNb; _filtersHandler = ScriptableObject.CreateInstance <GATFiltersHandler>(); _filtersHandler.InitFiltersHandler(1); //GATTracks are mono, panning occurs after filtering. _gains = new float[GATInfo.NbOfChannels]; for (i = 0; i < _gains.Length; i++) { _gains[i] = .5f; } OnEnable(); }
/// <summary> /// Plays the sample directly through the specified player. /// If no AGATPanInfo reference was specified when creating the instance, /// doesn't do anything. /// </summary> public void PlayScheduled(GATPlayer player, double dspTime, float gain = 1f) { if (panInfo == null) { #if GAT_DEBUG Debug.LogWarning("No panInfo set!"); return; #endif } if (PlayingStatus != Status.ReadyToPlay) { return; } PlayingStatus = Status.Scheduled; player.PlayDataScheduled(_dataOwner.AudioData, dspTime, panInfo, gain, PlayerWillMixSample); _endDspTime = dspTime + MaxDuration; }
void OnEnable() { Frequency = _frequency; if (player == null) { player = GATManager.DefaultPlayer; } if (isTrackFilter) { _filterParam = new GATFilterParam(_trackNb, filterSlot, paramName, player); } else { _filterParam = new GATFilterParam(filterSlot, paramName, player); } player.onPlayerWillMix += OnPlayerWillMix; }
/// <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."); } } }
/// <summary> /// Starts playback through the user specified player. /// </summary> public void PlayThroughTrack(GATPlayer player, int trackNb, float gain = 1f) { #if GAT_DEBUG if (IsPlaying) { Debug.LogWarning("Already playing!"); return; } #endif IsPlaying = true; _keepLooping = true; _nextIndex = _attackStartIndex; //reset the play head _currentState = State.Attack; _data = _dataOwner.AudioData; if (!_noLoop) { UpdateZeroCrossings(); } player.PlayData(_data, trackNb, gain, PlayerWillMixSample); }
void OnDestroy() { if (__uniqueInstance != this) //Destroying an illegal duplicate { return; } //Call static cleaners first GATPlayer.CleanUpStatics(); if (__allocator != null) { __allocator.Dispose(); __allocator = null; } DefaultPlayer = null; __uniqueInstance = null; onMainThreadResumed = null; //System.GC.Collect(); }
/// <summary> /// Initialize a filter parameter handler for a player filter. /// If player is null, the default player is used instead. /// paramName should be the exact name of the property /// to tweak. /// </summary> public GATFilterParam( int slotNb, string paramName, GATPlayer player = null ) { Type t; if( player == null ) player = GATManager.DefaultPlayer; Filter = player.FiltersHandler.GetFilterAtSlot( slotNb ); if( Filter == null ) { throw new GATException( "No filter found in slot " + slotNb + " of player." ); } t = Filter.GetType(); _propInfo = t.GetProperty( paramName, BindingFlags.Public | BindingFlags.Instance ); if( _propInfo == null ) { throw new GATException( "No such filter!" ); } }
public IGATBufferedSampleOptions Play(GATPlayer player, AGATPanInfo panInfo, float gain = 1f, GATPlayer.OnShouldMixSample mixCallback = null) { UpdateAudioData(); return(player.PlayData(_audioData, panInfo, gain, mixCallback)); //Only use AudioData property when playing, as it updates }
public IGATBufferedSampleOptions PlayScheduled(GATPlayer player, double dspTime, int trackNb, float gain = 1f, GATPlayer.OnShouldMixSample mixCallback = null) { UpdateAudioData(); return(player.PlayDataScheduled(_audioData, dspTime, trackNb, gain, mixCallback)); //Only use AudioData property when playing, as it updates }
public PlayingSamplesQueue(GATPlayer parentPlayer) : base() { _parentPlayer = parentPlayer; }