package nxm.audio.lib;

import java.io.IOException;
import java.io.InputStream;

/** A class that holds information for audio input streams
 *  @author Jay Hallam
 *  @since  NeXtMidas 2.1.0
 */
public class AudioInputStream extends InputStream {

  protected AudioFormat format = null;
  protected long frameLength = 0;
  protected long framePos = 0;
  protected int frameSize = 0;
  InputStream stream = null;

  /** AudioInputStream Constructor
   *  @param stream the byte array input stream
   *  @param format the audio format
   *  @param length the frame length
   */
  public AudioInputStream(InputStream stream, AudioFormat format, long length) {
    this.stream = stream;
    this.format = format;
    this.frameLength = length;
    this.framePos = 0;
    this.frameSize = format.getFrameSize();
  }

  public int available() throws IOException {
    return stream.available();
  }

  public void close() throws IOException {
    stream.close();
  }

  /** Get the audio format
   *  @return the audio format
   */
  public AudioFormat getFormat() {
    return format;
  }

  /** Get the frame length
   *  @return the frame length
   */
  public long getFrameLength() {
    return frameLength;
  }

  public void mark(int readlimit) {
    stream.mark(readlimit);
  }

  public boolean markSupported() {
    return stream.markSupported();
  }

  public int read() throws IOException {
    return stream.read();
  }

  public int read(byte [] b) throws IOException {
    return stream.read(b);
  }

  public int read(byte [] b, int off, int len) throws IOException {
    return stream.read(b, off, len);
  }

  public void reset() throws IOException {
    stream.reset();
  }

  public long skip(long n) throws IOException {
    return stream.skip(n);
  }

}
