/// <summary>
 /// Starts mixing the stream to the specified track.
 /// An exception is thrown if the track already has a contributor.
 /// </summary>
 public void Start()
 {
     if (_track.SubscribeContributor(this) == false)
     {
         throw new GATException("Track " + _track.TrackNb + " already has a contributor.");
     }
     _stream.AddAudioThreadStreamClient(this);
 }
예제 #2
0
        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;
        }
예제 #3
0
        /// <summary>
        /// Start caching the stream.
        /// </summary>
        /// <param name="targetDspTime">The dsp time at which caching should start. Pass 0 to start as soon as possible.</param>
        /// <param name="handler">Optional callback fired when the cache is full.</param>
        public void Start(double targetDspTime = 0d, AtEndHandler handler = null)
        {
            if (_vDoCache || _waiting)
            {
                return;
            }

            _waiting       = true;
            _vPosition     = 0;
            _onEnd         = handler;
            _targetDspTime = targetDspTime;
            _stream.AddAudioThreadStreamClient(this);
        }
        /// <summary>
        /// The splitter will begin broadcasting it's
        /// sub streams immediately.
        /// </summary>
        public GATAudioThreadStreamSplitter(IGATAudioThreadStream stream, GATDataAllocationMode bufferAllocationMode)
        {
            int i;

            _sourceStreamChannels = stream.NbOfChannels;
            if (_sourceStreamChannels < 2)
            {
                Debug.LogWarning("source stream is mono: " + stream.StreamName);
            }

            IntPtr outputBufferPointer = IntPtr.Zero;

            _sharedBufferSize = stream.BufferSizePerChannel;


            if (bufferAllocationMode == GATDataAllocationMode.Unmanaged)
            {
                _sharedBufferArray = new float[_sharedBufferSize];
                _sharedBuffer      = new GATData(_sharedBufferArray);
            }
            else
            {
                if (bufferAllocationMode == GATDataAllocationMode.Fixed)
                {
                    _sharedBuffer = GATManager.GetFixedDataContainer(_sharedBufferSize, "StreamSplitter buffer");
                }
                else
                {
                    _sharedBuffer = GATManager.GetDataContainer(_sharedBufferSize);
                }

                _sharedBufferArray  = _sharedBuffer.ParentArray;
                outputBufferPointer = _sharedBuffer.GetPointer();
            }

            _memOffset = _sharedBuffer.MemOffset;

            _streamProxies = new GATAudioThreadStreamProxy[_sourceStreamChannels];

            for (i = 0; i < _sourceStreamChannels; i++)
            {
                _streamProxies[i] = new GATAudioThreadStreamProxy(_sharedBufferSize, 1, outputBufferPointer, _sharedBuffer.MemOffset, (stream.StreamName + " split " + i));
            }

            stream.AddAudioThreadStreamClient(this);

            _sourceStream = stream;
        }
예제 #5
0
        void OnEnable()         // We subscribe to the player's stream in OnEnable, and unsubscribe in OnDisable
        {
            // audio thread stream access is protected behind an explicit implementation of IGATAudioThreadStreamOwner.GetAudioThreadStream()
            // Handling of streams is delicate: the callback they provide is on the audio thread and needs special care.
            // We first cast the default player to IGATAudioThreadStreamOwner in order to get access to audio stream getter methods.
            IGATAudioThreadStreamOwner streamOwner = ( IGATAudioThreadStreamOwner )GATManager.DefaultPlayer;

            _observedStream = streamOwner.GetAudioThreadStream(0);

            // The point of this tutorial is to demonstrate stereo capture!
            if (_observedStream.NbOfChannels != 2)
            {
                Debug.LogError("This tutorial only works with stereo ouptut!");
                Destroy(this);
                return;
            }
            _observedStream.AddAudioThreadStreamClient(this);               //Subscribe to the stream: we will now receive the HandleAudioThreadStream callback.
        }
