1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Stepan Moskovchenko 2007-11-17 06:39:02 +00:00
parent 39429616c3
commit 7f1fbe4af2
2 changed files with 20 additions and 5 deletions

View file

@ -17,7 +17,7 @@
* *
****************************************************************************/ ****************************************************************************/
#define FRACTSIZE 10 #define FRACTSIZE 12
#define BUF_SIZE 8192 /* 32 kB output buffers */ #define BUF_SIZE 8192 /* 32 kB output buffers */
#define NBUF 2 #define NBUF 2

View file

@ -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]]; struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]];
so->wf=wf; so->wf=wf;
unsigned int delta= 0;
delta = (((gustable[note+chPBNoteOffset[ch]]<<FRACTSIZE) / (wf->rootFreq)) * wf->sampRate / (SAMPLE_RATE));
delta = (delta * chPBFractBend[ch])>> 16;
/* 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));
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; so->delta = delta;
} }
@ -250,7 +265,7 @@ inline void pressNote(int ch, int note, int vol)
struct GWaveform * wf = drumSet[note]->waveforms[0]; struct GWaveform * wf = drumSet[note]->waveforms[0];
voices[a].wf=wf; 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) if(wf->mode & 28)
// printf("\nWoah, a drum patch has a loop. Stripping the loop..."); // printf("\nWoah, a drum patch has a loop. Stripping the loop...");
wf->mode = wf->mode & (255-28); wf->mode = wf->mode & (255-28);