Difference between revisions of "HERAD"

From Video Game Music Preservation Foundation Wiki
Jump to: navigation, search
(Musical Notation: MIDI Channel info)
(Technical Specifiations: Further updates)
Line 92: Line 92:
 
===Speech Synthesis===
 
===Speech Synthesis===
  
As heard in the KGB song, "Gorbi", speech synthesis is possible with HERAD.  However, since the music data for KGB is currently compressed in an unknown algorithm, it is unknown how HERAD handles this data.
+
As heard in the KGB song, "Gorbi", the word "[[wikipedia:Mikhail_Gorbachev|Gorbachev]]" is played.  It was assumed that speech synthesis or perhaps PCM audio was possible with HERAD; however, after analyzing the uncompressed music file, it turns out the speech synthesis is just very clever MIDI sequencing and OPL2 programming done by Stéphane Picq to produce pseudo-speech synthesis.
  
 
===Version Compatibility===
 
===Version Compatibility===
 
The format has two known versions, which have several differences; however, neither version has any FourCC or header data denoting which version it is.  In order to detect the proper version, each music file needs to be inspected.
 
The format has two known versions, which have several differences; however, neither version has any FourCC or header data denoting which version it is.  In order to detect the proper version, each music file needs to be inspected.
  
The first version was used in [[Dune (DOS)]] and [[KGB (DOS)]], and the second version was used in [[MegaRace (DOS)]].
+
The first version was used in [[Dune (DOS)|Dune]] and [[KGB (DOS)|KGB]], and the second version was used in [[MegaRace (DOS)|MegaRace]].
  
 
==File structure==
 
==File structure==

Revision as of 01:30, 1 October 2016

HERAD System
HSQ.png
Developer: Rémi Herbulot
Header: Custom
Content: Notational
Instruments: Optional
Target Output
Output - Digital Audio - No.png Output - MIDI.png Output - FM Synthesis.png Output - PSG - No.png
Released: 1992-??-??
First Game: Dune (DOS)
Extensions
  • *.adl
  • *.agd
  • *.sdb
  • *.m32
  • *.hsq
  • *.sqx
  • *.sqz

Herbulot AdLib (HERAD) System was created by Rémi Herbulot, one of Cryo Interactive Entertainment co-founders and lead programmers. Stéphane Picq, Cryo's first music composer also helped design HERAD with Herbulot. There are two versions of HERAD that are known to exist.

Stéphane Picq had this to say about HERAD:

I designed HERAD because the existing softwares [sic] didn't take advantages of all sound parameters, and were very poor in expressiveness, the only dynamic being volume of notes. Basically, in HERAD several individual parameters of the soundpatches (like volume of operators) can be modulated individually, by velocity, modulation wheel, or aftertouch, like a real synth. Also, we used some "hidden" parameters not documented by Adlib, but mentioned in the Yamaha technical notice of the chip FM YM3812.

Dune (the first game to utilize HERAD) lists in the credit roll a special thanks to "Henri Chalifour and Grant Hamilton from the Ad Lib Company", who also were involved in the development of the music format.

Henri Chalifour said this in regards to HERAD development on Dune:

Regarding my involvement with Cryo Interactive, as far as I remember I shared with Mr. Picq some tricks, recipes and advices [sic] concerning sound designing. Being quite comfortable within the Ad Lib environment, It was however a modest contribution that I brought.

HERAD was used in only three games: Dune, KGB aka Conspiracy, and MegaRace. All three games have been arguably rated as some of the best DOS game soundtracks ever written for OPL2.

Players

(Category)
  • RdosPlay - DOS - only version 1 (OPL2/OPL3 music)

Converters

(Category)

HERAD to ?

? to HERAD

Games

(Category)
Released Title Sample
1992-??-?? Dune (DOS)
1992-??-?? KGB (DOS)
1993-??-?? MegaRace (DOS)

Technical Specifiations

File Formats

HERAD comes in several different file formats. The data is usually packed inside HSQ or SQX files.

  • HSQ are compressed files with the Herbulot Sequencer algorithm, which is similar to LZ** dictionary algorithms. HSQ files can be found in Dune and MegaRace.
  • SQX is another compression format, that seems to be similar to HSQ, but decompression is currently not possible except for playback in RDOSPlay.
  • In the non-interactive demo for Dune, the music files are compressed in a format called SQZ, however, these files are identical to HSQ files.

Once the data is decompressed, there are several different file extensions that are used. Since HSQ doesn't keep the original data's filename or extention, it is assumed that these file extentions are retronyms and were given to the raw data after they were decompressed.

