private void loadSampleData(BufferedInputStream in, Sample sample) throws IOException { int sampleLength = sample.getLength(); int loopEnd = sample.getLoopEnd(); int loopStart = sample.getLoopStart(); short[] sampleData; if (sample.getQuality() == 16) { sampleLength >>= 1; loopEnd >>= 1; loopStart >>= 1; byte[] temp = read(in, 2 * sampleLength); sampleData = new short[sampleLength + 4]; int tmpPos = 0; int samp = 0; for (int i = 0; i < sampleLength; i++, tmpPos += 2) { samp += make16Bit(temp, tmpPos); sampleData[i] = (short) (samp); } } else { sampleData = new short[sampleLength + 4]; byte[] temp = read(in, sampleLength); int samp = 0; for (int i = 0; i < sampleLength; i++) { samp += temp[i] & 0xff; sampleData[i] = (short) (samp << 8); } } if (sampleLength > 0) { int pos2 = 0; int loopType = sample.getLoopType(); if ((loopType & Sample.PINGPONG_LOOP) == 0) { if ((loopType & Sample.FORWARD_LOOP) != 0) pos2 = loopStart; for (int i = 0; i < 3; i++) sampleData[sampleLength + 1 + i] = sampleData[pos2 + i]; } else if ((loopType & Sample.PINGPONG_LOOP) != 0) { pos2 = loopStart + loopEnd; for (int i = 0; i < 3; i++) sampleData[sampleLength + 1 + i] = sampleData[pos2 - 1 - i]; } System.arraycopy(sampleData, 0, sampleData, 1, sampleLength); if ((loopType & Sample.FORWARD_LOOP) != 0) sampleData[0] = sampleData[loopStart + loopEnd]; else if ((loopType & Sample.PINGPONG_LOOP) != 0) sampleData[0] = sampleData[loopStart + 2]; } loopStart <<= 10; loopEnd <<= 10; sample.setLoopStart(loopStart); sample.setLoopEnd(loopEnd); sample.setLength(sampleLength); sample.setData(sampleData); }
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); }