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.Random;
   28   
   29   import javax.sound.midi.Patch;
   30   import javax.sound.sampled.AudioFormat;
   31   
   32   /**
   33    * Emergency Soundbank generator.
   34    * Used when no other default soundbank can be found.
   35    *
   36    * @author Karl Helgason
   37    */
   38   public class EmergencySoundbank {
   39   
   40       private final static String[] general_midi_instruments = {
   41           "Acoustic Grand Piano",
   42           "Bright Acoustic Piano",
   43           "Electric Grand Piano",
   44           "Honky-tonk Piano",
   45           "Electric Piano 1",
   46           "Electric Piano 2",
   47           "Harpsichord",
   48           "Clavi",
   49           "Celesta",
   50           "Glockenspiel",
   51           "Music Box",
   52           "Vibraphone",
   53           "Marimba",
   54           "Xylophone",
   55           "Tubular Bells",
   56           "Dulcimer",
   57           "Drawbar Organ",
   58           "Percussive Organ",
   59           "Rock Organ",
   60           "Church Organ",
   61           "Reed Organ",
   62           "Accordion",
   63           "Harmonica",
   64           "Tango Accordion",
   65           "Acoustic Guitar (nylon)",
   66           "Acoustic Guitar (steel)",
   67           "Electric Guitar (jazz)",
   68           "Electric Guitar (clean)",
   69           "Electric Guitar (muted)",
   70           "Overdriven Guitar",
   71           "Distortion Guitar",
   72           "Guitar harmonics",
   73           "Acoustic Bass",
   74           "Electric Bass (finger)",
   75           "Electric Bass (pick)",
   76           "Fretless Bass",
   77           "Slap Bass 1",
   78           "Slap Bass 2",
   79           "Synth Bass 1",
   80           "Synth Bass 2",
   81           "Violin",
   82           "Viola",
   83           "Cello",
   84           "Contrabass",
   85           "Tremolo Strings",
   86           "Pizzicato Strings",
   87           "Orchestral Harp",
   88           "Timpani",
   89           "String Ensemble 1",
   90           "String Ensemble 2",
   91           "SynthStrings 1",
   92           "SynthStrings 2",
   93           "Choir Aahs",
   94           "Voice Oohs",
   95           "Synth Voice",
   96           "Orchestra Hit",
   97           "Trumpet",
   98           "Trombone",
   99           "Tuba",
  100           "Muted Trumpet",
  101           "French Horn",
  102           "Brass Section",
  103           "SynthBrass 1",
  104           "SynthBrass 2",
  105           "Soprano Sax",
  106           "Alto Sax",
  107           "Tenor Sax",
  108           "Baritone Sax",
  109           "Oboe",
  110           "English Horn",
  111           "Bassoon",
  112           "Clarinet",
  113           "Piccolo",
  114           "Flute",
  115           "Recorder",
  116           "Pan Flute",
  117           "Blown Bottle",
  118           "Shakuhachi",
  119           "Whistle",
  120           "Ocarina",
  121           "Lead 1 (square)",
  122           "Lead 2 (sawtooth)",
  123           "Lead 3 (calliope)",
  124           "Lead 4 (chiff)",
  125           "Lead 5 (charang)",
  126           "Lead 6 (voice)",
  127           "Lead 7 (fifths)",
  128           "Lead 8 (bass + lead)",
  129           "Pad 1 (new age)",
  130           "Pad 2 (warm)",
  131           "Pad 3 (polysynth)",
  132           "Pad 4 (choir)",
  133           "Pad 5 (bowed)",
  134           "Pad 6 (metallic)",
  135           "Pad 7 (halo)",
  136           "Pad 8 (sweep)",
  137           "FX 1 (rain)",
  138           "FX 2 (soundtrack)",
  139           "FX 3 (crystal)",
  140           "FX 4 (atmosphere)",
  141           "FX 5 (brightness)",
  142           "FX 6 (goblins)",
  143           "FX 7 (echoes)",
  144           "FX 8 (sci-fi)",
  145           "Sitar",
  146           "Banjo",
  147           "Shamisen",
  148           "Koto",
  149           "Kalimba",
  150           "Bag pipe",
  151           "Fiddle",
  152           "Shanai",
  153           "Tinkle Bell",
  154           "Agogo",
  155           "Steel Drums",
  156           "Woodblock",
  157           "Taiko Drum",
  158           "Melodic Tom",
  159           "Synth Drum",
  160           "Reverse Cymbal",
  161           "Guitar Fret Noise",
  162           "Breath Noise",
  163           "Seashore",
  164           "Bird Tweet",
  165           "Telephone Ring",
  166           "Helicopter",
  167           "Applause",
  168           "Gunshot"
  169       };
  170   
  171       public static SF2Soundbank createSoundbank() throws Exception {
  172           SF2Soundbank sf2 = new SF2Soundbank();
  173           sf2.setName("Emergency GM sound set");
  174           sf2.setVendor("Generated");
  175           sf2.setDescription("Emergency generated soundbank");
  176   
  177           /*
  178            *  percussion instruments
  179            */
  180   
  181           SF2Layer bass_drum = new_bass_drum(sf2);
  182           SF2Layer snare_drum = new_snare_drum(sf2);
  183           SF2Layer tom = new_tom(sf2);
  184           SF2Layer open_hihat = new_open_hihat(sf2);
  185           SF2Layer closed_hihat = new_closed_hihat(sf2);
  186           SF2Layer crash_cymbal = new_crash_cymbal(sf2);
  187           SF2Layer side_stick = new_side_stick(sf2);
  188   
  189           SF2Layer[] drums = new SF2Layer[128];
  190           drums[35] = bass_drum;
  191           drums[36] = bass_drum;
  192           drums[38] = snare_drum;
  193           drums[40] = snare_drum;
  194           drums[41] = tom;
  195           drums[43] = tom;
  196           drums[45] = tom;
  197           drums[47] = tom;
  198           drums[48] = tom;
  199           drums[50] = tom;
  200           drums[42] = closed_hihat;
  201           drums[44] = closed_hihat;
  202           drums[46] = open_hihat;
  203           drums[49] = crash_cymbal;
  204           drums[51] = crash_cymbal;
  205           drums[52] = crash_cymbal;
  206           drums[55] = crash_cymbal;
  207           drums[57] = crash_cymbal;
  208           drums[59] = crash_cymbal;
  209   
  210           // Use side_stick for missing drums:
  211           drums[37] = side_stick;
  212           drums[39] = side_stick;
  213           drums[53] = side_stick;
  214           drums[54] = side_stick;
  215           drums[56] = side_stick;
  216           drums[58] = side_stick;
  217           drums[69] = side_stick;
  218           drums[70] = side_stick;
  219           drums[75] = side_stick;
  220           drums[60] = side_stick;
  221           drums[61] = side_stick;
  222           drums[62] = side_stick;
  223           drums[63] = side_stick;
  224           drums[64] = side_stick;
  225           drums[65] = side_stick;
  226           drums[66] = side_stick;
  227           drums[67] = side_stick;
  228           drums[68] = side_stick;
  229           drums[71] = side_stick;
  230           drums[72] = side_stick;
  231           drums[73] = side_stick;
  232           drums[74] = side_stick;
  233           drums[76] = side_stick;
  234           drums[77] = side_stick;
  235           drums[78] = side_stick;
  236           drums[79] = side_stick;
  237           drums[80] = side_stick;
  238           drums[81] = side_stick;
  239   
  240   
  241           SF2Instrument drum_instrument = new SF2Instrument(sf2);
  242           drum_instrument.setName("Standard Kit");
  243           drum_instrument.setPatch(new ModelPatch(0, 0, true));
  244           sf2.addInstrument(drum_instrument);
  245           for (int i = 0; i < drums.length; i++) {
  246               if (drums[i] != null) {
  247                   SF2InstrumentRegion region = new SF2InstrumentRegion();
  248                   region.setLayer(drums[i]);
  249                   region.putBytes(SF2InstrumentRegion.GENERATOR_KEYRANGE,
  250                           new byte[]{(byte) i, (byte) i});
  251                   drum_instrument.getRegions().add(region);
  252               }
  253           }
  254   
  255   
  256           /*
  257            *  melodic instruments
  258            */
  259   
  260           SF2Layer gpiano = new_gpiano(sf2);
  261           SF2Layer gpiano2 = new_gpiano2(sf2);
  262           SF2Layer gpiano_hammer = new_piano_hammer(sf2);
  263           SF2Layer piano1 = new_piano1(sf2);
  264           SF2Layer epiano1 = new_epiano1(sf2);
  265           SF2Layer epiano2 = new_epiano2(sf2);
  266   
  267           SF2Layer guitar = new_guitar1(sf2);
  268           SF2Layer guitar_pick = new_guitar_pick(sf2);
  269           SF2Layer guitar_dist = new_guitar_dist(sf2);
  270           SF2Layer bass1 = new_bass1(sf2);
  271           SF2Layer bass2 = new_bass2(sf2);
  272           SF2Layer synthbass = new_synthbass(sf2);
  273           SF2Layer string2 = new_string2(sf2);
  274           SF2Layer orchhit = new_orchhit(sf2);
  275           SF2Layer choir = new_choir(sf2);
  276           SF2Layer solostring = new_solostring(sf2);
  277           SF2Layer organ = new_organ(sf2);
  278           SF2Layer ch_organ = new_ch_organ(sf2);
  279           SF2Layer bell = new_bell(sf2);
  280           SF2Layer flute = new_flute(sf2);
  281   
  282           SF2Layer timpani = new_timpani(sf2);
  283           SF2Layer melodic_toms = new_melodic_toms(sf2);
  284           SF2Layer trumpet = new_trumpet(sf2);
  285           SF2Layer trombone = new_trombone(sf2);
  286           SF2Layer brass_section = new_brass_section(sf2);
  287           SF2Layer horn = new_horn(sf2);
  288           SF2Layer sax = new_sax(sf2);
  289           SF2Layer oboe = new_oboe(sf2);
  290           SF2Layer bassoon = new_bassoon(sf2);
  291           SF2Layer clarinet = new_clarinet(sf2);
  292           SF2Layer reverse_cymbal = new_reverse_cymbal(sf2);
  293   
  294           SF2Layer defaultsound = piano1;
  295   
  296           newInstrument(sf2, "Piano", new Patch(0, 0), gpiano, gpiano_hammer);
  297           newInstrument(sf2, "Piano", new Patch(0, 1), gpiano2, gpiano_hammer);
  298           newInstrument(sf2, "Piano", new Patch(0, 2), piano1);
  299           {
  300               SF2Instrument ins = newInstrument(sf2, "Honky-tonk Piano",
  301                       new Patch(0, 3), piano1, piano1);
  302               SF2InstrumentRegion region = ins.getRegions().get(0);
  303               region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 80);
  304               region.putInteger(SF2Region.GENERATOR_FINETUNE, 30);
  305               region = ins.getRegions().get(1);
  306               region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 30);
  307           }
  308           newInstrument(sf2, "Rhodes", new Patch(0, 4), epiano2);
  309           newInstrument(sf2, "Rhodes", new Patch(0, 5), epiano2);
  310           newInstrument(sf2, "Clavinet", new Patch(0, 6), epiano1);
  311           newInstrument(sf2, "Clavinet", new Patch(0, 7), epiano1);
  312           newInstrument(sf2, "Rhodes", new Patch(0, 8), epiano2);
  313           newInstrument(sf2, "Bell", new Patch(0, 9), bell);
  314           newInstrument(sf2, "Bell", new Patch(0, 10), bell);
  315           newInstrument(sf2, "Vibraphone", new Patch(0, 11), bell);
  316           newInstrument(sf2, "Marimba", new Patch(0, 12), bell);
  317           newInstrument(sf2, "Marimba", new Patch(0, 13), bell);
  318           newInstrument(sf2, "Bell", new Patch(0, 14), bell);
  319           newInstrument(sf2, "Rock Organ", new Patch(0, 15), organ);
  320           newInstrument(sf2, "Rock Organ", new Patch(0, 16), organ);
  321           newInstrument(sf2, "Perc Organ", new Patch(0, 17), organ);
  322           newInstrument(sf2, "Rock Organ", new Patch(0, 18), organ);
  323           newInstrument(sf2, "Church Organ", new Patch(0, 19), ch_organ);
  324           newInstrument(sf2, "Accordion", new Patch(0, 20), organ);
  325           newInstrument(sf2, "Accordion", new Patch(0, 21), organ);
  326           newInstrument(sf2, "Accordion", new Patch(0, 22), organ);
  327           newInstrument(sf2, "Accordion", new Patch(0, 23), organ);
  328           newInstrument(sf2, "Guitar", new Patch(0, 24), guitar, guitar_pick);
  329           newInstrument(sf2, "Guitar", new Patch(0, 25), guitar, guitar_pick);
  330           newInstrument(sf2, "Guitar", new Patch(0, 26), guitar, guitar_pick);
  331           newInstrument(sf2, "Guitar", new Patch(0, 27), guitar, guitar_pick);
  332           newInstrument(sf2, "Guitar", new Patch(0, 28), guitar, guitar_pick);
  333           newInstrument(sf2, "Distorted Guitar", new Patch(0, 29), guitar_dist);
  334           newInstrument(sf2, "Distorted Guitar", new Patch(0, 30), guitar_dist);
  335           newInstrument(sf2, "Guitar", new Patch(0, 31), guitar, guitar_pick);
  336           newInstrument(sf2, "Finger Bass", new Patch(0, 32), bass1);
  337           newInstrument(sf2, "Finger Bass", new Patch(0, 33), bass1);
  338           newInstrument(sf2, "Finger Bass", new Patch(0, 34), bass1);
  339           newInstrument(sf2, "Frettless Bass", new Patch(0, 35), bass2);
  340           newInstrument(sf2, "Frettless Bass", new Patch(0, 36), bass2);
  341           newInstrument(sf2, "Frettless Bass", new Patch(0, 37), bass2);
  342           newInstrument(sf2, "Synth Bass1", new Patch(0, 38), synthbass);
  343           newInstrument(sf2, "Synth Bass2", new Patch(0, 39), synthbass);
  344           newInstrument(sf2, "Solo String", new Patch(0, 40), string2, solostring);
  345           newInstrument(sf2, "Solo String", new Patch(0, 41), string2, solostring);
  346           newInstrument(sf2, "Solo String", new Patch(0, 42), string2, solostring);
  347           newInstrument(sf2, "Solo String", new Patch(0, 43), string2, solostring);
  348           newInstrument(sf2, "Solo String", new Patch(0, 44), string2, solostring);
  349           newInstrument(sf2, "Def", new Patch(0, 45), defaultsound);
  350           newInstrument(sf2, "Harp", new Patch(0, 46), bell);
  351           newInstrument(sf2, "Timpani", new Patch(0, 47), timpani);
  352           newInstrument(sf2, "Strings", new Patch(0, 48), string2);
  353           SF2Instrument slow_strings =
  354                   newInstrument(sf2, "Slow Strings", new Patch(0, 49), string2);
  355           SF2InstrumentRegion region = slow_strings.getRegions().get(0);
  356           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, 2500);
  357           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 2000);
  358           newInstrument(sf2, "Synth Strings", new Patch(0, 50), string2);
  359           newInstrument(sf2, "Synth Strings", new Patch(0, 51), string2);
  360   
  361   
  362           newInstrument(sf2, "Choir", new Patch(0, 52), choir);
  363           newInstrument(sf2, "Choir", new Patch(0, 53), choir);
  364           newInstrument(sf2, "Choir", new Patch(0, 54), choir);
  365           {
  366               SF2Instrument ins = newInstrument(sf2, "Orch Hit",
  367                       new Patch(0, 55), orchhit, orchhit, timpani);
  368               region = ins.getRegions().get(0);
  369               region.putInteger(SF2Region.GENERATOR_COARSETUNE, -12);
  370               region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
  371           }
  372           newInstrument(sf2, "Trumpet", new Patch(0, 56), trumpet);
  373           newInstrument(sf2, "Trombone", new Patch(0, 57), trombone);
  374           newInstrument(sf2, "Trombone", new Patch(0, 58), trombone);
  375           newInstrument(sf2, "Trumpet", new Patch(0, 59), trumpet);
  376           newInstrument(sf2, "Horn", new Patch(0, 60), horn);
  377           newInstrument(sf2, "Brass Section", new Patch(0, 61), brass_section);
  378           newInstrument(sf2, "Brass Section", new Patch(0, 62), brass_section);
  379           newInstrument(sf2, "Brass Section", new Patch(0, 63), brass_section);
  380           newInstrument(sf2, "Sax", new Patch(0, 64), sax);
  381           newInstrument(sf2, "Sax", new Patch(0, 65), sax);
  382           newInstrument(sf2, "Sax", new Patch(0, 66), sax);
  383           newInstrument(sf2, "Sax", new Patch(0, 67), sax);
  384           newInstrument(sf2, "Oboe", new Patch(0, 68), oboe);
  385           newInstrument(sf2, "Horn", new Patch(0, 69), horn);
  386           newInstrument(sf2, "Bassoon", new Patch(0, 70), bassoon);
  387           newInstrument(sf2, "Clarinet", new Patch(0, 71), clarinet);
  388           newInstrument(sf2, "Flute", new Patch(0, 72), flute);
  389           newInstrument(sf2, "Flute", new Patch(0, 73), flute);
  390           newInstrument(sf2, "Flute", new Patch(0, 74), flute);
  391           newInstrument(sf2, "Flute", new Patch(0, 75), flute);
  392           newInstrument(sf2, "Flute", new Patch(0, 76), flute);
  393           newInstrument(sf2, "Flute", new Patch(0, 77), flute);
  394           newInstrument(sf2, "Flute", new Patch(0, 78), flute);
  395           newInstrument(sf2, "Flute", new Patch(0, 79), flute);
  396           newInstrument(sf2, "Organ", new Patch(0, 80), organ);
  397           newInstrument(sf2, "Organ", new Patch(0, 81), organ);
  398           newInstrument(sf2, "Flute", new Patch(0, 82), flute);
  399           newInstrument(sf2, "Organ", new Patch(0, 83), organ);
  400           newInstrument(sf2, "Organ", new Patch(0, 84), organ);
  401           newInstrument(sf2, "Choir", new Patch(0, 85), choir);
  402           newInstrument(sf2, "Organ", new Patch(0, 86), organ);
  403           newInstrument(sf2, "Organ", new Patch(0, 87), organ);
  404           newInstrument(sf2, "Synth Strings", new Patch(0, 88), string2);
  405           newInstrument(sf2, "Organ", new Patch(0, 89), organ);
  406           newInstrument(sf2, "Def", new Patch(0, 90), defaultsound);
  407           newInstrument(sf2, "Choir", new Patch(0, 91), choir);
  408           newInstrument(sf2, "Organ", new Patch(0, 92), organ);
  409           newInstrument(sf2, "Organ", new Patch(0, 93), organ);
  410           newInstrument(sf2, "Organ", new Patch(0, 94), organ);
  411           newInstrument(sf2, "Organ", new Patch(0, 95), organ);
  412           newInstrument(sf2, "Organ", new Patch(0, 96), organ);
  413           newInstrument(sf2, "Organ", new Patch(0, 97), organ);
  414           newInstrument(sf2, "Bell", new Patch(0, 98), bell);
  415           newInstrument(sf2, "Organ", new Patch(0, 99), organ);
  416           newInstrument(sf2, "Organ", new Patch(0, 100), organ);
  417           newInstrument(sf2, "Organ", new Patch(0, 101), organ);
  418           newInstrument(sf2, "Def", new Patch(0, 102), defaultsound);
  419           newInstrument(sf2, "Synth Strings", new Patch(0, 103), string2);
  420           newInstrument(sf2, "Def", new Patch(0, 104), defaultsound);
  421           newInstrument(sf2, "Def", new Patch(0, 105), defaultsound);
  422           newInstrument(sf2, "Def", new Patch(0, 106), defaultsound);
  423           newInstrument(sf2, "Def", new Patch(0, 107), defaultsound);
  424           newInstrument(sf2, "Marimba", new Patch(0, 108), bell);
  425           newInstrument(sf2, "Sax", new Patch(0, 109), sax);
  426           newInstrument(sf2, "Solo String", new Patch(0, 110), string2, solostring);
  427           newInstrument(sf2, "Oboe", new Patch(0, 111), oboe);
  428           newInstrument(sf2, "Bell", new Patch(0, 112), bell);
  429           newInstrument(sf2, "Melodic Toms", new Patch(0, 113), melodic_toms);
  430           newInstrument(sf2, "Marimba", new Patch(0, 114), bell);
  431           newInstrument(sf2, "Melodic Toms", new Patch(0, 115), melodic_toms);
  432           newInstrument(sf2, "Melodic Toms", new Patch(0, 116), melodic_toms);
  433           newInstrument(sf2, "Melodic Toms", new Patch(0, 117), melodic_toms);
  434           newInstrument(sf2, "Reverse Cymbal", new Patch(0, 118), reverse_cymbal);
  435           newInstrument(sf2, "Reverse Cymbal", new Patch(0, 119), reverse_cymbal);
  436           newInstrument(sf2, "Guitar", new Patch(0, 120), guitar);
  437           newInstrument(sf2, "Def", new Patch(0, 121), defaultsound);
  438           {
  439               SF2Instrument ins = newInstrument(sf2, "Seashore/Reverse Cymbal",
  440                       new Patch(0, 122), reverse_cymbal);
  441               region = ins.getRegions().get(0);
  442               region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
  443               region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 18500);
  444               region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 4500);
  445               region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, -4500);
  446           }
  447           {
  448               SF2Instrument ins = newInstrument(sf2, "Bird/Flute",
  449                       new Patch(0, 123), flute);
  450               region = ins.getRegions().get(0);
  451               region.putInteger(SF2Region.GENERATOR_COARSETUNE, 24);
  452               region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, -3000);
  453               region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
  454           }
  455           newInstrument(sf2, "Def", new Patch(0, 124), side_stick);
  456           {
  457               SF2Instrument ins = newInstrument(sf2, "Seashore/Reverse Cymbal",
  458                       new Patch(0, 125), reverse_cymbal);
  459               region = ins.getRegions().get(0);
  460               region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
  461               region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 18500);
  462               region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 4500);
  463               region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, -4500);
  464           }
  465           newInstrument(sf2, "Applause/crash_cymbal",
  466                   new Patch(0, 126), crash_cymbal);
  467           newInstrument(sf2, "Gunshot/side_stick", new Patch(0, 127), side_stick);
  468   
  469           for (SF2Instrument instrument : sf2.getInstruments()) {
  470               Patch patch = instrument.getPatch();
  471               if (patch instanceof ModelPatch) {
  472                   if (((ModelPatch) patch).isPercussion())
  473                       continue;
  474               }
  475               instrument.setName(general_midi_instruments[patch.getProgram()]);
  476           }
  477   
  478           return sf2;
  479   
  480       }
  481   
  482       public static SF2Layer new_bell(SF2Soundbank sf2) {
  483           Random random = new Random(102030201);
  484           int x = 8;
  485           int fftsize = 4096 * x;
  486           double[] data = new double[fftsize * 2];
  487           double base = x * 25;
  488           double start_w = 0.01;
  489           double end_w = 0.05;
  490           double start_a = 0.2;
  491           double end_a = 0.00001;
  492           double a = start_a;
  493           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
  494           for (int i = 0; i < 40; i++) {
  495               double detune = 1 + (random.nextDouble() * 2 - 1) * 0.01;
  496               double w = start_w + (end_w - start_w) * (i / 40.0);
  497               complexGaussianDist(data, base * (i + 1) * detune, w, a);
  498               a *= a_step;
  499           }
  500           SF2Sample sample = newSimpleFFTSample(sf2, "EPiano", data, base);
  501           SF2Layer layer = newLayer(sf2, "EPiano", sample);
  502           SF2Region region = layer.getRegions().get(0);
  503           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
  504           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
  505           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
  506           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
  507           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
  508           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, 1200);
  509           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
  510           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -9000);
  511           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 16000);
  512           return layer;
  513       }
  514   
  515       public static SF2Layer new_guitar1(SF2Soundbank sf2) {
  516   
  517           int x = 8;
  518           int fftsize = 4096 * x;
  519           double[] data = new double[fftsize * 2];
  520           double base = x * 25;
  521           double start_w = 0.01;
  522           double end_w = 0.01;
  523           double start_a = 2;
  524           double end_a = 0.01;
  525           double a = start_a;
  526           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
  527   
  528           double[] aa = new double[40];
  529           for (int i = 0; i < 40; i++) {
  530               aa[i] = a;
  531               a *= a_step;
  532           }
  533   
  534           aa[0] = 2;
  535           aa[1] = 0.5;
  536           aa[2] = 0.45;
  537           aa[3] = 0.2;
  538           aa[4] = 1;
  539           aa[5] = 0.5;
  540           aa[6] = 2;
  541           aa[7] = 1;
  542           aa[8] = 0.5;
  543           aa[9] = 1;
  544           aa[9] = 0.5;
  545           aa[10] = 0.2;
  546           aa[11] = 1;
  547           aa[12] = 0.7;
  548           aa[13] = 0.5;
  549           aa[14] = 1;
  550   
  551           for (int i = 0; i < 40; i++) {
  552               double w = start_w + (end_w - start_w) * (i / 40.0);
  553               complexGaussianDist(data, base * (i + 1), w, aa[i]);
  554           }
  555   
  556           SF2Sample sample = newSimpleFFTSample(sf2, "Guitar", data, base);
  557           SF2Layer layer = newLayer(sf2, "Guitar", sample);
  558           SF2Region region = layer.getRegions().get(0);
  559           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
  560           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
  561           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
  562           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 2400);
  563           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
  564   
  565           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -100);
  566           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
  567           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -6000);
  568           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 16000);
  569           region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -20);
  570           return layer;
  571       }
  572   
  573       public static SF2Layer new_guitar_dist(SF2Soundbank sf2) {
  574   
  575           int x = 8;
  576           int fftsize = 4096 * x;
  577           double[] data = new double[fftsize * 2];
  578           double base = x * 25;
  579           double start_w = 0.01;
  580           double end_w = 0.01;
  581           double start_a = 2;
  582           double end_a = 0.01;
  583           double a = start_a;
  584           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
  585   
  586           double[] aa = new double[40];
  587           for (int i = 0; i < 40; i++) {
  588               aa[i] = a;
  589               a *= a_step;
  590           }
  591   
  592           aa[0] = 5;
  593           aa[1] = 2;
  594           aa[2] = 0.45;
  595           aa[3] = 0.2;
  596           aa[4] = 1;
  597           aa[5] = 0.5;
  598           aa[6] = 2;
  599           aa[7] = 1;
  600           aa[8] = 0.5;
  601           aa[9] = 1;
  602           aa[9] = 0.5;
  603           aa[10] = 0.2;
  604           aa[11] = 1;
  605           aa[12] = 0.7;
  606           aa[13] = 0.5;
  607           aa[14] = 1;
  608   
  609           for (int i = 0; i < 40; i++) {
  610               double w = start_w + (end_w - start_w) * (i / 40.0);
  611               complexGaussianDist(data, base * (i + 1), w, aa[i]);
  612           }
  613   
  614   
  615           SF2Sample sample = newSimpleFFTSample_dist(sf2, "Distorted Guitar",
  616                   data, base, 10000.0);
  617   
  618   
  619           SF2Layer layer = newLayer(sf2, "Distorted Guitar", sample);
  620           SF2Region region = layer.getRegions().get(0);
  621           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
  622           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
  623           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
  624           //region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 2400);
  625           //region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 200);
  626   
  627           //region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -100);
  628           //region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
  629           //region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -1000);
  630           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 8000);
  631           //region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -20);
  632           return layer;
  633       }
  634   
  635       public static SF2Layer new_guitar_pick(SF2Soundbank sf2) {
  636   
  637           double datab[];
  638   
  639           // Make treble part
  640           {
  641               int m = 2;
  642               int fftlen = 4096 * m;
  643               double[] data = new double[2 * fftlen];
  644               Random random = new Random(3049912);
  645               for (int i = 0; i < data.length; i += 2)
  646                   data[i] = (2.0 * (random.nextDouble() - 0.5));
  647               fft(data);
  648               // Remove all negative frequency
  649               for (int i = fftlen / 2; i < data.length; i++)
  650                   data[i] = 0;
  651               for (int i = 0; i < 2048 * m; i++) {
  652                   data[i] *= Math.exp(-Math.abs((i - 23) / ((double) m)) * 1.2)
  653                           + Math.exp(-Math.abs((i - 40) / ((double) m)) * 0.9);
  654               }
  655               randomPhase(data, new Random(3049912));
  656               ifft(data);
  657               normalize(data, 0.8);
  658               data = realPart(data);
  659               double gain = 1.0;
  660               for (int i = 0; i < data.length; i++) {
  661                   data[i] *= gain;
  662                   gain *= 0.9994;
  663               }
  664               datab = data;
  665   
  666               fadeUp(data, 80);
  667           }
  668   
  669           SF2Sample sample = newSimpleDrumSample(sf2, "Guitar Noise", datab);
  670   
  671           SF2Layer layer = new SF2Layer(sf2);
  672           layer.setName("Guitar Noise");
  673   
  674           SF2GlobalRegion global = new SF2GlobalRegion();
  675           layer.setGlobalZone(global);
  676           sf2.addResource(layer);
  677   
  678           SF2LayerRegion region = new SF2LayerRegion();
  679           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
  680           //region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
  681   //        region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
  682   /*
  683           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, 0);
  684           region.putInteger(SF2Region.GENERATOR_SUSTAINMODENV, 1000);
  685           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
  686           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -11000);
  687           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 12000);
  688            */
  689   
  690           region.setSample(sample);
  691           layer.getRegions().add(region);
  692   
  693           return layer;
  694       }
  695   
  696       public static SF2Layer new_gpiano(SF2Soundbank sf2) {
  697           //Random random = new Random(302030201);
  698           int x = 8;
  699           int fftsize = 4096 * x;
  700           double[] data = new double[fftsize * 2];
  701           double base = x * 25;
  702           double start_a = 0.2;
  703           double end_a = 0.001;
  704           double a = start_a;
  705           double a_step = Math.pow(end_a / start_a, 1.0 / 15.0);
  706   
  707           double[] aa = new double[30];
  708           for (int i = 0; i < 30; i++) {
  709               aa[i] = a;
  710               a *= a_step;
  711           }
  712   
  713           aa[0] *= 2;
  714           //aa[2] *= 0.1;
  715           aa[4] *= 2;
  716   
  717   
  718           aa[12] *= 0.9;
  719           aa[13] *= 0.7;
  720           for (int i = 14; i < 30; i++) {
  721               aa[i] *= 0.5;
  722           }
  723   
  724   
  725           for (int i = 0; i < 30; i++) {
  726               //double detune = 1 + (random.nextDouble()*2 - 1)*0.0001;
  727               double w = 0.2;
  728               double ai = aa[i];
  729               if (i > 10) {
  730                   w = 5;
  731                   ai *= 10;
  732               }
  733               int adjust = 0;
  734               if (i > 5) {
  735                   adjust = (i - 5) * 7;
  736               }
  737               complexGaussianDist(data, base * (i + 1) + adjust, w, ai);
  738           }
  739   
  740           SF2Sample sample = newSimpleFFTSample(sf2, "Grand Piano", data, base, 200);
  741           SF2Layer layer = newLayer(sf2, "Grand Piano", sample);
  742           SF2Region region = layer.getRegions().get(0);
  743           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
  744           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -7000);
  745           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
  746           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
  747           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
  748           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -6000);
  749           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
  750           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -5500);
  751           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 18000);
  752           return layer;
  753       }
  754   
  755       public static SF2Layer new_gpiano2(SF2Soundbank sf2) {
  756           //Random random = new Random(302030201);
  757           int x = 8;
  758           int fftsize = 4096 * x;
  759           double[] data = new double[fftsize * 2];
  760           double base = x * 25;
  761           double start_a = 0.2;
  762           double end_a = 0.001;
  763           double a = start_a;
  764           double a_step = Math.pow(end_a / start_a, 1.0 / 20.0);
  765   
  766           double[] aa = new double[30];
  767           for (int i = 0; i < 30; i++) {
  768               aa[i] = a;
  769               a *= a_step;
  770           }
  771   
  772           aa[0] *= 1;
  773           //aa[2] *= 0.1;
  774           aa[4] *= 2;
  775   
  776   
  777           aa[12] *= 0.9;
  778           aa[13] *= 0.7;
  779           for (int i = 14; i < 30; i++) {
  780               aa[i] *= 0.5;
  781           }
  782   
  783   
  784           for (int i = 0; i < 30; i++) {
  785               //double detune = 1 + (random.nextDouble()*2 - 1)*0.0001;
  786               double w = 0.2;
  787               double ai = aa[i];
  788               if (i > 10) {
  789                   w = 5;
  790                   ai *= 10;
  791               }
  792               int adjust = 0;
  793               if (i > 5) {
  794                   adjust = (i - 5) * 7;
  795               }
  796               complexGaussianDist(data, base * (i + 1) + adjust, w, ai);
  797           }
  798   
  799           SF2Sample sample = newSimpleFFTSample(sf2, "Grand Piano", data, base, 200);
  800           SF2Layer layer = newLayer(sf2, "Grand Piano", sample);
  801           SF2Region region = layer.getRegions().get(0);
  802           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
  803           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -7000);
  804           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
  805           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
  806           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
  807           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -6000);
  808           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
  809           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -5500);
  810           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 18000);
  811           return layer;
  812       }
  813   
  814       public static SF2Layer new_piano_hammer(SF2Soundbank sf2) {
  815   
  816           double datab[];
  817   
  818           // Make treble part
  819           {
  820               int m = 2;
  821               int fftlen = 4096 * m;
  822               double[] data = new double[2 * fftlen];
  823               Random random = new Random(3049912);
  824               for (int i = 0; i < data.length; i += 2)
  825                   data[i] = (2.0 * (random.nextDouble() - 0.5));
  826               fft(data);
  827               // Remove all negative frequency
  828               for (int i = fftlen / 2; i < data.length; i++)
  829                   data[i] = 0;
  830               for (int i = 0; i < 2048 * m; i++)
  831                   data[i] *= Math.exp(-Math.abs((i - 37) / ((double) m)) * 0.05);
  832               randomPhase(data, new Random(3049912));
  833               ifft(data);
  834               normalize(data, 0.6);
  835               data = realPart(data);
  836               double gain = 1.0;
  837               for (int i = 0; i < data.length; i++) {
  838                   data[i] *= gain;
  839                   gain *= 0.9997;
  840               }
  841               datab = data;
  842   
  843               fadeUp(data, 80);
  844           }
  845   
  846           SF2Sample sample = newSimpleDrumSample(sf2, "Piano Hammer", datab);
  847   
  848           SF2Layer layer = new SF2Layer(sf2);
  849           layer.setName("Piano Hammer");
  850   
  851           SF2GlobalRegion global = new SF2GlobalRegion();
  852           layer.setGlobalZone(global);
  853           sf2.addResource(layer);
  854   
  855           SF2LayerRegion region = new SF2LayerRegion();
  856           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
  857           //region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
  858   /*
  859           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, 0);
  860           region.putInteger(SF2Region.GENERATOR_SUSTAINMODENV, 1000);
  861           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
  862           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -11000);
  863           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 12000);
  864            */
  865   
  866           region.setSample(sample);
  867           layer.getRegions().add(region);
  868   
  869           return layer;
  870       }
  871   
  872       public static SF2Layer new_piano1(SF2Soundbank sf2) {
  873           //Random random = new Random(302030201);
  874           int x = 8;
  875           int fftsize = 4096 * x;
  876           double[] data = new double[fftsize * 2];
  877           double base = x * 25;
  878           double start_a = 0.2;
  879           double end_a = 0.0001;
  880           double a = start_a;
  881           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
  882   
  883           double[] aa = new double[30];
  884           for (int i = 0; i < 30; i++) {
  885               aa[i] = a;
  886               a *= a_step;
  887           }
  888   
  889           aa[0] *= 5;
  890           aa[2] *= 0.1;
  891           aa[7] *= 5;
  892   
  893   
  894           for (int i = 0; i < 30; i++) {
  895               //double detune = 1 + (random.nextDouble()*2 - 1)*0.0001;
  896               double w = 0.2;
  897               double ai = aa[i];
  898               if (i > 12) {
  899                   w = 5;
  900                   ai *= 10;
  901               }
  902               int adjust = 0;
  903               if (i > 5) {
  904                   adjust = (i - 5) * 7;
  905               }
  906               complexGaussianDist(data, base * (i + 1) + adjust, w, ai);
  907           }
  908   
  909           complexGaussianDist(data, base * (15.5), 1, 0.1);
  910           complexGaussianDist(data, base * (17.5), 1, 0.01);
  911   
  912           SF2Sample sample = newSimpleFFTSample(sf2, "EPiano", data, base, 200);
  913           SF2Layer layer = newLayer(sf2, "EPiano", sample);
  914           SF2Region region = layer.getRegions().get(0);
  915           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
  916           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
  917           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
  918           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
  919           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
  920           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -1200);
  921           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
  922           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -5500);
  923           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 16000);
  924           return layer;
  925       }
  926   
  927       public static SF2Layer new_epiano1(SF2Soundbank sf2) {
  928           Random random = new Random(302030201);
  929           int x = 8;
  930           int fftsize = 4096 * x;
  931           double[] data = new double[fftsize * 2];
  932           double base = x * 25;
  933           double start_w = 0.05;
  934           double end_w = 0.05;
  935           double start_a = 0.2;
  936           double end_a = 0.0001;
  937           double a = start_a;
  938           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
  939           for (int i = 0; i < 40; i++) {
  940               double detune = 1 + (random.nextDouble() * 2 - 1) * 0.0001;
  941               double w = start_w + (end_w - start_w) * (i / 40.0);
  942               complexGaussianDist(data, base * (i + 1) * detune, w, a);
  943               a *= a_step;
  944           }
  945   
  946   
  947   
  948           SF2Sample sample = newSimpleFFTSample(sf2, "EPiano", data, base);
  949           SF2Layer layer = newLayer(sf2, "EPiano", sample);
  950           SF2Region region = layer.getRegions().get(0);
  951           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
  952           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
  953           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
  954           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
  955           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
  956           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, 1200);
  957           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
  958           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -9000);
  959           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 16000);
  960           return layer;
  961       }
  962   
  963       public static SF2Layer new_epiano2(SF2Soundbank sf2) {
  964           Random random = new Random(302030201);
  965           int x = 8;
  966           int fftsize = 4096 * x;
  967           double[] data = new double[fftsize * 2];
  968           double base = x * 25;
  969           double start_w = 0.01;
  970           double end_w = 0.05;
  971           double start_a = 0.2;
  972           double end_a = 0.00001;
  973           double a = start_a;
  974           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
  975           for (int i = 0; i < 40; i++) {
  976               double detune = 1 + (random.nextDouble() * 2 - 1) * 0.0001;
  977               double w = start_w + (end_w - start_w) * (i / 40.0);
  978               complexGaussianDist(data, base * (i + 1) * detune, w, a);
  979               a *= a_step;
  980           }
  981   
  982           SF2Sample sample = newSimpleFFTSample(sf2, "EPiano", data, base);
  983           SF2Layer layer = newLayer(sf2, "EPiano", sample);
  984           SF2Region region = layer.getRegions().get(0);
  985           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
  986           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
  987           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
  988           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 8000);
  989           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
  990           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, 2400);
  991           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
  992           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -9000);
  993           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 16000);
  994           region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
  995           return layer;
  996       }
  997   
  998       public static SF2Layer new_bass1(SF2Soundbank sf2) {
  999           int x = 8;
 1000           int fftsize = 4096 * x;
 1001           double[] data = new double[fftsize * 2];
 1002           double base = x * 25;
 1003           double start_w = 0.05;
 1004           double end_w = 0.05;
 1005           double start_a = 0.2;
 1006           double end_a = 0.02;
 1007           double a = start_a;
 1008           double a_step = Math.pow(end_a / start_a, 1.0 / 25.0);
 1009   
 1010           double[] aa = new double[25];
 1011           for (int i = 0; i < 25; i++) {
 1012               aa[i] = a;
 1013               a *= a_step;
 1014           }
 1015   
 1016           aa[0] *= 8;
 1017           aa[1] *= 4;
 1018           aa[3] *= 8;
 1019           aa[5] *= 8;
 1020   
 1021           for (int i = 0; i < 25; i++) {
 1022               double w = start_w + (end_w - start_w) * (i / 40.0);
 1023               complexGaussianDist(data, base * (i + 1), w, aa[i]);
 1024           }
 1025   
 1026   
 1027           SF2Sample sample = newSimpleFFTSample(sf2, "Bass", data, base);
 1028           SF2Layer layer = newLayer(sf2, "Bass", sample);
 1029           SF2Region region = layer.getRegions().get(0);
 1030           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1031           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
 1032           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
 1033           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1034           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
 1035           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -3000);
 1036           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
 1037           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -5000);
 1038           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 11000);
 1039           region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
 1040           return layer;
 1041       }
 1042   
 1043       public static SF2Layer new_synthbass(SF2Soundbank sf2) {
 1044           int x = 8;
 1045           int fftsize = 4096 * x;
 1046           double[] data = new double[fftsize * 2];
 1047           double base = x * 25;
 1048           double start_w = 0.05;
 1049           double end_w = 0.05;
 1050           double start_a = 0.2;
 1051           double end_a = 0.02;
 1052           double a = start_a;
 1053           double a_step = Math.pow(end_a / start_a, 1.0 / 25.0);
 1054   
 1055           double[] aa = new double[25];
 1056           for (int i = 0; i < 25; i++) {
 1057               aa[i] = a;
 1058               a *= a_step;
 1059           }
 1060   
 1061           aa[0] *= 16;
 1062           aa[1] *= 4;
 1063           aa[3] *= 16;
 1064           aa[5] *= 8;
 1065   
 1066           for (int i = 0; i < 25; i++) {
 1067               double w = start_w + (end_w - start_w) * (i / 40.0);
 1068               complexGaussianDist(data, base * (i + 1), w, aa[i]);
 1069           }
 1070   
 1071   
 1072           SF2Sample sample = newSimpleFFTSample(sf2, "Bass", data, base);
 1073           SF2Layer layer = newLayer(sf2, "Bass", sample);
 1074           SF2Region region = layer.getRegions().get(0);
 1075           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1076           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
 1077           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
 1078           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1079           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
 1080           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -3000);
 1081           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
 1082           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -3000);
 1083           region.putInteger(SF2Region.GENERATOR_INITIALFILTERQ, 100);
 1084           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 8000);
 1085           region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
 1086           return layer;
 1087       }
 1088   
 1089       public static SF2Layer new_bass2(SF2Soundbank sf2) {
 1090           int x = 8;
 1091           int fftsize = 4096 * x;
 1092           double[] data = new double[fftsize * 2];
 1093           double base = x * 25;
 1094           double start_w = 0.05;
 1095           double end_w = 0.05;
 1096           double start_a = 0.2;
 1097           double end_a = 0.002;
 1098           double a = start_a;
 1099           double a_step = Math.pow(end_a / start_a, 1.0 / 25.0);
 1100   
 1101           double[] aa = new double[25];
 1102           for (int i = 0; i < 25; i++) {
 1103               aa[i] = a;
 1104               a *= a_step;
 1105           }
 1106   
 1107           aa[0] *= 8;
 1108           aa[1] *= 4;
 1109           aa[3] *= 8;
 1110           aa[5] *= 8;
 1111   
 1112           for (int i = 0; i < 25; i++) {
 1113               double w = start_w + (end_w - start_w) * (i / 40.0);
 1114               complexGaussianDist(data, base * (i + 1), w, aa[i]);
 1115           }
 1116   
 1117   
 1118           SF2Sample sample = newSimpleFFTSample(sf2, "Bass2", data, base);
 1119           SF2Layer layer = newLayer(sf2, "Bass2", sample);
 1120           SF2Region region = layer.getRegions().get(0);
 1121           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1122           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -8000);
 1123           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
 1124           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1125           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
 1126           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -6000);
 1127           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
 1128           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 5000);
 1129           region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
 1130           return layer;
 1131       }
 1132   
 1133       public static SF2Layer new_solostring(SF2Soundbank sf2) {
 1134           int x = 8;
 1135           int fftsize = 4096 * x;
 1136           double[] data = new double[fftsize * 2];
 1137           double base = x * 25;
 1138           double start_w = 2;
 1139           double end_w = 2;
 1140           double start_a = 0.2;
 1141           double end_a = 0.01;
 1142   
 1143           double[] aa = new double[18];
 1144           double a = start_a;
 1145           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
 1146           for (int i = 0; i < aa.length; i++) {
 1147               a *= a_step;
 1148               aa[i] = a;
 1149           }
 1150   
 1151           aa[0] *= 5;
 1152           aa[1] *= 5;
 1153           aa[2] *= 5;
 1154           aa[3] *= 4;
 1155           aa[4] *= 4;
 1156           aa[5] *= 3;
 1157           aa[6] *= 3;
 1158           aa[7] *= 2;
 1159   
 1160           for (int i = 0; i < aa.length; i++) {
 1161               double w = start_w + (end_w - start_w) * (i / 40.0);
 1162               complexGaussianDist(data, base * (i + 1), w, a);
 1163           }
 1164           SF2Sample sample = newSimpleFFTSample(sf2, "Strings", data, base);
 1165           SF2Layer layer = newLayer(sf2, "Strings", sample);
 1166           SF2Region region = layer.getRegions().get(0);
 1167           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1168           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -5000);
 1169           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 1000);
 1170           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1171           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1172           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
 1173           region.putInteger(SF2Region.GENERATOR_FREQVIBLFO, -1000);
 1174           region.putInteger(SF2Region.GENERATOR_VIBLFOTOPITCH, 15);
 1175           return layer;
 1176   
 1177       }
 1178   
 1179       public static SF2Layer new_orchhit(SF2Soundbank sf2) {
 1180           int x = 8;
 1181           int fftsize = 4096 * x;
 1182           double[] data = new double[fftsize * 2];
 1183           double base = x * 25;
 1184           double start_w = 2;
 1185           double end_w = 80;
 1186           double start_a = 0.2;
 1187           double end_a = 0.001;
 1188           double a = start_a;
 1189           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
 1190           for (int i = 0; i < 40; i++) {
 1191               double w = start_w + (end_w - start_w) * (i / 40.0);
 1192               complexGaussianDist(data, base * (i + 1), w, a);
 1193               a *= a_step;
 1194           }
 1195           complexGaussianDist(data, base * 4, 300, 1);
 1196   
 1197   
 1198           SF2Sample sample = newSimpleFFTSample(sf2, "Och Strings", data, base);
 1199           SF2Layer layer = newLayer(sf2, "Och Strings", sample);
 1200           SF2Region region = layer.getRegions().get(0);
 1201           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1202           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -5000);
 1203           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 200);
 1204           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 200);
 1205           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
 1206           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
 1207           return layer;
 1208   
 1209       }
 1210   
 1211       public static SF2Layer new_string2(SF2Soundbank sf2) {
 1212           int x = 8;
 1213           int fftsize = 4096 * x;
 1214           double[] data = new double[fftsize * 2];
 1215           double base = x * 25;
 1216           double start_w = 2;
 1217           double end_w = 80;
 1218           double start_a = 0.2;
 1219           double end_a = 0.001;
 1220           double a = start_a;
 1221           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
 1222           for (int i = 0; i < 40; i++) {
 1223               double w = start_w + (end_w - start_w) * (i / 40.0);
 1224               complexGaussianDist(data, base * (i + 1), w, a);
 1225               a *= a_step;
 1226           }
 1227           SF2Sample sample = newSimpleFFTSample(sf2, "Strings", data, base);
 1228           SF2Layer layer = newLayer(sf2, "Strings", sample);
 1229           SF2Region region = layer.getRegions().get(0);
 1230           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1231           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -5000);
 1232           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 1000);
 1233           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1234           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1235           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
 1236           return layer;
 1237   
 1238       }
 1239   
 1240       public static SF2Layer new_choir(SF2Soundbank sf2) {
 1241           int x = 8;
 1242           int fftsize = 4096 * x;
 1243           double[] data = new double[fftsize * 2];
 1244           double base = x * 25;
 1245           double start_w = 2;
 1246           double end_w = 80;
 1247           double start_a = 0.2;
 1248           double end_a = 0.001;
 1249           double a = start_a;
 1250           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
 1251           double[] aa = new double[40];
 1252           for (int i = 0; i < aa.length; i++) {
 1253               a *= a_step;
 1254               aa[i] = a;
 1255           }
 1256   
 1257           aa[5] *= 0.1;
 1258           aa[6] *= 0.01;
 1259           aa[7] *= 0.1;
 1260           aa[8] *= 0.1;
 1261   
 1262           for (int i = 0; i < aa.length; i++) {
 1263               double w = start_w + (end_w - start_w) * (i / 40.0);
 1264               complexGaussianDist(data, base * (i + 1), w, aa[i]);
 1265           }
 1266           SF2Sample sample = newSimpleFFTSample(sf2, "Strings", data, base);
 1267           SF2Layer layer = newLayer(sf2, "Strings", sample);
 1268           SF2Region region = layer.getRegions().get(0);
 1269           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1270           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -5000);
 1271           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 1000);
 1272           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1273           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1274           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
 1275           return layer;
 1276   
 1277       }
 1278   
 1279       public static SF2Layer new_organ(SF2Soundbank sf2) {
 1280           Random random = new Random(102030201);
 1281           int x = 1;
 1282           int fftsize = 4096 * x;
 1283           double[] data = new double[fftsize * 2];
 1284           double base = x * 15;
 1285           double start_w = 0.01;
 1286           double end_w = 0.01;
 1287           double start_a = 0.2;
 1288           double end_a = 0.001;
 1289           double a = start_a;
 1290           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
 1291   
 1292           for (int i = 0; i < 12; i++) {
 1293               double w = start_w + (end_w - start_w) * (i / 40.0);
 1294               complexGaussianDist(data, base * (i + 1), w,
 1295                       a * (0.5 + 3 * (random.nextDouble())));
 1296               a *= a_step;
 1297           }
 1298           SF2Sample sample = newSimpleFFTSample(sf2, "Organ", data, base);
 1299           SF2Layer layer = newLayer(sf2, "Organ", sample);
 1300           SF2Region region = layer.getRegions().get(0);
 1301           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1302           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
 1303           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
 1304           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1305           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1306           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
 1307           return layer;
 1308   
 1309       }
 1310   
 1311       public static SF2Layer new_ch_organ(SF2Soundbank sf2) {
 1312           int x = 1;
 1313           int fftsize = 4096 * x;
 1314           double[] data = new double[fftsize * 2];
 1315           double base = x * 15;
 1316           double start_w = 0.01;
 1317           double end_w = 0.01;
 1318           double start_a = 0.2;
 1319           double end_a = 0.001;
 1320           double a = start_a;
 1321           double a_step = Math.pow(end_a / start_a, 1.0 / 60.0);
 1322   
 1323           double[] aa = new double[60];
 1324           for (int i = 0; i < aa.length; i++) {
 1325               a *= a_step;
 1326               aa[i] = a;
 1327           }
 1328   
 1329           aa[0] *= 5;
 1330           aa[1] *= 2;
 1331           aa[2] = 0;
 1332           aa[4] = 0;
 1333           aa[5] = 0;
 1334           aa[7] *= 7;
 1335           aa[9] = 0;
 1336           aa[10] = 0;
 1337           aa[12] = 0;
 1338           aa[15] *= 7;
 1339           aa[18] = 0;
 1340           aa[20] = 0;
 1341           aa[24] = 0;
 1342           aa[27] *= 5;
 1343           aa[29] = 0;
 1344           aa[30] = 0;
 1345           aa[33] = 0;
 1346           aa[36] *= 4;
 1347           aa[37] = 0;
 1348           aa[39] = 0;
 1349           aa[42] = 0;
 1350           aa[43] = 0;
 1351           aa[47] = 0;
 1352           aa[50] *= 4;
 1353           aa[52] = 0;
 1354           aa[55] = 0;
 1355           aa[57] = 0;
 1356   
 1357   
 1358           aa[10] *= 0.1;
 1359           aa[11] *= 0.1;
 1360           aa[12] *= 0.1;
 1361           aa[13] *= 0.1;
 1362   
 1363           aa[17] *= 0.1;
 1364           aa[18] *= 0.1;
 1365           aa[19] *= 0.1;
 1366           aa[20] *= 0.1;
 1367   
 1368           for (int i = 0; i < 60; i++) {
 1369               double w = start_w + (end_w - start_w) * (i / 40.0);
 1370               complexGaussianDist(data, base * (i + 1), w, aa[i]);
 1371               a *= a_step;
 1372           }
 1373           SF2Sample sample = newSimpleFFTSample(sf2, "Organ", data, base);
 1374           SF2Layer layer = newLayer(sf2, "Organ", sample);
 1375           SF2Region region = layer.getRegions().get(0);
 1376           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1377           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -10000);
 1378           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
 1379           return layer;
 1380   
 1381       }
 1382   
 1383       public static SF2Layer new_flute(SF2Soundbank sf2) {
 1384           int x = 8;
 1385           int fftsize = 4096 * x;
 1386           double[] data = new double[fftsize * 2];
 1387           double base = x * 15;
 1388   
 1389           complexGaussianDist(data, base * 1, 0.001, 0.5);
 1390           complexGaussianDist(data, base * 2, 0.001, 0.5);
 1391           complexGaussianDist(data, base * 3, 0.001, 0.5);
 1392           complexGaussianDist(data, base * 4, 0.01, 0.5);
 1393   
 1394           complexGaussianDist(data, base * 4, 100, 120);
 1395           complexGaussianDist(data, base * 6, 100, 40);
 1396           complexGaussianDist(data, base * 8, 100, 80);
 1397   
 1398           complexGaussianDist(data, base * 5, 0.001, 0.05);
 1399           complexGaussianDist(data, base * 6, 0.001, 0.06);
 1400           complexGaussianDist(data, base * 7, 0.001, 0.04);
 1401           complexGaussianDist(data, base * 8, 0.005, 0.06);
 1402           complexGaussianDist(data, base * 9, 0.005, 0.06);
 1403           complexGaussianDist(data, base * 10, 0.01, 0.1);
 1404           complexGaussianDist(data, base * 11, 0.08, 0.7);
 1405           complexGaussianDist(data, base * 12, 0.08, 0.6);
 1406           complexGaussianDist(data, base * 13, 0.08, 0.6);
 1407           complexGaussianDist(data, base * 14, 0.08, 0.6);
 1408           complexGaussianDist(data, base * 15, 0.08, 0.5);
 1409           complexGaussianDist(data, base * 16, 0.08, 0.5);
 1410           complexGaussianDist(data, base * 17, 0.08, 0.2);
 1411   
 1412   
 1413           complexGaussianDist(data, base * 1, 10, 8);
 1414           complexGaussianDist(data, base * 2, 10, 8);
 1415           complexGaussianDist(data, base * 3, 10, 8);
 1416           complexGaussianDist(data, base * 4, 10, 8);
 1417           complexGaussianDist(data, base * 5, 10, 8);
 1418           complexGaussianDist(data, base * 6, 20, 9);
 1419           complexGaussianDist(data, base * 7, 20, 9);
 1420           complexGaussianDist(data, base * 8, 20, 9);
 1421           complexGaussianDist(data, base * 9, 20, 8);
 1422           complexGaussianDist(data, base * 10, 30, 8);
 1423           complexGaussianDist(data, base * 11, 30, 9);
 1424           complexGaussianDist(data, base * 12, 30, 9);
 1425           complexGaussianDist(data, base * 13, 30, 8);
 1426           complexGaussianDist(data, base * 14, 30, 8);
 1427           complexGaussianDist(data, base * 15, 30, 7);
 1428           complexGaussianDist(data, base * 16, 30, 7);
 1429           complexGaussianDist(data, base * 17, 30, 6);
 1430   
 1431           SF2Sample sample = newSimpleFFTSample(sf2, "Flute", data, base);
 1432           SF2Layer layer = newLayer(sf2, "Flute", sample);
 1433           SF2Region region = layer.getRegions().get(0);
 1434           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1435           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
 1436           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
 1437           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1438           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1439           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
 1440           return layer;
 1441   
 1442       }
 1443   
 1444       public static SF2Layer new_horn(SF2Soundbank sf2) {
 1445           int x = 8;
 1446           int fftsize = 4096 * x;
 1447           double[] data = new double[fftsize * 2];
 1448           double base = x * 15;
 1449   
 1450           double start_a = 0.5;
 1451           double end_a = 0.00000000001;
 1452           double a = start_a;
 1453           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
 1454           for (int i = 0; i < 40; i++) {
 1455               if (i == 0)
 1456                   complexGaussianDist(data, base * (i + 1), 0.1, a * 0.2);
 1457               else
 1458                   complexGaussianDist(data, base * (i + 1), 0.1, a);
 1459               a *= a_step;
 1460           }
 1461   
 1462           complexGaussianDist(data, base * 2, 100, 1);
 1463   
 1464   
 1465           SF2Sample sample = newSimpleFFTSample(sf2, "Horn", data, base);
 1466           SF2Layer layer = newLayer(sf2, "Horn", sample);
 1467           SF2Region region = layer.getRegions().get(0);
 1468           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1469           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
 1470           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
 1471           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1472           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1473   
 1474           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -500);
 1475           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
 1476           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, 5000);
 1477           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 4500);
 1478           return layer;
 1479   
 1480       }
 1481   
 1482       public static SF2Layer new_trumpet(SF2Soundbank sf2) {
 1483           int x = 8;
 1484           int fftsize = 4096 * x;
 1485           double[] data = new double[fftsize * 2];
 1486           double base = x * 15;
 1487   
 1488           double start_a = 0.5;
 1489           double end_a = 0.00001;
 1490           double a = start_a;
 1491           double a_step = Math.pow(end_a / start_a, 1.0 / 80.0);
 1492           double[] aa = new double[80];
 1493           for (int i = 0; i < 80; i++) {
 1494               aa[i] = a;
 1495               a *= a_step;
 1496           }
 1497   
 1498           aa[0] *= 0.05;
 1499           aa[1] *= 0.2;
 1500           aa[2] *= 0.5;
 1501           aa[3] *= 0.85;
 1502   
 1503           for (int i = 0; i < 80; i++) {
 1504               complexGaussianDist(data, base * (i + 1), 0.1, aa[i]);
 1505           }
 1506   
 1507           complexGaussianDist(data, base * 5, 300, 3);
 1508   
 1509   
 1510           SF2Sample sample = newSimpleFFTSample(sf2, "Trumpet", data, base);
 1511           SF2Layer layer = newLayer(sf2, "Trumpet", sample);
 1512           SF2Region region = layer.getRegions().get(0);
 1513           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1514           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -10000);
 1515           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
 1516           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1517           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1518   
 1519           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -4000);
 1520           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, -2500);
 1521           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, 5000);
 1522           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 4500);
 1523           region.putInteger(SF2Region.GENERATOR_INITIALFILTERQ, 10);
 1524           return layer;
 1525   
 1526       }
 1527   
 1528       public static SF2Layer new_brass_section(SF2Soundbank sf2) {
 1529           int x = 8;
 1530           int fftsize = 4096 * x;
 1531           double[] data = new double[fftsize * 2];
 1532           double base = x * 15;
 1533   
 1534           double start_a = 0.5;
 1535           double end_a = 0.005;
 1536           double a = start_a;
 1537           double a_step = Math.pow(end_a / start_a, 1.0 / 30.0);
 1538           double[] aa = new double[30];
 1539           for (int i = 0; i < 30; i++) {
 1540               aa[i] = a;
 1541               a *= a_step;
 1542           }
 1543   
 1544           aa[0] *= 0.8;
 1545           aa[1] *= 0.9;
 1546   
 1547           double w = 5;
 1548           for (int i = 0; i < 30; i++) {
 1549               complexGaussianDist(data, base * (i + 1), 0.1 * w, aa[i] * w);
 1550               w += 6; //*= w_step;
 1551           }
 1552   
 1553           complexGaussianDist(data, base * 6, 300, 2);
 1554   
 1555   
 1556           SF2Sample sample = newSimpleFFTSample(sf2, "Brass Section", data, base);
 1557           SF2Layer layer = newLayer(sf2, "Brass Section", sample);
 1558           SF2Region region = layer.getRegions().get(0);
 1559           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1560           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -9200);
 1561           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
 1562           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1563           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1564   
 1565           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -3000);
 1566           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
 1567           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, 5000);
 1568           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 4500);
 1569           return layer;
 1570   
 1571       }
 1572   
 1573       public static SF2Layer new_trombone(SF2Soundbank sf2) {
 1574           int x = 8;
 1575           int fftsize = 4096 * x;
 1576           double[] data = new double[fftsize * 2];
 1577           double base = x * 15;
 1578   
 1579           double start_a = 0.5;
 1580           double end_a = 0.001;
 1581           double a = start_a;
 1582           double a_step = Math.pow(end_a / start_a, 1.0 / 80.0);
 1583           double[] aa = new double[80];
 1584           for (int i = 0; i < 80; i++) {
 1585               aa[i] = a;
 1586               a *= a_step;
 1587           }
 1588   
 1589           aa[0] *= 0.3;
 1590           aa[1] *= 0.7;
 1591   
 1592           for (int i = 0; i < 80; i++) {
 1593               complexGaussianDist(data, base * (i + 1), 0.1, aa[i]);
 1594           }
 1595   
 1596           complexGaussianDist(data, base * 6, 300, 2);
 1597   
 1598   
 1599           SF2Sample sample = newSimpleFFTSample(sf2, "Trombone", data, base);
 1600           SF2Layer layer = newLayer(sf2, "Trombone", sample);
 1601           SF2Region region = layer.getRegions().get(0);
 1602           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1603           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -8000);
 1604           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
 1605           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1606           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1607   
 1608           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -2000);
 1609           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
 1610           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, 5000);
 1611           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 4500);
 1612           region.putInteger(SF2Region.GENERATOR_INITIALFILTERQ, 10);
 1613           return layer;
 1614   
 1615       }
 1616   
 1617       public static SF2Layer new_sax(SF2Soundbank sf2) {
 1618           int x = 8;
 1619           int fftsize = 4096 * x;
 1620           double[] data = new double[fftsize * 2];
 1621           double base = x * 15;
 1622   
 1623           double start_a = 0.5;
 1624           double end_a = 0.01;
 1625           double a = start_a;
 1626           double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
 1627           for (int i = 0; i < 40; i++) {
 1628               if (i == 0 || i == 2)
 1629                   complexGaussianDist(data, base * (i + 1), 0.1, a * 4);
 1630               else
 1631                   complexGaussianDist(data, base * (i + 1), 0.1, a);
 1632               a *= a_step;
 1633           }
 1634   
 1635           complexGaussianDist(data, base * 4, 200, 1);
 1636   
 1637           SF2Sample sample = newSimpleFFTSample(sf2, "Sax", data, base);
 1638           SF2Layer layer = newLayer(sf2, "Sax", sample);
 1639           SF2Region region = layer.getRegions().get(0);
 1640           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1641           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
 1642           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
 1643           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1644           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1645   
 1646           region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -3000);
 1647           region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
 1648           region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, 5000);
 1649           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 4500);
 1650           return layer;
 1651   
 1652       }
 1653   
 1654       public static SF2Layer new_oboe(SF2Soundbank sf2) {
 1655           int x = 8;
 1656           int fftsize = 4096 * x;
 1657           double[] data = new double[fftsize * 2];
 1658           double base = x * 15;
 1659   
 1660           complexGaussianDist(data, base * 5, 100, 80);
 1661   
 1662   
 1663           complexGaussianDist(data, base * 1, 0.01, 0.53);
 1664           complexGaussianDist(data, base * 2, 0.01, 0.51);
 1665           complexGaussianDist(data, base * 3, 0.01, 0.48);
 1666           complexGaussianDist(data, base * 4, 0.01, 0.49);
 1667           complexGaussianDist(data, base * 5, 0.01, 5);
 1668           complexGaussianDist(data, base * 6, 0.01, 0.51);
 1669           complexGaussianDist(data, base * 7, 0.01, 0.50);
 1670           complexGaussianDist(data, base * 8, 0.01, 0.59);
 1671           complexGaussianDist(data, base * 9, 0.01, 0.61);
 1672           complexGaussianDist(data, base * 10, 0.01, 0.52);
 1673           complexGaussianDist(data, base * 11, 0.01, 0.49);
 1674           complexGaussianDist(data, base * 12, 0.01, 0.51);
 1675           complexGaussianDist(data, base * 13, 0.01, 0.48);
 1676           complexGaussianDist(data, base * 14, 0.01, 0.51);
 1677           complexGaussianDist(data, base * 15, 0.01, 0.46);
 1678           complexGaussianDist(data, base * 16, 0.01, 0.35);
 1679           complexGaussianDist(data, base * 17, 0.01, 0.20);
 1680           complexGaussianDist(data, base * 18, 0.01, 0.10);
 1681           complexGaussianDist(data, base * 19, 0.01, 0.5);
 1682           complexGaussianDist(data, base * 20, 0.01, 0.1);
 1683   
 1684   
 1685           SF2Sample sample = newSimpleFFTSample(sf2, "Oboe", data, base);
 1686           SF2Layer layer = newLayer(sf2, "Oboe", sample);
 1687           SF2Region region = layer.getRegions().get(0);
 1688           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1689           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
 1690           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
 1691           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1692           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1693           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
 1694           return layer;
 1695   
 1696       }
 1697   
 1698       public static SF2Layer new_bassoon(SF2Soundbank sf2) {
 1699           int x = 8;
 1700           int fftsize = 4096 * x;
 1701           double[] data = new double[fftsize * 2];
 1702           double base = x * 15;
 1703   
 1704           complexGaussianDist(data, base * 2, 100, 40);
 1705           complexGaussianDist(data, base * 4, 100, 20);
 1706   
 1707           complexGaussianDist(data, base * 1, 0.01, 0.53);
 1708           complexGaussianDist(data, base * 2, 0.01, 5);
 1709           complexGaussianDist(data, base * 3, 0.01, 0.51);
 1710           complexGaussianDist(data, base * 4, 0.01, 0.48);
 1711           complexGaussianDist(data, base * 5, 0.01, 1.49);
 1712           complexGaussianDist(data, base * 6, 0.01, 0.51);
 1713           complexGaussianDist(data, base * 7, 0.01, 0.50);
 1714           complexGaussianDist(data, base * 8, 0.01, 0.59);
 1715           complexGaussianDist(data, base * 9, 0.01, 0.61);
 1716           complexGaussianDist(data, base * 10, 0.01, 0.52);
 1717           complexGaussianDist(data, base * 11, 0.01, 0.49);
 1718           complexGaussianDist(data, base * 12, 0.01, 0.51);
 1719           complexGaussianDist(data, base * 13, 0.01, 0.48);
 1720           complexGaussianDist(data, base * 14, 0.01, 0.51);
 1721           complexGaussianDist(data, base * 15, 0.01, 0.46);
 1722           complexGaussianDist(data, base * 16, 0.01, 0.35);
 1723           complexGaussianDist(data, base * 17, 0.01, 0.20);
 1724           complexGaussianDist(data, base * 18, 0.01, 0.10);
 1725           complexGaussianDist(data, base * 19, 0.01, 0.5);
 1726           complexGaussianDist(data, base * 20, 0.01, 0.1);
 1727   
 1728   
 1729           SF2Sample sample = newSimpleFFTSample(sf2, "Flute", data, base);
 1730           SF2Layer layer = newLayer(sf2, "Flute", sample);
 1731           SF2Region region = layer.getRegions().get(0);
 1732           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1733           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
 1734           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
 1735           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1736           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1737           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
 1738           return layer;
 1739   
 1740       }
 1741   
 1742       public static SF2Layer new_clarinet(SF2Soundbank sf2) {
 1743           int x = 8;
 1744           int fftsize = 4096 * x;
 1745           double[] data = new double[fftsize * 2];
 1746           double base = x * 15;
 1747   
 1748           complexGaussianDist(data, base * 1, 0.001, 0.5);
 1749           complexGaussianDist(data, base * 2, 0.001, 0.02);
 1750           complexGaussianDist(data, base * 3, 0.001, 0.2);
 1751           complexGaussianDist(data, base * 4, 0.01, 0.1);
 1752   
 1753           complexGaussianDist(data, base * 4, 100, 60);
 1754           complexGaussianDist(data, base * 6, 100, 20);
 1755           complexGaussianDist(data, base * 8, 100, 20);
 1756   
 1757           complexGaussianDist(data, base * 5, 0.001, 0.1);
 1758           complexGaussianDist(data, base * 6, 0.001, 0.09);
 1759           complexGaussianDist(data, base * 7, 0.001, 0.02);
 1760           complexGaussianDist(data, base * 8, 0.005, 0.16);
 1761           complexGaussianDist(data, base * 9, 0.005, 0.96);
 1762           complexGaussianDist(data, base * 10, 0.01, 0.9);
 1763           complexGaussianDist(data, base * 11, 0.08, 1.2);
 1764           complexGaussianDist(data, base * 12, 0.08, 1.8);
 1765           complexGaussianDist(data, base * 13, 0.08, 1.6);
 1766           complexGaussianDist(data, base * 14, 0.08, 1.2);
 1767           complexGaussianDist(data, base * 15, 0.08, 0.9);
 1768           complexGaussianDist(data, base * 16, 0.08, 0.5);
 1769           complexGaussianDist(data, base * 17, 0.08, 0.2);
 1770   
 1771   
 1772           complexGaussianDist(data, base * 1, 10, 8);
 1773           complexGaussianDist(data, base * 2, 10, 8);
 1774           complexGaussianDist(data, base * 3, 10, 8);
 1775           complexGaussianDist(data, base * 4, 10, 8);
 1776           complexGaussianDist(data, base * 5, 10, 8);
 1777           complexGaussianDist(data, base * 6, 20, 9);
 1778           complexGaussianDist(data, base * 7, 20, 9);
 1779           complexGaussianDist(data, base * 8, 20, 9);
 1780           complexGaussianDist(data, base * 9, 20, 8);
 1781           complexGaussianDist(data, base * 10, 30, 8);
 1782           complexGaussianDist(data, base * 11, 30, 9);
 1783           complexGaussianDist(data, base * 12, 30, 9);
 1784           complexGaussianDist(data, base * 13, 30, 8);
 1785           complexGaussianDist(data, base * 14, 30, 8);
 1786           complexGaussianDist(data, base * 15, 30, 7);
 1787           complexGaussianDist(data, base * 16, 30, 7);
 1788           complexGaussianDist(data, base * 17, 30, 6);
 1789   
 1790           SF2Sample sample = newSimpleFFTSample(sf2, "Clarinet", data, base);
 1791           SF2Layer layer = newLayer(sf2, "Clarinet", sample);
 1792           SF2Region region = layer.getRegions().get(0);
 1793           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 1794           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
 1795           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
 1796           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
 1797           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
 1798           region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
 1799           return layer;
 1800   
 1801       }
 1802   
 1803       public static SF2Layer new_timpani(SF2Soundbank sf2) {
 1804   
 1805           double datab[];
 1806           double datah[];
 1807   
 1808           // Make Bass Part
 1809           {
 1810               int fftlen = 4096 * 8;
 1811               double[] data = new double[2 * fftlen];
 1812               double base = 48;
 1813               complexGaussianDist(data, base * 2, 0.2, 1);
 1814               complexGaussianDist(data, base * 3, 0.2, 0.7);
 1815               complexGaussianDist(data, base * 5, 10, 1);
 1816               complexGaussianDist(data, base * 6, 9, 1);
 1817               complexGaussianDist(data, base * 8, 15, 1);
 1818               complexGaussianDist(data, base * 9, 18, 0.8);
 1819               complexGaussianDist(data, base * 11, 21, 0.5);
 1820               complexGaussianDist(data, base * 13, 28, 0.3);
 1821               complexGaussianDist(data, base * 14, 22, 0.1);
 1822               randomPhase(data, new Random(3049912));
 1823               ifft(data);
 1824               normalize(data, 0.5);
 1825               data = realPart(data);
 1826   
 1827               double d_len = data.length;
 1828               for (int i = 0; i < data.length; i++) {
 1829                   double g = (1.0 - (i / d_len));
 1830                   data[i] *= g * g;
 1831               }
 1832               fadeUp(data, 40);
 1833               datab = data;
 1834           }
 1835   
 1836           // Make treble part
 1837           {
 1838               int fftlen = 4096 * 4;
 1839               double[] data = new double[2 * fftlen];
 1840               Random random = new Random(3049912);
 1841               for (int i = 0; i < data.length; i += 2) {
 1842                   data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
 1843               }
 1844               fft(data);
 1845               // Remove all negative frequency
 1846               for (int i = fftlen / 2; i < data.length; i++)
 1847                   data[i] = 0;
 1848               for (int i = 1024 * 4; i < 2048 * 4; i++)
 1849                   data[i] = 1.0 - (i - 4096) / 4096.0;
 1850               for (int i = 0; i < 300; i++) {
 1851                   double g = (1.0 - (i / 300.0));
 1852                   data[i] *= 1.0 + 20 * g * g;
 1853               }
 1854               for (int i = 0; i < 24; i++)
 1855                   data[i] = 0;
 1856               randomPhase(data, new Random(3049912));
 1857               ifft(data);
 1858               normalize(data, 0.9);
 1859               data = realPart(data);
 1860               double gain = 1.0;
 1861               for (int i = 0; i < data.length; i++) {
 1862                   data[i] *= gain;
 1863                   gain *= 0.9998;
 1864               }
 1865               datah = data;
 1866           }
 1867   
 1868           for (int i = 0; i < datah.length; i++)
 1869               datab[i] += datah[i] * 0.02;
 1870   
 1871           normalize(datab, 0.9);
 1872   
 1873           SF2Sample sample = newSimpleDrumSample(sf2, "Timpani", datab);
 1874   
 1875           SF2Layer layer = new SF2Layer(sf2);
 1876           layer.setName("Timpani");
 1877   
 1878           SF2GlobalRegion global = new SF2GlobalRegion();
 1879           layer.setGlobalZone(global);
 1880           sf2.addResource(layer);
 1881   
 1882           SF2LayerRegion region = new SF2LayerRegion();
 1883           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
 1884           region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
 1885           region.setSample(sample);
 1886           layer.getRegions().add(region);
 1887   
 1888           return layer;
 1889       }
 1890   
 1891       public static SF2Layer new_melodic_toms(SF2Soundbank sf2) {
 1892   
 1893           double datab[];
 1894           double datah[];
 1895   
 1896           // Make Bass Part
 1897           {
 1898               int fftlen = 4096 * 4;
 1899               double[] data = new double[2 * fftlen];
 1900               complexGaussianDist(data, 30, 0.5, 1);
 1901               randomPhase(data, new Random(3049912));
 1902               ifft(data);
 1903               normalize(data, 0.8);
 1904               data = realPart(data);
 1905   
 1906               double d_len = data.length;
 1907               for (int i = 0; i < data.length; i++)
 1908                   data[i] *= (1.0 - (i / d_len));
 1909               datab = data;
 1910           }
 1911   
 1912           // Make treble part
 1913           {
 1914               int fftlen = 4096 * 4;
 1915               double[] data = new double[2 * fftlen];
 1916               Random random = new Random(3049912);
 1917               for (int i = 0; i < data.length; i += 2)
 1918                   data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
 1919               fft(data);
 1920               // Remove all negative frequency
 1921               for (int i = fftlen / 2; i < data.length; i++)
 1922                   data[i] = 0;
 1923               for (int i = 1024 * 4; i < 2048 * 4; i++)
 1924                   data[i] = 1.0 - (i - 4096) / 4096.0;
 1925               for (int i = 0; i < 200; i++) {
 1926                   double g = (1.0 - (i / 200.0));
 1927                   data[i] *= 1.0 + 20 * g * g;
 1928               }
 1929               for (int i = 0; i < 30; i++)
 1930                   data[i] = 0;
 1931               randomPhase(data, new Random(3049912));
 1932               ifft(data);
 1933               normalize(data, 0.9);
 1934               data = realPart(data);
 1935               double gain = 1.0;
 1936               for (int i = 0; i < data.length; i++) {
 1937                   data[i] *= gain;
 1938                   gain *= 0.9996;
 1939               }
 1940               datah = data;
 1941           }
 1942   
 1943           for (int i = 0; i < datah.length; i++)
 1944               datab[i] += datah[i] * 0.5;
 1945           for (int i = 0; i < 5; i++)
 1946               datab[i] *= i / 5.0;
 1947   
 1948           normalize(datab, 0.99);
 1949   
 1950           SF2Sample sample = newSimpleDrumSample(sf2, "Melodic Toms", datab);
 1951           sample.setOriginalPitch(63);
 1952   
 1953           SF2Layer layer = new SF2Layer(sf2);
 1954           layer.setName("Melodic Toms");
 1955   
 1956           SF2GlobalRegion global = new SF2GlobalRegion();
 1957           layer.setGlobalZone(global);
 1958           sf2.addResource(layer);
 1959   
 1960           SF2LayerRegion region = new SF2LayerRegion();
 1961           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
 1962           //region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
 1963           region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
 1964           region.setSample(sample);
 1965           layer.getRegions().add(region);
 1966   
 1967           return layer;
 1968       }
 1969   
 1970       public static SF2Layer new_reverse_cymbal(SF2Soundbank sf2) {
 1971           double datah[];
 1972           {
 1973               int fftlen = 4096 * 4;
 1974               double[] data = new double[2 * fftlen];
 1975               Random random = new Random(3049912);
 1976               for (int i = 0; i < data.length; i += 2)
 1977                   data[i] = (2.0 * (random.nextDouble() - 0.5));
 1978               for (int i = fftlen / 2; i < data.length; i++)
 1979                   data[i] = 0;
 1980               for (int i = 0; i < 100; i++)
 1981                   data[i] = 0;
 1982   
 1983               for (int i = 0; i < 512 * 2; i++) {
 1984                   double gain = (i / (512.0 * 2.0));
 1985                   data[i] = 1 - gain;
 1986               }
 1987               datah = data;
 1988           }
 1989   
 1990           SF2Sample sample = newSimpleFFTSample(sf2, "Reverse Cymbal",
 1991                   datah, 100, 20);
 1992   
 1993           SF2Layer layer = new SF2Layer(sf2);
 1994           layer.setName("Reverse Cymbal");
 1995   
 1996           SF2GlobalRegion global = new SF2GlobalRegion();
 1997           layer.setGlobalZone(global);
 1998           sf2.addResource(layer);
 1999   
 2000           SF2LayerRegion region = new SF2LayerRegion();
 2001           region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -200);
 2002           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, -12000);
 2003           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 2004           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
 2005           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
 2006           region.setSample(sample);
 2007           layer.getRegions().add(region);
 2008   
 2009           return layer;
 2010       }
 2011   
 2012       public static SF2Layer new_snare_drum(SF2Soundbank sf2) {
 2013   
 2014           double datab[];
 2015           double datah[];
 2016   
 2017           // Make Bass Part
 2018           {
 2019               int fftlen = 4096 * 4;
 2020               double[] data = new double[2 * fftlen];
 2021               complexGaussianDist(data, 24, 0.5, 1);
 2022               randomPhase(data, new Random(3049912));
 2023               ifft(data);
 2024               normalize(data, 0.5);
 2025               data = realPart(data);
 2026   
 2027               double d_len = data.length;
 2028               for (int i = 0; i < data.length; i++)
 2029                   data[i] *= (1.0 - (i / d_len));
 2030               datab = data;
 2031           }
 2032   
 2033           // Make treble part
 2034           {
 2035               int fftlen = 4096 * 4;
 2036               double[] data = new double[2 * fftlen];
 2037               Random random = new Random(3049912);
 2038               for (int i = 0; i < data.length; i += 2)
 2039                   data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
 2040               fft(data);
 2041               // Remove all negative frequency
 2042               for (int i = fftlen / 2; i < data.length; i++)
 2043                   data[i] = 0;
 2044               for (int i = 1024 * 4; i < 2048 * 4; i++)
 2045                   data[i] = 1.0 - (i - 4096) / 4096.0;
 2046               for (int i = 0; i < 300; i++) {
 2047                   double g = (1.0 - (i / 300.0));
 2048                   data[i] *= 1.0 + 20 * g * g;
 2049               }
 2050               for (int i = 0; i < 24; i++)
 2051                   data[i] = 0;
 2052               randomPhase(data, new Random(3049912));
 2053               ifft(data);
 2054               normalize(data, 0.9);
 2055               data = realPart(data);
 2056               double gain = 1.0;
 2057               for (int i = 0; i < data.length; i++) {
 2058                   data[i] *= gain;
 2059                   gain *= 0.9998;
 2060               }
 2061               datah = data;
 2062           }
 2063   
 2064           for (int i = 0; i < datah.length; i++)
 2065               datab[i] += datah[i];
 2066           for (int i = 0; i < 5; i++)
 2067               datab[i] *= i / 5.0;
 2068   
 2069           SF2Sample sample = newSimpleDrumSample(sf2, "Snare Drum", datab);
 2070   
 2071           SF2Layer layer = new SF2Layer(sf2);
 2072           layer.setName("Snare Drum");
 2073   
 2074           SF2GlobalRegion global = new SF2GlobalRegion();
 2075           layer.setGlobalZone(global);
 2076           sf2.addResource(layer);
 2077   
 2078           SF2LayerRegion region = new SF2LayerRegion();
 2079           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
 2080           region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
 2081           region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
 2082           region.setSample(sample);
 2083           layer.getRegions().add(region);
 2084   
 2085           return layer;
 2086       }
 2087   
 2088       public static SF2Layer new_bass_drum(SF2Soundbank sf2) {
 2089   
 2090           double datab[];
 2091           double datah[];
 2092   
 2093           // Make Bass Part
 2094           {
 2095               int fftlen = 4096 * 4;
 2096               double[] data = new double[2 * fftlen];
 2097               complexGaussianDist(data, 1.8 * 5 + 1, 2, 1);
 2098               complexGaussianDist(data, 1.8 * 9 + 1, 2, 1);
 2099               randomPhase(data, new Random(3049912));
 2100               ifft(data);
 2101               normalize(data, 0.9);
 2102               data = realPart(data);
 2103               double d_len = data.length;
 2104               for (int i = 0; i < data.length; i++)
 2105                   data[i] *= (1.0 - (i / d_len));
 2106               datab = data;
 2107           }
 2108   
 2109           // Make treble part
 2110           {
 2111               int fftlen = 4096;
 2112               double[] data = new double[2 * fftlen];
 2113               Random random = new Random(3049912);
 2114               for (int i = 0; i < data.length; i += 2)
 2115                   data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
 2116               fft(data);
 2117               // Remove all negative frequency
 2118               for (int i = fftlen / 2; i < data.length; i++)
 2119                   data[i] = 0;
 2120               for (int i = 1024; i < 2048; i++)
 2121                   data[i] = 1.0 - (i - 1024) / 1024.0;
 2122               for (int i = 0; i < 512; i++)
 2123                   data[i] = 10 * i / 512.0;
 2124               for (int i = 0; i < 10; i++)
 2125                   data[i] = 0;
 2126               randomPhase(data, new Random(3049912));
 2127               ifft(data);
 2128               normalize(data, 0.9);
 2129               data = realPart(data);
 2130               double gain = 1.0;
 2131               for (int i = 0; i < data.length; i++) {
 2132                   data[i] *= gain;
 2133                   gain *= 0.999;
 2134               }
 2135               datah = data;
 2136           }
 2137   
 2138           for (int i = 0; i < datah.length; i++)
 2139               datab[i] += datah[i] * 0.5;
 2140           for (int i = 0; i < 5; i++)
 2141               datab[i] *= i / 5.0;
 2142   
 2143           SF2Sample sample = newSimpleDrumSample(sf2, "Bass Drum", datab);
 2144   
 2145           SF2Layer layer = new SF2Layer(sf2);
 2146           layer.setName("Bass Drum");
 2147   
 2148           SF2GlobalRegion global = new SF2GlobalRegion();
 2149           layer.setGlobalZone(global);
 2150           sf2.addResource(layer);
 2151   
 2152           SF2LayerRegion region = new SF2LayerRegion();
 2153           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
 2154           region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
 2155           region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
 2156           region.setSample(sample);
 2157           layer.getRegions().add(region);
 2158   
 2159           return layer;
 2160       }
 2161   
 2162       public static SF2Layer new_tom(SF2Soundbank sf2) {
 2163   
 2164           double datab[];
 2165           double datah[];
 2166   
 2167           // Make Bass Part
 2168           {
 2169               int fftlen = 4096 * 4;
 2170               double[] data = new double[2 * fftlen];
 2171               complexGaussianDist(data, 30, 0.5, 1);
 2172               randomPhase(data, new Random(3049912));
 2173               ifft(data);
 2174               normalize(data, 0.8);
 2175               data = realPart(data);
 2176   
 2177               double d_len = data.length;
 2178               for (int i = 0; i < data.length; i++)
 2179                   data[i] *= (1.0 - (i / d_len));
 2180               datab = data;
 2181           }
 2182   
 2183           // Make treble part
 2184           {
 2185               int fftlen = 4096 * 4;
 2186               double[] data = new double[2 * fftlen];
 2187               Random random = new Random(3049912);
 2188               for (int i = 0; i < data.length; i += 2)
 2189                   data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
 2190               fft(data);
 2191               // Remove all negative frequency
 2192               for (int i = fftlen / 2; i < data.length; i++)
 2193                   data[i] = 0;
 2194               for (int i = 1024 * 4; i < 2048 * 4; i++)
 2195                   data[i] = 1.0 - (i - 4096) / 4096.0;
 2196               for (int i = 0; i < 200; i++) {
 2197                   double g = (1.0 - (i / 200.0));
 2198                   data[i] *= 1.0 + 20 * g * g;
 2199               }
 2200               for (int i = 0; i < 30; i++)
 2201                   data[i] = 0;
 2202               randomPhase(data, new Random(3049912));
 2203               ifft(data);
 2204               normalize(data, 0.9);
 2205               data = realPart(data);
 2206               double gain = 1.0;
 2207               for (int i = 0; i < data.length; i++) {
 2208                   data[i] *= gain;
 2209                   gain *= 0.9996;
 2210               }
 2211               datah = data;
 2212           }
 2213   
 2214           for (int i = 0; i < datah.length; i++)
 2215               datab[i] += datah[i] * 0.5;
 2216           for (int i = 0; i < 5; i++)
 2217               datab[i] *= i / 5.0;
 2218   
 2219           normalize(datab, 0.99);
 2220   
 2221           SF2Sample sample = newSimpleDrumSample(sf2, "Tom", datab);
 2222           sample.setOriginalPitch(50);
 2223   
 2224           SF2Layer layer = new SF2Layer(sf2);
 2225           layer.setName("Tom");
 2226   
 2227           SF2GlobalRegion global = new SF2GlobalRegion();
 2228           layer.setGlobalZone(global);
 2229           sf2.addResource(layer);
 2230   
 2231           SF2LayerRegion region = new SF2LayerRegion();
 2232           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
 2233           //region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
 2234           region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
 2235           region.setSample(sample);
 2236           layer.getRegions().add(region);
 2237   
 2238           return layer;
 2239       }
 2240   
 2241       public static SF2Layer new_closed_hihat(SF2Soundbank sf2) {
 2242           double datah[];
 2243   
 2244           // Make treble part
 2245           {
 2246               int fftlen = 4096 * 4;
 2247               double[] data = new double[2 * fftlen];
 2248               Random random = new Random(3049912);
 2249               for (int i = 0; i < data.length; i += 2)
 2250                   data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
 2251               fft(data);
 2252               // Remove all negative frequency
 2253               for (int i = fftlen / 2; i < data.length; i++)
 2254                   data[i] = 0;
 2255               for (int i = 1024 * 4; i < 2048 * 4; i++)
 2256                   data[i] = 1.0 - (i - 4096) / 4096.0;
 2257               for (int i = 0; i < 2048; i++)
 2258                   data[i] = 0.2 + 0.8 * (i / 2048.0);
 2259               randomPhase(data, new Random(3049912));
 2260               ifft(data);
 2261               normalize(data, 0.9);
 2262               data = realPart(data);
 2263               double gain = 1.0;
 2264               for (int i = 0; i < data.length; i++) {
 2265                   data[i] *= gain;
 2266                   gain *= 0.9996;
 2267               }
 2268               datah = data;
 2269           }
 2270   
 2271           for (int i = 0; i < 5; i++)
 2272               datah[i] *= i / 5.0;
 2273           SF2Sample sample = newSimpleDrumSample(sf2, "Closed Hi-Hat", datah);
 2274   
 2275           SF2Layer layer = new SF2Layer(sf2);
 2276           layer.setName("Closed Hi-Hat");
 2277   
 2278           SF2GlobalRegion global = new SF2GlobalRegion();
 2279           layer.setGlobalZone(global);
 2280           sf2.addResource(layer);
 2281   
 2282           SF2LayerRegion region = new SF2LayerRegion();
 2283           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
 2284           region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
 2285           region.putInteger(SF2Region.GENERATOR_EXCLUSIVECLASS, 1);
 2286           region.setSample(sample);
 2287           layer.getRegions().add(region);
 2288   
 2289           return layer;
 2290       }
 2291   
 2292       public static SF2Layer new_open_hihat(SF2Soundbank sf2) {
 2293           double datah[];
 2294           {
 2295               int fftlen = 4096 * 4;
 2296               double[] data = new double[2 * fftlen];
 2297               Random random = new Random(3049912);
 2298               for (int i = 0; i < data.length; i += 2)
 2299                   data[i] = (2.0 * (random.nextDouble() - 0.5));
 2300               for (int i = fftlen / 2; i < data.length; i++)
 2301                   data[i] = 0;
 2302               for (int i = 0; i < 200; i++)
 2303                   data[i] = 0;
 2304               for (int i = 0; i < 2048 * 4; i++) {
 2305                   double gain = (i / (2048.0 * 4.0));
 2306                   data[i] = gain;
 2307               }
 2308               datah = data;
 2309           }
 2310   
 2311           SF2Sample sample = newSimpleFFTSample(sf2, "Open Hi-Hat", datah, 1000, 5);
 2312   
 2313           SF2Layer layer = new SF2Layer(sf2);
 2314           layer.setName("Open Hi-Hat");
 2315   
 2316           SF2GlobalRegion global = new SF2GlobalRegion();
 2317           layer.setGlobalZone(global);
 2318           sf2.addResource(layer);
 2319   
 2320           SF2LayerRegion region = new SF2LayerRegion();
 2321           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 1500);
 2322           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 2323           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 1500);
 2324           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
 2325           region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
 2326           region.putInteger(SF2Region.GENERATOR_EXCLUSIVECLASS, 1);
 2327           region.setSample(sample);
 2328           layer.getRegions().add(region);
 2329   
 2330           return layer;
 2331       }
 2332   
 2333       public static SF2Layer new_crash_cymbal(SF2Soundbank sf2) {
 2334           double datah[];
 2335           {
 2336               int fftlen = 4096 * 4;
 2337               double[] data = new double[2 * fftlen];
 2338               Random random = new Random(3049912);
 2339               for (int i = 0; i < data.length; i += 2)
 2340                   data[i] = (2.0 * (random.nextDouble() - 0.5));
 2341               for (int i = fftlen / 2; i < data.length; i++)
 2342                   data[i] = 0;
 2343               for (int i = 0; i < 100; i++)
 2344                   data[i] = 0;
 2345               for (int i = 0; i < 512 * 2; i++) {
 2346                   double gain = (i / (512.0 * 2.0));
 2347                   data[i] = gain;
 2348               }
 2349               datah = data;
 2350           }
 2351   
 2352           SF2Sample sample = newSimpleFFTSample(sf2, "Crash Cymbal", datah, 1000, 5);
 2353   
 2354           SF2Layer layer = new SF2Layer(sf2);
 2355           layer.setName("Crash Cymbal");
 2356   
 2357           SF2GlobalRegion global = new SF2GlobalRegion();
 2358           layer.setGlobalZone(global);
 2359           sf2.addResource(layer);
 2360   
 2361           SF2LayerRegion region = new SF2LayerRegion();
 2362           region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 1800);
 2363           region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
 2364           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 1800);
 2365           region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
 2366           region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
 2367           region.setSample(sample);
 2368           layer.getRegions().add(region);
 2369   
 2370           return layer;
 2371       }
 2372   
 2373       public static SF2Layer new_side_stick(SF2Soundbank sf2) {
 2374           double datab[];
 2375   
 2376           // Make treble part
 2377           {
 2378               int fftlen = 4096 * 4;
 2379               double[] data = new double[2 * fftlen];
 2380               Random random = new Random(3049912);
 2381               for (int i = 0; i < data.length; i += 2)
 2382                   data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
 2383               fft(data);
 2384               // Remove all negative frequency
 2385               for (int i = fftlen / 2; i < data.length; i++)
 2386                   data[i] = 0;
 2387               for (int i = 1024 * 4; i < 2048 * 4; i++)
 2388                   data[i] = 1.0 - (i - 4096) / 4096.0;
 2389               for (int i = 0; i < 200; i++) {
 2390                   double g = (1.0 - (i / 200.0));
 2391                   data[i] *= 1.0 + 20 * g * g;
 2392               }
 2393               for (int i = 0; i < 30; i++)
 2394                   data[i] = 0;
 2395               randomPhase(data, new Random(3049912));
 2396               ifft(data);
 2397               normalize(data, 0.9);
 2398               data = realPart(data);
 2399               double gain = 1.0;
 2400               for (int i = 0; i < data.length; i++) {
 2401                   data[i] *= gain;
 2402                   gain *= 0.9996;
 2403               }
 2404               datab = data;
 2405           }
 2406   
 2407           for (int i = 0; i < 10; i++)
 2408               datab[i] *= i / 10.0;
 2409   
 2410           SF2Sample sample = newSimpleDrumSample(sf2, "Side Stick", datab);
 2411   
 2412           SF2Layer layer = new SF2Layer(sf2);
 2413           layer.setName("Side Stick");
 2414   
 2415           SF2GlobalRegion global = new SF2GlobalRegion();
 2416           layer.setGlobalZone(global);
 2417           sf2.addResource(layer);
 2418   
 2419           SF2LayerRegion region = new SF2LayerRegion();
 2420           region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
 2421           region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
 2422           region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -50);
 2423           region.setSample(sample);
 2424           layer.getRegions().add(region);
 2425   
 2426           return layer;
 2427   
 2428       }
 2429   
 2430       public static SF2Sample newSimpleFFTSample(SF2Soundbank sf2, String name,
 2431               double[] data, double base) {
 2432           return newSimpleFFTSample(sf2, name, data, base, 10);
 2433       }
 2434   
 2435       public static SF2Sample newSimpleFFTSample(SF2Soundbank sf2, String name,
 2436               double[] data, double base, int fadeuptime) {
 2437   
 2438           int fftsize = data.length / 2;
 2439           AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
 2440           double basefreq = (base / fftsize) * format.getSampleRate() * 0.5;
 2441   
 2442           randomPhase(data);
 2443           ifft(data);
 2444           data = realPart(data);
 2445           normalize(data, 0.9);
 2446           float[] fdata = toFloat(data);
 2447           fdata = loopExtend(fdata, fdata.length + 512);
 2448           fadeUp(fdata, fadeuptime);
 2449           byte[] bdata = toBytes(fdata, format);
 2450   
 2451           /*
 2452            * Create SoundFont2 sample.
 2453            */
 2454           SF2Sample sample = new SF2Sample(sf2);
 2455           sample.setName(name);
 2456           sample.setData(bdata);
 2457           sample.setStartLoop(256);
 2458           sample.setEndLoop(fftsize + 256);
 2459           sample.setSampleRate((long) format.getSampleRate());
 2460           double orgnote = (69 + 12)
 2461                   + (12 * Math.log(basefreq / 440.0) / Math.log(2));
 2462           sample.setOriginalPitch((int) orgnote);
 2463           sample.setPitchCorrection((byte) (-(orgnote - (int) orgnote) * 100.0));
 2464           sf2.addResource(sample);
 2465   
 2466           return sample;
 2467       }
 2468   
 2469       public static SF2Sample newSimpleFFTSample_dist(SF2Soundbank sf2,
 2470               String name, double[] data, double base, double preamp) {
 2471   
 2472           int fftsize = data.length / 2;
 2473           AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
 2474           double basefreq = (base / fftsize) * format.getSampleRate() * 0.5;
 2475   
 2476           randomPhase(data);
 2477           ifft(data);
 2478           data = realPart(data);
 2479   
 2480           for (int i = 0; i < data.length; i++) {
 2481               data[i] = (1 - Math.exp(-Math.abs(data[i] * preamp)))
 2482                       * Math.signum(data[i]);
 2483           }
 2484   
 2485           normalize(data, 0.9);
 2486           float[] fdata = toFloat(data);
 2487           fdata = loopExtend(fdata, fdata.length + 512);
 2488           fadeUp(fdata, 80);
 2489           byte[] bdata = toBytes(fdata, format);
 2490   
 2491           /*
 2492            * Create SoundFont2 sample.
 2493            */
 2494           SF2Sample sample = new SF2Sample(sf2);
 2495           sample.setName(name);
 2496           sample.setData(bdata);
 2497           sample.setStartLoop(256);
 2498           sample.setEndLoop(fftsize + 256);
 2499           sample.setSampleRate((long) format.getSampleRate());
 2500           double orgnote = (69 + 12)
 2501                   + (12 * Math.log(basefreq / 440.0) / Math.log(2));
 2502           sample.setOriginalPitch((int) orgnote);
 2503           sample.setPitchCorrection((byte) (-(orgnote - (int) orgnote) * 100.0));
 2504           sf2.addResource(sample);
 2505   
 2506           return sample;
 2507       }
 2508   
 2509       public static SF2Sample newSimpleDrumSample(SF2Soundbank sf2, String name,
 2510               double[] data) {
 2511   
 2512           int fftsize = data.length;
 2513           AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
 2514   
 2515           byte[] bdata = toBytes(toFloat(realPart(data)), format);
 2516   
 2517           /*
 2518            * Create SoundFont2 sample.
 2519            */
 2520           SF2Sample sample = new SF2Sample(sf2);
 2521           sample.setName(name);
 2522           sample.setData(bdata);
 2523           sample.setStartLoop(256);
 2524           sample.setEndLoop(fftsize + 256);
 2525           sample.setSampleRate((long) format.getSampleRate());
 2526           sample.setOriginalPitch(60);
 2527           sf2.addResource(sample);
 2528   
 2529           return sample;
 2530       }
 2531   
 2532       public static SF2Layer newLayer(SF2Soundbank sf2, String name, SF2Sample sample) {
 2533           SF2LayerRegion region = new SF2LayerRegion();
 2534           region.setSample(sample);
 2535   
 2536           SF2Layer layer = new SF2Layer(sf2);
 2537           layer.setName(name);
 2538           layer.getRegions().add(region);
 2539           sf2.addResource(layer);
 2540   
 2541           return layer;
 2542       }
 2543   
 2544       public static SF2Instrument newInstrument(SF2Soundbank sf2, String name,
 2545               Patch patch, SF2Layer... layers) {
 2546   
 2547           /*
 2548            * Create SoundFont2 instrument.
 2549            */
 2550           SF2Instrument ins = new SF2Instrument(sf2);
 2551           ins.setPatch(patch);
 2552           ins.setName(name);
 2553           sf2.addInstrument(ins);
 2554   
 2555           /*
 2556            * Create region for instrument.
 2557            */
 2558           for (int i = 0; i < layers.length; i++) {
 2559               SF2InstrumentRegion insregion = new SF2InstrumentRegion();
 2560               insregion.setLayer(layers[i]);
 2561               ins.getRegions().add(insregion);
 2562           }
 2563   
 2564           return ins;
 2565       }
 2566   
 2567       static public void ifft(double[] data) {
 2568           new FFT(data.length / 2, 1).transform(data);
 2569       }
 2570   
 2571       static public void fft(double[] data) {
 2572           new FFT(data.length / 2, -1).transform(data);
 2573       }
 2574   
 2575       public static void complexGaussianDist(double[] cdata, double m,
 2576               double s, double v) {
 2577           for (int x = 0; x < cdata.length / 4; x++) {
 2578               cdata[x * 2] += v * (1.0 / (s * Math.sqrt(2 * Math.PI))
 2579                       * Math.exp((-1.0 / 2.0) * Math.pow((x - m) / s, 2.0)));
 2580           }
 2581       }
 2582   
 2583       static public void randomPhase(double[] data) {
 2584           for (int i = 0; i < data.length; i += 2) {
 2585               double phase = Math.random() * 2 * Math.PI;
 2586               double d = data[i];
 2587               data[i] = Math.sin(phase) * d;
 2588               data[i + 1] = Math.cos(phase) * d;
 2589           }
 2590       }
 2591   
 2592       static public void randomPhase(double[] data, Random random) {
 2593           for (int i = 0; i < data.length; i += 2) {
 2594               double phase = random.nextDouble() * 2 * Math.PI;
 2595               double d = data[i];
 2596               data[i] = Math.sin(phase) * d;
 2597               data[i + 1] = Math.cos(phase) * d;
 2598           }
 2599       }
 2600   
 2601       static public void normalize(double[] data, double target) {
 2602           double maxvalue = 0;
 2603           for (int i = 0; i < data.length; i++) {
 2604               if (data[i] > maxvalue)
 2605                   maxvalue = data[i];
 2606               if (-data[i] > maxvalue)
 2607                   maxvalue = -data[i];
 2608           }
 2609           if (maxvalue == 0)
 2610               return;
 2611           double gain = target / maxvalue;
 2612           for (int i = 0; i < data.length; i++)
 2613               data[i] *= gain;
 2614       }
 2615   
 2616       static public void normalize(float[] data, double target) {
 2617           double maxvalue = 0.5;
 2618           for (int i = 0; i < data.length; i++) {
 2619               if (data[i * 2] > maxvalue)
 2620                   maxvalue = data[i * 2];
 2621               if (-data[i * 2] > maxvalue)
 2622                   maxvalue = -data[i * 2];
 2623           }
 2624           double gain = target / maxvalue;
 2625           for (int i = 0; i < data.length; i++)
 2626               data[i * 2] *= gain;
 2627       }
 2628   
 2629       static public double[] realPart(double[] in) {
 2630           double[] out = new double[in.length / 2];
 2631           for (int i = 0; i < out.length; i++) {
 2632               out[i] = in[i * 2];
 2633           }
 2634           return out;
 2635       }
 2636   
 2637       static public double[] imgPart(double[] in) {
 2638           double[] out = new double[in.length / 2];
 2639           for (int i = 0; i < out.length; i++) {
 2640               out[i] = in[i * 2];
 2641           }
 2642           return out;
 2643       }
 2644   
 2645       static public float[] toFloat(double[] in) {
 2646           float[] out = new float[in.length];
 2647           for (int i = 0; i < out.length; i++) {
 2648               out[i] = (float) in[i];
 2649           }
 2650           return out;
 2651       }
 2652   
 2653       static public byte[] toBytes(float[] in, AudioFormat format) {
 2654           byte[] out = new byte[in.length * format.getFrameSize()];
 2655           return AudioFloatConverter.getConverter(format).toByteArray(in, out);
 2656       }
 2657   
 2658       static public void fadeUp(double[] data, int samples) {
 2659           double dsamples = samples;
 2660           for (int i = 0; i < samples; i++)
 2661               data[i] *= i / dsamples;
 2662       }
 2663   
 2664       static public void fadeUp(float[] data, int samples) {
 2665           double dsamples = samples;
 2666           for (int i = 0; i < samples; i++)
 2667               data[i] *= i / dsamples;
 2668       }
 2669   
 2670       static public double[] loopExtend(double[] data, int newsize) {
 2671           double[] outdata = new double[newsize];
 2672           int p_len = data.length;
 2673           int p_ps = 0;
 2674           for (int i = 0; i < outdata.length; i++) {
 2675               outdata[i] = data[p_ps];
 2676               p_ps++;
 2677               if (p_ps == p_len)
 2678                   p_ps = 0;
 2679           }
 2680           return outdata;
 2681       }
 2682   
 2683       static public float[] loopExtend(float[] data, int newsize) {
 2684           float[] outdata = new float[newsize];
 2685           int p_len = data.length;
 2686           int p_ps = 0;
 2687           for (int i = 0; i < outdata.length; i++) {
 2688               outdata[i] = data[p_ps];
 2689               p_ps++;
 2690               if (p_ps == p_len)
 2691                   p_ps = 0;
 2692           }
 2693           return outdata;
 2694       }
 2695   }

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