Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/media/sound/DLSSample.java
38924 views
/*1* Copyright (c) 2007, 2013, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package com.sun.media.sound;2526import java.io.InputStream;27import java.util.Arrays;28import javax.sound.midi.Soundbank;29import javax.sound.midi.SoundbankResource;30import javax.sound.sampled.AudioFormat;31import javax.sound.sampled.AudioInputStream;3233/**34* This class is used to store the sample data itself.35* A sample is encoded as PCM audio stream36* and in DLS Level 1 files it is always a mono 8/16 bit stream.37* They are stored just like RIFF WAVE files are stored.38* It is stored inside a "wave" List Chunk inside DLS files.39*40* @author Karl Helgason41*/42public final class DLSSample extends SoundbankResource {4344byte[] guid = null;45DLSInfo info = new DLSInfo();46DLSSampleOptions sampleoptions;47ModelByteBuffer data;48AudioFormat format;4950public DLSSample(Soundbank soundBank) {51super(soundBank, null, AudioInputStream.class);52}5354public DLSSample() {55super(null, null, AudioInputStream.class);56}5758public DLSInfo getInfo() {59return info;60}6162public Object getData() {63AudioFormat format = getFormat();6465InputStream is = data.getInputStream();66if (is == null)67return null;68return new AudioInputStream(is, format, data.capacity());69}7071public ModelByteBuffer getDataBuffer() {72return data;73}7475public AudioFormat getFormat() {76return format;77}7879public void setFormat(AudioFormat format) {80this.format = format;81}8283public void setData(ModelByteBuffer data) {84this.data = data;85}8687public void setData(byte[] data) {88this.data = new ModelByteBuffer(data);89}9091public void setData(byte[] data, int offset, int length) {92this.data = new ModelByteBuffer(data, offset, length);93}9495public String getName() {96return info.name;97}9899public void setName(String name) {100info.name = name;101}102103public DLSSampleOptions getSampleoptions() {104return sampleoptions;105}106107public void setSampleoptions(DLSSampleOptions sampleOptions) {108this.sampleoptions = sampleOptions;109}110111public String toString() {112return "Sample: " + info.name;113}114115public byte[] getGuid() {116return guid == null ? null : Arrays.copyOf(guid, guid.length);117}118119public void setGuid(byte[] guid) {120this.guid = guid == null ? null : Arrays.copyOf(guid, guid.length);121}122}123124125