From afd482f51bda8dbf67255c770219582b6f71910c Mon Sep 17 00:00:00 2001 From: Frank Gevaerts Date: Sun, 16 Jun 2013 19:11:03 +0200 Subject: [PATCH] midi: Recalculate (and rename) the note frequency table. gustable[] contained plain note frequencies in milliHertz, but was named and documented to appear like a table of magic numbers. The values also seemed to be slightly inaccurate (up to about 0.01Hz, so probably irrelevant). This changes the name to freqtable to make the purpose clearer, and uses slightly better values. Change-Id: I6b568d834c8c2c92161bed5290572a29733e28dc --- apps/plugins/midi/guspat.c | 39 +++++++++++++++++++++-------------- apps/plugins/midi/guspat.h | 2 +- apps/plugins/midi/sequencer.c | 6 +++--- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/apps/plugins/midi/guspat.c b/apps/plugins/midi/guspat.c index c5b5832ddb..f650555520 100644 --- a/apps/plugins/midi/guspat.c +++ b/apps/plugins/midi/guspat.c @@ -22,21 +22,30 @@ #include "guspat.h" #include "midiutil.h" -/* This came from one of the Gravis documents */ -const uint32_t gustable[]= +/* Note frequencies in milliHz, base A = 440000 + * Calculated using: + * double base_a=440000; + * double offset; + * for(offset=-69;offset<=58;offset++) + * { + * int value = (int)round(base_a*pow(2,offset/12)); + * printf("%d, ",value); + * } + */ +const uint32_t freqtable[]= { - 8175, 8661, 9177, 9722, 10300, 10913, 11562, 12249, 12978, 13750, 14567, 15433, - 16351, 17323, 18354, 19445, 20601, 21826, 23124, 24499, 25956, 27500, 29135, 30867, - 32703, 34647, 36708, 38890, 41203, 43653, 46249, 48999, 51913, 54999, 58270, 61735, - 65406, 69295, 73416, 77781, 82406, 87306, 92498, 97998, 103826, 109999, 116540, 123470, - 130812, 138591, 146832, 155563, 164813, 174614, 184997, 195997, 207652, 219999, 233081, 246941, - 261625, 277182, 293664, 311126, 329627, 349228, 369994, 391995, 415304, 440000, 466163, 493883, - 523251, 554365, 587329, 622254, 659255, 698456, 739989, 783991, 830609, 880000, 932328, 987767, - 1046503, 1108731, 1174660, 1244509, 1318511, 1396914, 1479979, 1567983, 1661220, 1760002, 1864657, 1975536, - 2093007, 2217464, 2349321, 2489019, 2637024, 2793830, 2959960, 3135968, 3322443, 3520006, 3729316, 3951073, - 4186073, 4434930, 4698645, 4978041, 5274051, 5587663, 5919922, 6271939, 6644889, 7040015, 7458636, 7902150, - 8372036, 8869863, 9397293, 9956085, 10548105, 11175328, 11839847, 12543881 -}; +/* C, C#, D, D#, E, F, F#, G, G#, A, A#, B */ + 8176, 8662, 9177, 9723, 10301, 10913, 11562, 12250, 12978, 13750, 14568, 15434, + 16352, 17324, 18354, 19445, 20602, 21827, 23125, 24500, 25957, 27500, 29135, 30868, + 32703, 34648, 36708, 38891, 41203, 43654, 46249, 48999, 51913, 55000, 58270, 61735, + 65406, 69296, 73416, 77782, 82407, 87307, 92499, 97999, 103826, 110000, 116541, 123471, + 130813, 138591, 146832, 155563, 164814, 174614, 184997, 195998, 207652, 220000, 233082, 246942, + 261626, 277183, 293665, 311127, 329628, 349228, 369994, 391995, 415305, 440000, 466164, 493883, + 523251, 554365, 587330, 622254, 659255, 698456, 739989, 783991, 830609, 880000, 932328, 987767, + 1046502, 1108731, 1174659, 1244508, 1318510, 1396913, 1479978, 1567982, 1661219, 1760000, 1864655, 1975533, + 2093005, 2217461, 2349318, 2489016, 2637020, 2793826, 2959955, 3135963, 3322438, 3520000, 3729310, 3951066, + 4186009, 4434922, 4698636, 4978032, 5274041, 5587652, 5919911, 6271927, 6644875, 7040000, 7458620, 7902133, + 8372018, 8869844, 9397273, 9956063, 10548082, 11175303, 11839822, 12543854 }; static unsigned int readWord(int file) { @@ -141,7 +150,7 @@ static struct GWaveform * loadWaveform(int file) static int selectWaveform(struct GPatch * pat, int midiNote) { /* We divide by 100 here because everyone's freq formula is slightly different */ - unsigned int tabFreq = gustable[midiNote]/100; /* Comparison */ + unsigned int tabFreq = freqtable[midiNote]/100; /* Comparison */ unsigned int a=0; for(a=0; anumWaveforms; a++) { diff --git a/apps/plugins/midi/guspat.h b/apps/plugins/midi/guspat.h index ebb5f227d7..428d99ba0e 100644 --- a/apps/plugins/midi/guspat.h +++ b/apps/plugins/midi/guspat.h @@ -19,7 +19,7 @@ * ****************************************************************************/ -extern const uint32_t gustable[]; +extern const uint32_t freqtable[]; struct GWaveform { diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c index e860dbd2dd..d35a057c32 100644 --- a/apps/plugins/midi/sequencer.c +++ b/apps/plugins/midi/sequencer.c @@ -148,12 +148,12 @@ static void findDelta(struct SynthObject * so, int ch, int note) /* Old formula: - delta = (((gustable[note+chPBNoteOffset[ch]]<rootFreq)) * wf->sampRate / (SAMPLE_RATE)); + delta = (((freqtable[note+chPBNoteOffset[ch]]<rootFreq)) * wf->sampRate / (SAMPLE_RATE)); Plus some pitch stuff. See old SVN for how it used to be */ - delta = (((gustable[note+chPBNoteOffset[ch]]))); /* anywhere from 8000 to 8000000 */ + delta = (((freqtable[note+chPBNoteOffset[ch]]))); /* anywhere from 8000 to 8000000 */ delta = delta * wf->sampRate; /* approx 20000 - 44000 but can vary with tuning */ delta = (delta * chPBFractBend[ch]); /* approx 60000 - 70000 */ delta = delta / (SAMPLE_RATE); /* 44100 or 22050 */ @@ -263,7 +263,7 @@ static inline void pressNote(int ch, int note, int vol) struct GWaveform * wf = drumSet[note]->waveforms[0]; voices[a].wf = wf; - voices[a].delta = (((gustable[note]<rootFreq) * wf->sampRate / SAMPLE_RATE); + voices[a].delta = (((freqtable[note]<rootFreq) * wf->sampRate / SAMPLE_RATE); if (wf->mode & 28) // midi_debug("\nWoah, a drum patch has a loop. Stripping the loop..."); wf->mode = wf->mode & (255-28);