Path: blob/master/src/java.desktop/share/classes/com/sun/media/sound/DLSSample.java
41161 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*/2425package com.sun.media.sound;2627import java.io.InputStream;28import java.util.Arrays;2930import javax.sound.midi.Soundbank;31import javax.sound.midi.SoundbankResource;32import javax.sound.sampled.AudioFormat;33import javax.sound.sampled.AudioInputStream;3435/**36* This class is used to store the sample data itself.37* A sample is encoded as PCM audio stream38* and in DLS Level 1 files it is always a mono 8/16 bit stream.39* They are stored just like RIFF WAVE files are stored.40* It is stored inside a "wave" List Chunk inside DLS files.41*42* @author Karl Helgason43*/44public final class DLSSample extends SoundbankResource {4546byte[] guid = null;47DLSInfo info = new DLSInfo();48DLSSampleOptions sampleoptions;49ModelByteBuffer data;50AudioFormat format;5152public DLSSample(Soundbank soundBank) {53super(soundBank, null, AudioInputStream.class);54}5556public DLSSample() {57super(null, null, AudioInputStream.class);58}5960public DLSInfo getInfo() {61return info;62}6364@Override65public Object getData() {66AudioFormat format = getFormat();6768InputStream is = data.getInputStream();69if (is == null)70return null;71return new AudioInputStream(is, format, data.capacity());72}7374public ModelByteBuffer getDataBuffer() {75return data;76}7778public AudioFormat getFormat() {79return format;80}8182public void setFormat(AudioFormat format) {83this.format = format;84}8586public void setData(ModelByteBuffer data) {87this.data = data;88}8990public void setData(byte[] data) {91this.data = new ModelByteBuffer(data);92}9394public void setData(byte[] data, int offset, int length) {95this.data = new ModelByteBuffer(data, offset, length);96}9798@Override99public String getName() {100return info.name;101}102103public void setName(String name) {104info.name = name;105}106107public DLSSampleOptions getSampleoptions() {108return sampleoptions;109}110111public void setSampleoptions(DLSSampleOptions sampleOptions) {112this.sampleoptions = sampleOptions;113}114115@Override116public String toString() {117return "Sample: " + info.name;118}119120public byte[] getGuid() {121return guid == null ? null : Arrays.copyOf(guid, guid.length);122}123124public void setGuid(byte[] guid) {125this.guid = guid == null ? null : Arrays.copyOf(guid, guid.length);126}127}128129130