< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/SF2Sample.java

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */

  25 package com.sun.media.sound;
  26 
  27 import java.io.InputStream;
  28 
  29 import javax.sound.midi.Soundbank;
  30 import javax.sound.midi.SoundbankResource;
  31 import javax.sound.sampled.AudioFormat;
  32 import javax.sound.sampled.AudioInputStream;
  33 
  34 /**
  35  * Soundfont sample storage.
  36  *
  37  * @author Karl Helgason
  38  */
  39 public final class SF2Sample extends SoundbankResource {
  40 
  41     String name = "";
  42     long startLoop = 0;
  43     long endLoop = 0;
  44     long sampleRate = 44100;
  45     int originalPitch = 60;
  46     byte pitchCorrection = 0;
  47     int sampleLink = 0;
  48     int sampleType = 0;
  49     ModelByteBuffer data;
  50     ModelByteBuffer data24;
  51 
  52     public SF2Sample(Soundbank soundBank) {
  53         super(soundBank, null, AudioInputStream.class);
  54     }
  55 
  56     public SF2Sample() {
  57         super(null, null, AudioInputStream.class);
  58     }
  59 

  60     public Object getData() {
  61 
  62         AudioFormat format = getFormat();
  63         /*
  64         if (sampleFile != null) {
  65             FileInputStream fis;
  66             try {
  67                 fis = new FileInputStream(sampleFile);
  68                 RIFFReader riff = new RIFFReader(fis);
  69                 if (!riff.getFormat().equals("RIFF")) {
  70                     throw new RIFFInvalidDataException(
  71                         "Input stream is not a valid RIFF stream!");
  72                 }
  73                 if (!riff.getType().equals("sfbk")) {
  74                     throw new RIFFInvalidDataException(
  75                         "Input stream is not a valid SoundFont!");
  76                 }
  77                 while (riff.hasNextChunk()) {
  78                     RIFFReader chunk = riff.nextChunk();
  79                     if (chunk.getFormat().equals("LIST")) {


 129         this.data24 = data24;
 130     }
 131 
 132     public void setData24(byte[] data24) {
 133         this.data24 = new ModelByteBuffer(data24);
 134     }
 135 
 136     public void setData24(byte[] data24, int offset, int length) {
 137         this.data24 = new ModelByteBuffer(data24, offset, length);
 138     }
 139 
 140     /*
 141     public void setData(File file, int offset, int length) {
 142         this.data = null;
 143         this.sampleFile = file;
 144         this.sampleOffset = offset;
 145         this.sampleLen = length;
 146     }
 147     */
 148 

 149     public String getName() {
 150         return name;
 151     }
 152 
 153     public void setName(String name) {
 154         this.name = name;
 155     }
 156 
 157     public long getEndLoop() {
 158         return endLoop;
 159     }
 160 
 161     public void setEndLoop(long endLoop) {
 162         this.endLoop = endLoop;
 163     }
 164 
 165     public int getOriginalPitch() {
 166         return originalPitch;
 167     }
 168 


 193     public void setSampleRate(long sampleRate) {
 194         this.sampleRate = sampleRate;
 195     }
 196 
 197     public int getSampleType() {
 198         return sampleType;
 199     }
 200 
 201     public void setSampleType(int sampleType) {
 202         this.sampleType = sampleType;
 203     }
 204 
 205     public long getStartLoop() {
 206         return startLoop;
 207     }
 208 
 209     public void setStartLoop(long startLoop) {
 210         this.startLoop = startLoop;
 211     }
 212 

 213     public String toString() {
 214         return "Sample: " + name;
 215     }
 216 }


   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.sound;
  27 
  28 import java.io.InputStream;
  29 
  30 import javax.sound.midi.Soundbank;
  31 import javax.sound.midi.SoundbankResource;
  32 import javax.sound.sampled.AudioFormat;
  33 import javax.sound.sampled.AudioInputStream;
  34 
  35 /**
  36  * Soundfont sample storage.
  37  *
  38  * @author Karl Helgason
  39  */
  40 public final class SF2Sample extends SoundbankResource {
  41 
  42     String name = "";
  43     long startLoop = 0;
  44     long endLoop = 0;
  45     long sampleRate = 44100;
  46     int originalPitch = 60;
  47     byte pitchCorrection = 0;
  48     int sampleLink = 0;
  49     int sampleType = 0;
  50     ModelByteBuffer data;
  51     ModelByteBuffer data24;
  52 
  53     public SF2Sample(Soundbank soundBank) {
  54         super(soundBank, null, AudioInputStream.class);
  55     }
  56 
  57     public SF2Sample() {
  58         super(null, null, AudioInputStream.class);
  59     }
  60 
  61     @Override
  62     public Object getData() {
  63 
  64         AudioFormat format = getFormat();
  65         /*
  66         if (sampleFile != null) {
  67             FileInputStream fis;
  68             try {
  69                 fis = new FileInputStream(sampleFile);
  70                 RIFFReader riff = new RIFFReader(fis);
  71                 if (!riff.getFormat().equals("RIFF")) {
  72                     throw new RIFFInvalidDataException(
  73                         "Input stream is not a valid RIFF stream!");
  74                 }
  75                 if (!riff.getType().equals("sfbk")) {
  76                     throw new RIFFInvalidDataException(
  77                         "Input stream is not a valid SoundFont!");
  78                 }
  79                 while (riff.hasNextChunk()) {
  80                     RIFFReader chunk = riff.nextChunk();
  81                     if (chunk.getFormat().equals("LIST")) {


 131         this.data24 = data24;
 132     }
 133 
 134     public void setData24(byte[] data24) {
 135         this.data24 = new ModelByteBuffer(data24);
 136     }
 137 
 138     public void setData24(byte[] data24, int offset, int length) {
 139         this.data24 = new ModelByteBuffer(data24, offset, length);
 140     }
 141 
 142     /*
 143     public void setData(File file, int offset, int length) {
 144         this.data = null;
 145         this.sampleFile = file;
 146         this.sampleOffset = offset;
 147         this.sampleLen = length;
 148     }
 149     */
 150 
 151     @Override
 152     public String getName() {
 153         return name;
 154     }
 155 
 156     public void setName(String name) {
 157         this.name = name;
 158     }
 159 
 160     public long getEndLoop() {
 161         return endLoop;
 162     }
 163 
 164     public void setEndLoop(long endLoop) {
 165         this.endLoop = endLoop;
 166     }
 167 
 168     public int getOriginalPitch() {
 169         return originalPitch;
 170     }
 171 


 196     public void setSampleRate(long sampleRate) {
 197         this.sampleRate = sampleRate;
 198     }
 199 
 200     public int getSampleType() {
 201         return sampleType;
 202     }
 203 
 204     public void setSampleType(int sampleType) {
 205         this.sampleType = sampleType;
 206     }
 207 
 208     public long getStartLoop() {
 209         return startLoop;
 210     }
 211 
 212     public void setStartLoop(long startLoop) {
 213         this.startLoop = startLoop;
 214     }
 215 
 216     @Override
 217     public String toString() {
 218         return "Sample: " + name;
 219     }
 220 }
< prev index next >