I2sDevice
public
class
I2sDevice
extends Object
implements
Closeable
| java.lang.Object | |
| ↳ | com.google.android.things.pio.I2sDevice |
Controls an I2S device.
Opening an I2S device takes ownership of it for the whole system, preventing anyone else from
opening/accessing this device until you call close(). Forgetting to call close()
will prevent anyone (including the same process/app) from using the device.
Summary
Public methods | |
|---|---|
void
|
close()
Close and release the device. |
int
|
read(short[] buffer, int offsetInShorts, int sizeInShorts)
Read raw audio in from the audio device. |
int
|
read(byte[] buffer, int offsetInBytes, int sizeInBytes)
Read raw audio in from the audio device. |
int
|
read(ByteBuffer buffer, int sizeInBytes)
Read raw audio in from the audio device. |
void
|
setFormat(AudioFormat format)
Set device configurations encoded as an Android AudioFormat. |
int
|
write(ByteBuffer buffer, int sizeInBytes)
Write raw audio to the audio device. |
int
|
write(byte[] buffer, int offsetInBytes, int sizeInBytes)
Write raw audio to the audio device. |
int
|
write(short[] buffer, int offsetInShorts, int sizeInShorts)
Write raw audio to the audio device. |
Inherited methods | |
|---|---|
java.lang.Object
| |
java.io.Closeable
| |
java.lang.AutoCloseable
| |
Public methods
close
</div>
void close ()
Close and release the device.
Must be called in order to make the device available to other users.</p>
| Throws | |
|---|---|
IOException |
if the I2sDevice is already closed. |
</div>
read
</div>
int read (short[] buffer,
int offsetInShorts,
int sizeInShorts)
Read raw audio in from the audio device.
This call blocks until the entire operation is completed.</p>
| Parameters | |
|---|---|
buffer |
short:
Buffer to read into. |
offsetInShorts |
int:
Offset into the supplied array to begin storing output. |
sizeInShorts |
int
|
| Returns | |
|---|---|
int |
The number of floats read. |
| Throws | |
|---|---|
|
IOException |
IllegalArgumentException |
|
IOException |
|
</div>
read
</div>
int read (byte[] buffer,
int offsetInBytes,
int sizeInBytes)
Read raw audio in from the audio device.
This call blocks until the entire operation is completed.</p>
| Parameters | |
|---|---|
buffer |
byte:
Buffer to read into. |
offsetInBytes |
int:
Offset into the supplied array to begin storing output. |
sizeInBytes |
int:
Number of bytes to read. Offset + size may not be larger than the buffer. |
| Returns | |
|---|---|
int |
The number of bytes read. |
| Throws | |
|---|---|
|
IOException |
IllegalArgumentException |
|
IOException |
|
</div>
read
</div>
int read (ByteBuffer buffer,
int sizeInBytes)
Read raw audio in from the audio device.
This call blocks until the entire operation is completed.</p>
| Parameters | |
|---|---|
buffer |
ByteBuffer:
Buffer to read into. |
sizeInBytes |
int:
Number of bytes to read. It is recommended but not enforced that the
number of bytes requested is a multiple of the frame size (sample size in bytes multiplied
by the channel count). |
| Returns | |
|---|---|
int |
The number of bytes read. |
| Throws | |
|---|---|
|
IOException |
IllegalArgumentException |
|
IOException |
|
</div>
setFormat
</div>
void setFormat (AudioFormat format)
Set device configurations encoded as an Android AudioFormat.
| Parameters | |
|---|---|
format |
AudioFormat:
AudioFormat specifying encoding, bits per sample, channels and rate. |
| Throws | |
|---|---|
|
IOException |
IllegalArgumentException |
|
IOException |
|
</div>
write
</div>
int write (ByteBuffer buffer,
int sizeInBytes)
Write raw audio to the audio device.
This call blocks until the entire operation is completed.</p>
| Parameters | |
|---|---|
buffer |
ByteBuffer:
Buffer to read into. |
sizeInBytes |
int:
Number of bytes to read. It is recommended but not enforced that the
number of bytes requested is a multiple of the frame size (sample size in bytes multiplied
by the channel count). |
| Returns | |
|---|---|
int |
The number of bytes read. |
| Throws | |
|---|---|
|
IOException |
IllegalArgumentException |
|
IOException |
|
</div>
write
</div>
int write (byte[] buffer,
int offsetInBytes,
int sizeInBytes)
Write raw audio to the audio device.
This call blocks until the entire operation is completed.</p>
| Parameters | |
|---|---|
buffer |
byte:
Data to write. |
offsetInBytes |
int:
Offset into the supplied array to begin accessing data. |
sizeInBytes |
int:
Number of bytes to write. Offset + size may not exceed buffer length. |
| Returns | |
|---|---|
int |
|
| Throws | |
|---|---|
|
IOException |
|
IllegalArgumentException |
IOException |
|
See also:
read(byte[], int, int)
</div>
write
</div>
int write (short[] buffer,
int offsetInShorts,
int sizeInShorts)
Write raw audio to the audio device.
This call blocks until the entire operation is completed.</p>
| Parameters | |
|---|---|
buffer |
short:
Data to write. |
offsetInShorts |
int:
Offset into the supplied array to begin accessing data. |
sizeInShorts |
int:
Number of shorts to write. Offset + size may not exceed buffer length. |
| Returns | |
|---|---|
int |
|
| Throws | |
|---|---|
|
IOException |
IllegalArgumentException |
|
IOException |
|
</div>
</div>