Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4702328

Wrong time in sequence for SMPTE based types

XMLWordPrintable

    • mantis
    • generic
    • generic, other
    • Verified



      Name: vtR10009 Date: 06/14/2002


        Spec for Sequence constructor from javax.sound.midi package states:
      "For SMTPE timing, divisionType specifies the number of frames per second
      and the resolution is specified in ticks per frame. The sequence will be
      initialized with the number of tracks specified by numTracks."
      So the microsecond length should be calculated as:
         lengthInMs = (tickLength * 1000000)/(divType * Res)
      But implementation returns wrong length multiplied by thousand.

      This bug causes failure of new JCK test:
      api/javax_sound/midi/Sequence/index.html#get

      To reproduce the bug run the following test with JDK build 1.4.1-beta-b14:
      ------------------------------- test.java --------------------------------
      import javax.sound.midi.*;

      public class test{
          public static void main(String args[]) {
              int[][] dataMes = { {ShortMessage.NOTE_ON, 10, 0x24, 0x50} ,
                      { ShortMessage.NOTE_OFF, 10, 0x24, 0x44 },
                      { ShortMessage.NOTE_ON, 10, 0x24, 0x50 },
                      { ShortMessage.NOTE_ON, 10, 0x26, 0x50 },
                      { ShortMessage.NOTE_OFF, 10, 0x26, 0x53 } };
              long[] ticks = { 0, 68, 240, 240, 286};
              int res = 240;
              ShortMessage msg;
              Sequence midiData = null;
              Track track;
              boolean failed = false;
          

              try {
                  midiData = new Sequence(Sequence.SMPTE_24 , res);
              } catch (InvalidMidiDataException invMidiEx) {
                  invMidiEx.printStackTrace(System.out);
                  System.out.println("Unexpected InvalidMidiDataException: "
                          + invMidiEx.getMessage());
                  failed = true;
              }
              track = midiData.createTrack();
              for (int i = 0; i < dataMes.length; i++) {
                  msg = new ShortMessage();
                  try {
                      msg.setMessage(dataMes[i][0], dataMes[i][1], dataMes[i][2],
                              dataMes[i][3]);
                  } catch (InvalidMidiDataException invMidiEx) {
                      invMidiEx.printStackTrace(System.out);
                      System.out.println("Unexpected InvalidMidiDataException: "
                              + invMidiEx.getMessage());
                      failed = true;
                  }
                  track.add(new MidiEvent(msg, ticks[i]));
              }
              // lengthInMs = (tickLength*1000000)/(divType*Res)
              if (midiData.getMicrosecondLength() != (long) (midiData.getTickLength()
                      * 1000000) / (res * Sequence.SMPTE_24)) {
                  failed = true;
                  System.out.println("getMicrosecondLength() returns wrong length: "
                          + midiData.getMicrosecondLength());
                  System.out.println("getMicrosecondLength() must return length: "
                          + (long) ((midiData.getTickLength() * 1000000) / (res *
      Sequence.SMPTE_24)));
              }
              if (midiData.getTickLength() != 286) {
                  failed = true;
                  System.out.println("getTickLength() returns wrong length: "
                          + midiData.getTickLength());
              }

              if( failed == true ) {
                  System.out.println("test failed");
                  System.exit(1);
              } else {
                  System.out.println("OKAY");
                  System.exit(0);
              }
              
          }
      }

      ---------------------------Logs-------------------------------------------
      novo101:templates$ javac test.java; java -showversion test
      java version "1.4.1-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
      Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)

      getMicrosecondLength() returns wrong length: 49652777
      getMicrosecondLength() must return length: 49652
      test failed
      --------------------------------------------------------------------------
      ======================================================================

            fbomerssunw Florian Bomers (Inactive)
            vitcsunw Vitc Vitc (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: