1 | <?php |
||
7 | class VibratingString |
||
8 | { |
||
9 | private $frequency; |
||
10 | |||
11 | /** |
||
12 | * VibratingString constructor. |
||
13 | * |
||
14 | * @param float $frequency The open string frequency (in Hz). |
||
15 | */ |
||
16 | public function __construct(float $frequency) |
||
20 | |||
21 | /** |
||
22 | * Calculate the frequency for a stop. |
||
23 | * |
||
24 | * @param float $stringLength The length of the vibrating part of the |
||
25 | * string, as a fraction of the whole string. |
||
26 | * |
||
27 | * @return float A frequency (in Hz). |
||
28 | */ |
||
29 | public function getStoppedFrequency(float $stringLength = 1.0): float |
||
36 | |||
37 | /** |
||
38 | * Find the sounding frequency of a harmonic-pressure stop on this string. |
||
39 | * |
||
40 | * @param float $stringLength The string length, as a fraction, between the |
||
41 | * open string and the stop (either side: both |
||
42 | * .2 and .8 would produce the same result). |
||
43 | * |
||
44 | * @return float The sounding frequency of a harmonic-pressure stop at the |
||
45 | * given string length. |
||
46 | */ |
||
47 | public function getHarmonicSoundingFrequency(float $stringLength = 1.0): float |
||
53 | |||
54 | /** |
||
55 | * Calculate the length of this string needed to produce a given frequency. |
||
56 | * |
||
57 | * @param float $frequency The frequency for which to calculate the string |
||
58 | * length. |
||
59 | * |
||
60 | * @return float |
||
61 | * The length of the vibrating part of the string, as a fraction of the |
||
62 | * whole string's length. |
||
63 | */ |
||
64 | public function getStringLength(float $frequency): float |
||
73 | |||
74 | /** |
||
75 | * Convert a string length to a harmonic number. |
||
76 | * |
||
77 | * @param float $stringLength The string length between the open string and |
||
78 | * the harmonic-pressure stop (either side), as a |
||
79 | * fraction. |
||
80 | * |
||
81 | * @throws \InvalidArgumentException If the stop is not a sounding natural |
||
82 | * harmonic. |
||
83 | * |
||
84 | * @return int The harmonic number. |
||
85 | */ |
||
86 | public static function getHarmonicNumber(float $stringLength): int |
||
96 | |||
97 | /** |
||
98 | * Validate a string length. |
||
99 | * |
||
100 | * @param float $length |
||
101 | * |
||
102 | * @throws \InvalidArgumentException If the string length is invalid. |
||
103 | */ |
||
104 | public static function validateStringLength(float $length): void |
||
111 | |||
112 | /** |
||
113 | * Convert a number of cents to a string length. |
||
114 | * |
||
115 | * @param float $cents The number of cents between the open string and the |
||
116 | * stopped pitch. |
||
117 | * |
||
118 | * @return float The length of the vibrating string, as a fraction of the |
||
119 | * whole string's length. |
||
120 | */ |
||
121 | private function centsToStringLength(float $cents): float |
||
125 | } |
||
126 |