I have some sound recorded from an ASIO device, which is stored as an array of floats. It seems that the sample type of the audio is "ASIOSTInt32LSB". I'm trying to figure out how to play this audio back on an Android device.
I have tried creating an AudioTrack and writing the byte array of the audio from the ASIO device to the track, but I'm getting the errors which can be seen below. I've tried normalising the float array values to the range -1.0 to 1.0, but this had no effect. I have also tried to use MediaPlayer instead of AudioTrack, and create a temp file which takes the value of the byte array, but that didn't work either.
private void playSound(byte[] soundArray)
{
final int TEST_SR = 22050; //This is from an example I found online.
final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO;
final int TEST_FORMAT = AudioFormat.ENCODING_PCM_FLOAT;
final int TEST_MODE = AudioTrack.MODE_STATIC;.
final int TEST_STREAM_TYPE = AudioManager.STREAM_ALARM;
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, soundArray.length, TEST_MODE);
track.write(soundArray, 0, soundArray.length);
}
I want the sound to play back, but instead the errors below are produced:
2019-02-13 20:19:29.665 16618-16653/com.xx.yy E/AudioTrack: AudioFlinger could not create track, status: -12
2019-02-13 20:19:29.666 16618-16653/com.xx.yy E/AudioTrack-JNI: Error -12 initializing AudioTrack
2019-02-13 20:19:29.667 16618-16653/com.xx.yy E/android.media.AudioTrack: Error code -20 when initializing AudioTrack.