Enterprise MIDI English

From Enterprise Wiki
Revision as of 19:29, 9 September 2017 by Gflorez (talk | contribs) (Egyéb)

Jump to: navigation, search


A *.mid file doesn't contain any wav sample sound but only the "notes" themselves. The notes can be associated to musical instrument sounds. These instrument sounds are built into the operating system or synthesizer. Midi can sound even 16 layers (channels) at the same time and within one channel even more voices, chords. A special midi channel is the 10th where drums can sound. Our aim is to sound midi files through the EP Dave sound chip. As Dave can handle 3+1 channels altogether most midi files from the net need conversion to get suitable sounding.

Midi hardware also exists for the Enterprise but there are not many pieces. Now a PC midi player/editor application can be connected to the EP128Emu to get the EP sounding midi. To do this you need:

  • Installing a midi port e.g. loopMIDI. In Linux the Midi Through port can be used or editor programs (e.g. Qtractor) also can create a port that can be directly connected to the emulator. A hardware midi keyboard can also be used, in this case loopMIDI is not needed.
  • An EP128Emu version that supports midi input. (The latest emulator can be downloaded from sourceforge, this should be updated with this newer beta version. So it only needs unpacking and you should overwrite the existing files of the emulator.)

If using Windows is the case, you need to configure the midi input (loopMIDI port (I MMSystem)) in the Options -> Sound -> Configure menu item. After that, start a midi player, editor, or virtual keyboard on the PC where output the loopMIDI OUT is set. Start the emulator, load the application called Midiplay on it. After that, the midi player's will sound on the emulated EP, using DAVE's capabilities.

To minimize audio delay and timing errors, you should reduce the default latency setting (70 ms) and select an output device using a low audio API (ALSA or WASAPI), especially when using a MIDI keyboard. Also, it is advisable to avoid OpenGL video emulator modes requiring high CPUs or waiting (eg "resample to monitor refresh rate").

The EP application, Midiplay, includes several files, for example, envelope.txt, see below.

How to use Midiplay in the emulator?

With this application you can play the midi file with the emulated EP as the instrument. If you are using a midi editor (eg Cakewalk, Sonar, etc.), you can also hear the notes through the emulator. It is possible to convert an edited midi file into a loadable and playable EP file (midiconv, see below). Midiplay will automatically check if the default folder contains a converted file called mididata.bin (the maximum size is 1040 bytes of header + 8192 bytes of envelope + 28671 bytes of MIDI data) and, if it is found, the song will be played indefinitely in a loop. If there is no such file, the app will wait for notes received via loopMIDI. While the program is running, the screen will stay completely dark, as no special display is required. It is desirable to run the app on a turbocharged (eg 10 MHz) configuration, but it also works at 4 MHz.

Once started the app, you can use these buttons:

F1: Restarts the program, rewrites envelope.txt and (if available) mididata.bin .

F4: Switches off all sounds, useful for "stuck" sounds. The MIDI controller 123 can also be used for similar purposes.

F6: Full MIDI reset, with the exception of all sounds, the controls, bend and instruments are reset, and the playback position is also returned to the start of the file. The controls and bending can also be reset with the 121 controller.

F8: Exit.

Which MIDI channel (1-16) correspond to each Dave channel? Midi channels are managed by the player as "logical" channels. So each of the eleven(sixteen????) stores their entire status separately:

  • from the 128 keys, which one is pressed and, if so, the assigned DAVE channel.
  • the program (instrument).
  • 4 controllers (7, 10, 76, 77)
  • bend (only the top 8 bits are taken into account, the range is fixed at +/- 2 semitones)

This information is independent of the DAVE channels in which the MIDI sounds are played. This is determined by the following algorithm:

  • in case of an incoming note on the percussion Midi channel (10), it will be played unconditionally on the DAVE channel 3, immediately interrupting the previous sound.
  • otherwise, from the 0-2 Dave channels, one is better choice than the other two when they are through the envelope process (off> release> attack / decay> sustain), then
  • if you have not been able to make a decision and you need to interrupt the active sound because all 3 music channels are busy, the older (or previously released) sound will be replaced
  • if they are equal then a fixed order will be followed:
    • MIDI channel 1: 0 > 2 > 1
    • MIDI channel 2: 2 > 0 > 1
    • MIDI channel 3: 0 > 2 > 1
    • MIDI channel 4: 2 > 0 > 1
    • ...etc.

