Completed
Push — master ( 0da1f0...b17898 )
by Patrick
01:56
created

Cent::centsToFrequency()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ExtendedStrings\Harmonics;
6
7
class Cent
8
{
9
    /**
10
     * @param float $lower
11
     * @param float $upper
12
     *
13
     * @return float
14
     *   The number of cents between the two frequencies.
15
     */
16
    public static function frequenciesToCents(float $lower, float $upper): float
17
    {
18
        return Math::isZero($lower) ? 0 : 1200 * (log($upper / $lower) / log(2));
19
    }
20
21
    /**
22
     * @param float $cents
23
     * @param float $base
24
     *
25
     * @return float
26
     */
27
    public static function centsToFrequency(float $cents, float $base): float
28
    {
29
        return $base * pow(2, $cents / 1200);
30
    }
31
}
32