コード例 #1
0
  /**
   * Creates a new oscillator from a preset in a SoundFont file.
   *
   * @param frequency - The frequency determines what key was pressed.
   * @parma preset - The SoundFont preset to get the sample data from.
   * @param sampleRateInHz - The sample rate of the output synthesizer.
   */
  public SoundFontOscillator(FrequencyProvider frequency, Preset preset, double sampleRateInHz) {
    super(frequency);
    logger_ = Logger.getLogger(getClass().getName());
    preset_ = preset;
    sampleRateInHz_ = sampleRateInHz;

    // Find the max sample length.
    maxSampleLength_ = 1;
    for (Zone pzone : preset_.getZoneList()) {
      Instrument instrument = pzone.getInstrument();
      if (instrument != null) {
        for (Zone izone : instrument.getZoneList()) {
          Sample sample = izone.getSample();
          int length = (int) Math.ceil((sampleRateInHz_ * izone.getCount()) / sample.getRate());
          if (length > maxSampleLength_) {
            maxSampleLength_ = length;
          }
        }
      }
    }

    currentSample_ = null;
    currentSampleIndex_ = 0;

    buffer_ = new double[maxSampleLength_];
    Arrays.fill(buffer_, 0.0);
    bufferIndex_ = 0;
  }
コード例 #2
0
 private static ImmutableSortedSet<Method> findAllBenchmarkMethods(
     Class<?> benchmarkClass, Instrument instrument) throws InvalidBenchmarkException {
   ImmutableSortedSet.Builder<Method> result =
       ImmutableSortedSet.orderedBy(
           Ordering.natural()
               .onResultOf(
                   new Function<Method, String>() {
                     @Override
                     public String apply(Method method) {
                       return method.getName();
                     }
                   }));
   Set<String> benchmarkMethodNames = new HashSet<String>();
   Set<String> overloadedMethodNames = new TreeSet<String>();
   for (Method method : benchmarkClass.getDeclaredMethods()) {
     if (instrument.isBenchmarkMethod(method)) {
       method.setAccessible(true);
       result.add(method);
       if (!benchmarkMethodNames.add(method.getName())) {
         overloadedMethodNames.add(method.getName());
       }
     }
   }
   if (!overloadedMethodNames.isEmpty()) {
     throw new InvalidBenchmarkException(
         "Overloads are disallowed for benchmark methods, found overloads of %s in benchmark %s",
         overloadedMethodNames, benchmarkClass);
   }
   return result.build();
 }
コード例 #3
0
ファイル: Module.java プロジェクト: Gerald1973/Scrolling
 public static int calculateModuleLength(byte[] moduleHeader) {
   int moduleLength =
       1084 + 4 * calculateNumChannels(moduleHeader) * 64 * calculateNumPatterns(moduleHeader);
   for (int instIdx = 1; instIdx < 32; instIdx++) {
     moduleLength += Instrument.calculateSampleDataLength(moduleHeader, instIdx);
   }
   return moduleLength;
 }
コード例 #4
0
 /** Initializes the "current sample" based on the given key and velocity. */
 private synchronized void initSample(int key, int velocity) {
   // Find any sample in this preset that can handle the given key and velocity.
   currentSample_ = null;
   for (Zone pzone : preset_.getZoneList()) {
     Instrument instrument = pzone.getInstrument();
     if (instrument != null) {
       for (Zone izone : instrument.getZoneList()) {
         if (izone.inKeyRange(key)
             && izone.inVelocityRange(velocity)
             && izone.getSample() != null) {
           currentSample_ = izone;
           currentSampleIndex_ = currentSample_.getStart();
           return;
         }
       }
     }
   }
 }
コード例 #5
0
 public static MakeOrderAccount create(
     TradingConsole tradingConsole,
     SettingsManager settingsManager,
     Account account,
     Instrument instrument,
     boolean isForDelivery) {
   return MakeOrderAccount.create(
       tradingConsole, settingsManager, account.get_Id(), instrument.get_Id(), isForDelivery);
 }
コード例 #6
0
  public void write(long time, Instrument instrument1, Instrument instrument2) {
    double bid1 = instrument1.getBid();
    double ask1 = instrument1.getAsk();
    double bid2 = instrument2.getBid();
    double ask2 = instrument2.getAsk();

    if (bid1 > 0 && ask1 > 0 && bid2 > 0 && ask2 > 0) {
      StringBuilder sb = new StringBuilder();
      sb.append(dateFormat.format(new Date(time))).append(",");
      sb.append(decimalFormat.format(bid1)).append(",");
      sb.append(decimalFormat.format(ask1)).append(",");
      sb.append(decimalFormat.format(bid2)).append(",");
      sb.append(decimalFormat.format(ask2));

      writer.println(sb);
      writer.flush();
    }
  }
