Interfacing android and arduino through an audio connection.

Monday, 12 September 2011

Demodulation in Android device (II): Reading sound.

After being ablo to record sound with the LG-GT540, I needed to read the data that I obtained from the MIC.

In order to do this, I used the ByteBuffer class:

public ByteBuffer wrap (byte [] array, int start, int byteCount)

Creates a new byte buffer by wrapping the given byte array.
The new buffer's position will be start, limit will be start + byteCount, capacity will be the length of the array.
 
Parameters
array the byte array which the new buffer will be based on.
start the start index, must not be negative and not greater than array.length.
byteCount the length, must not be negative and not greater than array.length - start.
Returns 
     The created byte buffer.
 

public abstract short  getshort()

Returns the short at the current position and increases the position by 2.
The 2 bytes starting at the current position are composed into a short according to the current byte order and returned.
Returns
      the short at the current position.
ByteOrder class:

public static final ByteOrder LITTLE_ENDIAN

Little endian means that the first byte (lowest address) is the least significant, and the last byte (highest address) is the most significant.

With all these classes and functions, I was able to analyze what I recorded.



No comments:

Post a Comment