INDExOS / media-for-mobile

Media for Mobile
Other
456 stars 178 forks source link

Microphone recording not working if frame.getByteBuffer().isDirect() == false #70

Open sjvc opened 6 years ago

sjvc commented 6 years ago

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);

Hope it helps.