summaryrefslogtreecommitdiff
path: root/apps/plugins/midi
diff options
context:
space:
mode:
authorStepan Moskovchenko <stevenm@rockbox.org>2007-11-17 06:39:02 +0000
committerStepan Moskovchenko <stevenm@rockbox.org>2007-11-17 06:39:02 +0000
commit7f1fbe4af2d7e44e808418a969f5d2301b002c61 (patch)
tree7cbd226bb0afc1ccaca9410225f1a4691ce4eacc /apps/plugins/midi
parent39429616c3ab5dd3919b6fb0bc3a24ef0127240b (diff)
downloadrockbox-7f1fbe4af2d7e44e808418a969f5d2301b002c61.zip
rockbox-7f1fbe4af2d7e44e808418a969f5d2301b002c61.tar.gz
rockbox-7f1fbe4af2d7e44e808418a969f5d2301b002c61.tar.bz2
rockbox-7f1fbe4af2d7e44e808418a969f5d2301b002c61.tar.xz
MIDI: Increase percision of synthesizer by a factor of 4 - makes certain parts (guitar bends, mostly)
sound more natural. Also, completely rearrange the order of operations in the delta computation. Had to use long longs. Probably not a good idea for speed, but the order can be optimized more later. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15652 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/midi')
-rw-r--r--apps/plugins/midi/midiutil.h2
-rw-r--r--apps/plugins/midi/sequencer.c21
2 files changed, 19 insertions, 4 deletions
diff --git a/apps/plugins/midi/midiutil.h b/apps/plugins/midi/midiutil.h
index 18d493b..c3c5d91 100644
--- a/apps/plugins/midi/midiutil.h
+++ b/apps/plugins/midi/midiutil.h
@@ -17,7 +17,7 @@
*
****************************************************************************/
-#define FRACTSIZE 10
+#define FRACTSIZE 12
#define BUF_SIZE 8192 /* 32 kB output buffers */
#define NBUF 2
diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c
index bd2f33b..e2a9f7d 100644
--- a/apps/plugins/midi/sequencer.c
+++ b/apps/plugins/midi/sequencer.c
@@ -144,10 +144,25 @@ static void findDelta(struct SynthObject * so, int ch, int note)
{
struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]];
so->wf=wf;
- unsigned int delta= 0;
+
+ /* Used to be unsigned int, but math had to be done in different order to avoid overflow */
+ unsigned long long delta= 0;
+
+/*
+ Old formula:
delta = (((gustable[note+chPBNoteOffset[ch]]<<FRACTSIZE) / (wf->rootFreq)) * wf->sampRate / (SAMPLE_RATE));
- delta = (delta * chPBFractBend[ch])>> 16;
+ Plus some pitch stuff. See old SVN for how it used to be
+*/
+
+ delta = (((gustable[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 */
+ delta = delta / (wf->rootFreq); /* anywhere from 8000 to 8000000 */
+
+ /* Pitch bend is encoded as a fractional of 16 bits, hence the 16 */
+ delta = delta >> (16 - FRACTSIZE); /* a shift of approx 4 bits */
so->delta = delta;
}
@@ -250,7 +265,7 @@ 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]<<10) / wf->rootFreq) * wf->sampRate / SAMPLE_RATE);
+ voices[a].delta = (((gustable[note]<<FRACTSIZE) / wf->rootFreq) * wf->sampRate / SAMPLE_RATE);
if(wf->mode & 28)
// printf("\nWoah, a drum patch has a loop. Stripping the loop...");
wf->mode = wf->mode & (255-28);