コード例 #7
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return true;
   if (getClass() != obj.getClass()) return false;
   final Note other = (Note) obj;
   if (duration != other.duration) return false;
   if (!instrument.equals(other.instrument)) return false;
   if (!pitch.equals(other.pitch)) return false;
   return true;
 }
コード例 #8
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   long temp;
   temp = Double.doubleToLongBits(duration);
   result = prime * result + (int) (temp ^ (temp >>> 32));
   result = prime * result + ((instrument == null) ? 0 : instrument.hashCode());
   result = prime * result + ((pitch == null) ? 0 : pitch.hashCode());
   return result;
 }
コード例 #9
0
 @Provides
 static ImmutableSet<Instrumentation> provideInstrumentations(
     CaliperOptions options, BenchmarkClass benchmarkClass, ImmutableSet<Instrument> instruments)
     throws InvalidBenchmarkException {
   ImmutableSet.Builder<Instrumentation> builder = ImmutableSet.builder();
   ImmutableSet<String> benchmarkMethodNames = options.benchmarkMethodNames();
   Set<String> unusedBenchmarkNames = new HashSet<String>(benchmarkMethodNames);
   for (Instrument instrument : instruments) {
     for (Method method : findAllBenchmarkMethods(benchmarkClass.benchmarkClass(), instrument)) {
       if (benchmarkMethodNames.isEmpty() || benchmarkMethodNames.contains(method.getName())) {
         builder.add(instrument.createInstrumentation(method));
         unusedBenchmarkNames.remove(method.getName());
       }
     }
   }
   if (!unusedBenchmarkNames.isEmpty()) {
     throw new InvalidBenchmarkException(
         "Invalid benchmark method(s) specified in options: " + unusedBenchmarkNames);
   }
   return builder.build();
 }