예제 #6
0
    void SetupTracksInfo()
    {
        GATTrack track;
        int      nbOfTracks;

        nbOfTracks        = _player.NbOfTracks;
        _trackStreams     = new IGATAudioThreadStream[nbOfTracks];
        _trackLevels      = new float[nbOfTracks];
        _trackFiltersInfo = new TrackFiltersInfo[nbOfTracks];

        for (int i = 0; i < nbOfTracks; i++)
        {
            track = _player.GetTrack(i);

            _trackStreams[i] = track.GetAudioThreadStream(0);

            if (_trackStreams[i] != null)
            {
                _trackStreams[i].AddAudioThreadStreamClient(this);
            }

            if (track != null)
            {
                _trackFiltersInfo[i] = new TrackFiltersInfo(track.FiltersHandler);
            }
        }

        _playerStream         = (( IGATAudioThreadStreamOwner )_player).GetAudioThreadStream(0);
        _playerChannelsLevels = new float[GATInfo.NbOfChannels];
        _playerFiltersInfo    = new TrackFiltersInfo(_player.FiltersHandler);

        if (_playerStream != null)
        {
            _playerStream.AddAudioThreadStreamClient(this);
        }
    }
예제 #7
0
    void SetupTracksInfo()
    {
        GATTrack track;
        int nbOfTracks;

        nbOfTracks 			= _player.NbOfTracks;
        _trackStreams 		= new IGATAudioThreadStream[ nbOfTracks ];
        _trackLevels  		= new float[ nbOfTracks ];
        _trackFiltersInfo	= new TrackFiltersInfo[ nbOfTracks ];

        for( int i = 0; i < nbOfTracks; i++ )
        {
            track = _player.GetTrack( i );

            _trackStreams[ i ] = track.GetAudioThreadStream( 0 );

            if( _trackStreams[ i ] != null )
            {
                _trackStreams[ i ].AddAudioThreadStreamClient( this );
            }

            if( track != null )
            {
                _trackFiltersInfo[ i ] = new TrackFiltersInfo( track.FiltersHandler );
            }
        }

        _playerStream 			= ( ( IGATAudioThreadStreamOwner )_player ).GetAudioThreadStream( 0 );
        _playerChannelsLevels 	= new float[ GATInfo.NbOfChannels ];
        _playerFiltersInfo 		= new TrackFiltersInfo( _player.FiltersHandler );

        if( _playerStream != null )
        {
            _playerStream.AddAudioThreadStreamClient( this );
        }
    }
        /// <summary>
        /// The splitter will begin broadcasting it's 
        /// sub streams immediately. 
        /// </summary>
        public GATAudioThreadStreamSplitter( IGATAudioThreadStream stream, GATDataAllocationMode bufferAllocationMode )
        {
            int i;

            _sourceStreamChannels = stream.NbOfChannels;
            if( _sourceStreamChannels < 2 )
            {
                Debug.LogWarning( "source stream is mono: " + stream.StreamName );
            }

            IntPtr outputBufferPointer = IntPtr.Zero;

            _sharedBufferSize	= stream.BufferSizePerChannel;

            if( bufferAllocationMode == GATDataAllocationMode.Unmanaged )
            {
                _sharedBufferArray = new float[ _sharedBufferSize ];
                _sharedBuffer = new GATData( _sharedBufferArray );
            }
            else
            {
                if( bufferAllocationMode == GATDataAllocationMode.Fixed )
                {
                    _sharedBuffer = GATManager.GetFixedDataContainer( _sharedBufferSize, "StreamSplitter buffer" );
                }
                else
                {
                    _sharedBuffer = GATManager.GetDataContainer( _sharedBufferSize );
                }

                _sharedBufferArray 	= _sharedBuffer.ParentArray;
                outputBufferPointer = _sharedBuffer.GetPointer();
            }

            _memOffset			= _sharedBuffer.MemOffset;

            _streamProxies = new GATAudioThreadStreamProxy[ _sourceStreamChannels ];

            for( i = 0; i < _sourceStreamChannels; i++ )
            {
                _streamProxies[ i ] = new GATAudioThreadStreamProxy( _sharedBufferSize, 1, outputBufferPointer, _sharedBuffer.MemOffset, ( stream.StreamName + " split " + i ) );
            }

            stream.AddAudioThreadStreamClient( this );

            _sourceStream = stream;
        }