Ejemplo n.º 1
0
        public int GetHashCode(double tolerance)
        {
            // Normalize DNE vectors (since we consider any with any NaN component the same).
            if (this.DNE)
            {
                return(double.NaN.GetHashCode());
            }

            // The hash code is dependent on the tolerance: more precision -> less rounding.
            // Rounding the hashcodes is necessary, since for a given tolerence we might
            // consider two quantities to be equal, but their hashcodes might differ
            // without the rounding.

            double inverse  = 1 / tolerance;
            int    decimals = (int)Math.Log10(inverse);

            return
                (Math.Round(X, decimals).GetHashCode() ^
                 Math.Round(Y, decimals).GetHashCode() ^
                 Math.Round(Z, decimals).GetHashCode() ^
                 Math.Round(W, decimals).GetHashCode());

            // if 0 tolerance
            //return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode();
        }
Ejemplo n.º 2
0
        public override int GetHashCode()
        {
            double inverse  = 1 / Tolerance.Threshold;
            int    decimals = (int)Math.Log10(inverse);

            return
                (Math.Round(Radius, decimals).GetHashCode() ^
                 Math.Round(Length, decimals).GetHashCode());
        }
Ejemplo n.º 3
0
        public int GetHashCode(double d)
        {
            if (Infinity.IsInfinite(d))
            {
                return(double.PositiveInfinity.GetHashCode());
            }

            double inverse  = 1 / m_tolerance;
            int    decimals = (int)Math.Log10(inverse);

            return(Math.Round(d, decimals).GetHashCode());
        }
