0

I'm trying to process the audio buffer in the Android ExoPlayer. In the writeBuffer function of the DefaultAudioSink class, Audio data's coming in a ByteBuffer object. In my case, I want to get the values (as Byte[] if possible) from this ByteBuffer to process the datas before to create a new ByteBuffer and give it to the audioTrack.

I firstly tried to clone the original ByteBuffer in a new ByteBuffer, then send it to the audioTrack (as described in Deep copy duplicate() of Java's ByteBuffer ), to verify it is still working. But the result is an empty buffer for the destination AND the original one (as with this solution)

public static ByteBuffer clone(ByteBuffer original) {
    ByteBuffer clone = ByteBuffer.allocate(original.capacity());
    original.rewind();//copy from the beginning
    clone.put(original);
    original.rewind();
    clone.flip();
    return clone;
}

or something like accelerated audio (if I remove the rewind calls).

A simple

ByteBuffer newBuffer = buffer.duplicate();

has the same behavior.

I'm trying to understand why I can't get a working duplicated audio ByteBuffer, that I can transfer to the AudioTrack and hear the same sound.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ben.
  • 45
  • 6

1 Answers1

0

Have you tried copying and wrapping the returned ByteBuffer's array? i.e.

byte[] copy = Arrays.copyOf(original.array(), original.array().length)
return ByteBuffer.wrap(copy, 0, copy.length)
Submersed
  • 8,810
  • 2
  • 30
  • 38