[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch
From: |
jimmy |
Subject: |
[fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch |
Date: |
Thu, 10 Feb 2011 14:00:37 -0800 (PST) |
--- On Sat, 5 Feb 2011, "Pedro Lopez-Cabanillas" <address@hidden> wrote:
> > And to the rest of you - this bank select handling
> seems to be a never
> > ending debate, and it's not my area of expertise, so
> let me know if this
> > change screwed something up for you.
>
> Looks OK, and also works fine in my tests with a few MIDI
> files created for XG synths that I've found in my HD.
>
> You are perceiving that there is debate around this matter,
> when in fact the controversy comes from many years ago, when
> the MIDI manufacturers defined those different standards
> (GM, GS and XG) and people used the synths to create
> MIDI files following each one. Now, to render those old MIDI
> files using FluidSynth we would like that FS follow
> each one of the conventions as closely as possible. I've
> never been a XG user, so changeset #340 included several
> TODOs and FIXMEs that this patch has finally addressed. But
> there is still one (FIXME: pending implementation of SYSEX
> midi mode changes) that somebody has to work on, and there
> may be a few issues more than bank changes involved.
>
> Regards,
> Pedro
The Fluidsynth MSB, LSB handling code is not easy to read the first few dozen
times for me, involving several bit masks, bit inversion, bit shift and can
easily clear out other fields. Perhaps we can put in some comments to help
explain it quickly. Please do it, keep this with the code, probably above
fluid_channel_set_bank_msb(), or fluid_channel_set_bank_lsb():
/* The MSB, LSB calculation has 2 parts:
* "(oldval & ~BANKLSB_MASKVAL)" , and
* " | (someval << BANK_SHIFTVAL)
* where:
* (oldval & ~BANKLSB_MASKVAL) means zeroes out 7-bit LSB field
* (oldval & ~BANKMSB_MASKVAL) means zeroes out 7-bit MSB field
* (oldval & ~BANK_MASKVAL) means zeroes out 14-bit field (both MSB,LSB)
* and:
* " | (someval << BANK_SHIFTVAL) means add in 7-bit variable "someval" as LSB
field
* " | (someval << (BANK_SHIFTVAL + 7)) means add in 7-bit variable "someval"
as MSB field
*/
/* Set bank MSB 7 bits. */
void
fluid_channel_set_bank_msb(fluid_channel_t* chan, int bankmsb)
{ . . . }
After reading such comments in the code, it is so easy and much quicker to make
changes. Isn't it?
-----
I haven't read much on GS, so if someone who knows about GS bank handling, can
you check and see if GS bank number can be calculated MMA-style? It is
basically convert the combined MSB, LSB as a decimal number, as us in Cakewalk
.ins instrument definition files.
MSB, LSB calculation is only confusing because of the way it was "assumed" by
programmers, especially on older devices.
I believe MSB, LSB are straight forward. The calculation is always MMA style.
It is basically a 14-bit unsigned interger split up as 2 7-bit unsigned
integers (because MIDI is operating on 8-bits, but the highest bit is already
used for other things). First 7-bits (left to right) of that 14-bit is called
the MSB, the rest is the LSB. So to calculate it as a decimal number it is
(128*MSB) + LSB. In C, multiply by 128 is the same as bit-shift to the left 7
places.
In ancient cultures 8-) , hardware was limited. So, some of them only use one
byte instead of both bytes, "assuming" the other byte was 0 and perhaps didn't
have the hardware component for it. For example, LSB is "optional" in older XG
instruments. It probably means that some of their old equipments didn't use
LSB (memory was expensive), while their newer equipments do, and they want them
to still work together.
Programmers, especially "reversed engineers" of those days would see only one
byte (one CC message), never see the other CC-message, and may claim that there
was no use at all for that other byte, just ignore it altogether in their
programs (and/or midi files). When in fact, optional really means it should be
counted as 0, and not "short circuited" from program flow altogether (the way
drum channel is assumed in Fluidsynth calculation of MSB, and especially LSB).
I guess originally MSB=128 was usable on any channels, because some (drum, or
voice generator) hardwares probably didn't even have 16 channels. So some midi
hardwares just work fine by itself, but would mess up big time when hooked up
with other midi equipments. Midi specs came out and recommend certain things,
including drum channel being #10. Many people assume that is the only thing to
do, no exception, and hard-code drum related thing to channel 10, just because
most hardwares were made to only satisfy the GM specs and nothing more. The
way I see it, both GS and XG have done it right by allowing drums on any
channel. Although, I'm not too familiar with GS in detail.
The old "assumptions" of how GS does it, how XG does it, resulted in code that
assume too much and cut out the full calculation. I think both of them are
calculated the same as MMA-style. For example, in XG drum bank usage,
currently only MSB is used. But it should not be assumed that LSB will never
be used with drum banks. The "return if channel is drum-channel" check in both
Fluidsynth functions should not be there, I believe.
-----
The way I see it, the check "if channel is drum-channel" in both
fluid_channel_set_bank_msb(), and fluid_channel_set_bank_lsb() should be ripped
out.
For example, in GM mode it is "commonly" assumed that it can use any bank
number except bank number 128. And that channel 10, defaults to bank number
128 cannot be changed to any other number.
That's just wrong. I think any channel should still be able to change to use
bank number 128 (which has drum sounds for notes). Of course, XG uses MSB=128
(that is 128*128, or 16384 in MMA-style decimal number, 16383 for 0-offset), I
believe GS uses LSB=128, that's all.
On the other hand, I think channel 10 should still be able to use any
banknumber, too. Not being tied to bank number 128.
Regardless, once a channel is determined to be drum, or melodic, the only
difference between them is the bank fall-back lookup scheme. Melodic channels
fall-back eventually to bank number 0. Drum channels fall-back to bank number
128 (XG use of MSB=120, or 126, for example).
2-3 years ago I put in the patch for melodic bank number fall-back scheme.
Back then, if a bank could not be found, the channel went completely silent.
Since then, for XG midi files that uses drum bank 126, I will hear Piano. It
doesn't sound good, or right, but at least now I know something needed to be
changed (the midi file), or fixed (in the soft synth), rather than not knowing
anything is there at all.
Now with drum channel auto switching (at least in XG mode), I can say that drum
channels finally sound like drums. If it doesn't sound good, maybe a better
soundfont could help. I don't have to hear Piano thumping on drum channels (on
channel other than 10) any more.
Jimmy
- [fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch, jimmy, 2011/02/07
- [fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch, jimmy, 2011/02/09
- Re: [fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch, David Henningsson, 2011/02/10
- Re: [fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch, Pedro Lopez-Cabanillas, 2011/02/10
- Re: [fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch, jimmy, 2011/02/10
- Re: [fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch, David Henningsson, 2011/02/11
- Re: [fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch, jimmy, 2011/02/11
- Re: [fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch, jimmy, 2011/02/10
[fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch,
jimmy <=
[fluid-dev] Re: Patch for channel_type, also XG drum-channel autoswitch, jimmy, 2011/02/10