コード例 #10
0
  public void updateMusician(Musician m) {
    try {
      PreparedStatement stmt =
          conn.prepareStatement(
              "update musicians m set first_name = ?,"
                  + "last_name = ?, birthdate = ?, habitation_id = ?, password = ?",
              ResultSet.TYPE_FORWARD_ONLY,
              ResultSet.CONCUR_READ_ONLY);
      stmt.setString(1, m.getFirstName());
      stmt.setString(2, m.getLastName());
      stmt.setTimestamp(3, new java.sql.Timestamp(m.getBirthdate().getTime()));
      stmt.setInt(4, m.getHabitation().getId());
      stmt.setString(5, m.getPassword());
      stmt.executeUpdate();

      // set instrument_skills
      stmt =
          conn.prepareStatement(
              "delete from instrument_skills where musician_id = ?",
              ResultSet.TYPE_FORWARD_ONLY,
              ResultSet.CONCUR_READ_ONLY);
      stmt.setInt(1, m.getId());
      stmt.executeUpdate();

      for (Instrument i : m.getSkills()) {
        stmt =
            conn.prepareStatement(
                "insert into instrument_skills values(?, ?)",
                ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_READ_ONLY);
        stmt.setInt(1, m.getId());
        stmt.setInt(2, i.getId());
        stmt.executeUpdate();
      }

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
コード例 #11
0
  Instrument replace_instrument(byte[] mod_header, int idx, byte[] data_input, int replacetranspose)
      throws IOException {
    int header_offset, sample_data_length;
    int loop_start, loop_length, sample_idx, fine_tune;
    Instrument instrument;
    Sample sample;
    // byte[] raw_sample_data;
    short[] sample_data;
    header_offset = (idx - 1) * 30 + 20;

    instrument = new Instrument();
    sample = new Sample();
    // sample_data_length = unsigned_short_be( mod_header, header_offset + 22 ) << 1;
    sample_data_length = data_input.length;
    System.out.println("Sampledata bytes: " + sample_data_length);
    fine_tune = mod_header[header_offset + 24] & 0x0F;
    if (fine_tune > 7) {
      fine_tune -= 16;
    }
    sample.transpose = (fine_tune + (replacetranspose * 10) << IBXM.FP_SHIFT) / 96;
    sample.volume = mod_header[header_offset + 25] & 0x7F;
    loop_start = unsigned_short_be(mod_header, header_offset + 26) << 1;
    loop_length = unsigned_short_be(mod_header, header_offset + 28) << 1;
    if (loop_length < 4) {
      loop_length = 0;
    }
    // raw_sample_data = new byte[ sample_data_length ];
    sample_data = new short[sample_data_length];

    for (sample_idx = 0; sample_idx < data_input.length; sample_idx++) {
      sample_data[sample_idx] = (short) (data_input[sample_idx] << 8);
    }
    sample.set_sample_data(sample_data, loop_start, loop_length, false);
    instrument.set_num_samples(1);
    instrument.set_sample(0, sample);
    return instrument;
  }
コード例 #12
0
ファイル: CraftPlayer.java プロジェクト: ktulych/MCPBukkit
  public void playNote(Location loc, Instrument instrument, Note note) {
    if (getHandle().field_71135_a == null) return;

    int id =
        getHandle().field_70170_p.func_72798_a(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    getHandle()
        .field_71135_a
        .func_72567_b(
            new net.minecraft.network.packet.Packet54PlayNoteBlock(
                loc.getBlockX(),
                loc.getBlockY(),
                loc.getBlockZ(),
                id,
                instrument.getType(),
                note.getId()));
  }
コード例 #13
0
  public void update(String dataSourceKey, boolean isDblClickAsk) {
    if (!this._isForDelivery && this._buySellType == BuySellType.Both) {
      boolean isBuy = Instrument.getSelectIsBuy(this._instrument, isDblClickAsk);

      this._isBuyForCurrent = isBuy;
      this._isBuyForCombo = isBuy ? Language.Buy : Language.Sell;
      TradingConsole.bindingManager.update(dataSourceKey, this);
      this.setStyle(dataSourceKey);

      this._isBuyForCurrent = !isBuy;
      this._isBuyForCombo = (!isBuy) ? Language.Buy : Language.Sell;
      TradingConsole.bindingManager.update(dataSourceKey, this);
      this.setStyle(dataSourceKey);
    } else {
      TradingConsole.bindingManager.update(dataSourceKey, this);
      this.setStyle(dataSourceKey);
    }
  }
コード例 #14
0
 public void perform() throws PerformanceException {
   for (Instrument instrument : instruments) {
     instrument.play();
   }
 }
コード例 #15
0
ファイル: OME.java プロジェクト: hflynn/bioformats
  protected Element asXMLElement(Document document, Element OME_element) {
    // Creating XML block for OME

    if (OME_element == null) {
      OME_element = document.createElementNS(NAMESPACE, "OME");
    }

    if (uuid != null) {
      // Attribute property UUID
      OME_element.setAttribute("UUID", uuid.toString());
    }
    if (creator != null) {
      // Attribute property Creator
      OME_element.setAttribute("Creator", creator.toString());
    }
    if (projects != null) {
      // Element property Project which is complex (has
      // sub-elements) and occurs more than once
      for (Project projects_value : projects) {
        OME_element.appendChild(projects_value.asXMLElement(document));
      }
    }
    if (datasets != null) {
      // Element property Dataset which is complex (has
      // sub-elements) and occurs more than once
      for (Dataset datasets_value : datasets) {
        OME_element.appendChild(datasets_value.asXMLElement(document));
      }
    }
    if (experiments != null) {
      // Element property Experiment which is complex (has
      // sub-elements) and occurs more than once
      for (Experiment experiments_value : experiments) {
        OME_element.appendChild(experiments_value.asXMLElement(document));
      }
    }
    if (plates != null) {
      // Element property Plate which is complex (has
      // sub-elements) and occurs more than once
      for (Plate plates_value : plates) {
        OME_element.appendChild(plates_value.asXMLElement(document));
      }
    }
    if (screens != null) {
      // Element property Screen which is complex (has
      // sub-elements) and occurs more than once
      for (Screen screens_value : screens) {
        OME_element.appendChild(screens_value.asXMLElement(document));
      }
    }
    if (experimenters != null) {
      // Element property Experimenter which is complex (has
      // sub-elements) and occurs more than once
      for (Experimenter experimenters_value : experimenters) {
        OME_element.appendChild(experimenters_value.asXMLElement(document));
      }
    }
    if (experimenterGroups != null) {
      // Element property ExperimenterGroup which is complex (has
      // sub-elements) and occurs more than once
      for (ExperimenterGroup experimenterGroups_value : experimenterGroups) {
        OME_element.appendChild(experimenterGroups_value.asXMLElement(document));
      }
    }
    if (instruments != null) {
      // Element property Instrument which is complex (has
      // sub-elements) and occurs more than once
      for (Instrument instruments_value : instruments) {
        OME_element.appendChild(instruments_value.asXMLElement(document));
      }
    }
    if (images != null) {
      // Element property Image which is complex (has
      // sub-elements) and occurs more than once
      for (Image images_value : images) {
        OME_element.appendChild(images_value.asXMLElement(document));
      }
    }
    if (structuredAnnotations != null) {
      // Element property StructuredAnnotations which is complex (has
      // sub-elements)
      OME_element.appendChild(structuredAnnotations.asXMLElement(document));
    }
    if (roIs != null) {
      // Element property ROI which is complex (has
      // sub-elements) and occurs more than once
      for (ROI roIs_value : roIs) {
        OME_element.appendChild(roIs_value.asXMLElement(document));
      }
    }
    if (binaryOnly != null) {
      // Element property BinaryOnly which is complex (has
      // sub-elements)
      OME_element.appendChild(binaryOnly.asXMLElement(document));
    }
    return super.asXMLElement(document, OME_element);
  }
コード例 #16
0
ファイル: User.java プロジェクト: syriley/9dials
 public User addInstrument(Instrument instrument) {
   instrument.save();
   instruments.add(instrument);
   return this;
 }
コード例 #17
0
 public void perform() throws PerformanceException {
   System.out.print("Playing " + song + " : ");
   instrument.play();
 }
コード例 #18
0
 // Doesn’t care about type, so new types
 // added to the system still work right:
 public static void tune(Instrument i) {
   // ...
   i.play(Note.MIDDLE_C);
 }
コード例 #19
0
ファイル: XmLoader.java プロジェクト: quarnster/silence
  public void readInstrument(BufferedInputStream in, Instrument instr) throws IOException {
    // Instrument size
    int size = make32Bit(read(in, 4));

    // Instrument name
    read(in, 22);

    // Instrument type (always 0)
    // Note: not always 0 but it says so in the documents...
    in.read();

    // Number of samples in instrument
    Sample[] sample = new Sample[make16Bit(read(in, 2))];

    if (sample.length == 0) {
      read(in, size - 29);
    } else {
      // Sample header size
      int ssize = make32Bit(read(in, 4));
      if (ssize != 40) {
        throw new IOException("samplesize != 40!");
      }

      // Sample number for all notes
      instr.setSampleForNote(read(in, 96));

      // Points for volume envelope
      byte[] volEnvData = read(in, 48);

      // Points for panning envelope
      byte[] panEnvData = read(in, 48);

      // Number of volume points
      int points = in.read();
      Envelope volumeEnvelope = new Envelope();
      volumeEnvelope.setData(makeEnvelopePoints(points, volEnvData));

      // Number of panning points
      points = in.read();
      Envelope panningEnvelope = new Envelope();
      panningEnvelope.setData(makeEnvelopePoints(points, panEnvData));

      // Volume sustain point
      volumeEnvelope.setSustainPosition(in.read());

      // Volume loop start point
      volumeEnvelope.setLoopStart(in.read());

      // Volume loop end point
      volumeEnvelope.setLoopEnd(in.read());

      // Panning sustain point
      panningEnvelope.setSustainPosition(in.read());

      // Panning loop start point
      panningEnvelope.setLoopStart(in.read());

      // Panning loop end point
      panningEnvelope.setLoopEnd(in.read());

      // Volume type: bit 0: on; 1: Sustain; 2: Loop
      volumeEnvelope.setType(in.read());

      // Panning type: bit 0: on; 1: Sustain; 2: Loop
      panningEnvelope.setType(in.read());

      // Vibrato type
      Vibrato vibrato = new Vibrato();
      vibrato.setType(in.read());

      // Vibrato sweep
      vibrato.setSweep(in.read());

      // Vibrato depth
      vibrato.setDepth(in.read());

      // Vibrato rate
      vibrato.setRate(in.read());

      // Volume fadeout
      instr.setFadeout(make16Bit(read(in, 2)));

      // reserved
      read(in, 22);

      for (int i = 0; i < sample.length; i++) {
        sample[i] = new Sample();
        loadSample(in, sample[i]);
      }
      for (int i = 0; i < sample.length; i++) {
        loadSampleData(in, sample[i]);
      }

      instr.setPanningEnvelope(panningEnvelope);
      instr.setVolumeEnvelope(volumeEnvelope);
      instr.setVibrato(vibrato);
      instr.setSamples(sample);
    }
  }