GBE-HD sound replacement by midi

The emulator can convert the APU state to midi equivalent and sends to midi device in real time. 3 new tags are added to hires.txt format:
<midi>c,duty,instrument,harmonic,volume
c: 0=square channel 1, 1=square channel2
duty: 0-3 See https://gbdev.io/pandocs/Audio_Registers.html#ff11--nr11-channel-1-length-timer--duty-cycle
instrument: 0-127 See https://en.wikipedia.org/wiki/General_MIDI for list of instrument. Subtract 1 from the number.
harmonic: n=normal, y=play 3 notes at the same time with one at 1 octave above and one at 1 octave below. May sound better in some cases.
volume: 0-100

<wave>h,instrument,harmonic,volume
h: Values from memory address FF30-FF3F
instrument,harmonic,volume: See above

<noise>b,per,volume
B: Value of register NR43
per: percussion instruments see https://en.wikipedia.org/wiki/General_MIDI. Do not need to subtract 1 from the number
volume: see above



GBE-HD sound replacement by ogg file

The emulator allows the user to play ogg file during gameplay. There are two types of playing the file. One is to play as music, which only one can play at a time, can be set to loop and can be paused. The other is the play the file as sound effect. Sound effects can overlap each other and they cannot loop or pause. To use this feature, the following is required in the hires.txt file:
1. Memory addresses for which the emulator will monitor
2. Rules of what to do when a write or read to those addresses occurs
3. List of ogg files to play 

Defining multiple rules for the same address creates a rule chain which the emulator will run in order. The format of defining an address to be written to and the handling rule is:
<writeaddress>address,function,replacement,value1,value2
address: the memory address in HEX
function: one of the following values - 
    0 =None
    1 =Play music
    2 =Set music looping
    3 =Set music not looping
    4 =Stop music
    5 =Pause music
    6 =Resume music
    7 =Set music volume
    8 =Play sound effect
    9 =Stop all sound effect
    10=Set sound effect volume
replacement: one of the following values -
    0 =No change
    1 =Replace the value with value1 defined in the rule
    2 =Block the write
value1:HEX value, usage differs depending on the function
value2:HEX value, usage differs depending on the function

A replacement will take effect only if the function is executed. And the last effective replacement determines if the write will proceed or be blocked. An effective replacement 1 in the middle of the chain will change the value for the rest of the rules in the chain. Function 0, 7 and 10 are always executed. For functions 2-6 and 9, value2 is used as a bit mask and is applied to the value of the write and compare with value1 to decide whether the funciton will be executed.

Detailed explanation of each function:
Function 0: Nothing happens. This can be used to an extra step in the chain to run the replacement rule.
Function 1: Stop any other music file currently playing, then start playing the music file with ID matching to the value of the write if it is not currently playing already. This function only count as executed if a music file is playing.
Function 2: Set music to looping. This setting take effect on the next music file being played. So the user can run this function once to change for the rest of the gameplay or add to a chain before playing music.
Function 3: Set music to not looping. This setting take effect on the next music file being played.
Funciotn 4: Stop any music file currently playing
Funciotn 5: Pause any music file currently playing and the position is kept
Funciotn 6: Resume play any music file being paused
Funciotn 7: Setting the music volume. The value in the write is mapped to the range defined by value1 and value2 where value1 is silence and value2 is the max volume.
Function 8: Start playing the sound effect file with ID matching to the value of the write. This function only count as executed if a sound effect file has started playing.
Function 9: Stop any sound effect file currently playing
Function 10: Setting the sound effect volume. The value in the write is mapped to the range defined by value1 and value2 where value1 is silence and value2 is the max volume.

Example 

The format of defining an address to read from and the handling rule is:
<readaddress>address,function,calculation,value1,value2
address: the memory address in HEX
function: one of the following values - 
    0 =Value from previous rule
    1 =Value1
    2 =Music ID (last value passed to a function 1 write address even if it is not executed) 
    3 =A music file is playing
    4 =Looping is set
    5 =A playing music file is paused
    6 =Music volume
    7 =Sound effect volume
calculation: one of the following values -
    0 =Overwrite with new value
    1 =Combine old value and new value with bitwise or
    2 =Combine old value and new value with bitwise and
    3 =Apply bitwise not to old value
value1:HEX value, usage differs depending on the function
value2:HEX value, usage differs depending on the function

A read from an address with rules defined always get the value replaced by the result of the rules. Function 3-5 use value1 when true and value2 when false. 

The format of defining music files and sound effect files is:
<bgm>ID,filename
<sfx>ID,filename
ID: HEX value