code: public void trim(int leftTrimNumberOfSample, int rightTrimNumberOfSample) {
  
          long chunkSize = waveHeader.getChunkSize();
          long subChunk2Size = waveHeader.getSubChunk2Size();
  
          long totalTrimmed = leftTrimNumberOfSample + rightTrimNumberOfSample;
  
          if (totalTrimmed > subChunk2Size) {
              leftTrimNumberOfSample = (int) subChunk2Size;
          }
  
          // update wav info
          chunkSize -= totalTrimmed;
          subChunk2Size -= totalTrimmed;
  
          if (chunkSize >= 0 && subChunk2Size >= 0) {
              waveHeader.setChunkSize(chunkSize);
              waveHeader.setSubChunk2Size(subChunk2Size);
  
              byte[] trimmedData = new byte[(int) subChunk2Size];
              System.arraycopy(data, (int) leftTrimNumberOfSample, trimmedData, 0, (int) subChunk2Size);
              data = trimmedData;
          } else {
              System.err.println("Trim error: Negative length");
          }
      }
docs: Trim the wave data
  
  @param leftTrimNumberOfSample
  Number of sample trimmed from beginning
  @param rightTrimNumberOfSample
  Number of sample trimmed from ending