JDK-4702328 : Wrong time in sequence for SMPTE based types
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.3.0,1.4.1
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,other
  • CPU: generic
  • Submitted: 2002-06-14
  • Updated: 2003-03-17
  • Resolved: 2002-11-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
Related Reports
Duplicate :  
Description

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
--------------------------------------------------------------------------
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis mantis-b08 VERIFIED IN: mantis-beta
14-06-2004

EVALUATION ###@###.### 2002-06-14 Fix needed. ###@###.### 2002-10-30 Fixed for mantis. Note that the test program contains a bug, too: the calculation of the microsecondlength in the if clause lacks paranthesises. The correct way of checking this is: long micros = (long) ((midiData.getTickLength() * 1000000) / (res * Sequence.SMPTE_24)); if (midiData.getMicrosecondLength() != micros) { failed = true; System.out.println("getMicrosecondLength() returns wrong length: " + midiData.getMicrosecondLength()); System.out.println("getMicrosecondLength() must return length: " + micros); }
11-06-2004