コード例 #1
0
        public static Task <float []> Calculate(Soundfile soundfile)
        {
            if (!MainWindow.ShowHiddenParameters)
            {
                return(Task.Run(() => Array.Empty <float> ()));
            }
            SoundfileValidator.ValidateBasics(soundfile);
            var f1 = soundfile.BEFrequencyStart;
            var f2 = soundfile.BEFrequencyStop;

            return(Task.Run(() =>
            {
                var count = soundfile.GetSamples().Length / soundfile.FrameLength;
                var csf = new float [count];
                _ = Parallel.For(0, count, (i) =>
                {
                    var maxUp = soundfile.GetFftPerFrame(i).Max(f => f * f);
                    double down = 0;
                    for (int s = f1; s < Math.Min(f2 + 1, soundfile.GetFftPerFrame(i).Length); s++)
                    {
                        down += soundfile.GetFftPerFrame(i) [s] * soundfile.GetFftPerFrame(i) [s];
                    }
                    down /= f2 - f1 + 1;
                    var add = (float)(maxUp / down);
                    if (!float.IsNaN(add) && !float.IsInfinity(add))
                    {
                        csf [i] = add;
                    }
                });
                return csf;
            }));
        }
コード例 #2
0
        public static Task <float []> Calculate(Soundfile soundfile)
        {
            SoundfileValidator.ValidateBasics(soundfile);
            var centroid = soundfile.GetFrequencyCentroid();

            if (centroid is null || centroid.Length == 0)
            {
                throw new InvalidOperationException($"{nameof (soundfile)} does not have frequency centroid calculated. Calculate it first.");
            }
            return(Task.Run(() =>
            {
                var count = soundfile.GetSamples().Length / soundfile.FrameLength;
                var bandwidth = new float [count];
                _ = Parallel.For(0, count, (i) =>
                {
                    var singleFrame = soundfile.GetFftPerFrame(i);
                    float sumUp = 0, sumDown = 0;
                    for (int s = 0; s < singleFrame.Length; s++)
                    {
                        sumUp += (s - centroid [i]) * (s - centroid [i]) * singleFrame [s] * singleFrame [s];
                        sumDown += singleFrame [s] * singleFrame [s];
                    }
                    var band = sumUp / sumDown;
                    bandwidth [i] = float.IsInfinity(band) || float.IsNaN(band) ? 0 : sumUp / sumDown;
                });
                return bandwidth;
            }));
        }
コード例 #3
0
        public void setProp(string aProperty, object aValue)
        {
            int featureIndex = aProperty.IndexOf('.');

            if ((featureIndex != -1))
            {
                string featurePath     = aProperty.Substring(0, featureIndex);
                string featureProperty = aProperty.Substring((featureIndex + 1));
                if ((featurePath == "Soundfile"))
                {
                    Soundfile.setProp(featureProperty, aValue);
                }
                if ((featurePath == "LocationSettings"))
                {
                    LocationSettings.setProp(featureProperty, aValue);
                }
            }
        }
コード例 #4
0
        public void setProp(string aProperty, object aValue)
        {
            int featureIndex = aProperty.IndexOf('.');

            if ((featureIndex != -1))
            {
                string featurePath     = aProperty.Substring(0, featureIndex);
                string featureProperty = aProperty.Substring((featureIndex + 1));
                if ((featurePath == "Soundfile"))
                {
                    Soundfile.setProp(featureProperty, aValue);
                }
                if ((featurePath == "DialogChoice"))
                {
                    DialogChoice.setProp(featureProperty, aValue);
                }
            }
        }
コード例 #5
0
        public Articy.Unity.Interfaces.ScriptDataProxy getProp(string aProperty)
        {
            int featureIndex = aProperty.IndexOf('.');

            if ((featureIndex != -1))
            {
                string featurePath     = aProperty.Substring(0, featureIndex);
                string featureProperty = aProperty.Substring((featureIndex + 1));
                if ((featurePath == "Soundfile"))
                {
                    return(Soundfile.getProp(featureProperty));
                }
                if ((featurePath == "LocationSettings"))
                {
                    return(LocationSettings.getProp(featureProperty));
                }
            }
            return(null);
        }
コード例 #6
0
 public static Task <float []> Calculate(Soundfile soundfile)
 {
     SoundfileValidator.ValidateBasics(soundfile);
     return(Task.Run(() =>
     {
         var volume = new float [soundfile.GetSamples().Length / soundfile.FrameLength];
         _ = Parallel.For(0, soundfile.GetSamples().Length / soundfile.FrameLength, (i) =>
         {
             var singleVolume = soundfile.GetFftPerFrame(i);
             float sum = 0;
             foreach (var j in singleVolume)
             {
                 sum += j * j;
             }
             volume [i] = (sum / soundfile.FrameLength);
         });
         return volume;
     }));
 }
コード例 #7
0
 public static Task <float []> Calculate(Soundfile soundfile)
 {
     SoundfileValidator.ValidateBasics(soundfile);
     return(Task.Run(() =>
     {
         var fc = new float [soundfile.GetSamples().Length / soundfile.FrameLength];
         _ = Parallel.For(0, soundfile.GetSamples().Length / soundfile.FrameLength, (i) =>
         {
             var singleFc = soundfile.GetFftPerFrame(i);
             float sumUp = 0, sumDown = 0;
             for (int s = 0; s < singleFc.Length; s++)
             {
                 sumUp += s * singleFc [s];
                 sumDown += singleFc [s];
             }
             var cent = sumUp / sumDown;
             fc [i] = float.IsNaN(cent) || float.IsInfinity(cent) ? 0 : sumUp / sumDown;
         });
         return fc;
     }));
 }
