src/share/classes/com/sun/media/sound/SF2Soundbank.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2013, 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


 600             sm24_chunk.write(data.array(),
 601             data.arrayOffset(),
 602             data.capacity());*/
 603             smpl_chunk.write(pad);
 604         }
 605     }
 606 
 607     private void writeModulators(RIFFWriter writer, List<SF2Modulator> modulators)
 608             throws IOException {
 609         for (SF2Modulator modulator : modulators) {
 610             writer.writeUnsignedShort(modulator.sourceOperator);
 611             writer.writeUnsignedShort(modulator.destinationOperator);
 612             writer.writeShort(modulator.amount);
 613             writer.writeUnsignedShort(modulator.amountSourceOperator);
 614             writer.writeUnsignedShort(modulator.transportOperator);
 615         }
 616     }
 617 
 618     private void writeGenerators(RIFFWriter writer, Map<Integer, Short> generators)
 619             throws IOException {
 620         Short keyrange = (Short) generators.get(SF2Region.GENERATOR_KEYRANGE);
 621         Short velrange = (Short) generators.get(SF2Region.GENERATOR_VELRANGE);
 622         if (keyrange != null) {
 623             writer.writeUnsignedShort(SF2Region.GENERATOR_KEYRANGE);
 624             writer.writeShort(keyrange);
 625         }
 626         if (velrange != null) {
 627             writer.writeUnsignedShort(SF2Region.GENERATOR_VELRANGE);
 628             writer.writeShort(velrange);
 629         }
 630         for (Map.Entry<Integer, Short> generator : generators.entrySet()) {
 631             if (generator.getKey() == SF2Region.GENERATOR_KEYRANGE)
 632                 continue;
 633             if (generator.getKey() == SF2Region.GENERATOR_VELRANGE)
 634                 continue;
 635             writer.writeUnsignedShort(generator.getKey());
 636             writer.writeShort(generator.getValue());
 637         }
 638     }
 639 
 640     private void writePdtaChunk(RIFFWriter writer) throws IOException {
 641 


 689 
 690         RIFFWriter pmod_chunk = writer.writeChunk("pmod");
 691         for (SF2Instrument preset : this.instruments) {
 692             if (preset.getGlobalRegion() != null) {
 693                 writeModulators(pmod_chunk,
 694                         preset.getGlobalRegion().getModulators());
 695             }
 696             for (SF2InstrumentRegion region : preset.getRegions())
 697                 writeModulators(pmod_chunk, region.getModulators());
 698         }
 699         pmod_chunk.write(new byte[10]);
 700 
 701         RIFFWriter pgen_chunk = writer.writeChunk("pgen");
 702         for (SF2Instrument preset : this.instruments) {
 703             if (preset.getGlobalRegion() != null) {
 704                 writeGenerators(pgen_chunk,
 705                         preset.getGlobalRegion().getGenerators());
 706             }
 707             for (SF2InstrumentRegion region : preset.getRegions()) {
 708                 writeGenerators(pgen_chunk, region.getGenerators());
 709                 int ix = (int) layers.indexOf(region.layer);
 710                 if (ix != -1) {
 711                     pgen_chunk.writeUnsignedShort(SF2Region.GENERATOR_INSTRUMENT);
 712                     pgen_chunk.writeShort((short) ix);
 713                 }
 714             }
 715         }
 716         pgen_chunk.write(new byte[4]);
 717 
 718         RIFFWriter inst_chunk = writer.writeChunk("inst");
 719         int inst_zone_count = 0;
 720         for (SF2Layer instrument : this.layers) {
 721             inst_chunk.writeString(instrument.name, 20);
 722             inst_chunk.writeUnsignedShort(inst_zone_count);
 723             if (instrument.getGlobalRegion() != null)
 724                 inst_zone_count += 1;
 725             inst_zone_count += instrument.getRegions().size();
 726         }
 727         inst_chunk.writeString("EOI", 20);
 728         inst_chunk.writeUnsignedShort(inst_zone_count);
 729 


   1 /*
   2  * Copyright (c) 2007, 2014, 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


 600             sm24_chunk.write(data.array(),
 601             data.arrayOffset(),
 602             data.capacity());*/
 603             smpl_chunk.write(pad);
 604         }
 605     }
 606 
 607     private void writeModulators(RIFFWriter writer, List<SF2Modulator> modulators)
 608             throws IOException {
 609         for (SF2Modulator modulator : modulators) {
 610             writer.writeUnsignedShort(modulator.sourceOperator);
 611             writer.writeUnsignedShort(modulator.destinationOperator);
 612             writer.writeShort(modulator.amount);
 613             writer.writeUnsignedShort(modulator.amountSourceOperator);
 614             writer.writeUnsignedShort(modulator.transportOperator);
 615         }
 616     }
 617 
 618     private void writeGenerators(RIFFWriter writer, Map<Integer, Short> generators)
 619             throws IOException {
 620         Short keyrange = generators.get(SF2Region.GENERATOR_KEYRANGE);
 621         Short velrange = generators.get(SF2Region.GENERATOR_VELRANGE);
 622         if (keyrange != null) {
 623             writer.writeUnsignedShort(SF2Region.GENERATOR_KEYRANGE);
 624             writer.writeShort(keyrange);
 625         }
 626         if (velrange != null) {
 627             writer.writeUnsignedShort(SF2Region.GENERATOR_VELRANGE);
 628             writer.writeShort(velrange);
 629         }
 630         for (Map.Entry<Integer, Short> generator : generators.entrySet()) {
 631             if (generator.getKey() == SF2Region.GENERATOR_KEYRANGE)
 632                 continue;
 633             if (generator.getKey() == SF2Region.GENERATOR_VELRANGE)
 634                 continue;
 635             writer.writeUnsignedShort(generator.getKey());
 636             writer.writeShort(generator.getValue());
 637         }
 638     }
 639 
 640     private void writePdtaChunk(RIFFWriter writer) throws IOException {
 641 


 689 
 690         RIFFWriter pmod_chunk = writer.writeChunk("pmod");
 691         for (SF2Instrument preset : this.instruments) {
 692             if (preset.getGlobalRegion() != null) {
 693                 writeModulators(pmod_chunk,
 694                         preset.getGlobalRegion().getModulators());
 695             }
 696             for (SF2InstrumentRegion region : preset.getRegions())
 697                 writeModulators(pmod_chunk, region.getModulators());
 698         }
 699         pmod_chunk.write(new byte[10]);
 700 
 701         RIFFWriter pgen_chunk = writer.writeChunk("pgen");
 702         for (SF2Instrument preset : this.instruments) {
 703             if (preset.getGlobalRegion() != null) {
 704                 writeGenerators(pgen_chunk,
 705                         preset.getGlobalRegion().getGenerators());
 706             }
 707             for (SF2InstrumentRegion region : preset.getRegions()) {
 708                 writeGenerators(pgen_chunk, region.getGenerators());
 709                 int ix = layers.indexOf(region.layer);
 710                 if (ix != -1) {
 711                     pgen_chunk.writeUnsignedShort(SF2Region.GENERATOR_INSTRUMENT);
 712                     pgen_chunk.writeShort((short) ix);
 713                 }
 714             }
 715         }
 716         pgen_chunk.write(new byte[4]);
 717 
 718         RIFFWriter inst_chunk = writer.writeChunk("inst");
 719         int inst_zone_count = 0;
 720         for (SF2Layer instrument : this.layers) {
 721             inst_chunk.writeString(instrument.name, 20);
 722             inst_chunk.writeUnsignedShort(inst_zone_count);
 723             if (instrument.getGlobalRegion() != null)
 724                 inst_zone_count += 1;
 725             inst_zone_count += instrument.getRegions().size();
 726         }
 727         inst_chunk.writeString("EOI", 20);
 728         inst_chunk.writeUnsignedShort(inst_zone_count);
 729