diff options
author | Stepan Moskovchenko <stevenm@rockbox.org> | 2006-05-01 23:22:59 +0000 |
---|---|---|
committer | Stepan Moskovchenko <stevenm@rockbox.org> | 2006-05-01 23:22:59 +0000 |
commit | b2f1b5dd183b1171c81796946c868f2df8df9647 (patch) | |
tree | 3f2fcd3bdf2e2f9e00ad253d671b5c27a52280ad /apps/plugins/midi/sequencer.c | |
parent | 9e3da0d6d5bc9d02b939dedd62e05f8893940c1a (diff) | |
download | rockbox-b2f1b5dd183b1171c81796946c868f2df8df9647.tar.gz rockbox-b2f1b5dd183b1171c81796946c868f2df8df9647.zip |
----------------------------------------------------------------------
Added Karl Kurbjun's sound output patch, cleaned up some output.
Main file is now midiplay.c, midi2wav is still in there for anyone who
wants it. Set sampling rate to 22k, and increased note decay time.
Reduced number of concurrent active voices and made new notes replace
used voices if none are available. This makes lag less apparent.
I really hope this wont go red. (turns around and runs)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9858 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/midi/sequencer.c')
-rw-r--r-- | apps/plugins/midi/sequencer.c | 109 |
1 files changed, 78 insertions, 31 deletions
diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c index 4ae5a9f5fe..3c026276c2 100644 --- a/apps/plugins/midi/sequencer.c +++ b/apps/plugins/midi/sequencer.c | |||
@@ -22,22 +22,22 @@ extern struct plugin_api * rb; | |||
22 | long tempo=375000; | 22 | long tempo=375000; |
23 | 23 | ||
24 | 24 | ||
25 | void setVol(int ch, int vol) | 25 | inline void setVol(int ch, int vol) |
26 | { | 26 | { |
27 | printf("\nvolume[%d] %d ==> %d", ch, chVol[ch], vol); | 27 | // printf("\nvolume[%d] %d ==> %d", ch, chVol[ch], vol); |
28 | chVol[ch]=vol; | 28 | chVol[ch]=vol; |
29 | } | 29 | } |
30 | 30 | ||
31 | void setPan(int ch, int pan) | 31 | inline void setPan(int ch, int pan) |
32 | { | 32 | { |
33 | printf("\npanning[%d] %d ==> %d", ch, chPanRight[ch], pan); | 33 | // printf("\npanning[%d] %d ==> %d", ch, chPanRight[ch], pan); |
34 | 34 | ||
35 | chPanLeft[ch]=128-pan; | 35 | chPanLeft[ch]=128-pan; |
36 | chPanRight[ch]=pan; | 36 | chPanRight[ch]=pan; |
37 | } | 37 | } |
38 | 38 | ||
39 | 39 | ||
40 | void setPatch(int ch, int pat) | 40 | inline void setPatch(int ch, int pat) |
41 | { | 41 | { |
42 | chPat[ch]=pat; | 42 | chPat[ch]=pat; |
43 | } | 43 | } |
@@ -52,18 +52,64 @@ void setPatch(int ch, int pat) | |||
52 | /* | 52 | /* |
53 | long pitchTbl[]= | 53 | long pitchTbl[]= |
54 | { | 54 | { |
55 | 58386,58491,58597,58703,58809,58915,59022,59128,59235,59342,59449,59557,59664,59772,59880,59988,60097,60205, | 55 | 58386,58491,58597,58703,58809,58915,59022,59128,59235,59342,59449,59557, |
56 | 60314,60423,60532,60642,60751,60861,60971,61081,61191,61302,61413,61524,61635,61746,61858,61970,62081,62194, | 56 | 59664,59772,59880,59988,60097,60205,60314,60423,60532,60642,60751,60861, |
57 | 62306,62419,62531,62644,62757,62871,62984,63098,63212,63326,63441,63555,63670,63785,63901,64016,64132,64248, | 57 | 60971,61081,61191,61302,61413,61524,61635,61746,61858,61970,62081,62194, |
58 | 64364,64480,64596,64713,64830,64947,65065,65182,65300,65418,65536,65654,65773,65892,66011,66130,66250,66369, | 58 | 62306,62419,62531,62644,62757,62871,62984,63098,63212,63326,63441,63555, |
59 | 66489,66609,66730,66850,66971,67092,67213,67335,67456,67578,67700,67823,67945,68068,68191,68314,68438,68561, | 59 | 63670,63785,63901,64016,64132,64248,64364,64480,64596,64713,64830,64947, |
60 | 68685,68809,68933,69058,69183,69308,69433,69558,69684,69810,69936,70062,70189,70316,70443,70570,70698,70825, | 60 | 65065,65182,65300,65418,65536,65654,65773,65892,66011,66130,66250,66369, |
61 | 70953,71082,71210,71339,71468,71597,71726,71856,71985,72115,72246,72376,72507,72638,72769,72901,73032,73164, | 61 | 66489,66609,66730,66850,66971,67092,67213,67335,67456,67578,67700,67823, |
62 | 73297,73429 | 62 | 67945,68068,68191,68314,68438,68561,68685,68809,68933,69058,69183,69308, |
63 | 69433,69558,69684,69810,69936,70062,70189,70316,70443,70570,70698,70825, | ||
64 | 70953,71082,71210,71339,71468,71597,71726,71856,71985,72115,72246,72376, | ||
65 | 72507,72638,72769,72901,73032,73164,73297,73429 | ||
63 | }; | 66 | }; |
64 | */ | 67 | */ |
65 | long pitchTbl[]={ | 68 | |
66 | 58386,58412,58439,58465,58491,58518,58544,58571,58597,58624,58650,58676,58703,58729,58756,58782,58809,58836,58862,58889,58915,58942,58968,58995,59022,59048,59075,59102,59128,59155,59182,59208,59235,59262,59289,59315,59342,59369,59396,59423,59449,59476,59503,59530,59557,59584,59611,59638,59664,59691,59718,59745,59772,59799,59826,59853,59880,59907,59934,59961,59988,60015,60043,60070,60097,60124,60151,60178,60205,60233,60260,60287,60314,60341,60369,60396,60423,60450,60478,60505,60532,60560,60587,60614,60642,60669,60696,60724,60751,60779,60806,60833,60861,60888,60916,60943,60971,60998,61026,61054,61081,61109,61136,61164,61191,61219,61247,61274,61302,61330,61357,61385,61413,61440,61468,61496,61524,61551,61579,61607,61635,61663,61690,61718,61746,61774,61802,61830,61858,61886,61914,61942,61970,61997,62025,62053,62081,62109,62138,62166,62194,62222,62250,62278,62306,62334,62362,62390,62419,62447,62475,62503,62531,62560,62588,62616,62644,62673,62701,62729,62757,62786,62814,62843,62871,62899,62928,62956,62984,63013,63041,63070,63098,63127,63155,63184,63212,63241,63269,63298,63326,63355,63384,63412,63441,63470,63498,63527,63555,63584,63613,63642,63670,63699,63728,63757,63785,63814,63843,63872,63901,63929,63958,63987,64016,64045,64074,64103,64132,64161,64190,64219,64248,64277,64306,64335,64364,64393,64422,64451,64480,64509,64538,64567,64596,64626,64655,64684,64713,64742,64772,64801,64830,64859,64889,64918,64947,64976,65006,65035,65065,65094,65123,65153,65182,65211,65241,65270,65300,65329,65359,65388,65418,65447,65477,65506,65536,65566,65595,65625,65654,65684,65714,65743,65773,65803,65832,65862,65892,65922,65951,65981,66011,66041,66071,66100,66130,66160,66190,66220,66250,66280,66309,66339,66369,66399,66429,66459,66489,66519,66549,66579,66609,66639,66670,66700,66730,66760,66790,66820,66850,66880,66911,66941,66971,67001,67032,67062,67092,67122,67153,67183,67213,67244,67274,67304,67335,67365,67395,67426,67456,67487,67517,67548,67578,67609,67639,67670,67700,67731,67761,67792,67823,67853,67884,67915,67945,67976,68007,68037,68068,68099,68129,68160,68191,68222,68252,68283,68314,68345,68376,68407,68438,68468,68499,68530,68561,68592,68623,68654,68685,68716,68747,68778,68809,68840,68871,68902,68933,68965,68996,69027,69058,69089,69120,69152,69183,69214,69245,69276,69308,69339,69370,69402,69433,69464,69496,69527,69558,69590,69621,69653,69684,69716,69747,69778,69810,69841,69873,69905,69936,69968,69999,70031,70062,70094,70126,70157,70189,70221,70252,70284,70316,70348,70379,70411,70443,70475,70507,70538,70570,70602,70634,70666,70698,70730,70762,70793,70825,70857,70889,70921,70953,70985,71017,71049,71082,71114,71146,71178,71210,71242,71274,71306,71339,71371,71403,71435,71468,71500,71532,71564,71597,71629,71661,71694,71726,71758,71791,71823,71856,71888,71920,71953,71985,72018,72050,72083,72115,72148,72181,72213,72246,72278,72311,72344,72376,72409,72442,72474,72507,72540,72573,72605,72638,72671,72704,72736,72769,72802,72835,72868,72901,72934,72967,72999,73032,73065,73098,73131,73164,73197,73230,73264,73297,73330,73363,73396,73429,73462,73495,73528 | 69 | long pitchTbl[] ICONST_ATTR={ |
70 | 58386,58412,58439,58465,58491,58518,58544,58571,58597,58624,58650,58676, | ||
71 | 58703,58729,58756,58782,58809,58836,58862,58889,58915,58942,58968,58995, | ||
72 | 59022,59048,59075,59102,59128,59155,59182,59208,59235,59262,59289,59315, | ||
73 | 59342,59369,59396,59423,59449,59476,59503,59530,59557,59584,59611,59638, | ||
74 | 59664,59691,59718,59745,59772,59799,59826,59853,59880,59907,59934,59961, | ||
75 | 59988,60015,60043,60070,60097,60124,60151,60178,60205,60233,60260,60287, | ||
76 | 60314,60341,60369,60396,60423,60450,60478,60505,60532,60560,60587,60614, | ||
77 | 60642,60669,60696,60724,60751,60779,60806,60833,60861,60888,60916,60943, | ||
78 | 60971,60998,61026,61054,61081,61109,61136,61164,61191,61219,61247,61274, | ||
79 | 61302,61330,61357,61385,61413,61440,61468,61496,61524,61551,61579,61607, | ||
80 | 61635,61663,61690,61718,61746,61774,61802,61830,61858,61886,61914,61942, | ||
81 | 61970,61997,62025,62053,62081,62109,62138,62166,62194,62222,62250,62278, | ||
82 | 62306,62334,62362,62390,62419,62447,62475,62503,62531,62560,62588,62616, | ||
83 | 62644,62673,62701,62729,62757,62786,62814,62843,62871,62899,62928,62956, | ||
84 | 62984,63013,63041,63070,63098,63127,63155,63184,63212,63241,63269,63298, | ||
85 | 63326,63355,63384,63412,63441,63470,63498,63527,63555,63584,63613,63642, | ||
86 | 63670,63699,63728,63757,63785,63814,63843,63872,63901,63929,63958,63987, | ||
87 | 64016,64045,64074,64103,64132,64161,64190,64219,64248,64277,64306,64335, | ||
88 | 64364,64393,64422,64451,64480,64509,64538,64567,64596,64626,64655,64684, | ||
89 | 64713,64742,64772,64801,64830,64859,64889,64918,64947,64976,65006,65035, | ||
90 | 65065,65094,65123,65153,65182,65211,65241,65270,65300,65329,65359,65388, | ||
91 | 65418,65447,65477,65506,65536,65566,65595,65625,65654,65684,65714,65743, | ||
92 | 65773,65803,65832,65862,65892,65922,65951,65981,66011,66041,66071,66100, | ||
93 | 66130,66160,66190,66220,66250,66280,66309,66339,66369,66399,66429,66459, | ||
94 | 66489,66519,66549,66579,66609,66639,66670,66700,66730,66760,66790,66820, | ||
95 | 66850,66880,66911,66941,66971,67001,67032,67062,67092,67122,67153,67183, | ||
96 | 67213,67244,67274,67304,67335,67365,67395,67426,67456,67487,67517,67548, | ||
97 | 67578,67609,67639,67670,67700,67731,67761,67792,67823,67853,67884,67915, | ||
98 | 67945,67976,68007,68037,68068,68099,68129,68160,68191,68222,68252,68283, | ||
99 | 68314,68345,68376,68407,68438,68468,68499,68530,68561,68592,68623,68654, | ||
100 | 68685,68716,68747,68778,68809,68840,68871,68902,68933,68965,68996,69027, | ||
101 | 69058,69089,69120,69152,69183,69214,69245,69276,69308,69339,69370,69402, | ||
102 | 69433,69464,69496,69527,69558,69590,69621,69653,69684,69716,69747,69778, | ||
103 | 69810,69841,69873,69905,69936,69968,69999,70031,70062,70094,70126,70157, | ||
104 | 70189,70221,70252,70284,70316,70348,70379,70411,70443,70475,70507,70538, | ||
105 | 70570,70602,70634,70666,70698,70730,70762,70793,70825,70857,70889,70921, | ||
106 | 70953,70985,71017,71049,71082,71114,71146,71178,71210,71242,71274,71306, | ||
107 | 71339,71371,71403,71435,71468,71500,71532,71564,71597,71629,71661,71694, | ||
108 | 71726,71758,71791,71823,71856,71888,71920,71953,71985,72018,72050,72083, | ||
109 | 72115,72148,72181,72213,72246,72278,72311,72344,72376,72409,72442,72474, | ||
110 | 72507,72540,72573,72605,72638,72671,72704,72736,72769,72802,72835,72868, | ||
111 | 72901,72934,72967,72999,73032,73065,73098,73131,73164,73197,73230,73264, | ||
112 | 73297,73330,73363,73396,73429,73462,73495,73528 | ||
67 | }; | 113 | }; |
68 | 114 | ||
69 | void findDelta(struct SynthObject * so, int ch, int note) | 115 | void findDelta(struct SynthObject * so, int ch, int note) |
@@ -75,9 +121,9 @@ void findDelta(struct SynthObject * so, int ch, int note) | |||
75 | so->delta = (so->delta * pitchTbl[chPW[ch]])>> 16; | 121 | so->delta = (so->delta * pitchTbl[chPW[ch]])>> 16; |
76 | } | 122 | } |
77 | 123 | ||
78 | void setPW(int ch, int msb, int lsb) | 124 | inline void setPW(int ch, int msb, int lsb) |
79 | { | 125 | { |
80 | printf("\npitchw[%d] %d ==> %d", ch, chPW[ch], msb); | 126 | // printf("\npitchw[%d] %d ==> %d", ch, chPW[ch], msb); |
81 | chPW[ch] = msb<<2|lsb>>5; | 127 | chPW[ch] = msb<<2|lsb>>5; |
82 | 128 | ||
83 | int a=0; | 129 | int a=0; |
@@ -92,7 +138,7 @@ void setPW(int ch, int msb, int lsb) | |||
92 | 138 | ||
93 | void pressNote(int ch, int note, int vol) | 139 | void pressNote(int ch, int note, int vol) |
94 | { | 140 | { |
95 | 141 | static int lastKill = 0; | |
96 | //Silences all channels but one, for easy debugging, for me. | 142 | //Silences all channels but one, for easy debugging, for me. |
97 | /* | 143 | /* |
98 | if(ch == 0) return; | 144 | if(ch == 0) return; |
@@ -123,11 +169,16 @@ void pressNote(int ch, int note, int vol) | |||
123 | } | 169 | } |
124 | if(a==MAX_VOICES-1) | 170 | if(a==MAX_VOICES-1) |
125 | { | 171 | { |
126 | printf("\nOVERFLOW: Too many voices playing at once. No more left"); | 172 | // printf("\nVoice kill"); |
127 | printf("\nVOICE DUMP: "); | 173 | // printf("\nToo many voices playing at once. No more left"); |
128 | for(a=0; a<48; a++) | 174 | // printf("\nVOICE DUMP: "); |
129 | printf("\n#%d Ch=%d Note=%d curRate=%d curOffset=%d curPoint=%d targetOffset=%d", a, voices[a].ch, voices[a].note, voices[a].curRate, voices[a].curOffset, voices[a].curPoint, voices[a].targetOffset); | 175 | // for(a=0; a<48; a++) |
130 | return; /* None available */ | 176 | // printf("\n#%d Ch=%d Note=%d curRate=%d curOffset=%d curPoint=%d targetOffset=%d", a, voices[a].ch, voices[a].note, voices[a].curRate, voices[a].curOffset, voices[a].curPoint, voices[a].targetOffset); |
177 | lastKill++; | ||
178 | if(lastKill == MAX_VOICES) | ||
179 | lastKill = 0; | ||
180 | a = lastKill; | ||
181 | // return; /* None available */ | ||
131 | } | 182 | } |
132 | voices[a].ch=ch; | 183 | voices[a].ch=ch; |
133 | voices[a].note=note; | 184 | voices[a].note=note; |
@@ -163,7 +214,7 @@ void pressNote(int ch, int note, int vol) | |||
163 | voices[a].wf=wf; | 214 | voices[a].wf=wf; |
164 | voices[a].delta = (((gustable[note]<<10) / wf->rootFreq) * wf->sampRate / SAMPLE_RATE); | 215 | voices[a].delta = (((gustable[note]<<10) / wf->rootFreq) * wf->sampRate / SAMPLE_RATE); |
165 | if(wf->mode & 28) | 216 | if(wf->mode & 28) |
166 | printf("\nWoah, a drum patch has a loop. Stripping the loop..."); | 217 | // printf("\nWoah, a drum patch has a loop. Stripping the loop..."); |
167 | wf->mode = wf->mode & (255-28); | 218 | wf->mode = wf->mode & (255-28); |
168 | 219 | ||
169 | /* Turn it on */ | 220 | /* Turn it on */ |
@@ -172,7 +223,7 @@ void pressNote(int ch, int note, int vol) | |||
172 | 223 | ||
173 | } else | 224 | } else |
174 | { | 225 | { |
175 | printf("\nWarning: drum %d does not have a patch defined... Ignoring it", note); | 226 | /* printf("\nWarning: drum %d does not have a patch defined... Ignoring it", note); */ |
176 | } | 227 | } |
177 | } | 228 | } |
178 | } | 229 | } |
@@ -244,11 +295,7 @@ void sendEvent(struct Event * ev) | |||
244 | } | 295 | } |
245 | } | 296 | } |
246 | 297 | ||
247 | 298 | int tick(void) | |
248 | |||
249 | |||
250 | |||
251 | int tick(struct MIDIfile * mf) | ||
252 | { | 299 | { |
253 | if(mf==NULL) | 300 | if(mf==NULL) |
254 | return 0; | 301 | return 0; |
@@ -280,7 +327,7 @@ int tick(struct MIDIfile * mf) | |||
280 | sendEvent(e); | 327 | sendEvent(e); |
281 | if(((e->status&0xF0) == MIDI_PRGM)) | 328 | if(((e->status&0xF0) == MIDI_PRGM)) |
282 | { | 329 | { |
283 | printf("\nPatch Event, patch[%d] ==> %d", e->status&0xF, e->d1); | 330 | /* printf("\nPatch Event, patch[%d] ==> %d", e->status&0xF, e->d1); */ |
284 | } | 331 | } |
285 | } | 332 | } |
286 | else | 333 | else |