• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package org.drrickorang.loopback;
18 
19 
20 /**
21  * This class is a pipe that allows one writer and one reader.
22  */
23 
24 public abstract class Pipe {
25     public static final int OVERRUN = -2;   // when there's an overrun, return this value
26 
27     protected int       mSamplesOverrun;
28     protected int       mOverruns;
29     protected final int mMaxValues;   // always in power of two
30 
31 
32     /** maxSamples must be >= 2. */
Pipe(int maxSamples)33     public Pipe(int maxSamples) {
34         mMaxValues = Utilities.roundup(maxSamples); // round up to the nearest power of 2
35     }
36 
37 
38     /**
39      * Read at most "count" number of samples into array "buffer", starting from index "offset".
40      * If the available samples to read is smaller than count, just read as much as it can and
41      * return the amount of samples read (non-blocking). offset + count must be <= buffer.length.
42      */
read(short[] buffer, int offset, int count)43     public abstract int read(short[] buffer, int offset, int count);
44 
45 
46     /** Return the amount of samples available to read. */
availableToRead()47     public abstract int availableToRead();
48 
49 
50     /** Clear the pipe. */
flush()51     public abstract void flush();
52 }
53