829N/A/*
6321N/A * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
829N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
829N/A *
829N/A * This code is free software; you can redistribute it and/or modify it
829N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
829N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
829N/A *
829N/A * This code is distributed in the hope that it will be useful, but WITHOUT
829N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
829N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
829N/A * version 2 for more details (a copy is included in the LICENSE file that
829N/A * accompanied this code).
829N/A *
829N/A * You should have received a copy of the GNU General Public License version
829N/A * 2 along with this work; if not, write to the Free Software Foundation,
829N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
829N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
829N/A */
829N/Apackage com.sun.media.sound;
829N/A
829N/Aimport java.io.InputStream;
3957N/Aimport java.util.Arrays;
829N/Aimport javax.sound.midi.Soundbank;
829N/Aimport javax.sound.midi.SoundbankResource;
829N/Aimport javax.sound.sampled.AudioFormat;
829N/Aimport javax.sound.sampled.AudioInputStream;
829N/A
829N/A/**
829N/A * This class is used to store the sample data itself.
829N/A * A sample is encoded as PCM audio stream
829N/A * and in DLS Level 1 files it is always a mono 8/16 bit stream.
829N/A * They are stored just like RIFF WAVE files are stored.
829N/A * It is stored inside a "wave" List Chunk inside DLS files.
829N/A *
829N/A * @author Karl Helgason
829N/A */
6321N/Apublic final class DLSSample extends SoundbankResource {
829N/A
6321N/A byte[] guid = null;
6321N/A DLSInfo info = new DLSInfo();
6321N/A DLSSampleOptions sampleoptions;
6321N/A ModelByteBuffer data;
6321N/A AudioFormat format;
829N/A
829N/A public DLSSample(Soundbank soundBank) {
829N/A super(soundBank, null, AudioInputStream.class);
829N/A }
829N/A
829N/A public DLSSample() {
829N/A super(null, null, AudioInputStream.class);
829N/A }
829N/A
829N/A public DLSInfo getInfo() {
829N/A return info;
829N/A }
829N/A
829N/A public Object getData() {
829N/A AudioFormat format = getFormat();
829N/A
829N/A InputStream is = data.getInputStream();
829N/A if (is == null)
829N/A return null;
829N/A return new AudioInputStream(is, format, data.capacity());
829N/A }
829N/A
829N/A public ModelByteBuffer getDataBuffer() {
829N/A return data;
829N/A }
829N/A
829N/A public AudioFormat getFormat() {
829N/A return format;
829N/A }
829N/A
829N/A public void setFormat(AudioFormat format) {
829N/A this.format = format;
829N/A }
829N/A
829N/A public void setData(ModelByteBuffer data) {
829N/A this.data = data;
829N/A }
829N/A
829N/A public void setData(byte[] data) {
829N/A this.data = new ModelByteBuffer(data);
829N/A }
829N/A
829N/A public void setData(byte[] data, int offset, int length) {
829N/A this.data = new ModelByteBuffer(data, offset, length);
829N/A }
829N/A
829N/A public String getName() {
829N/A return info.name;
829N/A }
829N/A
829N/A public void setName(String name) {
829N/A info.name = name;
829N/A }
829N/A
829N/A public DLSSampleOptions getSampleoptions() {
829N/A return sampleoptions;
829N/A }
829N/A
829N/A public void setSampleoptions(DLSSampleOptions sampleOptions) {
829N/A this.sampleoptions = sampleOptions;
829N/A }
829N/A
829N/A public String toString() {
829N/A return "Sample: " + info.name;
829N/A }
829N/A
829N/A public byte[] getGuid() {
3957N/A return guid == null ? null : Arrays.copyOf(guid, guid.length);
829N/A }
829N/A
829N/A public void setGuid(byte[] guid) {
3957N/A this.guid = guid == null ? null : Arrays.copyOf(guid, guid.length);
829N/A }
829N/A}