Skip to content

Commit

Permalink
audio just noise and pts messed up
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaji Khan committed Mar 18, 2024
1 parent 9880122 commit 0549864
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions app/src/main/java/com/shajikhan/ladspa/amprack/Camera2.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,15 @@ private void prepareEncoder() {
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
Log.d(TAG, "format: " + format);

MediaFormat outputFormat = MediaFormat.createAudioFormat("audio/mp4a-latm", sampleRate, 1);
// MediaFormat outputFormat = MediaFormat.createAudioFormat("audio/mp4a-latm", sampleRate, 1);
MediaFormat outputFormat = new MediaFormat();
outputFormat.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
outputFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
outputFormat.setInteger(MediaFormat.KEY_BIT_RATE, 160000);
outputFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 16384);
// outputFormat.setInteger(MediaFormat.KEY_PCM_ENCODING, AudioFormat.ENCODING_PCM_FLOAT);
outputFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
outputFormat.setInteger(MediaFormat.KEY_PCM_ENCODING, AudioFormat.ENCODING_PCM_FLOAT);
outputFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, AudioEngine.getSampleRate());

// Create a MediaCodec encoder, and configure it with our format. Get a Surface
// we can use for input and wrap it with a class that handles the EGL work.
Expand Down Expand Up @@ -329,12 +333,13 @@ public void onInputBufferAvailable(@NonNull MediaCodec codec, int index) {
ByteBuffer buffer = codec.getInputBuffer(index);

avBuffer = mainActivity.avBuffer.pop();
avBuffer.floatBuffer.rewind();
// buffer.asFloatBuffer().put(avBuffer.floatBuffer);
// buffer.asFloatBuffer().put(avBuffer.floatBuffer);
// buffer.rewind();
for (int i = 0 ; i < avBuffer.size ; i ++)
buffer.putInt(i, (int) (avBuffer.floatBuffer.get(i) * 32767f));
buffer.rewind();
for (int i = 0 ; i < avBuffer.size ; i ++) {
buffer.putShort(i, (short) (avBuffer.floats [i] * 30000));
// Log.d(TAG, "onInputBufferAvailable: " + avBuffer.floats [i]);
}

Log.d(TAG, "[audio] onInputBufferAvailable: queued input buffer of size " + avBuffer.size +
String.format(" {%d:%d}", buffer.get(0), buffer.get(avBuffer.size - 1)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public class MainActivity extends AppCompatActivity implements ActivityCompat.On
boolean videoRecording = false ;
Camera2 camera2 ;
static class AVBuffer {
FloatBuffer floatBuffer ;
float [] floats ;
int size ;
}
public static LinkedList<AVBuffer> avBuffer = new LinkedList<>();
Expand Down Expand Up @@ -3438,8 +3438,8 @@ public static void pushToVideo (float [] data, int nframes) {
return;

AVBuffer buffer = new AVBuffer();
buffer.floatBuffer = FloatBuffer.wrap(data.clone());
buffer.size = nframes;
buffer.floats = data.clone();
avBuffer.addLast(buffer);
}

Expand Down

0 comments on commit 0549864

Please sign in to comment.