/********************************************************************************************************* "Ensemble" is the proprietary property of The Regents of the University of California ("The Regents.") Copyright (c) 2005-10 The Regents of the University of California, Davis campus. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted by nonprofit, research institutions for research use only, provided the conditions in the included license agreement are met. Refer to the file "ensemble_license.txt" for the license agreement, located in the top level directory of this distribution. **********************************************************************************************************/ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; /** * author Stefan Tomic * written for Ensemble * This class contains information on a sound * such as URL, duration to play, and pause time * also contains the AudioInputStream and file format * information. * * Written 8 August, 2006 * */ class SoundInfo { private static int DEFAULT_SAMPLE_SIZE_BITS = 16; public String soundFileURL; public double playDuration; public double pause; public AudioInputStream stream; public AudioFormat format; public SoundInfo(String sfURL) throws MalformedURLException, UnsupportedAudioFileException, IOException { soundFileURL = sfURL; playDuration=0; pause=0; stream = AudioSystem.getAudioInputStream(new URL(sfURL)); // At present, ALAW and ULAW encodings must be converted // to PCM_SIGNED before it can be played format = stream.getFormat(); if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) { format = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), DEFAULT_SAMPLE_SIZE_BITS, format.getChannels(), format.getChannels() * (DEFAULT_SAMPLE_SIZE_BITS / 8), format.getSampleRate(), true); // big endian stream = AudioSystem.getAudioInputStream(format, stream); } } public SoundInfo(String sfURL,double dur) throws MalformedURLException, UnsupportedAudioFileException, IOException { this(sfURL); playDuration = dur; pause=0; } public SoundInfo(String sfURL,double dur, double p) throws MalformedURLException, UnsupportedAudioFileException, IOException { this(sfURL); soundFileURL = sfURL; playDuration = dur; pause = p; } }