Ejemplo n.º 4
0
            public Table()
            {
                for (int i = 0; i < 128; i++)
                {
                    note2Freq[i]  = (float)(440 * Math.Pow(2, (i - 69) / 12.0));
                    bend2Pitch[i] = (float)Math.Pow(2, 2 * ((i - 64) / 127) / 12.0);

                    volm2Gain[i] = (float)Deci2Gain(40.0 * Math.Log10(i / 127.0));
                    pan2Left[i]  = (float)Deci2Gain(20.0 * Math.Log10(Math.Cos(Math.PI / 2 * (i / 127.0))));
                    pan2Right[i] = (float)Deci2Gain(20.0 * Math.Log10(Math.Sin(Math.PI / 2 * (i / 127.0))));
                }
            }
 public override string GetLabel(double amount)
 {
     if (useLogScale)
     {
         double logRange = Math.Log10(frequencyMax) - Math.Log10(frequencyMin); //TODO: Could simplify, log laws
         return(formatFrequency(Math.Pow(10, amount * logRange + Math.Log10(frequencyMin))));
     }
     else
     {
         int range = frequencyMax - frequencyMin;
         return(formatFrequency(range * amount + frequencyMin));
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 数量级
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int Magnitude(this double value)
        {
            if (value.Equals(0.0))
            {
                return(0);
            }
            double magnitude = Math.Log10(Math.Abs(value));
            var    truncated = (int)Math.Truncate(magnitude);

            return(magnitude < 0d && truncated != magnitude
                ? truncated - 1
                : truncated);
        }
Ejemplo n.º 7
0
        public int GetHashCode(CircleNE c)
        {
            if (c.IsLine)
            {
                return
                    (c.P1.GetHashCode() ^
                     c.P2.GetHashCode());
            }
            else
            {
                double inverse  = 1 / Tolerance.Threshold;
                int    decimals = (int)Math.Log10(inverse);

                return
                    (c.Center.GetHashCode() ^
                     c.CenterNE.GetHashCode() ^
                     Math.Round(c.Radius, decimals).GetHashCode());
            }
        }
Ejemplo n.º 8
0
        private static int Math_Log(ILuaState lua)
        {
            double x = lua.L_CheckNumber(1);
            double res;

            if (lua.IsNoneOrNil(2))
            {
                res = Math.Log(x);
            }
            else
            {
                double logBase = lua.L_CheckNumber(2);
                if (logBase == 10.0)
                {
                    res = Math.Log10(x);
                }
                else
                {
                    res = Math.Log(x, logBase);
                }
            }
            lua.PushNumber(res);
            return(1);
        }
Ejemplo n.º 9
0
            public Table(float sampleRate)
            {
                this.sampleRate = sampleRate;
                sampleRateRecip = 1f / sampleRate;

                minSampleCount = (int)(0.002 * sampleRate);

                for (int i = 0; i < 128; i++)
                {
                    note2Freq[i]  = (float)(440 * Math.Pow(2, (i - 69) / 12.0));
                    bend2Pitch[i] = (float)Math.Pow(2, 2 * ((i - 64) / 127) / 12.0);

                    volm2Gain[i] = (float)Db2Gain(40.0 * Math.Log10(i / 127.0));
                    pan2Left[i]  = (float)Db2Gain(20.0 * Math.Log10(Math.Cos(Math.PI / 2 * (i / 127.0))));
                    pan2Right[i] = (float)Db2Gain(20.0 * Math.Log10(Math.Sin(Math.PI / 2 * (i / 127.0))));
                }

                for (int i = 0; i < 256; i++)
                {
                    semi2Pitch[i] = (float)Math.Pow(2, (i - Semi2PitchCenter) / 12.0);
                    cent2Pitch[i] = (float)Math.Pow(2, (i - Semi2PitchCenter) / 1200.0);
                    db2Gain[i]    = (float)Db2Gain(i - Db2GainCenter);
                }
            }
Ejemplo n.º 10
0
 public static int IntExp(double x) => (int)SM.Log10(x);
Ejemplo n.º 11
0
 public static int IntExp(float x) => (int)SM.Log10(x);
Ejemplo n.º 12
0
 private static int Math_Log10(ILuaState lua)
 {
     lua.PushNumber(Math.Log10(lua.L_CheckNumber(1)));
     return(1);
 }
Ejemplo n.º 13
0
 public static double Log10(object self, [DefaultProtocol] double x)
 {
     return(DomainCheck(SM.Log10(x), "log10"));
 }
        public void Refresh()
        {
            AudioSourceVisualizer audioSourceVisualizer;

            try {
                audioSourceVisualizer = target as AudioSourceVisualizer;
            }
            catch (System.Exception e) {
                Debug.Log("Not ready");
                return;
            }
            AudioSource audioSource = audioSourceVisualizer.source;
            AudioClip   clip        = audioSource.clip;

            if (clip == null)
            {
                return; //Not ready
            }

            //First get the RMS of the audio channel as a whole

            /*float[] intensityBins = new float[AudioSourceVisualizerEditor.samples];
             * audioSource.GetOutputData(intensityBins, 0);
             * float sum = 0;
             * foreach(float sample in intensityBins) {
             *  sum += sample * sample; // sum squared samples
             * }
             * float rms = Mathf.Sqrt(sum / AudioSourceVisualizerEditor.samples); // rms = square root of average*/


            float[] spectrumBins = new float[samples];
            audioSource.GetSpectrumData(spectrumBins, 0, FFTWindow.Hanning);

            System.Func <double, float> frequencyIntensity = (double freq) => {
                if (freq > clip.frequency || freq < 0)
                {
                    return(0); //No data for this frequency
                }

                //spectrumBins is in the range 0 - clip.frequency
                int binIdx = (int)Math.Truncate(freq / clip.frequency * samples);
                return(spectrumBins[binIdx]);
            };

            int idx = 0;

            foreach (VisualElement bin in bins)
            {
                double binRange = (double)idx / bins.Length;
                double sampleFreq;
                if (audioSourceVisualizer.useLogScale)
                {
                    double fMin10 = Math.Log10(frequencyMin);
                    double fMax10 = Math.Log10(clip.frequency);
                    //Map from linear space with bins.Length to log space with samples as length
                    sampleFreq = Math.Pow(10.0, binRange * (fMax10 - fMin10) + fMin10);
                }
                else
                {
                    //Linear from frequencyMin to frequencyMax
                    sampleFreq = binRange * (clip.frequency -
                                             frequencyMin) + frequencyMin;
                }

                float intensity = frequencyIntensity(sampleFreq);
                float db        = 20 * Mathf.Log10(intensity / 1.0e-6f); // calculate dB from linear getSpectrumData
                float linear    = Mathf.Clamp(db / 80.0f, 0.0f, 1.0f);

                bin.style.height          = linear * (AudioSourceVisualizerEditor.height - 2) + 2;
                bin.style.backgroundColor = new Color(linear, 68.0f / 255.0f, 136.0f / 255.0f, 1.0f);

                idx++;
            }

            //Update xAxis
            xAxis.useLogScale  = audioSourceVisualizer.useLogScale;
            xAxis.frequencyMin = frequencyMin;
            xAxis.frequencyMax = clip.frequency;
            if (GetVisualizerWidth() != lastWidth)
            {
                xAxis.Redraw(); //Let it know it needs to redraw bc the width changed
            }
            lastWidth = GetVisualizerWidth();
        }
Ejemplo n.º 15
0
 public static double Log10(object self, double x)
 {
     return(DomainCheck(SM.Log10(x), "log10"));
 }