/// <summary>
        /// Tunes this Pitch to TunedPitch using a specific standard pitch and a specific tuning system.
        /// </summary>
        /// <param name="standardPitch">Standard pitch (i.e. A4 = 440 Hz, etc.)</param>
        /// <param name="tuningSystem"></param>
        /// <returns>Pitch with assigned frequency</returns>
        public TunedPitch Tune(TunedPitch standardPitch, TuningSystem tuningSystem)
        {
            var logarythmicProportion = tuningSystem.AllIntervalRatios[new BoundInterval(standardPitch, this)];
            var freq = standardPitch.Frequency * UsefulMath.CentsToLinear(logarythmicProportion);

            freq *= (this.Octave - standardPitch.Octave) + 1;
            return(new TunedPitch(this, freq));
        }
Exemple #2
0
        /// <summary>
        /// Converts cents value to approximated proportion.
        /// </summary>
        /// <param name="cents"></param>
        /// <param name="precision"></param>
        /// <returns></returns>
        public static Proportion GetApproximatedProportionFromCents(double cents, int precision = 6)
        {
            if (precision < 1 || precision > 20)
            {
                throw new ArgumentException("Precision must be between 1 and 20.", "precision");
            }

            var decimalValue    = UsefulMath.CentsToLinear(cents);
            var normalizedValue = decimalValue;
            var denominator     = 1;
            var maxDenominator  = Math.Pow(10, precision);

            while (normalizedValue % 10 != 0 && denominator <= maxDenominator)
            {
                denominator     *= 10;
                normalizedValue *= 10;
            }
            return(new Proportion((int)normalizedValue, denominator).Normalize());
        }