AndroidAudioInputStream.java (1894B)
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.android; 25 26 import java.io.IOException; 27 28 import android.media.AudioRecord; 29 import be.tarsos.dsp.io.TarsosDSPAudioFormat; 30 import be.tarsos.dsp.io.TarsosDSPAudioInputStream; 31 32 public class AndroidAudioInputStream implements TarsosDSPAudioInputStream{ 33 34 private final AudioRecord underlyingStream; 35 private final TarsosDSPAudioFormat format; 36 public AndroidAudioInputStream(AudioRecord underlyingStream, TarsosDSPAudioFormat format){ 37 this.underlyingStream = underlyingStream; 38 this.format = format; 39 } 40 41 @Override 42 public long skip(long bytesToSkip) throws IOException { 43 throw new IOException("Can not skip in audio stream"); 44 } 45 46 @Override 47 public int read(byte[] b, int off, int len) throws IOException { 48 return underlyingStream.read(b, off, len); 49 } 50 51 @Override 52 public void close() throws IOException { 53 underlyingStream.stop(); 54 underlyingStream.release(); 55 } 56 57 @Override 58 public TarsosDSPAudioFormat getFormat() { 59 return format; 60 } 61 62 @Override 63 public long getFrameLength() { 64 return -1; 65 } 66 67 }