Skip to content

Most visited

Recently visited

navigation

I2sDevice

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

Constants

int PCM_FORMAT_16_BIT

Constant used to specify signed 16-bit little-endian PCM

int PCM_FORMAT_24_BIT

Constant used to specify signed 24-bit little-endian PCM

int PCM_FORMAT_32_BIT

Constant used to specify signed 32-bit little-endian PCM

int PCM_FORMAT_8_BIT

Constant used to specify signed 8-bit PCM

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.

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

From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Constants

PCM_FORMAT_16_BIT

int PCM_FORMAT_16_BIT

Constant used to specify signed 16-bit little-endian PCM

Constant Value: 2 (0x00000002)

PCM_FORMAT_24_BIT

int PCM_FORMAT_24_BIT

Constant used to specify signed 24-bit little-endian PCM

Constant Value: 3 (0x00000003)

PCM_FORMAT_32_BIT

int PCM_FORMAT_32_BIT

Constant used to specify signed 32-bit little-endian PCM

Constant Value: 4 (0x00000004)

PCM_FORMAT_8_BIT

int PCM_FORMAT_8_BIT

Constant used to specify signed 8-bit PCM

Constant Value: 1 (0x00000001)

Public methods

close

void close ()

Close and release the device. Must be called in order to make the device available to other users.

Throws
IOException The I2sDevice is already closed.

read

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.

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 If there was an error reading from the device.
IllegalArgumentException If offset or size could lead to array access out of bounds.

read

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.

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 If there was an error reading from the device.
IllegalArgumentException If offset or size could lead to array access out of bounds.

read

int read (ByteBuffer buffer, 
                int sizeInBytes)

Read raw audio in from the audio device. This call blocks until the entire operation is completed.

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 If there was an error reading from the device.
IllegalArgumentException If offset or size could lead to array access out of bounds.

write

int write (ByteBuffer buffer, 
                int sizeInBytes)

Write raw audio to the audio device. This call blocks until the entire operation is completed.

Parameters
buffer ByteBuffer: Buffer to write out of. Must have a backing array.
sizeInBytes int: Number of bytes to write. 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 written.
Throws
IOException If there was an error writing to the device.
IllegalArgumentException If offset or size could lead to array access out of bounds.

write

int write (byte[] buffer, 
                int offsetInBytes, 
                int sizeInBytes)

Write raw audio to the audio device. This call blocks until the entire operation is completed.

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 The number of bytes written.
Throws
IOException If there was an error writing to the device.
IllegalArgumentException If offset or size could lead to array access out of bounds.

write

int write (short[] buffer, 
                int offsetInShorts, 
                int sizeInShorts)

Write raw audio to the audio device. This call blocks until the entire operation is completed.

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 The number of shorts written.
Throws
IOException If there was an error writing to the device.
IllegalArgumentException If offset or size could lead to array access out of bounds.
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.