コード例 #8
0
    public static void LoadSound()
    {
        if (File.Exists(path + "/ekafd/savefile_sound.game"))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path + "/ekafd/savefile_sound.game", FileMode.Open);
            playerCry = (Soundfile)formatter.Deserialize(stream);
            stream.Close();

            //player.GetComponent<AudioSource>().clip = AudioClip.Create("playerName", playerCry.data.Length, 1, 44100, false);
            //player.GetComponent<AudioSource>().clip.SetData(playerCry.data, 0);
        }
        else
        {
            if (!Directory.Exists(path + "/ekafd"))
            {
                Directory.CreateDirectory(path + "/ekafd");
            }
            playerCry = new Soundfile();
        }
    }
コード例 #9
0
 public static Task <float []> Calculate(Soundfile soundfile)
 {
     if (!MainWindow.ShowHiddenParameters)
     {
         return(Task.Run(() => Array.Empty <float> ()));
     }
     SoundfileValidator.ValidateBasics(soundfile);
     if (soundfile.GetVolume() is null || soundfile.GetBandEnergy() is null)
     {
         throw new InvalidOperationException("Volumen and Band Energy have to be calculated before calling this function.");
     }
     return(Task.Run(() =>
     {
         var be = soundfile.GetBandEnergy();
         var vol = soundfile.GetVolume();
         var count = be.Length;
         var ber = new float [count];
         _ = Parallel.For(0, count, (i) => ber [i] = be [i] / vol [i]);
         return ber;
     }));
 }
コード例 #10
0
        public static Task <float []> Calculate(Soundfile soundfile)
        {
            if (!MainWindow.ShowHiddenParameters)
            {
                return(Task.Run(() => Array.Empty <float> ()));
            }
            SoundfileValidator.ValidateBasics(soundfile);
            var f1 = soundfile.BEFrequencyStart;
            var f2 = soundfile.BEFrequencyStop;

            return(Task.Run(() =>
            {
                var count = soundfile.GetSamples().Length / soundfile.FrameLength;
                var sfm = new float [count];
                _ = Parallel.For(0, count, (i) =>
                {
                    double up = 1, down = 0;
                    var max = Math.Min(f2 + 1, soundfile.GetFftPerFrame(i).Length);
                    double n = max - f1;
                    for (int s = f1; s < max; s++)
                    {
                        if (soundfile.GetFftPerFrame(i) [s] == 0)
                        {
                            continue;
                        }
                        up *= Math.Pow(soundfile.GetFftPerFrame(i) [s], 2.0 / n);
                        down += soundfile.GetFftPerFrame(i) [s] * soundfile.GetFftPerFrame(i) [s];
                    }
                    down /= n;
                    var add = (float)(up / down);
                    if (!float.IsNaN(add) && !float.IsInfinity(add))
                    {
                        sfm [i] = add;
                    }
                });
                return sfm;
            }));
        }
コード例 #11
0
        public static Task <float []> Calculate(Soundfile soundfile)
        {
            SoundfileValidator.ValidateBasics(soundfile);
            var f1 = soundfile.BEFrequencyStart;
            var f2 = soundfile.BEFrequencyStop;

            return(Task.Run(() =>
            {
                var count = soundfile.GetSamples().Length / soundfile.FrameLength;
                var energy = new float [count];
                _ = Parallel.For(0, count, (i) =>
                {
                    float sumUp = 0, sumDown = 0;
                    for (int s = f1; s < Math.Min(f2 + 1, soundfile.GetFftPerFrame(i).Length); s++)
                    {
                        sumUp += soundfile.GetFftPerFrame(i) [s] * soundfile.GetFftPerFrame(i) [s];
                        sumDown++;
                    }
                    energy [i] = sumUp / sumDown;
                });
                return energy;
            }));
        }
コード例 #12
0
 private void CloneProperties(object aClone)
 {
     Articy.ManiacManfred.Templates.LocationSettingsTemplate newClone = ((Articy.ManiacManfred.Templates.LocationSettingsTemplate)(aClone));
     if ((Soundfile != null))
     {
         newClone.Soundfile = ((Articy.ManiacManfred.Features.SoundfileFeature)(Soundfile.CloneObject()));
     }
     if ((LocationSettings != null))
     {
         newClone.LocationSettings = ((Articy.ManiacManfred.Features.LocationSettingsFeature)(LocationSettings.CloneObject()));
     }
 }
コード例 #13
0
 private void CloneProperties(object aClone)
 {
     Articy.ManiacManfred.Templates.DialogChoiceTemplate newClone = ((Articy.ManiacManfred.Templates.DialogChoiceTemplate)(aClone));
     if ((Soundfile != null))
     {
         newClone.Soundfile = ((Articy.ManiacManfred.Features.SoundfileFeature)(Soundfile.CloneObject()));
     }
     if ((DialogChoice != null))
     {
         newClone.DialogChoice = ((Articy.ManiacManfred.Features.DialogChoiceFeature)(DialogChoice.CloneObject()));
     }
 }