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;
829N/A
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 * Soundfont sample storage.
829N/A *
829N/A * @author Karl Helgason
829N/A */
6321N/Apublic final class SF2Sample extends SoundbankResource {
829N/A
6321N/A String name = "";
6321N/A long startLoop = 0;
6321N/A long endLoop = 0;
6321N/A long sampleRate = 44100;
6321N/A int originalPitch = 60;
6321N/A byte pitchCorrection = 0;
6321N/A int sampleLink = 0;
6321N/A int sampleType = 0;
6321N/A ModelByteBuffer data;
6321N/A ModelByteBuffer data24;
829N/A
829N/A public SF2Sample(Soundbank soundBank) {
829N/A super(soundBank, null, AudioInputStream.class);
829N/A }
829N/A
829N/A public SF2Sample() {
829N/A super(null, null, AudioInputStream.class);
829N/A }
829N/A
829N/A public Object getData() {
829N/A
829N/A AudioFormat format = getFormat();
829N/A /*
829N/A if (sampleFile != null) {
829N/A FileInputStream fis;
829N/A try {
829N/A fis = new FileInputStream(sampleFile);
829N/A RIFFReader riff = new RIFFReader(fis);
829N/A if (!riff.getFormat().equals("RIFF")) {
829N/A throw new RIFFInvalidDataException(
829N/A "Input stream is not a valid RIFF stream!");
829N/A }
829N/A if (!riff.getType().equals("sfbk")) {
829N/A throw new RIFFInvalidDataException(
829N/A "Input stream is not a valid SoundFont!");
829N/A }
829N/A while (riff.hasNextChunk()) {
829N/A RIFFReader chunk = riff.nextChunk();
829N/A if (chunk.getFormat().equals("LIST")) {
829N/A if (chunk.getType().equals("sdta")) {
829N/A while(chunk.hasNextChunk()) {
829N/A RIFFReader chunkchunk = chunk.nextChunk();
829N/A if(chunkchunk.getFormat().equals("smpl")) {
829N/A chunkchunk.skip(sampleOffset);
829N/A return new AudioInputStream(chunkchunk,
829N/A format, sampleLen);
829N/A }
829N/A }
829N/A }
829N/A }
829N/A }
829N/A return null;
829N/A } catch (Exception e) {
829N/A return new Throwable(e.toString());
829N/A }
829N/A }
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 ModelByteBuffer getData24Buffer() {
829N/A return data24;
829N/A }
829N/A
829N/A public AudioFormat getFormat() {
829N/A return new AudioFormat(sampleRate, 16, 1, true, false);
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 void setData24(ModelByteBuffer data24) {
829N/A this.data24 = data24;
829N/A }
829N/A
829N/A public void setData24(byte[] data24) {
829N/A this.data24 = new ModelByteBuffer(data24);
829N/A }
829N/A
829N/A public void setData24(byte[] data24, int offset, int length) {
829N/A this.data24 = new ModelByteBuffer(data24, offset, length);
829N/A }
829N/A
829N/A /*
829N/A public void setData(File file, int offset, int length) {
829N/A this.data = null;
829N/A this.sampleFile = file;
829N/A this.sampleOffset = offset;
829N/A this.sampleLen = length;
829N/A }
829N/A */
829N/A
829N/A public String getName() {
829N/A return name;
829N/A }
829N/A
829N/A public void setName(String name) {
829N/A this.name = name;
829N/A }
829N/A
829N/A public long getEndLoop() {
829N/A return endLoop;
829N/A }
829N/A
829N/A public void setEndLoop(long endLoop) {
829N/A this.endLoop = endLoop;
829N/A }
829N/A
829N/A public int getOriginalPitch() {
829N/A return originalPitch;
829N/A }
829N/A
829N/A public void setOriginalPitch(int originalPitch) {
829N/A this.originalPitch = originalPitch;
829N/A }
829N/A
829N/A public byte getPitchCorrection() {
829N/A return pitchCorrection;
829N/A }
829N/A
829N/A public void setPitchCorrection(byte pitchCorrection) {
829N/A this.pitchCorrection = pitchCorrection;
829N/A }
829N/A
829N/A public int getSampleLink() {
829N/A return sampleLink;
829N/A }
829N/A
829N/A public void setSampleLink(int sampleLink) {
829N/A this.sampleLink = sampleLink;
829N/A }
829N/A
829N/A public long getSampleRate() {
829N/A return sampleRate;
829N/A }
829N/A
829N/A public void setSampleRate(long sampleRate) {
829N/A this.sampleRate = sampleRate;
829N/A }
829N/A
829N/A public int getSampleType() {
829N/A return sampleType;
829N/A }
829N/A
829N/A public void setSampleType(int sampleType) {
829N/A this.sampleType = sampleType;
829N/A }
829N/A
829N/A public long getStartLoop() {
829N/A return startLoop;
829N/A }
829N/A
829N/A public void setStartLoop(long startLoop) {
829N/A this.startLoop = startLoop;
829N/A }
829N/A
829N/A public String toString() {
829N/A return "Sample: " + name;
829N/A }
829N/A}