コード例 #1
0
ファイル: Example_04.cs プロジェクト: uniphonic/G-Audio
        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.
        }
コード例 #2
0
        /// <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.");
                }
            }
        }