|
1 |
| - |
| 1 | + |
2 | 2 |
|
3 | 3 | [](https://travis-ci.org/vadymmarkov/Pitchy)
|
4 | 4 | [](http://cocoadocs.org/docsets/Pitchy)
|
|
24 | 24 |
|
25 | 25 | ## Description
|
26 | 26 |
|
27 |
| -<img src="https://github.com/vadymmarkov/Pitchy/blob/master/Resources/PitchyIcon.png" alt="Cache Icon" align="right" /> |
| 27 | +<img src="https://github.com/vadymmarkov/Pitchy/blob/master/Resources/PitchyIcon.png" alt="Pitchy Icon" align="right" /> |
28 | 28 | **Pitchy** provides a simple way to get a music pitch from a frequency. Other
|
29 | 29 | than that it has a bunch of useful data structures, calculators and helper
|
30 | 30 | functions to work with notes, octaves and acoustic waves.
|
31 | 31 |
|
32 | 32 | From [Wikipedia](https://en.wikipedia.org/wiki/Pitch_(music)):
|
33 | 33 | > Pitch is a perceptual property of sounds that allows their ordering on a
|
34 |
| -> frequency-related scale,[1] or more commonly, pitch is the quality that makes |
| 34 | +> frequency-related scale, or more commonly, pitch is the quality that makes |
35 | 35 | > it possible to judge sounds as "higher" and "lower" in the sense associated
|
36 | 36 | > with musical melodies.
|
37 | 37 |
|
|
68 | 68 |
|
69 | 69 | print(pitchOffsets.closest.note.string) // "A4"
|
70 | 70 |
|
71 |
| - // You could also use acoustic wave of the pitch |
| 71 | + // You could also use acoustic wave |
72 | 72 | print(pitch.wave.wavelength) // 0.7795 meters
|
73 | 73 | } catch {
|
74 | 74 | // Handle errors
|
|
79 | 79 | Get an acoustic wave with wavelength, period and harmonics.
|
80 | 80 |
|
81 | 81 | ```swift
|
82 |
| -// AcousticWave(wavelength: 0.7795) |
83 |
| -// AcousticWave(period: 0.00227259) |
84 |
| -let wave = AcousticWave(frequency: 440.0) |
85 |
| - |
86 |
| -print(wave.frequency) // 440 Hz |
87 |
| -print(wave.wavelength) // 0.7795 meters |
88 |
| -print(wave.period) // 0.00227259 seconds |
89 |
| -print(wave.harmonics[0]) // 440 Hz |
90 |
| -print(wave.harmonics[1]) // 880 Hz |
| 82 | +do { |
| 83 | + // AcousticWave(wavelength: 0.7795) |
| 84 | + // AcousticWave(period: 0.00227259) |
| 85 | + let wave = try AcousticWave(frequency: 440.0) |
| 86 | + |
| 87 | + print(wave.frequency) // 440 Hz |
| 88 | + print(wave.wavelength) // 0.7795 meters |
| 89 | + print(wave.period) // 0.00227259 s |
| 90 | + print(wave.harmonics[0]) // 440 Hz |
| 91 | + print(wave.harmonics[1]) // 880 Hz |
| 92 | +} catch { |
| 93 | + // Handle errors |
| 94 | +} |
91 | 95 | ```
|
92 | 96 |
|
93 | 97 | ### Note
|
| 98 | +Note could be created with a corresponding frequency, letter + octave number or |
| 99 | +a pitch index. |
94 | 100 |
|
95 | 101 | ```swift
|
96 | 102 | do {
|
97 | 103 | // Note(frequency: 261.626)
|
98 | 104 | // Note(letter: .C, octave: 4)
|
99 |
| - note = try Note(index: -9) |
| 105 | + let note = try Note(index: -9) |
100 | 106 |
|
101 | 107 | print(note.index) // -9
|
102 | 108 | print(note.letter) // .C
|
@@ -126,14 +132,14 @@ do {
|
126 | 132 | let frequency1 = try NoteCalculator.frequency(index: 0) // 440.0 Hz
|
127 | 133 | let letter = try NoteCalculator.letter(index: 0) // .A
|
128 | 134 | let octave = try NoteCalculator.octave(index: 0) // 4
|
129 |
| - let index = try NoteCalculator.index(frequency: 440.0) // 0 |
130 |
| - let index = try NoteCalculator.index(letter: .A, octave: 4) // 0 |
| 135 | + let index1 = try NoteCalculator.index(frequency: 440.0) // 0 |
| 136 | + let index2 = try NoteCalculator.index(letter: .A, octave: 4) // 0 |
131 | 137 |
|
132 | 138 | // WaveCalculator
|
133 | 139 | let f = try WaveCalculator.frequency(wavelength: 0.7795) // 440.0 Hz
|
134 |
| - let wl1 = try WaveCalculator.wavelength(frequency: 440.0) // 0.7795 |
135 |
| - let wl2 = try WaveCalculator.wavelength(period: 0.00227259) // 0.7795 |
136 |
| - let period = try WaveCalculator.period(wavelength: 0.7795) // 0.00227259 |
| 140 | + let wl1 = try WaveCalculator.wavelength(frequency: 440.0) // 0.7795 meters |
| 141 | + let wl2 = try WaveCalculator.wavelength(period: 0.00227259) // 0.7795 meters |
| 142 | + let period = try WaveCalculator.period(wavelength: 0.7795) // 0.00227259 s |
137 | 143 | } catch {
|
138 | 144 | // Handle errors
|
139 | 145 | }
|
|
142 | 148 | ### Config
|
143 | 149 |
|
144 | 150 | With a help of `Config` it's possible to adjust minimum and maximum frequencies
|
145 |
| -that are used for validation in all calculations: |
| 151 | +that are used for validations in all calculations: |
146 | 152 |
|
147 | 153 | ```swift
|
148 | 154 | Config.minimumFrequency = 20.0
|
@@ -187,7 +193,7 @@ Vadym Markov, markov.vadym@gmail.com
|
187 | 193 |
|
188 | 194 | ## Contributing
|
189 | 195 |
|
190 |
| -Check the [CONTRIBUTING](https://github.com/hyperoslo/Cache/blob/master/CONTRIBUTING.md) |
| 196 | +Check the [CONTRIBUTING](https://github.com/vadymmarkov/Pitchy/blob/master/CONTRIBUTING.md) |
191 | 197 | file for more info.
|
192 | 198 |
|
193 | 199 | ## License
|
|
0 commit comments