From 47d8323deb8c7351c66a89599f15b60e06a5b814 Mon Sep 17 00:00:00 2001 From: Stepan Moskovchenko Date: Sun, 21 Oct 2007 19:47:33 +0000 Subject: MIDI: Fix ringing/beeks in music caused by improper parsing of some pitch bend events. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15252 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/midi/midiutil.c | 3 ++- apps/plugins/midi/midiutil.h | 15 ++++++++++++--- apps/plugins/midi/sequencer.c | 33 +++++++++++++++++++++++++++++++-- apps/plugins/midi/synth.c | 2 ++ 4 files changed, 47 insertions(+), 6 deletions(-) (limited to 'apps/plugins') diff --git a/apps/plugins/midi/midiutil.c b/apps/plugins/midi/midiutil.c index 92ab8db8d6..65ba9c8989 100644 --- a/apps/plugins/midi/midiutil.c +++ b/apps/plugins/midi/midiutil.c @@ -28,7 +28,8 @@ int chPW[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */ int chPBDepth[16] IBSS_ATTR; /* Channel pitch bend depth */ int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */ int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */ - +unsigned char chLastCtrlMSB[16]; /* MIDI regs, used for Controller 6. */ +unsigned char chLastCtrlLSB[16]; /* The non-registered ones are ignored */ struct GPatch * gusload(char *); struct GPatch * patchSet[128]; diff --git a/apps/plugins/midi/midiutil.h b/apps/plugins/midi/midiutil.h index cb89e004aa..dfffe39dd6 100644 --- a/apps/plugins/midi/midiutil.h +++ b/apps/plugins/midi/midiutil.h @@ -62,10 +62,19 @@ #define MIDI_PITCHW 224 /* MIDI Controllers */ -#define CTRL_PWDEPTH 6 +#define CTRL_DATAENT_MSB 6 #define CTRL_VOLUME 7 #define CTRL_BALANCE 8 #define CTRL_PANNING 10 +#define CTRL_NONREG_LSB 98 +#define CTRL_NONREG_MSB 99 +#define CTRL_REG_LSB 100 +#define CTRL_REG_MSB 101 + +#define REG_PITCHBEND_MSB 0 +#define REG_PITCHBEND_LSB 0 + + #define CHANNEL 1 /* Most of these are deprecated.. rampdown is used, maybe one other one too */ @@ -145,8 +154,8 @@ extern int chPW[16]; /* Channel pitch wheel, MSB only */ extern int chPBDepth[16]; /* Channel pitch bend depth (Controller 6 */ extern int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */ extern int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */ - - +extern unsigned char chLastCtrlMSB[16]; /* MIDI regs, used for Controller 6. */ +extern unsigned char chLastCtrlLSB[16]; /* The non-registered ones are ignored */ extern struct GPatch * gusload(char *); extern struct GPatch * patchSet[128]; diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c index 536d411902..c4ddfcf95a 100644 --- a/apps/plugins/midi/sequencer.c +++ b/apps/plugins/midi/sequencer.c @@ -299,10 +299,39 @@ static void sendEvent(struct Event * ev) chPan[status_low]=d2; return; } - case CTRL_PWDEPTH: + case CTRL_DATAENT_MSB: { /* TODO: Update all deltas. Is this really needed? */ - chPBDepth[status_low] = d2; + if(chLastCtrlMSB[status_low] == REG_PITCHBEND_MSB && + chLastCtrlLSB[status_low] == REG_PITCHBEND_LSB) + { +// printf("Pitch bend depth set to %d\n", d2); + chPBDepth[status_low] = d2; + } + return; + } + + case CTRL_NONREG_LSB: + { + chLastCtrlLSB[status_low] = 0xFF; /* Ignore nonregistered writes */ + return; + } + + case CTRL_NONREG_MSB: + { + chLastCtrlMSB[status_low] = 0xFF; /* Ignore nonregistered writes */ + return; + } + + case CTRL_REG_LSB: + { + chLastCtrlLSB[status_low] = d2; + return; + } + + case CTRL_REG_MSB: + { + chLastCtrlMSB[status_low] = d2; return; } diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c index 7ae7a78583..3c60d9bd82 100644 --- a/apps/plugins/midi/synth.c +++ b/apps/plugins/midi/synth.c @@ -68,6 +68,8 @@ int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig) chPBDepth[a]=2; /* Default bend value is 2 */ chPBNoteOffset[a]=0; /* No offset */ chPBFractBend[a]=65536; /* Center.. no bend */ + chLastCtrlMSB[a]=0; /* Set to pitch bend depth */ + chLastCtrlLSB[a]=0; /* Set to pitch bend depth */ } for(a=0; a<128; a++) { -- cgit v1.2.3