Save This Page
Home » openjdk-7 » com.sun.media » sound » [javadoc | source]
    1   /*
    2    * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    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.util.ArrayList;
   28   import java.util.HashMap;
   29   import java.util.List;
   30   import java.util.Map;
   31   
   32   /**
   33    * Soundfont general region.
   34    *
   35    * @author Karl Helgason
   36    */
   37   public class SF2Region {
   38   
   39       public final static int GENERATOR_STARTADDRSOFFSET = 0;
   40       public final static int GENERATOR_ENDADDRSOFFSET = 1;
   41       public final static int GENERATOR_STARTLOOPADDRSOFFSET = 2;
   42       public final static int GENERATOR_ENDLOOPADDRSOFFSET = 3;
   43       public final static int GENERATOR_STARTADDRSCOARSEOFFSET = 4;
   44       public final static int GENERATOR_MODLFOTOPITCH = 5;
   45       public final static int GENERATOR_VIBLFOTOPITCH = 6;
   46       public final static int GENERATOR_MODENVTOPITCH = 7;
   47       public final static int GENERATOR_INITIALFILTERFC = 8;
   48       public final static int GENERATOR_INITIALFILTERQ = 9;
   49       public final static int GENERATOR_MODLFOTOFILTERFC = 10;
   50       public final static int GENERATOR_MODENVTOFILTERFC = 11;
   51       public final static int GENERATOR_ENDADDRSCOARSEOFFSET = 12;
   52       public final static int GENERATOR_MODLFOTOVOLUME = 13;
   53       public final static int GENERATOR_UNUSED1 = 14;
   54       public final static int GENERATOR_CHORUSEFFECTSSEND = 15;
   55       public final static int GENERATOR_REVERBEFFECTSSEND = 16;
   56       public final static int GENERATOR_PAN = 17;
   57       public final static int GENERATOR_UNUSED2 = 18;
   58       public final static int GENERATOR_UNUSED3 = 19;
   59       public final static int GENERATOR_UNUSED4 = 20;
   60       public final static int GENERATOR_DELAYMODLFO = 21;
   61       public final static int GENERATOR_FREQMODLFO = 22;
   62       public final static int GENERATOR_DELAYVIBLFO = 23;
   63       public final static int GENERATOR_FREQVIBLFO = 24;
   64       public final static int GENERATOR_DELAYMODENV = 25;
   65       public final static int GENERATOR_ATTACKMODENV = 26;
   66       public final static int GENERATOR_HOLDMODENV = 27;
   67       public final static int GENERATOR_DECAYMODENV = 28;
   68       public final static int GENERATOR_SUSTAINMODENV = 29;
   69       public final static int GENERATOR_RELEASEMODENV = 30;
   70       public final static int GENERATOR_KEYNUMTOMODENVHOLD = 31;
   71       public final static int GENERATOR_KEYNUMTOMODENVDECAY = 32;
   72       public final static int GENERATOR_DELAYVOLENV = 33;
   73       public final static int GENERATOR_ATTACKVOLENV = 34;
   74       public final static int GENERATOR_HOLDVOLENV = 35;
   75       public final static int GENERATOR_DECAYVOLENV = 36;
   76       public final static int GENERATOR_SUSTAINVOLENV = 37;
   77       public final static int GENERATOR_RELEASEVOLENV = 38;
   78       public final static int GENERATOR_KEYNUMTOVOLENVHOLD = 39;
   79       public final static int GENERATOR_KEYNUMTOVOLENVDECAY = 40;
   80       public final static int GENERATOR_INSTRUMENT = 41;
   81       public final static int GENERATOR_RESERVED1 = 42;
   82       public final static int GENERATOR_KEYRANGE = 43;
   83       public final static int GENERATOR_VELRANGE = 44;
   84       public final static int GENERATOR_STARTLOOPADDRSCOARSEOFFSET = 45;
   85       public final static int GENERATOR_KEYNUM = 46;
   86       public final static int GENERATOR_VELOCITY = 47;
   87       public final static int GENERATOR_INITIALATTENUATION = 48;
   88       public final static int GENERATOR_RESERVED2 = 49;
   89       public final static int GENERATOR_ENDLOOPADDRSCOARSEOFFSET = 50;
   90       public final static int GENERATOR_COARSETUNE = 51;
   91       public final static int GENERATOR_FINETUNE = 52;
   92       public final static int GENERATOR_SAMPLEID = 53;
   93       public final static int GENERATOR_SAMPLEMODES = 54;
   94       public final static int GENERATOR_RESERVED3 = 55;
   95       public final static int GENERATOR_SCALETUNING = 56;
   96       public final static int GENERATOR_EXCLUSIVECLASS = 57;
   97       public final static int GENERATOR_OVERRIDINGROOTKEY = 58;
   98       public final static int GENERATOR_UNUSED5 = 59;
   99       public final static int GENERATOR_ENDOPR = 60;
  100       protected Map<Integer, Short> generators = new HashMap<Integer, Short>();
  101       protected List<SF2Modulator> modulators = new ArrayList<SF2Modulator>();
  102   
  103       public Map<Integer, Short> getGenerators() {
  104           return generators;
  105       }
  106   
  107       public boolean contains(int generator) {
  108           return generators.containsKey(generator);
  109       }
  110   
  111       static public short getDefaultValue(int generator) {
  112           if (generator == 8) return (short)13500;
  113           if (generator == 21) return (short)-12000;
  114           if (generator == 23) return (short)-12000;
  115           if (generator == 25) return (short)-12000;
  116           if (generator == 26) return (short)-12000;
  117           if (generator == 27) return (short)-12000;
  118           if (generator == 28) return (short)-12000;
  119           if (generator == 30) return (short)-12000;
  120           if (generator == 33) return (short)-12000;
  121           if (generator == 34) return (short)-12000;
  122           if (generator == 35) return (short)-12000;
  123           if (generator == 36) return (short)-12000;
  124           if (generator == 38) return (short)-12000;
  125           if (generator == 43) return (short)0x7F00;
  126           if (generator == 44) return (short)0x7F00;
  127           if (generator == 46) return (short)-1;
  128           if (generator == 47) return (short)-1;
  129           if (generator == 56) return (short)100;
  130           if (generator == 58) return (short)-1;
  131           return 0;
  132       }
  133   
  134       public short getShort(int generator) {
  135           if (!contains(generator))
  136               return getDefaultValue(generator);
  137           return generators.get(generator);
  138       }
  139   
  140       public void putShort(int generator, short value) {
  141           generators.put(generator, value);
  142       }
  143   
  144       public byte[] getBytes(int generator) {
  145           int val = getInteger(generator);
  146           byte[] bytes = new byte[2];
  147           bytes[0] = (byte) (0xFF & val);
  148           bytes[1] = (byte) ((0xFF00 & val) >> 8);
  149           return bytes;
  150       }
  151   
  152       public void putBytes(int generator, byte[] bytes) {
  153           generators.put(generator, (short) (bytes[0] + (bytes[1] << 8)));
  154       }
  155   
  156       public int getInteger(int generator) {
  157           return 0xFFFF & getShort(generator);
  158       }
  159   
  160       public void putInteger(int generator, int value) {
  161           generators.put(generator, (short) value);
  162       }
  163   
  164       public List<SF2Modulator> getModulators() {
  165           return modulators;
  166       }
  167   }

Save This Page
Home » openjdk-7 » com.sun.media » sound » [javadoc | source]