Therefore, Dave channel 1 will be in use only when 3 music sounds are active at the same time. Exactly the other two are certainly 0 and 2. Any of the logical MIDI channels can have any number of voices, but always have a maximum of 3 + 1 percussion.

The volume of the left and right channels can be approximated in the following way:

Left = ENV_L * ((VELOCITY + AFTERTOUCH + 1) / 128) * ((VOLUME + 1) / 128) * cos(PAN * (PI / 2) / 127.5) * sqrt(2)
Right = ENV_R * ((VELOCITY + AFTERTOUCH + 1) / 128) * ((VOLUME + 1) / 128) * sin(PAN * (PI / 2) / 127.5) * sqrt(2)

Where ENV_L = left envelope, ENV_R = right envelope, VELOCITY = strength of the key hit, AFTERTOUCH = extra pressure strength, VOLUME = volume (control 7), PAN = stereo position (control 10). If the envelope curve can be multiplied by 1, the multiplier is limited to 1. So, adjusting the stereo position only works correctly if VELOCITY and VOLUME together result in a minimum 3 dB reduction in the volume. The volume multiplication is actually only 1/128 resolution. The AFTERTOUCH parameter is set by the Axh and Dxh MIDI events, as the last key, the latter on the same channel at all active tones at the same time(?). For a new sound (event 9xh), always zero is the initial value.

Special settings for the MIDI files

The Midiplay player therefore pairs the individual midi channels with a certain logic to the Dave channels. However, we can also specify that a given MIDI channel must match a given Dave channel. In addition to the dynamic reservation, you can also set a fixed channel reservation. In fact, in most cases, it is necessary to use Dave's capabilities and convert the midi file downloaded from the net to a meaningful sound on EP.

For this, in the midi file, different controls can be used for different Dave specific settings. (Controllers are generally available in midi editing programs in the Controllers menu.)

71 (Harmonic Content) and 76 Controllers: STYLE Parameter / 4

The Style parameter is the same as the one after the Basic command SOUND STYLE, only divided by 4. So, for example, if 16 (low distortion) is desired, then 16/4 = 4 must be entered. If 144 (ring modulation + low distortion)must be applied, then 144/4 = 36 should be specified.

?????Four-stitch 4-bit distortion 2 adds the frequency correction, instead of the default 15, results in a 5-length pattern (higher)??????

Sound Variation (70) and Control 77 (Channel Control) only affect the bits 2 to 4:

- 0 = dynamic reservation

- 4 = fixes channel 0(one part only)

- 8 = fixes channel 1

- 12 = fixes channel 2

- 16, 24 = channel 0, up to 3 simultaneous voices system (this is more the same way MIDI channel is also possible)???????

- 20, 28 = Channel 1, up to 3 voices may alternate in the same way

Fixed assignment of DAVE channels is not exclusive, the dynamic MIDI channels can continue in use.


Midi files play the voices of various instruments. Envelope.txt will associate the sound (envelope curve) with these instruments, using this to use Dave's capabilities on EP. It is only necessary to use it for playback on a real-time input (MIDI port) and header-free mididata.bin, newer-format converted files also include the instruments.

The definition of an "instrument" looks like this:

<nowiki> AUDIO [D] [P] [: + CHANNEL, + HEIGHT] [, AUDIO2 ...] {</ nowiki>

 <nowiki> [L | R | S] DURATION, LEFT, RIGHT, BEND, HEART; </ nowiki>
 <nowiki> ... </ nowiki>
 <Nowiki>} </ nowiki>

????what is nowiki?

Multiple instruments can use the same envelope, multiple numbers separated by commas. The number of instruments is between 0 and 127 for normal channels, or between -1 and -127 for drums. Optionally, you can follow the 'P' character (see below), or select two additional parameters by separating the colon. When using the instrument, you will copy a note from the note by modifying the MIDI channel number and pitch. For example, at 1: 2.12, Instrument 1 plays a higher number of MIDI tunes than the two higher MIDI channels.

The 'D' character after the instrument number forces the full envelope curvature to be released even when the key is released early, for drums and 'R' envelope curves, this is the default, so there is no use for it, and 'L' or 'S'. 'P' changes the stereo position of the sounds depending on the pitch, no effect on the drum. By default, the ranges between 48 to 79 are set to 1..125, this can be changed with the 10 controller. With the 9 instrument (Glockenspiel), the effect is disabled by default by 'P'.

