Example #1
0
  private void loadSample(BufferedInputStream in, Sample sample) throws IOException {
    // Sample length
    int sampleLength = make32Bit(read(in, 4));

    // Sample loop start
    int loopStart = make32Bit(read(in, 4));

    // Sample loop length
    int loopEnd = make32Bit(read(in, 4));

    if (loopStart + loopEnd > sampleLength) loopEnd = (sampleLength) - loopStart;

    // Volume
    sample.setVolume(in.read());

    // Finetune (signend byte -128...+127)
    sample.setFineTune((byte) in.read());

    // Type: Bit 0-1: 0 = No loop,
    //                1 = Forward loop,
    //		  2 = Ping-pong loop;
    //                4: 16-bit sampledata
    int loopType = in.read();
    int sampleQuality = ((int) loopType & 0x10) != 0 ? 16 : 8;

    if ((loopType & 0x3) == 0 || loopEnd == 0) {
      // no looping
      loopStart = 0;
      loopEnd = sampleLength;
      loopType &= 0x10;
    }

    // Panning (0-255)
    sample.setPanning(in.read() & 0xff);

    // Relative note number (signed byte)
    sample.setRelativeNote((byte) in.read());

    // Reserved
    in.read();

    // Sample name
    read(in, 22);

    sample.setLength(sampleLength);
    sample.setLoopType(loopType);
    sample.setQuality(sampleQuality);
    sample.setLoopStart(loopStart);
    sample.setLoopEnd(loopEnd);
  }