我编写了一个perl脚本来生成要在C ++头中使用的注释信息条目列表。该脚本包含以下内容:
#!/bin/perl
use strict;
use warnings;
my @NOTES = ( "C" , "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" );
#2*(x/12)
my @CF_VALUES = (1, 1.0594630943592953, 1.122462048309373, 1.189207115002721, 1.2599210498948732, 1.3348398541700344, 1.4142135623730951, 1.4983070768766815, 1.5874010519681994, 1.681792830507429, 1.7817974362806785, 1.8877486253633868);
my @START_FREQS = (27.5,55,110,220,440,880,1760,3520,7040);
my $FREQUENCY = 0;
my $OCTAVE;
my $KEY;
my $INDEX = 12;
print "static const MidiNote_t Notes[" . 8 * 12 . "] = {\n";
#4 times
for ($OCTAVE=0; $OCTAVE<=8; $OCTAVE++)
{
for ($KEY=0; $KEY<12; $KEY++)
{
print "\t{ $INDEX, \"" . @NOTES[$KEY] . $OCTAVE . "\", " . @START_FREQS[$OCTAVE] * @CF_VALUES[$KEY] . " }";
if ($KEY == 11 && $OCTAVE == 8) {
print "\n};";
} else {
print ",\n";
}
$INDEX++;
}
}
生成的输出如下所示:
static const MidiNote_t Notes[96] = {
{ 12, "C0", 13.75 },
{ 13, "C#0", 14.5676175474403 },
{ 14, "D0", 15.4338531642539 },
{ 15, "D#0", 16.3515978312874 },
{ 16, "E0", 17.3239144360545 },
{ 17, "F0", 18.354047994838 },
{ 18, "F#0", 19.4454364826301 },
{ 19, "G0", 20.6017223070544 },
{ 20, "G#0", 21.8267644645627 },
{ 21, "A0", 23.1246514194772 },
{ 22, "A#0", 24.4997147488593 },
{ 23, "B0", 25.9565435987466 },
{ 24, "C1", 27.5 },
{ 25, "C#1", 29.1352350948806 },
...
虽然,我似乎无法在我的脚本生成的列表中得到结果频率,以与基本'A'频率对齐。
例如,A4应对应440 Hz,A0应为27.5 Hz。
如何正确对齐频率并将每个八度音阶中的每个音符与其相应的基音A音符频率相乘?
答案 0 :(得分:2)
您的计划希望@START_FREQS
中的值为C
个频率,而不是A
个频率。我们可以修改打印的值,使其基于A
将A
更换器上的所有内容分开,如下所示:
print "\t{ $INDEX, \"" . $NOTES[$KEY] . $OCTAVE . "\", " . $START_FREQS[$OCTAVE] * $CF_VALUES[$KEY] / $CF_VALUES[9] . " }";
这将是整个计划:
#!/bin/perl
use strict;
use warnings;
my @NOTES = ( "C" , "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" );
#2*(x/12)
my @CF_VALUES = (1, 1.0594630943592953, 1.122462048309373, 1.189207115002721, 1.2599210498948732, 1.3348398541700344, 1.4142135623730951, 1.4983070768766815, 1.5874010519681994, 1.681792830507429, 1.7817974362806785, 1.8877486253633868);
my @START_FREQS = (27.5,55,110,220,440,880,1760,3520,7040);
my $FREQUENCY = 0;
my $OCTAVE;
my $KEY;
my $INDEX = 12;
print "static const MidiNote_t Notes[" . 8 * 12 . "] = {\n";
#4 times
for ($OCTAVE=0; $OCTAVE<=8; $OCTAVE++)
{
for ($KEY=0; $KEY<12; $KEY++)
{
print "\t{ $INDEX, \"" . $NOTES[$KEY] . $OCTAVE . "\", " . $START_FREQS[$OCTAVE] * $CF_VALUES[$KEY] / $CF_VALUES[9] . " }";
if ($KEY == 11 && $OCTAVE == 8) {
print "\n};";
} else {
print ",\n";
}
$INDEX++;
}
}
给出这个输出:
static const MidiNote_t Notes[96] = {
{ 12, "C0", 16.3515978312874 },
{ 13, "C#0", 17.3239144360545 },
{ 14, "D0", 18.354047994838 },
{ 15, "D#0", 19.4454364826301 },
{ 16, "E0", 20.6017223070544 },
{ 17, "F0", 21.8267644645627 },
{ 18, "F#0", 23.1246514194772 },
{ 19, "G0", 24.4997147488593 },
{ 20, "G#0", 25.9565435987466 },
{ 21, "A0", 27.5 },
{ 22, "A#0", 29.1352350948806 },
{ 23, "B0", 30.8677063285078 },
{ 24, "C1", 32.7031956625748 },
{ 25, "C#1", 34.647828872109 },
{ 26, "D1", 36.7080959896759 },
{ 27, "D#1", 38.8908729652601 },
{ 28, "E1", 41.2034446141087 },
{ 29, "F1", 43.6535289291255 },
{ 30, "F#1", 46.2493028389543 },
{ 31, "G1", 48.9994294977187 },
{ 32, "G#1", 51.9130871974931 },
{ 33, "A1", 55 },
{ 34, "A#1", 58.2704701897612 },
{ 35, "B1", 61.7354126570155 },
{ 36, "C2", 65.4063913251497 },
{ 37, "C#2", 69.295657744218 },
{ 38, "D2", 73.4161919793519 },
{ 39, "D#2", 77.7817459305202 },
{ 40, "E2", 82.4068892282175 },
{ 41, "F2", 87.307057858251 },
{ 42, "F#2", 92.4986056779086 },
{ 43, "G2", 97.9988589954373 },
{ 44, "G#2", 103.826174394986 },
{ 45, "A2", 110 },
{ 46, "A#2", 116.540940379522 },
{ 47, "B2", 123.470825314031 },
{ 48, "C3", 130.812782650299 },
{ 49, "C#3", 138.591315488436 },
{ 50, "D3", 146.832383958704 },
{ 51, "D#3", 155.56349186104 },
{ 52, "E3", 164.813778456435 },
{ 53, "F3", 174.614115716502 },
{ 54, "F#3", 184.997211355817 },
{ 55, "G3", 195.997717990875 },
{ 56, "G#3", 207.652348789973 },
{ 57, "A3", 220 },
{ 58, "A#3", 233.081880759045 },
{ 59, "B3", 246.941650628062 },
{ 60, "C4", 261.625565300599 },
{ 61, "C#4", 277.182630976872 },
{ 62, "D4", 293.664767917408 },
{ 63, "D#4", 311.126983722081 },
{ 64, "E4", 329.62755691287 },
{ 65, "F4", 349.228231433004 },
{ 66, "F#4", 369.994422711634 },
{ 67, "G4", 391.995435981749 },
{ 68, "G#4", 415.304697579945 },
{ 69, "A4", 440 },
{ 70, "A#4", 466.16376151809 },
{ 71, "B4", 493.883301256124 },
{ 72, "C5", 523.251130601197 },
{ 73, "C#5", 554.365261953744 },
{ 74, "D5", 587.329535834815 },
{ 75, "D#5", 622.253967444162 },
{ 76, "E5", 659.25511382574 },
{ 77, "F5", 698.456462866008 },
{ 78, "F#5", 739.988845423269 },
{ 79, "G5", 783.990871963499 },
{ 80, "G#5", 830.60939515989 },
{ 81, "A5", 880 },
{ 82, "A#5", 932.32752303618 },
{ 83, "B5", 987.766602512248 },
{ 84, "C6", 1046.50226120239 },
{ 85, "C#6", 1108.73052390749 },
{ 86, "D6", 1174.65907166963 },
{ 87, "D#6", 1244.50793488832 },
{ 88, "E6", 1318.51022765148 },
{ 89, "F6", 1396.91292573202 },
{ 90, "F#6", 1479.97769084654 },
{ 91, "G6", 1567.981743927 },
{ 92, "G#6", 1661.21879031978 },
{ 93, "A6", 1760 },
{ 94, "A#6", 1864.65504607236 },
{ 95, "B6", 1975.5332050245 },
{ 96, "C7", 2093.00452240479 },
{ 97, "C#7", 2217.46104781498 },
{ 98, "D7", 2349.31814333926 },
{ 99, "D#7", 2489.01586977665 },
{ 100, "E7", 2637.02045530296 },
{ 101, "F7", 2793.82585146403 },
{ 102, "F#7", 2959.95538169308 },
{ 103, "G7", 3135.96348785399 },
{ 104, "G#7", 3322.43758063956 },
{ 105, "A7", 3520 },
{ 106, "A#7", 3729.31009214472 },
{ 107, "B7", 3951.06641004899 },
{ 108, "C8", 4186.00904480958 },
{ 109, "C#8", 4434.92209562995 },
{ 110, "D8", 4698.63628667852 },
{ 111, "D#8", 4978.03173955329 },
{ 112, "E8", 5274.04091060592 },
{ 113, "F8", 5587.65170292806 },
{ 114, "F#8", 5919.91076338615 },
{ 115, "G8", 6271.92697570799 },
{ 116, "G#8", 6644.87516127912 },
{ 117, "A8", 7040 },
{ 118, "A#8", 7458.62018428944 },
{ 119, "B8", 7902.13282009799 }
};