increase buffer

This commit is contained in:
Alexey Kuznetsov 2016-09-29 16:24:12 +03:00
commit e4af28517b
5 changed files with 15 additions and 17 deletions

View file

@ -1,7 +1,7 @@
package com.github.axet.audiorecorder.encoders;
public interface Encoder {
void encode(short[] buf);
void encode(short[] buf, int len);
void flush();

View file

@ -39,19 +39,19 @@ public class FileEncoder {
samples = rs.getSamples();
short[] buf = new short[1000];
short[] buf = new short[2048];
rs.open(buf.length);
try {
while (!Thread.currentThread().isInterrupted()) {
long len = rs.read(buf);
int len = rs.read(buf);
if (len <= 0) {
encoder.flush();
handler.post(done);
return;
} else {
encoder.encode(buf);
encoder.encode(buf, len);
handler.post(progress);
synchronized (thread) {
cur += len;
@ -62,7 +62,6 @@ public class FileEncoder {
Log.e(TAG, "Exception", e);
t = e;
handler.post(error);
throw e;
} finally {
encoder.close();
if (rs != null) {

View file

@ -11,7 +11,7 @@ import java.util.Map;
public class FormatM4A extends MuxerMP4 {
public FormatM4A(EncoderInfo info, File out) {
Map<String, MediaCodecInfo> map = findEncoder("audio/mp4");
Map<String, MediaCodecInfo> map = MuxerMP4.findEncoder("audio/mp4");
if (map.isEmpty())
throw new RuntimeException("mp4 not supported");
MediaFormat format = MuxerMP4.getDefault("audio/mp4a-latm", map);

View file

@ -97,12 +97,12 @@ public class FormatWAV implements Encoder {
}
}
public void encode(short[] buf) {
NumSamples += buf.length / info.channels;
public void encode(short[] buf, int buflen) {
NumSamples += buflen / info.channels;
try {
ByteBuffer bb = ByteBuffer.allocate(buf.length * (Short.SIZE / Byte.SIZE));
ByteBuffer bb = ByteBuffer.allocate(buflen * (Short.SIZE / Byte.SIZE));
bb.order(order);
for (int i = 0; i < buf.length; i++)
for (int i = 0; i < buflen; i++)
bb.putShort(buf[i]);
bb.flip();
outFile.write(bb.array());

View file

@ -84,9 +84,10 @@ public class MuxerMP4 implements Encoder {
}
}
public void encode(short[] buf) {
for (int offset = 0; offset < buf.length; ) {
int len = buf.length - offset;
@Override
public void encode(short[] buf, int buflen) {
for (int offset = 0; offset < buflen; ) {
int len = buflen - offset;
int inputIndex = encoder.dequeueInputBuffer(-1);
if (inputIndex < 0)
@ -98,12 +99,10 @@ public class MuxerMP4 implements Encoder {
len = Math.min(len, input.limit() / 2);
for (int i = 0; i < len; i++)
input.putShort(buf[i]);
int bytes = len * 2;
input.putShort(buf[offset + i]);
long ts = getCurrentTimeStamp();
encoder.queueInputBuffer(inputIndex, 0, bytes, ts, 0);
encoder.queueInputBuffer(inputIndex, 0, input.position(), ts, 0);
NumSamples += len / info.channels;
offset += len;