Musical Notation

  • The internal music notation is very similar to MIDI, however Pitch Bend and Meta events do differ.
  • M32 files usually contain one multi-channel track, while ADL/SDB/AGD files may contain multiple tracks.
  • Despite all MIDI tracks use channel 1, any channel number can be used as this number is simply ignored.

Speech Synthesis

As heard in the KGB song, "Gorbi", the word "Gorbachev" is played. It was assumed that speech synthesis or perhaps PCM audio was possible with HERAD; however, after analyzing the uncompressed music file, it turns out the speech synthesis is just very clever MIDI sequencing and OPL2 programming done by Stéphane Picq to produce pseudo-speech synthesis.

Version Compatibility

The format has two known versions, which have several differences; however, neither version has any FourCC or header data denoting which version it is. In order to detect the proper version, each music file needs to be inspected.

The first version was used in Dune and KGB, and the second version was used in MegaRace.

File structure

There are three chunks to HERAD files: the header, the MIDI data, and the AdLib Instrument chunk. Note that the Instrument chunk is absent in M32 files.

Header

All values in the header are in little endian format. For M32 files, the wFileSize value represents the total file size, while AGD and SDB files, it represents the file size without the instrument data block.

Data type Name Description
UINT16 wFileSize Size of uncompressed file / Instrument Chunk offset
UINT16[21] wOffsets Array of relative offsets to the MIDI tracks (0 = track doesn't exist)
UINT16 wLoopStart Loop starts at this measure (0 = don't loop)
UINT16 wLoopEnd Loop ends at this measure (0 = don't loop)
UINT16 wLoopCount Number of times the selected measures will play (0 = loop forever; >0 - play N times)
UINT16 wSpeed Fixed point value that controls music speed. Value range is 0x0100 - 0x8100
UINT8[32] bUnknown5 Unknown array of bytes only in AGD files (settings for Adlib Gold 1000 surround module?)

Looping

Looping a song works by specifying the start and end points with the wLoopStart and wLoopEnd bytes, and denoting how many times the loop should play with the wLoopCount byte. This can be used to either play a song forever, or to play a song that doesn't repeat but has a short segment that loops instead (like a repeating melody or phrase). For example, to loop the first two measures of the song, the wLoopStart byte will be 01 and the wLoopEnd byte will be 03. A measure is 96 MIDI ticks in duration.

For version 1 songs, in order for music to repeat, this loop data must be in place. Version 2 songs that are being played back in MegaRace's sound engine will automatically repeat forever even if the wLoopCount field specifies that the song should only be played once. If there are no loop points in the file, the version 2 song will automatically repeat from beginning to end. As a result, several tracks in MegaRace (NewSan, Maeva and Terminal City) have short loops that are only a few measures long. Because those loop points are being used, the music continues to loop the song from beginning to end due to the sound engine. The other remaining tracks from MegaRace (Factory Land, Skyholder and Fractalian Space) have intros to them that are not repeated so their loop points start at the end of the intro and finish when the song is over.

Speed / Tempo

The default tempo is 500 BPM with the MIDI data at 24 ticks per quarter note. Obviously, this default value is way too fast so to slow down the music, a fixed-point value must be entered into the wSpeed field. To calculate the tempo of the song, take 500 and divide it by the value. Since this is a fixed-point number, some BPM will be at odd values. Some of these values were taken from MegaRace and Dune files.

Speed value Fixed-Point value Approximate BPM
0x0100 1.0 500
0x03E0 3.875 129.032
0x0400 4.0 125
0x042B 4.168 119.961
0x04B8 4.71875 105.960
0x0500 5 100

MIDI notation

  • Most of the status bytes are compatible with the MIDI standard.
  • It looks like running status is not supported as all known songs programmed in HERAD never use it.
  • All MIDI data for Cryo's games uses 24 ticks per quarter note.
MIDI message Description MIDI compatible
8# xx xx Note Off (version 1) Yes
8# xx Note Off (version 2) No
9# xx xx Note On Yes
A# ?? ?? Poly Aftertouch (unused) Unknown
B# ?? ?? Control Change (unused) Unknown
C# xx Program Change (uses internal instruments for AGD and SDB) Yes
D# xx Channel Aftertouch Yes
E# xx Pitch Bend No
FF Track End

Note Off

For the Note Off command in version 2 songs, the velocity byte has been removed. Some older MIDI sequencers back in the '80s and early '90s did this to stop sending redundant data.

Pitch Bend

The Pitch Bend command has only the MSB byte available. Like the MIDI Standard dictates, 0x40 is the "center" of the pitch bend range. Sending this 0x40 data byte after the Pitch Bend status byte will result in no change to the pitch. This event does differ from it's MIDI counterpart since the value range for Pitch Bend is 0x00 to 0x80, which surpasses MIDI's 7-bit value range. 0x00 equals to 2 semitones down and 0x80 equals to 2 semitones up.

The frequency number range for pitch bends is 325 to 685. For example, if the sequencer were to play a 2 semitone pitch bend downwards from C to B flat, it would start at FNum 343, go down to 325 and then decrease the block number and continue the pitch bend at 650 (which is 1 semitone down from C) and finally stopping at 614 aka B flat. If a 2 semitone pitch bend upwards were to happen at B, the FNum will start at 650, continue to increment the FNum until it reaches 685. Once there, it goes to the next block number and resumes increasing the FNum starting at 343 before finishing the pitch bend 2 semitones up at 364 (which is C sharp).

Because the pitch bend event has a full 8-bit value instead of MIDI's standard 7-bit value, it is possible to go up higher above 0x80, however this produces inaccurate results. For example, a value of 0xFF will produce a pitch almost 6 semitones up.

Channel Aftertouch

In the MegaRace music files, Channel Aftertouch only occurs one time in one song (Fractalian Space).

Note Pitch / Frequency Number Table

HERAD uses MIDI Notes C1 to B8 (0x18 to 0x77). If any MIDI notes are out of range, the sequencer will play note C1. The Block number corresponds with the MIDI octave (Block number 0 = MIDI octave 1, Block number 1 = MIDI octave 2, etc).

MIDI Note F-Num
C 343
C# 364
D 385
D# 408
E 433
F 459
F# 486
G 515
G# 546
A 579
A# 614
B 650

Instrument Data

The instrument chunk contains all the OPL register values needed for each instrument, along with some macros that control various parameters of the instrument during playback. Each instrument is 0x28 bytes long. Version 2 of HERAD introduced a keymap instrument that can be used for linking several instruments into one; this allows for some very complex drum sequencing.

To use an instrument, the MIDI notation must use the "Program Change" message and specify a number for the instrument to be used. All instruments are listed sequentially and the first instrument is always number #0. Let's say we want to play the 13th instrument in the chunk. We tell the MIDI data to Program Change to instrument number #12 (C0 0C) and the notation after that will play using that instrument until the end of the track or another Program Change message is sent.

It seems that the OPL register values are almost in the exact same layout as the BNK format (technical). Thanks to Malvineous for his documentation on the BNK file format.

These offsets are still a work in progress and need more research.

Offset Size Name Description OPL base register Notes
0x0 1
Mode
Denotes if this is an instrument or a version 2 keymap.
Normally 0x0 in version 1 songs; either 0x1 or 0xFF in version 2 songs
As long as this value is not set to 0xFF in a version 2 song, this can be set to any number.
0x1 1
Voice number
Most likely a meta identifier (changing this value has no effect in any song)
0x2 1 ksl
Modulator Key scaling level
0x40 (bits 6-7)
0x3 1 multiple
Modulator Frequency multiplier
0x20 (bits 0-3)
0x4 1 feedback
Feedback
0xC0 (bits 1-3)
0x5 1 attack
Modulator Attack
0x60 (upper four bits)
0x6 1 sustain
Modulator Sustain
0x80 (upper four bits)
0x7 1 eg
Modulator Envelope gain
0x20 (bit 5) nonzero value is on
0x8 1 decay
Modulator Delay
0x60 (lower four bits)
0x9 1 releaseRate
Modulator Release
0x80 (lower four bits)
0xA 1 totalLevel
Modulator Output Level
0x40 (bit 0-5) Output level is NOT affected by MIDI Velocity. To enable velocity, see offset 0x1E
0xB 1 am
Modulator Amplitude modulation (Tremolo)
0x20 (bit 7)
0xC 1 vib
Modulator Frequency Vibrato
0x20 (bit 6)
0xD 1 ksr
Modulator Key scaling/envelope rate
0x20 (bit 4)
0xE 1 con
Connector
0xC0 (bit 0, inverted) 0: OPL bit set to 1
other: OPL bit set to 0
0xF 1 ksl
Carrier Key scaling level
0x40 (bits 6-7)
0x10 1 multiple
Carrier Frequency multiplier
0x20 (bits 0-3)
0x11 1
Panning (OPL3)
0xC0 (upper four bits) This controls the upper bits of the 0xC0 register to control panning in OPL3.
3 = both speakers; 2 = right speaker; 1 = left speaker
MegaRace uses 3 as the default value. Dune's OPL2 driver ignores this byte and sets it to 0.
Dune's OPL3 driver defaults any invaild value to both speakers.
0x12 1 attack
Carrier Attack
0x60 (upper four bits)
0x13 1 sustain
Carrier Sustain
0x80 (upper four bits)
0x14 1 eg
Carrier Envelope gain
0x20 (bit 5) nonzero value is on
0x15 1 decay
Carrier Delay
0x60 (lower four bits)
0x16 1 releaseRate
Carrier Release
0x80 (lower four bits)
0x17 1 totalLevel
Carrier Output Level
0x40 (bit 0-5) Output level is NOT affected by MIDI Velocity. To enable velocity, see offset 0x1F
0x18 1 am
Carrier Amplitude modulation (Tremolo)
0x20 (bit 7)
0x19 1 vib
Carrier Frequency Vibrato
0x20 (bit 6)
0x1A 1 ksr
Carrier Key scaling/envelope rate
0x20 (bit 4)
0x1B 1 HERAD Macro
Feedback Scaling - Aftertouch
0xC0 (bits 1-3) This modifies feedback based off of MIDI Aftertouch events.
Value range goes from 1-6 and FF-FA; 0 turns the scaling off.
If Feedback (0x4) has already been assigned, that value will be added to the scaling.
0x1C 1
Modulator Waveform Select
0xE0 (bits 0-1)
0x1D 1
Carrier Waveform Select
0xE0 (bits 0-1)
0x1E 1 HERAD Macro
Modulator Output Level Scaling
0x40 (bit 0-5) This uses the MIDI NoteOn velocity to control the Modulator Output level
Value range goes from 1-4 and FF-FC; 0 turns the scaling off.
Due to the design of the OPL2 chip, the higher values will decrease the volume and vice versa.
0x1F 1 HERAD Macro
Carrier Output Level Scaling
0x40 (bit 0-5) Same as previous macro, only this affects the Carrier operator.
Seems to multiply the velocity value; as a result some notes that are too loud
or quiet will not be affected since the sum will be out of range for the OPL chip.
0x20 1 HERAD Macro
Feedback Scaling - Velocity
0xC0 (bits 1-3) Same concept as the previous two macros, however this modifies feedback based off of MIDI NoteOn velocity.
Value range goes from 1-6 and FF-FA; 0 turns the scaling off.
If Feedback (0x4) has already been assigned, that value will be added to the scaling.
0x21 1 HERAD Macro
Pitch Bend Range Flag
Increases pitch bend range (Fine tune = 0, Coarse tune = 1)
0x22 1 HERAD Macro
Root Note Pitch
Normally set at 0x0 and can accept signed integers, for example, 0xC = an octave higher; 0xF4 = an octave lower
This macro functions very differently in HERAD version 2, see Root Note Macro
0x23 1 HERAD Macro
Pitch Bend Duration
Duration of the pitch bend in ticks
0x24 1 HERAD Macro
Pitch Bend Range
Signed integer value.
For each MIDI tick, increase or decrease the FNUM by 1 when fine tune is on.
When coarse tune is on, a 60-note scale is used (see Coarse Pitch Bend Frequency Table).
0x25 1 HERAD Macro
Unknown
More research needed.
0x26 1 HERAD Macro
Modulator Output Level Aftertouch Scaling
This uses the MIDI Channel Aftertouch events to modify the modulator output level.
Just like in 0x1E, the value range goes from 1-4 and FF-FC; 0 turns the scaling off.
For some reason, in version 2 instruments, this is always set to 0x1
0x27 1 HERAD Macro
Carrier Output Level Aftertouch Scaling
This uses the MIDI Channel Aftertouch events to modify the carrier output level.
Just like in 0x1F, the value range goes from 1-4 and FF-FC; 0 turns the scaling off.
In MegaRace, this is always set to zero.
In order for this macro to function, the 0x1F byte MUST be enabled.

Coarse Pitch Bend Frequency Table

When the Pitch Bend Range Flag (0x21) is set to the coarse tune setting, 4 additional F-Nums are added to each note of the standard 12-note scale, resulting in a 60-note scale. The sequencer will cycle through all the F-Nums until the next Note Off or the pitch bend exceeds the MIDI Note Range or until the end of the Pitch Bend Duration (0x23).

MIDI Note and Corresponding F-Num F-Nums that proceed after Note On
C 343 348 353 358 363
C# 364 369 374 379 384
D 385 390 395 400 405
D# 408 413 418 423 428
E 433 438 443 448 453
F 459 464 469 474 479
F# 486 492 498 504 510
G 515 521 527 533 539
G# 546 552 558 564 570
A 579 585 591 597 603
A# 614 620 626 632 638
B 650 656 662 668 674

Root Note Macro

In the instrument chunk, offset 0x22 controls the root note of an instrument relative to a MIDI note's pitch, so for example, if you have a drum sound that you want to play at a particular pitch or you need your bass to be played an octave lower, you can set this byte to the pitch you want and the sequencer will play the instrument accordingly.

In HERAD version 1, the MIDI sequencer will take any note that's thrown at it and change the pitch, so if the value is 1 and the MIDI note that's being played is C4, then the sequencer will play C#4. If the note that needs to be changed is out of range on the MIDI keyboard (C1 to B8), HERAD will just play note C1 instead.

HERAD version 2 introduces some very different functionality when it comes to handling the root note. From value ranges D1-FF to 01-30, the root note works exactly the same as version 1. However, from D0 to B9 and 31 to 90, the pitches cycle through again but this time, MIDI Note pitches are ignored, so any note that is triggered in the sequencer has it's pitch overridden by the root note value.

The value range 91-B8 produces the same functionality, except if a MIDI Control Change event occurs, no notes after it will be played until the song repeats. No known HERAD instruments use this value range so it's most likely that this behavior is a glitch and is not used.

Root Note Macro Value Range Function
31 - 90 MIDI NoteOn Pitch is ignored, all notes that are triggered will play the root note's pitch.
Note that 30 and 31 share the same pitch, the only difference is that 30 can still be affected by MIDI pitch and 31 has it's pitch locked.
01 - 30 Root note goes upward.
00 No change
FF - D1 Signed integer; Root note goes downward.
D0 - B9 Signed integer; MIDI NoteOn Pitch is ignored, all notes that are triggered will play the root note's pitch.
Note that D0 and D1 share the same pitch, the only difference is that D0 can still be affected by MIDI pitch and D1 has it's pitch locked.
B8 - 91 Unused; does the same thing as the previous value range, except any MIDI Control Change events will cause no further notes to play until the song repeats.

Keymap

Introduced in version 2 songs, a keymap control was added into the instrument chunk. All 6 songs in MegaRace use this keymapping for their drum sequencing. Like the other separate instruments in this chunk, it is also 0x28 bytes long, but differs greatly from the other instruments since it doesn't contain any OPL register values.

It is essentially an array of instruments that are mapped to different MIDI notes. Instead of having to send a Program Change MIDI message every time a different drum instrument is used, this keymap greatly reduces the amount of MIDI messages being sent since all the drum sounds are located in one instrument.

Offset Description Notes
0x0
Mode
Must always be 0xFF; this denotes that this is a keymap
0x1
Voice Number
Most likely a meta identifier (so far, changing this value results in no effect)
0x2
Keymap Offset
Must always be 0x18; changing this will offset the instruments sounds.
Leaving this at 0x18 will have the keymap start at MIDI pitch #48 (aka C4).
Decreasing the value will start the keymap at a lower pitch.
For example, if you change the value to 0x11, the keymap will start at MIDI pitch #41 (aka F3)
0x3
Unknown
So far, changing this value results in no effect to any instruments inside the keymap range.
Some instruments outside the keymap range may be affected, but these aren't suppose to be heard anyway.
0x4-0x27
Instrument Array
List of instruments

The keymap starts at MIDI pitch #48 (aka C4) and continues with each consecutive pitch (48, 49, 50, ..., etc).

Sometimes in the instrument array, there will be an instrument that covers several MIDI pitches, instead of just a single instance (for example, a tom-tom drum that requires different pitches). This is done by specifying the instrument's number (i.e. 0x10) and then for every repeating instrument, the keymap instrument's number itself is referenced. For example, let's say our keymap instrument is number "0xC" and we want to repeat the instrument "0x10" 8 times. We do this like so: 10 0C 0C 0C 0C 0C 0C 0C.

Again, all instruments in the instrument chunk must be 0x28 bytes long, so when all the instruments in the array are specified, the remaining bytes are to be padded out by the keymap instrument number.

Links