コード例 #1
0
        internal void CreateInternalModel()
        {
            List <SoundToolKitMesh> stkMeshes = new List <SoundToolKitMesh>();

            Mesh[] internalMeshes = new Mesh[AcousticMeshNames.Count];

            for (var i = 0; i < AcousticMeshNames.Count; ++i)
            {
                var mesh = SoundToolKitManager.Instance.ResourceContainer.AcousticMeshes.FirstOrDefault(x => x.CombinedName() == AcousticMeshNames[i]);
                if (mesh != null)
                {
                    stkMeshes.Add(mesh);
                    internalMeshes[i] = mesh.GetStkMesh();
                }
                else
                {
                    SoundToolKitDebug.LogError("Mesh " + AcousticMeshNames[i] + " not found while trying to create internal MeshCluster.");
                }
            }

            Model = SoundToolKitManager.Instance.StkAudioEngine.ResourcesFactory.CreateModel(internalMeshes);

            if (Serialized)
            {
                RestoreGeometry();
            }
            else
            {
                SetGeometry(stkMeshes);
            }
        }
コード例 #2
0
        private void InitializeAudioEngine()
        {
            try
            {
                m_stkThreadPoolHandler = (taskData, task) =>
                {
                    return((ulong)m_stkTaskScheduler.Schedule(() => task(taskData)));
                };
                m_stkThreadPool = SoundToolKitBuilder.CreateCustomThreadPool(m_stkThreadPoolHandler);

                StkAudioEngine = SoundToolKitBuilder.CreateSoundToolKit(
                    new SoundToolKitBuilder.ThreadPoolRequest
                {
                    CustomThreadPool = m_stkThreadPool
                }, null, null);

                var resourcesDirectory = Path.Combine(Application.streamingAssetsPath, @"SoundToolKit\Resources\");

                var diffractionData = File.ReadAllBytes(resourcesDirectory + "diffraction_table_100_20.bin");
                var hrtfData        = File.ReadAllBytes(resourcesDirectory + "bqc_hrtf.bin");

                StkAudioEngine.SetDiffractionData(diffractionData);
                StkAudioEngine.AudioOutput.SetHrtfData(hrtfData);

                StkAudioEngine.AudioOutput.HrtfEnabled = true;
            }
            catch (Exception e)
            {
                SoundToolKitDebug.LogError("Message: " + e.Message + "\nStack Trace: " + e.InnerException);
            }
        }
コード例 #3
0
        private System.Func <float, float> GetPredefinedAttenuation()
        {
            switch (Attenuation)
            {
            case SoundAttenuation.Nothing:
                return((distance) => 1.0f);

            case SoundAttenuation.PointSource:
                return((distance) => SoundToolKit.Extensions.Attenuation.PointSource(distance, MinDistance));

            case SoundAttenuation.LineSource:
                return((distance) => SoundToolKit.Extensions.Attenuation.LineSource(distance, MinDistance));

            case SoundAttenuation.Linear:
                return((distance) => SoundToolKit.Extensions.Attenuation.Linear(distance, MinDistance, MaxDistance));

            case SoundAttenuation.Logarithmic:
                return((distance) => SoundToolKit.Extensions.Attenuation.Logarithmic(distance, MinDistance, MaxDistance));

            case SoundAttenuation.Inverse:
                return((distance) => SoundToolKit.Extensions.Attenuation.Inverse(distance, MinDistance, MaxDistance));

            case SoundAttenuation.ReverseLog:
                return((distance) => SoundToolKit.Extensions.Attenuation.ReverseLog(distance, MinDistance, MaxDistance));

            default:
                SoundToolKitDebug.LogError("Invalid attenuation type.");
                return((distance) => 0.0f);
            }
        }
コード例 #4
0
        internal byte[] ReadData()
        {
            var data = new byte[0];

            if (Valid)
            {
                data = File.ReadAllBytes(DataFilePath());
            }
            else
            {
                SoundToolKitDebug.LogError("Tried to read a non-existant SerializedGeometry file. " +
                                           "Make sure to serialize geometry before attempting to deserialize it.");
            }

            return(data);
        }
コード例 #5
0
ファイル: SoundToolKitMesh.cs プロジェクト: Milosz49/Cieszyn-
        internal void SetFaces()
        {
            if (Mesh == null)
            {
                SoundToolKitDebug.LogError("Trying to add an object that does not contain a valid MeshFilter " +
                                           "to the acoustic geometry of the scene (object: " + name + "). Aborting.");
                return;
            }

            var extractor = new MeshTrianglesExtractor(m_mesh, transform);

            m_faceVertices = extractor.TriangleVertices;

            var faceVerticesNumerics = new List <Numerics.Vector3>();

            m_faceVertices.ForEach(vertex => faceVerticesNumerics.Add(Vector3Extensions.ToNumerics(vertex)));

            m_acousticMesh.FaceVertices = faceVerticesNumerics;
        }
コード例 #6
0
        private float[] ConvertToArrayOfSamples(AudioClip audioClip)
        {
            var audioEngine = SoundToolKitManager.Instance.StkAudioEngine;
            var samples     = new float[audioClip.samples * audioClip.channels];

            SoundToolKitDebug.Assert(samples.Length > 0, "Precondition not met. AudioClip doesn't have any samples.");

            audioClip.GetData(samples, 0);

            //Note: Current release 1.0 of AudioEngine doesn't support more channels than 1.
            //      If we pass multi channeled sample only left channel will be used.

            if (audioClip.frequency != STK_REQUIRED_SAMPLE_RATE)
            {
                SoundToolKitDebug.LogError("Audio clip: " + audioClip.name + " has sample rate: " + audioClip.frequency + ". SoundToolKit requires: " + STK_REQUIRED_SAMPLE_RATE);
            }

            return(samples);
        }
コード例 #7
0
        private void InitializeAudioBridge()
        {
            try
            {
                m_audioBridge = new AudioBridge(StkAudioEngine)
                {
                    AudioOutput = StkAudioEngine.AudioOutput
                };
                AudioSettings.OnAudioConfigurationChanged += AudioSettings_OnAudioConfigurationChanged;

                AudioSettings_OnAudioConfigurationChanged(false);

                m_soundToolKitMixer = (AudioMixer)Resources.Load(MIXER_PATH);
            }
            catch (Exception e)
            {
                SoundToolKitDebug.LogError("Message: " + e.Message + "\nStack Trace: " + e.InnerException);
            }
        }
コード例 #8
0
 /// <summary>
 /// This method will synchronize each command send to SoundToolKit.
 /// </summary>
 public void UpdateAudio()
 {
     if (StkAudioEngine.Good)
     {
         StkAudioEngine.AdvanceTime((ulong)(Time.deltaTime * 1000) + 1);
         StkAudioEngine.Flush();
     }
     else if (!StkAudioEngine.Good && StkAudioEngine.Valid)
     {
         if (m_reinitializeCounter <= MAX_REINITIALIZE_COUNT)
         {
             ReInitialize();
         }
         else
         {
             SoundToolKitDebug.LogError("Manager crashed. Internal issue.");
         }
     }
 }