UniversalAudioInputStream.java (1915B)
1 /* 2 * _______ _____ _____ _____ 3 * |__ __| | __ \ / ____| __ \ 4 * | | __ _ _ __ ___ ___ ___| | | | (___ | |__) | 5 * | |/ _` | '__/ __|/ _ \/ __| | | |\___ \| ___/ 6 * | | (_| | | \__ \ (_) \__ \ |__| |____) | | 7 * |_|\__,_|_| |___/\___/|___/_____/|_____/|_| 8 * 9 * ------------------------------------------------------------- 10 * 11 * TarsosDSP is developed by Joren Six at IPEM, University Ghent 12 * 13 * ------------------------------------------------------------- 14 * 15 * Info: http://0110.be/tag/TarsosDSP 16 * Github: https://github.com/JorenSix/TarsosDSP 17 * Releases: http://0110.be/releases/TarsosDSP/ 18 * 19 * TarsosDSP includes modified source code by various authors, 20 * for credits and info, see README. 21 * 22 */ 23 24 package be.tarsos.dsp.io; 25 26 import java.io.IOException; 27 import java.io.InputStream; 28 29 public class UniversalAudioInputStream implements TarsosDSPAudioInputStream { 30 31 private final InputStream underlyingStream; 32 private final TarsosDSPAudioFormat format; 33 34 public UniversalAudioInputStream(InputStream underlyingInputStream, TarsosDSPAudioFormat format){ 35 this.underlyingStream = underlyingInputStream; 36 this.format = format; 37 } 38 39 @Override 40 public long skip(long bytesToSkip) throws IOException { 41 //the skip probably 42 int bytesSkipped = 0; 43 for(int i = 0 ; i < bytesToSkip ; i++){ 44 int theByte = underlyingStream.read(); 45 if(theByte!=-1){ 46 bytesSkipped++; 47 } 48 } 49 return bytesSkipped; 50 } 51 52 @Override 53 public int read(byte[] b, int off, int len) throws IOException { 54 return underlyingStream.read(b, off, len); 55 } 56 57 @Override 58 public void close() throws IOException { 59 underlyingStream.close(); 60 } 61 62 @Override 63 public TarsosDSPAudioFormat getFormat() { 64 return format; 65 } 66 67 @Override 68 public long getFrameLength() { 69 return -1; 70 } 71 72 }