summaryrefslogtreecommitdiff
path: root/apps/plugins/midi
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/midi')
-rw-r--r--apps/plugins/midi/midiutil.c5
-rw-r--r--apps/plugins/midi/midiutil.h20
-rw-r--r--apps/plugins/midi/sequencer.c98
-rw-r--r--apps/plugins/midi/synth.c2
4 files changed, 27 insertions, 98 deletions
diff --git a/apps/plugins/midi/midiutil.c b/apps/plugins/midi/midiutil.c
index 8cf8ffcde6..92ab8db8d6 100644
--- a/apps/plugins/midi/midiutil.c
+++ b/apps/plugins/midi/midiutil.c
@@ -25,7 +25,10 @@ int chVol[16] IBSS_ATTR; /* Channel volume */
25int chPan[16] IBSS_ATTR; /* Channel panning */ 25int chPan[16] IBSS_ATTR; /* Channel panning */
26int chPat[16] IBSS_ATTR; /* Channel patch */ 26int chPat[16] IBSS_ATTR; /* Channel patch */
27int chPW[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */ 27int chPW[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */
28int chPBDepth[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */ 28int chPBDepth[16] IBSS_ATTR; /* Channel pitch bend depth */
29int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */
30int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */
31
29 32
30struct GPatch * gusload(char *); 33struct GPatch * gusload(char *);
31struct GPatch * patchSet[128]; 34struct GPatch * patchSet[128];
diff --git a/apps/plugins/midi/midiutil.h b/apps/plugins/midi/midiutil.h
index 911774440e..30f0009dc7 100644
--- a/apps/plugins/midi/midiutil.h
+++ b/apps/plugins/midi/midiutil.h
@@ -34,8 +34,7 @@
34 mainly because they have to use 44100Hz sample rate */ 34 mainly because they have to use 44100Hz sample rate */
35#define MAX_VOICES 16 35#define MAX_VOICES 16
36#else 36#else
37#define MAX_VOICES 24 /* Note: 24 midi channels is the minimum general midi 37#define MAX_VOICES 24 /* Note: 24 midi channels is the minimum general midi spec implementation */
38 spec implementation */
39#endif /* CPU_PP */ 38#endif /* CPU_PP */
40 39
41#else /* Simulator requires 44100Hz, and we can afford to use more voices */ 40#else /* Simulator requires 44100Hz, and we can afford to use more voices */
@@ -98,19 +97,6 @@ struct MIDIfile
98 int numPatches; 97 int numPatches;
99}; 98};
100 99
101/*
102struct SynthObject
103{
104 struct GWaveform * wf;
105 unsigned int delta;
106 unsigned int decay;
107 unsigned int cp;
108 unsigned char state, loopState, loopDir;
109 unsigned char note, vol, ch, isUsed;
110 int curRate, curOffset, targetOffset;
111 unsigned int curPoint;
112};
113*/
114 100
115struct SynthObject 101struct SynthObject
116{ 102{
@@ -161,6 +147,10 @@ extern int chPan[16]; /* Channel panning */
161extern int chPat[16]; /* Channel patch */ 147extern int chPat[16]; /* Channel patch */
162extern int chPW[16]; /* Channel pitch wheel, MSB only */ 148extern int chPW[16]; /* Channel pitch wheel, MSB only */
163extern int chPBDepth[16]; /* Channel pitch bend depth (Controller 6 */ 149extern int chPBDepth[16]; /* Channel pitch bend depth (Controller 6 */
150extern int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */
151extern int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */
152
153
164 154
165extern struct GPatch * gusload(char *); 155extern struct GPatch * gusload(char *);
166extern struct GPatch * patchSet[128]; 156extern struct GPatch * patchSet[128];
diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c
index 638c9ba43a..4c9520f91d 100644
--- a/apps/plugins/midi/sequencer.c
+++ b/apps/plugins/midi/sequencer.c
@@ -52,32 +52,19 @@ static inline void setPatch(int ch, int pat)
52} 52}
53 53
54 54
55
55/* 56/*
56 * Pitch Bend table, Computed by 57 This is the new pitch bend table. There are 512 entries.
57 * for i=0:127, fprintf('%d,', round(2^16*2^((i-64)/384))); end 58 The middle entry is exactly 65536 - no bending.
58 * (When typed into Matlab)
59 * 16 bit pitch bend table
60*/
61/*
62long pitchTbl[]=
63{
64 58386,58491,58597,58703,58809,58915,59022,59128,59235,59342,59449,59557,
65 59664,59772,59880,59988,60097,60205,60314,60423,60532,60642,60751,60861,
66 60971,61081,61191,61302,61413,61524,61635,61746,61858,61970,62081,62194,
67 62306,62419,62531,62644,62757,62871,62984,63098,63212,63326,63441,63555,
68 63670,63785,63901,64016,64132,64248,64364,64480,64596,64713,64830,64947,
69 65065,65182,65300,65418,65536,65654,65773,65892,66011,66130,66250,66369,
70 66489,66609,66730,66850,66971,67092,67213,67335,67456,67578,67700,67823,
71 67945,68068,68191,68314,68438,68561,68685,68809,68933,69058,69183,69308,
72 69433,69558,69684,69810,69936,70062,70189,70316,70443,70570,70698,70825,
73 70953,71082,71210,71339,71468,71597,71726,71856,71985,72115,72246,72376,
74 72507,72638,72769,72901,73032,73164,73297,73429
75};
76*/
77 59
60 The range of the table is one semitone /in either direction/
61 Ie, one semitone from the center.
78 62
79/* 512 entries here */ 63 Bends beyond this can be achieved by first offsetting the index
80/* 64 into the GUS frequency table by the appropriate number of semitones,
65 and then using this table to bend the rest of the way.
66
67 Generated using Matlab code:
81 for i=0:512, fprintf('%d,', round(2^16*2^((i-256)/1536))); end 68 for i=0:512, fprintf('%d,', round(2^16*2^((i-256)/1536))); end
82*/ 69*/
83 70
@@ -125,57 +112,8 @@ const uint32_t pitchTbl[] ICONST_ATTR={
125 68933,68949,68965,68980,68996,69011,69027,69042,69058,69074,69089,69105, 112 68933,68949,68965,68980,68996,69011,69027,69042,69058,69074,69089,69105,
126 69120,69136,69152,69167,69183,69198,69214,69230,69245,69261,69276,69292, 113 69120,69136,69152,69167,69183,69198,69214,69230,69245,69261,69276,69292,
127 69308,69323,69339,69355,69370,69386,69402,69417,69433 114 69308,69323,69339,69355,69370,69386,69402,69417,69433
128
129}; 115};
130 116
131/*
132 58386,58412,58439,58465,58491,58518,58544,58571,58597,58624,58650,58676,
133 58703,58729,58756,58782,58809,58836,58862,58889,58915,58942,58968,58995,
134 59022,59048,59075,59102,59128,59155,59182,59208,59235,59262,59289,59315,
135 59342,59369,59396,59423,59449,59476,59503,59530,59557,59584,59611,59638,
136 59664,59691,59718,59745,59772,59799,59826,59853,59880,59907,59934,59961,
137 59988,60015,60043,60070,60097,60124,60151,60178,60205,60233,60260,60287,
138 60314,60341,60369,60396,60423,60450,60478,60505,60532,60560,60587,60614,
139 60642,60669,60696,60724,60751,60779,60806,60833,60861,60888,60916,60943,
140 60971,60998,61026,61054,61081,61109,61136,61164,61191,61219,61247,61274,
141 61302,61330,61357,61385,61413,61440,61468,61496,61524,61551,61579,61607,
142 61635,61663,61690,61718,61746,61774,61802,61830,61858,61886,61914,61942,
143 61970,61997,62025,62053,62081,62109,62138,62166,62194,62222,62250,62278,
144 62306,62334,62362,62390,62419,62447,62475,62503,62531,62560,62588,62616,
145 62644,62673,62701,62729,62757,62786,62814,62843,62871,62899,62928,62956,
146 62984,63013,63041,63070,63098,63127,63155,63184,63212,63241,63269,63298,
147 63326,63355,63384,63412,63441,63470,63498,63527,63555,63584,63613,63642,
148 63670,63699,63728,63757,63785,63814,63843,63872,63901,63929,63958,63987,
149 64016,64045,64074,64103,64132,64161,64190,64219,64248,64277,64306,64335,
150 64364,64393,64422,64451,64480,64509,64538,64567,64596,64626,64655,64684,
151 64713,64742,64772,64801,64830,64859,64889,64918,64947,64976,65006,65035,
152 65065,65094,65123,65153,65182,65211,65241,65270,65300,65329,65359,65388,
153 65418,65447,65477,65506,65536,65566,65595,65625,65654,65684,65714,65743,
154 65773,65803,65832,65862,65892,65922,65951,65981,66011,66041,66071,66100,
155 66130,66160,66190,66220,66250,66280,66309,66339,66369,66399,66429,66459,
156 66489,66519,66549,66579,66609,66639,66670,66700,66730,66760,66790,66820,
157 66850,66880,66911,66941,66971,67001,67032,67062,67092,67122,67153,67183,
158 67213,67244,67274,67304,67335,67365,67395,67426,67456,67487,67517,67548,
159 67578,67609,67639,67670,67700,67731,67761,67792,67823,67853,67884,67915,
160 67945,67976,68007,68037,68068,68099,68129,68160,68191,68222,68252,68283,
161 68314,68345,68376,68407,68438,68468,68499,68530,68561,68592,68623,68654,
162 68685,68716,68747,68778,68809,68840,68871,68902,68933,68965,68996,69027,
163 69058,69089,69120,69152,69183,69214,69245,69276,69308,69339,69370,69402,
164 69433,69464,69496,69527,69558,69590,69621,69653,69684,69716,69747,69778,
165 69810,69841,69873,69905,69936,69968,69999,70031,70062,70094,70126,70157,
166 70189,70221,70252,70284,70316,70348,70379,70411,70443,70475,70507,70538,
167 70570,70602,70634,70666,70698,70730,70762,70793,70825,70857,70889,70921,
168 70953,70985,71017,71049,71082,71114,71146,71178,71210,71242,71274,71306,
169 71339,71371,71403,71435,71468,71500,71532,71564,71597,71629,71661,71694,
170 71726,71758,71791,71823,71856,71888,71920,71953,71985,72018,72050,72083,
171 72115,72148,72181,72213,72246,72278,72311,72344,72376,72409,72442,72474,
172 72507,72540,72573,72605,72638,72671,72704,72736,72769,72802,72835,72868,
173 72901,72934,72967,72999,73032,73065,73098,73131,73164,73197,73230,73264,
174 73297,73330,73363,73396,73429,73462,73495,73528
175};*/
176
177
178
179 117
180static void findDelta(struct SynthObject * so, int ch, int note) 118static void findDelta(struct SynthObject * so, int ch, int note)
181{ 119{
@@ -183,16 +121,8 @@ static void findDelta(struct SynthObject * so, int ch, int note)
183 struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]]; 121 struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]];
184 so->wf=wf; 122 so->wf=wf;
185 unsigned int delta= 0; 123 unsigned int delta= 0;
186 124 delta = (((gustable[note+chPBNoteOffset[ch]]<<FRACTSIZE) / (wf->rootFreq)) * wf->sampRate / (SAMPLE_RATE));
187 int totalBend = (chPW[ch]-256) * chPBDepth[ch]; 125 delta = (delta * chPBFractBend[ch])>> 16;
188
189 int noteOffset = totalBend >> 8;
190
191 int pitchOffset = totalBend - (noteOffset<<8);
192
193
194 delta = (((gustable[note+noteOffset]<<FRACTSIZE) / (wf->rootFreq)) * wf->sampRate / (SAMPLE_RATE));
195 delta = (delta * pitchTbl[pitchOffset+256])>> 16;
196 126
197 so->delta = delta; 127 so->delta = delta;
198} 128}
@@ -201,6 +131,10 @@ static inline void setPW(int ch, int msb, int lsb)
201{ 131{
202 chPW[ch] = msb<<2|lsb>>5; 132 chPW[ch] = msb<<2|lsb>>5;
203 133
134 int totalBend = (chPW[ch]-256) * chPBDepth[ch];
135 chPBNoteOffset[ch] = totalBend >> 8;
136 chPBFractBend[ch] = pitchTbl[(totalBend & 0xFF) + 256];
137
204 int a=0; 138 int a=0;
205 for(a = 0; a<MAX_VOICES; a++) 139 for(a = 0; a<MAX_VOICES; a++)
206 { 140 {
diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c
index f0fa93d60e..9ec5580310 100644
--- a/apps/plugins/midi/synth.c
+++ b/apps/plugins/midi/synth.c
@@ -66,6 +66,8 @@ int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
66 chPat[a]=0; /* Ac Gr Piano */ 66 chPat[a]=0; /* Ac Gr Piano */
67 chPW[a]=256; /* .. not .. bent ? */ 67 chPW[a]=256; /* .. not .. bent ? */
68 chPBDepth[a]=2; /* Default bend value is 2 */ 68 chPBDepth[a]=2; /* Default bend value is 2 */
69 chPBNoteOffset[a]=0; /* No offset */
70 chPBFractBend[a]=65536; /* Center.. no bend */
69 } 71 }
70 for(a=0; a<128; a++) 72 for(a=0; a<128; a++)
71 { 73 {