Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Unified Diff: webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java

Issue 2499613002: Adds stereo support for Java-based input and output audio on Android (Closed)
Patch Set: Feedback from magjed@ Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java
diff --git a/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java
index 3bda070eac1069a291c15fd4d85d92fb01d09faa..c3665442b06260557cf94c8e5cd2724926773da7 100644
--- a/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java
+++ b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java
@@ -170,8 +170,9 @@ public class WebRtcAudioRecord {
// Get the minimum buffer size required for the successful creation of
// an AudioRecord object, in byte units.
// Note that this size doesn't guarantee a smooth recording under load.
- int minBufferSize = AudioRecord.getMinBufferSize(
- sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
+ final int channelConfig = channelCountToConfiguration(channels);
+ int minBufferSize =
+ AudioRecord.getMinBufferSize(sampleRate, channelConfig, AudioFormat.ENCODING_PCM_16BIT);
if (minBufferSize == AudioRecord.ERROR || minBufferSize == AudioRecord.ERROR_BAD_VALUE) {
Logging.e(TAG, "AudioRecord.getMinBufferSize failed: " + minBufferSize);
return -1;
@@ -184,8 +185,8 @@ public class WebRtcAudioRecord {
int bufferSizeInBytes = Math.max(BUFFER_SIZE_FACTOR * minBufferSize, byteBuffer.capacity());
Logging.d(TAG, "bufferSizeInBytes: " + bufferSizeInBytes);
try {
- audioRecord = new AudioRecord(AudioSource.VOICE_COMMUNICATION, sampleRate,
- AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSizeInBytes);
+ audioRecord = new AudioRecord(AudioSource.VOICE_COMMUNICATION, sampleRate, channelConfig,
+ AudioFormat.ENCODING_PCM_16BIT, bufferSizeInBytes);
} catch (IllegalArgumentException e) {
Logging.e(TAG, e.getMessage());
return -1;
@@ -246,7 +247,7 @@ public class WebRtcAudioRecord {
// created instance uses the parameters that we asked for.
private boolean areParametersValid(int sampleRate, int channels) {
return (audioRecord.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT
- && audioRecord.getChannelConfiguration() == AudioFormat.CHANNEL_IN_MONO
+ && audioRecord.getChannelConfiguration() == channelCountToConfiguration(channels)
&& audioRecord.getAudioSource() == AudioSource.VOICE_COMMUNICATION
&& audioRecord.getSampleRate() == sampleRate && audioRecord.getChannelCount() == channels);
}
@@ -273,6 +274,10 @@ public class WebRtcAudioRecord {
}
}
+ private int channelCountToConfiguration(int channels) {
+ return (channels == 1 ? AudioFormat.CHANNEL_IN_MONO : AudioFormat.CHANNEL_IN_STEREO);
+ }
+
private native void nativeCacheDirectBufferAddress(ByteBuffer byteBuffer, long nativeAudioRecord);
private native void nativeDataIsRecorded(int bytes, long nativeAudioRecord);

Powered by Google App Engine
This is Rietveld 408576698