Difference between revisions of "NoteFreq"
(added explanation and example) |
(added example for controlling pitch of digitized instrument) |
||
Line 1: | Line 1: | ||
<c>noteFreq</c> is a public function that calculates the correct frequency for a given note. Notes are specified by [https://www.inspiredacoustics.com/en/MIDI_note_numbers_and_center_frequencies MIDI note number], where 60 is middle C, and there are 12 notes per octave. Thus 61 is middle C#, 62 is D above middle C, and 72 (12 values above 60) is "high C" (one octave above middle C). | <c>noteFreq</c> is a public function that calculates the correct frequency for a given note. Notes are specified by [https://www.inspiredacoustics.com/en/MIDI_note_numbers_and_center_frequencies MIDI note number], where 60 is middle C, and there are 12 notes per octave. Thus 61 is middle C#, 62 is D above middle C, and 72 (12 values above 60) is "high C" (one octave above middle C). | ||
− | + | == Usage Notes == | |
− | Use the result of the `noteFreq` call as the | + | Use the result of the `noteFreq` call as the <c>frequency</c> parameter to [[Sound.init]] (or assign it to [[Sound.freq]]. Assuming the [[Sound.waveform|waveform]] of the sound is a single cycle, the resulting sound will have the correct pitch for the note value passed to <c>noteFreq</c>. |
− | + | It may also be used with digitized sounds, particularly when for digitized instruments. In this case, divide the <c>noteFreq</c> of the desired note by the <c>noteFreq</c> of the note for which the instrument was recorded (typically 60, middle C). Then use the resulting factor as the <c>pitch</c> parameter to [[Sound.play]]. | |
− | This example plays middle C for 1 second. | + | == Example == |
+ | |||
+ | This example plays a synthesized middle C for 1 second. | ||
<ms>snd = new Sound | <ms>snd = new Sound | ||
Line 13: | Line 15: | ||
snd.play</ms> | snd.play</ms> | ||
− | === Value Table | + | The following example loads a digitized instrument (cello), plays it at its original pitch of middle C, and then plays it again as note 67 (middle G). |
+ | |||
+ | <ms>snd = file.loadSound("/sys/sounds/celloLongC4.wav") | ||
+ | snd.play // plays as note 60 (C4) | ||
+ | snd.play 1, 0, noteFreq(67)/noteFreq(60) // plays as note 67 (G4)</ms> | ||
+ | |||
+ | |||
+ | == Value Table == | ||
The table below shows notes and frequency values for all 127 standard MIDI notes. However, the <c>noteFreq</c> function also accepts non-integer values, making off-pitch notes as desired. | The table below shows notes and frequency values for all 127 standard MIDI notes. However, the <c>noteFreq</c> function also accepts non-integer values, making off-pitch notes as desired. |
Latest revision as of 22:39, 31 July 2020
noteFreq
is a public function that calculates the correct frequency for a given note. Notes are specified by MIDI note number, where 60 is middle C, and there are 12 notes per octave. Thus 61 is middle C#, 62 is D above middle C, and 72 (12 values above 60) is "high C" (one octave above middle C).
Usage Notes
Use the result of the `noteFreq` call as the frequency
parameter to Sound.init (or assign it to Sound.freq. Assuming the waveform of the sound is a single cycle, the resulting sound will have the correct pitch for the note value passed to noteFreq
.
It may also be used with digitized sounds, particularly when for digitized instruments. In this case, divide the noteFreq
of the desired note by the noteFreq
of the note for which the instrument was recorded (typically 60, middle C). Then use the resulting factor as the pitch
parameter to Sound.play.
Example
This example plays a synthesized middle C for 1 second.
snd = new Sound
snd.init 1, noteFreq(60)
snd.play
The following example loads a digitized instrument (cello), plays it at its original pitch of middle C, and then plays it again as note 67 (middle G).
snd = file.loadSound("/sys/sounds/celloLongC4.wav")
snd.play // plays as note 60 (C4)
snd.play 1, 0, noteFreq(67)/noteFreq(60) // plays as note 67 (G4)
Value Table
The table below shows notes and frequency values for all 127 standard MIDI notes. However, the noteFreq
function also accepts non-integer values, making off-pitch notes as desired.
Note Number | Musical Note | Frequency |
---|---|---|
0 | C-1 | 8.1758 |
1 | C#-1 | 8.6620 |
2 | D-1 | 9.1770 |
3 | D#-1 | 9.7227 |
4 | E-1 | 10.301 |
5 | F-1 | 10.914 |
6 | F#-1 | 11.563 |
7 | G-1 | 12.250 |
8 | G#-1 | 12.979 |
9 | A-1 | 13.750 |
10 | A#-1 | 14.568 |
11 | B-1 | 15.434 |
12 | C0 | 16.352 |
13 | C#0 | 17.324 |
14 | D0 | 18.354 |
15 | D#0 | 19.445 |
16 | E0 | 20.602 |
17 | F0 | 21.827 |
18 | F#0 | 23.125 |
19 | G0 | 24.500 |
20 | G#0 | 25.957 |
21 | A0 | 27.500 |
22 | A#0 | 29.135 |
23 | B0 | 30.868 |
24 | C1 | 32.703 |
25 | C#1 | 34.648 |
26 | D1 | 36.708 |
27 | D#1 | 38.891 |
28 | E1 | 41.203 |
29 | F1 | 43.654 |
30 | F#1 | 46.249 |
31 | G1 | 48.999 |
32 | G#1 | 51.913 |
33 | A1 | 55.000 |
34 | A#1 | 58.270 |
35 | B1 | 61.735 |
36 | C2 | 65.406 |
37 | C#2 | 69.296 |
38 | D2 | 73.416 |
39 | D#2 | 77.782 |
40 | E2 | 82.407 |
41 | F2 | 87.307 |
42 | F#2 | 92.499 |
43 | G2 | 97.999 |
44 | G#2 | 103.83 |
45 | A2 | 110.00 |
46 | A#2 | 116.54 |
47 | B2 | 123.47 |
48 | C3 | 130.81 |
49 | C#3 | 138.59 |
50 | D3 | 146.83 |
51 | D#3 | 155.56 |
52 | E3 | 164.81 |
53 | F3 | 174.61 |
54 | F#3 | 185.00 |
55 | G3 | 196.00 |
56 | G#3 | 207.65 |
57 | A3 | 220.00 |
58 | A#3 | 233.08 |
59 | B3 | 246.94 |
60 | Middle C4 | 261.63 |
61 | C#4 | 277.18 |
62 | D4 | 293.66 |
63 | D#4 | 311.13 |
64 | E4 | 329.63 |
65 | F4 | 349.23 |
66 | F#4 | 369.99 |
67 | G4 | 392.00 |
68 | G#4 | 415.30 |
69 | A4 | 440.00 |
70 | A#4 | 466.16 |
71 | B4 | 193.88 |
72 | C5 | 523.25 |
73 | C#5 | 554.37 |
74 | D5 | 587.33 |
75 | D#5 | 622.25 |
76 | E5 | 659.26 |
77 | F5 | 698.46 |
78 | F#5 | 739.99 |
79 | G5 | 783.99 |
80 | G#5 | 830.61 |
81 | A5 | 880.00 |
82 | A#5 | 932.33 |
83 | B5 | 987.77 |
84 | C6 | 1046.5 |
85 | C#6 | 1108.7 |
86 | D6 | 1174.7 |
87 | D#6 | 1244.5 |
88 | E6 | 1318.5 |
89 | F6 | 1396.6 |
90 | F#6 | 1480.0 |
91 | G6 | 1568.0 |
92 | G#6 | 1661.2 |
93 | A6 | 1760.0 |
94 | A#6 | 1864.7 |
95 | B6 | 1975.5 |
96 | C7 | 2093.0 |
97 | C#7 | 2217.5 |
98 | D7 | 2349.3 |
99 | D#7 | 2489.0 |
100 | E7 | 2637.0 |
101 | F7 | 2793.8 |
102 | F#7 | 2960.0 |
103 | G7 | 3136.0 |
104 | G#7 | 3322.4 |
105 | A7 | 3520.0 |
106 | A#7 | 3729.3 |
107 | B7 | 3951.1 |
108 | C8 | 4186.0 |
109 | C#8 | 4434.9 |
110 | D8 | 4698.6 |
111 | D#8 | 4978.0 |
112 | E8 | 5274.0 |
113 | F8 | 5587.7 |
114 | F#8 | 5919.9 |
115 | G8 | 6271.9 |
116 | G#8 | 6644.9 |
117 | A8 | 7040.0 |
118 | A#8 | 7458.6 |
119 | B8 | 7902.1 |
120 | C9 | 8372.0 |
121 | C#9 | 8869.8 |
122 | D9 | 9697.3 |
123 | D#9 | 9956.1 |
124 | E9 | 10548 |
125 | F9 | 11175 |
126 | F#9 | 11840 |
127 | G9 | 12544 |
Table is in Scientific Pitch Notation.