UNPKG

xen-dev-utils

Version:

Utility functions used by the Scale Workshop ecosystem

68 lines (67 loc) 3.97 kB
import { Fraction, FractionValue } from './fraction'; /** * Calculate best rational approximations to a given fraction that are * closer than any approximation with a smaller or equal denominator * unless non-monotonic approximations are requested as well. * @param value The fraction to simplify. * @param maxDenominator Maximum denominator to include. * @param maxLength Maximum length of the array of approximations. * @param includeSemiconvergents Include semiconvergents. * @param includeNonMonotonic Include non-monotonically improving approximations. * @returns An array of (semi)convergents. */ export declare function getConvergents(value: FractionValue, maxDenominator?: number, maxLength?: number, includeSemiconvergents?: boolean, includeNonMonotonic?: boolean): Fraction[]; /** * Approximate a musical interval by ratios of which neither the numerator or denominator * exceeds a specified limit, once all powers of 2 are removed. * @param cents Size of the musical interval measured in cents. * @param limit Maximum odd limit. * @returns All odd limit fractions within 600 cents of the input value sorted by closeness with cent offsets attached. */ export declare function approximateOddLimitWithErrors(cents: number, limit: number): [Fraction, number][]; /** * Approximate a musical interval by ratios of which neither the numerator or denominator * exceeds a specified limit, once all powers of 2 are removed. * @param cents Size of the musical interval measured in cents. * @param limit Maximum odd limit. * @returns All odd limit fractions within 600 cents of the input value sorted by closeness. */ export declare function approximateOddLimit(cents: number, limit: number): Fraction[]; /** * Approximate a musical interval by ratios of which are within a prime limit with * exponents that do not exceed the maximimum, exponent of 2 ignored. * @param cents Size of the musical interval measured in cents. * @param limitIndex The ordinal of the prime of the limit. * @param maxError Maximum error from the interval for inclusion in the result. * @param maxLength Maximum number of approximations to return. * @returns All valid fractions within `maxError` cents of the input value sorted by closeness with cent offsets attached. */ export declare function approximatePrimeLimitWithErrors(cents: number, limitIndex: number, maxExponent: number, maxError?: number, maxLength?: number): [Fraction, number][]; /** * Approximate a musical interval by ratios of which are within a prime limit with * exponents that do not exceed the maximimum, exponent of 2 ignored. * @param cents Size of the musical interval measured in cents. * @param limitIndex The ordinal of the prime of the limit. * @param maxError Maximum error from the interval for inclusion in the result. * @param maxLength Maximum number of approximations to return. * @returns All valid fractions within `maxError` cents of the input value sorted by closenesss. */ export declare function approximatePrimeLimit(cents: number, limitIndex: number, maxExponent: number, maxError?: number, maxLength?: number): Fraction[]; /** * Calculate an array of continued fraction elements representing the value. * https://en.wikipedia.org/wiki/Continued_fraction * @param value Value to turn into a continued fraction. * @returns An array of continued fraction elements. */ export declare function continuedFraction(value: number): number[]; /** * Approximate a value with a radical expression. * @param value Value to approximate. * @param maxIndex Maximum index of the radical. 2 means square root, 3 means cube root, etc. * @param maxHeight Maximum Benedetti height of the radicand in the approximation. * @returns Object with index of the radical and the radicand. Result is "index'th root or radicand". */ export declare function approximateRadical(value: number, maxIndex?: number, maxHeight?: number): { index: number; radicand: Fraction; };