Testing the library, I've found that when using the code inside else block of if (frame.getByteBuffer().isDirect()) in org.m4m.android.MicrophoneSource, the generated video runs faster, and there is no audio.
So I've changed this:
short [] buffer = new short[bufferSize];
actualRead = recorder.read(buffer, 0, bufferSize);
byte[] bytes = new byte[buffer.length * 2];
ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().put(buffer);
ByteBuffer bb = ByteBuffer.allocate(minBufferSize).put(bytes);
To this to make it work:
short [] buffer = new short[bufferSize / 2];
actualRead = recorder.read(buffer, 0, buffer.length) * 2;
frame.getByteBuffer().order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().put(buffer);
buffer should be half size of bufferSize, because 1 short = 2 bytes.
actualRead should be the double of short read because of the same reason.
There is no need to allocate a new byte array, and then a new ByteBuffer. We can (and should) use frame.getByteBuffer() directly.
For simplicity, here I'm allocating a new short array on each pull(Frame frame) call, but I'm really using a class attribute instead of a local variable, and I only instantiate it 1 time.
Testing the library, I've found that when using the code inside else block of
if (frame.getByteBuffer().isDirect())
inorg.m4m.android.MicrophoneSource
, the generated video runs faster, and there is no audio.So I've changed this:
To this to make it work:
buffer
should be half size of bufferSize, because 1 short = 2 bytes.actualRead
should be the double of short read because of the same reason.frame.getByteBuffer()
directly.pull(Frame frame)
call, but I'm really using a class attribute instead of a local variable, and I only instantiate it 1 time.Hope it helps.