cs526 logo
rainbow animatio

Solution to Homework #2: MIDI

Goal:

  • Learn how to use tool to create a MIDI file.
  • Learn the basic encoding techniques utilized by MIDI
  • Assignment Date: 2/3/2010

    Due Date: 2/10/2010

    Description:

    Part 1:

    Part2:

    1. The following is a MIDI file similar to Ballade2.mid.
      4d 54 68 64    4-character chunk ID: "MThd"
      00 00 00 06    length of the header: 6 bytes
      00 01          file format: format 1
      00 10          # of tracks: 16 tracks in this file
      00 c0      MSb=0, resolution per quarter note: 192 ticks per quarter note
      4d 54 72 6b    4-character chunk ID: "MTrk"
      00 00 00 7c    length of the track: 124 Bytes

      delta time track event   Intepretation
      ========= ===========    =====================================
      00 ff 7f 03 00 00 41     meta event, (?) 3 bytes
      00 ff 58 04 04 02 18 08  Time signature meta event, 4/4 meter?
      00 ff 51 03 0a 49 6d     Tempo meta event, 674157 microsec/quarternote
      00 ff 59 02 00 00        Key signature meta event, C major
      00 ff 01 2a 43 6f ...    Copyright meta event?

      4d 54 72 6b              4-character chunk ID: "MTrk"
      00 00 09 61              length of the chunk data: 2401 bytes

      delta track event   Interpretation
      time
      ===== ===========   =====================================
      00    ff 21 01 01   meta event?
      00    ff 03 14 50 ... instrument name, 20 bytes, Piano Treble
      00    c1 02         Program change on channel 1, patch #2
      00    b1 07 61      Control change on channel 1, volume level 91
                               (loud, 80 normal)
      00    b1 0a 7f      continuous controller(MIDI knob), max. postion(127)
      00    91 37 7f      Note on channel 1,note=55(G,octave3), vel=127(loud)
      60    39 7f         note=57, vel=127(loud) after 96/192 quarternote
                            (A, octave3), running status without command
      60    3c 7f         note=60(C, octave4), vel=127 after eighth note
      5e    41 7f         note=65(F, octave4), vel=127 after 94/192 qnote
      8140  43 7f         note=67(G, octave4), vel=127 after 192/192 qnote
      10    81 37 40      Note off, note=55, vel=64(med.) after 16/192 qnote
      8130  91 41 7f      Note on, note=65, vel=127 after 176/192 quarternote
      06    81 3c 40      Note off, note=60, vel=64 after 6/192 quarternote
      0c    37 40         note=55, vel=64, after 12/192 quarternote
      4e    91 37 7f      Note on, note=55, vel=127, after 78/192 qnote

      1. How long is the playtime of the first note (G Octave3) in terms of seconds?
        Ans: The playtime a quarter node is 00 ff 51 03 0a 49 6d     Tempo meta event, 674157 microsec/quarternote as indicted in the MTrk header. There are 192 ticks per quarter which indicated in MThd. Each tick is 3511 microseconds.
        (G Octave3) starts with 00    91 37 7f; ends with 10    81 37 40,
        In between these two MIDI events, there are following delta times: 60, 60, 5e, 8140, 10.

        The most significant bits in delta time field need to be removed. They are used to indicate the length of the field and not part of the value. For 8140, after removing the most significant bits, we got the remaing 7bit pattern, 0000001 1000000, which is equiavalent to 128+64=192.

        By removing the most significant bits to compute the equivalent decimal tick numbers, we get the equivalent of    
        96+96+ 94+(128+64)+16=494 ticks.
        Therefore the playtime of the first note (G Octave3) is 494*3511 microseconds = 1.73455 seconds
      2. If the above MIDI code after 4e 91 37 7f is followed by 00 91 30 60, explain these four bytes using the format similar to the above interpretation.
        Ans: 00    91 30 60      Note on channel 1,note=48(C,octave 3), vel=96( medium loud)
        See the Standard MIDI Key Assignments in the web page for the note.
      3. Assume that after 91 37 7f, we stop all notes with 60 41 00 00 43 00 00 37 00 00 FF 2F 00,
        1. How long is the music?

          Ans: We calculate the length of the music by couting the ticks from beginning to the end. We have the following delta times:
          60, 60, 5e, 8140, 10, 8130, 06, 0c, 4e, 60, 00, 00, 00, 00.
          96+96+ 94+192+16+176+  6+  12+78+96=862 ticks.
          Therefore the length of the music is 862*3511 microseconds = 3.026684 seconds
        2. Without counting the header and those bytes above 00 91 37 7f, how many bytes are used to encode the music using MIDI?

          Ans: 50 bytes.
        3. If we use the PCM encoding method for the same music with 44.1kHz sampling rate, and 16 bit per sample, stereo recording, how many bytes will be generated?
          Ans: 44,100*16**2*3.026684 bits/8 bits/bytes = 533907 bytes.
        4. What is the size ratio between that of PCM encoded data for this music and that of the MIDI?
          Ans: 533907/50= 10678:1