The duration (which can be set in video interrupt units, 0 inmediately before changing the parameters), the character 'S' means that the beginning of the segment is a "sustain" position from which the player will only continue to release the key. It does not make any sense for the drums. A section of the envelope can be repeated using the 'L' character, which will play in a loop infinite the rest of the envelope without adding a release phase. The effect of 'R' is similar to 'S', but in contrast, the envelope always runs to the end, but at 'S' it immediately breaks down to the specified point. When using 'L' and 'R' together, the interval between them is repeated (from the beginning of the L segment to the R before the end), and at the time of release, the repeat disappears and the envelope runs to the end.

Unlike EXOS, the volume is an absolute between 0 and 63, it is given the new volume at the beginning of the next segment that is reached by linear interpolation. However, it is also possible to define exponential envelope curves if the volume value is '*' before the volume value, then the number / 128 is multiplied by volume at each interruption. For example * 96, 0.75 is the multiplier, * 128 does not change the volume, etc. Bending is between -2048 and +2047, 64 corresponding to a musical half tone. Linear interpolation is also done here and the specified value reaches the beginning of the next segment. Drums can not be bent.

Distortion (STYLE) can not be interpolated in contrast with the other parameters, but its value is immediately changed, and it needs to be watched when it changes in sound.

Spaces, Tab characters and new rows can be used arbitrarily, the program ignores them. In the case of the '#' character, the rest of the line is considered a comment and ignored. The player program automatically stores the compiled (binary) envelope data into a file called envelope.bin. The format is: The player program automatically stores the compiled (binary) envelope data into a file called envelope.bin. This format is:

  • the following 256 bytes are the same for the drums, in the same format
  • 256 bytes envelope start position for normal instruments: bottom, top byte alternately, shift to 2 / or 8080h for start of envelope data if the instrument is not defined. The top 4 bit loads a special function so the maximum size of the addressable envelope data is 8192 bytes. The default is 2000h, which is not changed by using 'S'.
    • bit 15: forbids the instrument
    • bit 14: pitch-dependent stereo position (P)
    • bit 13: indicates the absence of a repeating stage (L)
    • bit 12: releases the full envelope curve (R)
  • 256 bytes envelope position for drums
  • up to 8192 bytes envelope data, every 50 Hz interrupt 4 bytes:
    • left volume between 0 and 63. Setting bit 6 is the beginning of a repeating phase (L), and 8 is the end that no longer repeats. The two bits are set together to hold the current pattern and then indicate a release phase (only R or S). It is a special case when the left volume has bit 7 set and the right volume is FFh, this indicates the end of the envelope and turning off the sound.
    • better volume is between 0 and 63 or 255 at the end of the envelope
    • bend lower 8 bits, its resolution is half a 1/64 part. Not used in drums
    • distortion and (for normal instruments only) the upper 4 bits of the bend are stored. In the case of a percussion instrument, it defines the full byte distortion

Converting MIDI files to midiplay format

Once we have finished editing a MIDI file, and it sounds correctly with DAVE instruments, it can be converted so it can be listened on the EP standalone. midiconv (older version 1, 2) is a command line application. On Windows, the command line interface (cmd.exe) can be accessed via the Start Menu. After entering the directory where midiconv.exe is with the CD command, it can be used as follows:


By default, IRQFREQ is 50.0363 Hz. If the tempo of the music is 125 or 150 BPM, or other value where the duration of a quarter note is an exact integer multiple of 20 ms, it is recommended to set IRQFREQ to 50. After running the command, the .bin file immediately appears in the same folder, and it can be played with the midiplay.com or midi_asm.com application on the Enterprise.

The format of the converted files:

  • 16 bytes EXOS header:
    • 00h, 6Dh
    • 2 bytes: file size without the header (LSB first), in the case of future compressed formats, this would be the total size of the compressed data
    • 2 bytes: uncompressed envelope data size
    • 2 bytes: uncompressed MIDI data size
    • 8 bytes: reserved for future versions, currently always 00h
  • envelope data (envelope.bin) in the above described format, midiconv automatically removes any unused envelopes
  • MIDI data, the format is similar to standard MIDI files (SMF), but it contains only channel messages on a single track without header, and the delta time between events has a fixed resolution of 1/IRQFREQ seconds. For example, the following sequence of bytes plays the 440 Hz "A" note on the first MIDI channel for one second, using instrument 11:
    • 00 C0 0B 00 90 45 7F 32 45 00

When using the -raw parameter, the program converts to a simple headerless format that includes only the raw MIDI data. In this case, it is not necessary to specify a path to an envelope file on the command line.


Name and program number of the midi instruments