Path: blob/master/test/jdk/javax/sound/midi/Sequence/MidiSMPTE.java
41152 views
/*1* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.ByteArrayInputStream;24import java.io.File;25import java.io.FileInputStream;26import java.io.InputStream;2728import javax.sound.midi.MidiSystem;29import javax.sound.midi.Sequence;3031/**32* @test33* @bug 429125034* @summary Midi files with SMPTE time do not play properly35*/36public class MidiSMPTE {3738public static void main(String[] args) throws Exception {39Sequence s = null;40//File midiFile = new File("outsmpte.mid");41//InputStream is = new FileInputStream(midiFile);42//is = new BufferedInputStream(is);43InputStream is = new ByteArrayInputStream(smptemidifile);44s = MidiSystem.getSequence(is);45long duration = s.getMicrosecondLength() / 1000000;46System.out.println("Duration: "+duration+" seconds ");47if (duration > 14) {48throw new Exception("SMPTE time reader is broken! Test FAILED");49}50System.out.println("Test passed");51}5253public static void printFile(String filename) throws Exception {54File file = new File(filename);55FileInputStream fis = new FileInputStream(file);56byte[] data = new byte[(int) file.length()];57fis.read(data);58String s = "";59for (int i=0; i<data.length; i++) {60s+=String.valueOf(data[i])+", ";61if (s.length()>72) {62System.out.println(s);63s="";64}65}66System.out.println(s);67}6869// A MIDI file with SMPTE timing70static byte[] smptemidifile = {7177, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 3, -30, 120, 77, 84, 114, 107, 0,720, 0, 123, 0, -112, 30, 100, -113, 49, -128, 50, 100, -114, 69, -112, 31,73100, -114, 33, -128, 51, 100, -114, 55, -112, 32, 100, -114, 120, -128, 52,74100, -114, 40, -112, 33, 100, -114, 26, -128, 53, 100, -114, 26, -112, 34,75100, -114, 76, -128, 54, 100, -114, 12, -112, 35, 100, -114, 91, -128, 55,76100, -114, 69, -112, 36, 100, -114, 33, -128, 56, 100, -114, 55, -112, 37,77100, -114, 84, -128, 57, 100, -114, 40, -112, 38, 100, -114, 26, -128, 58,78100, -114, 26, -112, 39, 100, -113, 24, -128, 59, 100, -113, 60, -112, 40,79100, -113, 110, -128, 60, 100, -113, 96, -112, 41, 100, -113, 39, -128, 61,80100, 0, -1, 47, 0, 77, 84, 114, 107, 0, 0, 0, 4, 0, -1, 47, 0, 77, 84, 114,81107, 0, 0, 0, 4, 0, -1, 47, 082};8384}858687