Ejemplo n.º 1
0
        public void AudioStreamTrackSetData()
        {
            GameObject  obj    = new GameObject("audio");
            AudioSource source = obj.AddComponent <AudioSource>();

            source.clip = AudioClip.Create("test1", 48000, 2, 48000, false);
            var track = new AudioStreamTrack(source);

            Assert.That(() => track.SetData(null, 0, 0), Throws.ArgumentNullException);

            float[] data = new float[2048];
            Assert.That(() => track.SetData(data, 0, 0), Throws.ArgumentException);

            Assert.That(() => track.SetData(data, 1, 0), Throws.ArgumentException);
            Assert.That(() => track.SetData(data, 0, 48000), Throws.ArgumentException);
            Assert.That(() => track.SetData(data, 1, 48000), Throws.Nothing);
            track.Dispose();
            UnityEngine.Object.DestroyImmediate(source.clip);
            UnityEngine.Object.DestroyImmediate(obj);
        }
        protected virtual void OnAudioFilterRead(float[] data, int channels)
        {
            NativeArray <float> nativeArray = new NativeArray <float>(data, Allocator.Temp);

            try
            {
                track?.SetData(ref nativeArray, channels, m_sampleRate);
            }
            // todo(kazuki):: Should catch only ObjectDisposedException but
            // AudioStreamTrack also throws NullReferenceException.
            catch (Exception)
            {
                track = null;
            }
            finally
            {
                nativeArray.Dispose();
            }
        }