瀏覽代碼

Add MIDI velocity to PlaySynthMusic example

dds
PaulStoffregen 10 年之前
父節點
當前提交
666991864f
共有 4 個檔案被更改,包括 905 行新增639 行删除
  1. +35
    -0
      examples/Synthesis/PlaySynthMusic/PlaySynthMusic.h
  2. +5
    -2
      examples/Synthesis/PlaySynthMusic/PlaySynthMusic.ino
  3. +1
    -1
      examples/Synthesis/PlaySynthMusic/miditones/miditonesV1.6.c
  4. +864
    -636
      examples/Synthesis/PlaySynthMusic/william_tell_overture.c

+ 35
- 0
examples/Synthesis/PlaySynthMusic/PlaySynthMusic.h 查看文件

@@ -31,5 +31,40 @@ const float tune_frequencies2_PGM[128] =
#define CMD_RESTART 0xe0 /* restart the score from the beginning */
#define CMD_STOP 0xf0 /* stop playing */

const float velocity2amplitude[127] = {
0.01778,0.01966,0.02164,0.02371,0.02588,0.02814,0.03049,0.03294,0.03549,0.03812,
0.04086,0.04369,0.04661,0.04963,0.05274,0.05594,0.05924,0.06264,0.06613,0.06972,
0.07340,0.07717,0.08104,0.08500,0.08906,0.09321,0.09746,0.10180,0.10624,0.11077,
0.11539,0.12011,0.12493,0.12984,0.13484,0.13994,0.14513,0.15042,0.15581,0.16128,
0.16685,0.17252,0.17828,0.18414,0.19009,0.19613,0.20227,0.20851,0.21484,0.22126,
0.22778,0.23439,0.24110,0.24790,0.25480,0.26179,0.26887,0.27605,0.28333,0.29070,
0.29816,0.30572,0.31337,0.32112,0.32896,0.33690,0.34493,0.35306,0.36128,0.36960,
0.37801,0.38651,0.39511,0.40381,0.41260,0.42148,0.43046,0.43953,0.44870,0.45796,
0.46732,0.47677,0.48631,0.49595,0.50569,0.51552,0.52544,0.53546,0.54557,0.55578,
0.56609,0.57648,0.58697,0.59756,0.60824,0.61902,0.62989,0.64085,0.65191,0.66307,
0.67432,0.68566,0.69710,0.70863,0.72026,0.73198,0.74380,0.75571,0.76771,0.77981,
0.79201,0.80430,0.81668,0.82916,0.84174,0.85440,0.86717,0.88003,0.89298,0.90602,
0.91917,0.93240,0.94573,0.95916,0.97268,0.98629,1.00000
};
/*
#! /usr/bin/perl
# The Interpretation of MIDI Velocity
# Roger B. Dannenberg
# School of Computer Science, Carnegie Mellon University
$dynamic_range = 35;
$r = 10 ** ($dynamic_range / 20);
$b = 127 / (126 * sqrt($r)) - 1/126;
$m = (1 - $b) / 127;
print "const float velocity2amplitude[127] = {\n";
for ($v=1; $v <= 127; $v++) {
$a = ($m * $v + $b) ** 2;
printf "%.5f", $a;
print "," if $v < 127;
print "\n" if ($v % 10) == 0;
}
print "\n};\n";
*/


// User must supply this score array
extern unsigned char score[];

+ 5
- 2
examples/Synthesis/PlaySynthMusic/PlaySynthMusic.ino 查看文件

@@ -239,9 +239,12 @@ if(1) {
// Play the note on 'chan'
if(opcode == CMD_PLAYNOTE) {
unsigned char note = *sp++;
unsigned char velocity = *sp++;
AudioNoInterrupts();
waves[chan]->begin(AMPLITUDE, tune_frequencies2_PGM[*sp++],
wave_type[chan]);
waves[chan]->begin(AMPLITUDE * velocity2amplitude[velocity-1],
tune_frequencies2_PGM[note],
wave_type[chan]);
envs[chan]->noteOn();
AudioInterrupts();
return;

+ 1
- 1
examples/Synthesis/PlaySynthMusic/miditones/miditonesV1.6.c 查看文件

@@ -942,7 +942,7 @@ int main(int argc,char *argv[]) {
fprintf (outfile, "0x%02X,%d, ", CMD_PLAYNOTE | tgnum, shifted_note);
outfile_items(2);
} else {
fprintf (outfile, "0x%02X,%d,%d ", CMD_PLAYNOTE | tgnum, shifted_note, trk->velocity);
fprintf (outfile, "0x%02X,%d,%d, ", CMD_PLAYNOTE | tgnum, shifted_note, trk->velocity);
outfile_items(3);
}
}

+ 864
- 636
examples/Synthesis/PlaySynthMusic/william_tell_overture.c
文件差異過大導致無法顯示
查看文件


Loading…
取消
儲存