JDK-4659445 : Different time length in Sequence and Sequencer
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-03-28
  • Updated: 2004-03-12
  • Resolved: 2003-09-27
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
5.0 tigerFixed
Related Reports
Relates :  
Relates :  
Description

Name: vtR10009			Date: 03/28/2002


Two methods return time length of Midi Sequence in Java Sound API:
  javax.sound.midi.Sequencer.getMicrosecondLength()
  javax.sound.midi.Sequence.getMicrosecondLength()

But these methods return different values for same sequence in 
JDK RI(1.4.1-beta-b06) and spec does not state anything that could 
imply the time may differ for particular Sequencer.

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

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

public class test{
    public static void main(String args[])
    {
        boolean failed = false;
        File seqfile;
        Sequencer seq = null;
        Sequence midiData = null;
        
        try {
            seq = MidiSystem.getSequencer();
            seq.open();
            seqfile = new File(".", args[0]);
            midiData = MidiSystem.getSequence(seqfile);
            seq.setSequence(midiData);
            if (seq.getMicrosecondLength() != midiData.getMicrosecondLength()) {
                System.out.println("Sequencer MicrosecondLength was : " 
                        + seq.getMicrosecondLength());
                System.out.println("Sequence MicrosecondLength was : " 
                        + midiData.getMicrosecondLength());
                failed = true;
            }

        } catch (MidiUnavailableException munEx) {
            munEx.printStackTrace();
        } catch (InvalidMidiDataException invmEx) {
            invmEx.printStackTrace();
        } catch (IOException ioEx) {
            ioEx.printStackTrace();
        }
    
        if( failed ) {
            System.err.println("Test failed!");
        } else {
            System.out.println("OKAY");
        }
        System.exit(0);
    }
}

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

Sequencer MicrosecondLength was : 31904280
Sequence MicrosecondLength was : 31879166
Test failed!
--------------------------------------------------------------------------
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b22 VERIFIED IN: tiger-b41
14-06-2004

PUBLIC COMMENTS Different time length in Sequence and Sequencer
10-06-2004

EVALUATION ###@###.### 2002-05-12 Needs to be fixed. ###@###.### 2002-10-30 No engineering resources for mantis time frame. Will be fixed with new sequencer implementation. ###@###.### 2003-08-08 Altough a new sequencer will not have this problem, certain installations will still depend on the old sequencer implementation. The old implementation uses a different method to calculate the length of a song depending whether it's a Sequence or a Sequencer. Slight differences are normal, since how to calculate the duration of a MIDI file is not specified fully by the MIDI file spec. (i.e. does playback stop with the last audible event, or with the last event in the file). Therefore it can be expected that any 2 different methods calculate a slightly different duration, but it is not expected that Java Sound will use 2 different methods internally. The described test case finds a difference of roughly 25 milliseconds. I am reluctant to add to the Java Sound specification that the method for calculating the duration of a MIDI file is not fully specified. I suggest modifying the JCK test so that it allows an epsilon, based on the duration of the file: long epsilon = seq.getMicrosecondLength() / 500; long diff = Math.abs(seq.getMicrosecondLength() - midiData.getMicrosecondLength()); if (diff > epsilon) { // error } This allows a cumulative error of 2 milliseconds for every second playback time of the file, which I consider largely acceptable. If the submitter thinks an addition to the spec should be made, it can be considered. ###@###.### 2003-09-26 The new sequencer will use the same method for Sequence and Sequencer.
26-09-2003