From 3026a023b8979b7ddcb3fe97bbc45531c89fda92 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Mon, 27 Jul 2009 07:12:26 -0700 Subject: [PATCH] Fix issue 2001517: AudioTrack compatibility issue. Modified enum values in AudioFormat.java and AudioSystem.h. Added code for backward compatibility in AudioTrack.java and AudioRecord.java. --- api/current.xml | 86 ++++++++++++++--------- include/media/AudioSystem.h | 46 ++++++------ media/java/android/media/AudioFormat.java | 51 +++++++------- media/java/android/media/AudioRecord.java | 26 +++++-- media/java/android/media/AudioTrack.java | 25 +++++-- 5 files changed, 142 insertions(+), 92 deletions(-) diff --git a/api/current.xml b/api/current.xml index 4dee3d2ad8ed5..c81997273f4ac 100644 --- a/api/current.xml +++ b/api/current.xml @@ -73496,7 +73496,7 @@ type="int" transient="false" volatile="false" - value="-1" + value="0" static="true" final="true" deprecated="not deprecated" @@ -73507,7 +73507,7 @@ type="int" transient="false" volatile="false" - value="524288" + value="32" static="true" final="true" deprecated="not deprecated" @@ -73518,7 +73518,7 @@ type="int" transient="false" volatile="false" - value="8388608" + value="512" static="true" final="true" deprecated="not deprecated" @@ -73529,7 +73529,7 @@ type="int" transient="false" volatile="false" - value="0" + value="1" static="true" final="true" deprecated="not deprecated" @@ -73540,7 +73540,7 @@ type="int" transient="false" volatile="false" - value="262144" + value="16" static="true" final="true" deprecated="not deprecated" @@ -73551,7 +73551,7 @@ type="int" transient="false" volatile="false" - value="4194304" + value="256" static="true" final="true" deprecated="not deprecated" @@ -73562,7 +73562,7 @@ type="int" transient="false" volatile="false" - value="65536" + value="4" static="true" final="true" deprecated="not deprecated" @@ -73573,7 +73573,7 @@ type="int" transient="false" volatile="false" - value="1048576" + value="64" static="true" final="true" deprecated="not deprecated" @@ -73584,7 +73584,7 @@ type="int" transient="false" volatile="false" - value="262144" + value="16" static="true" final="true" deprecated="not deprecated" @@ -73595,7 +73595,7 @@ type="int" transient="false" volatile="false" - value="16777216" + value="1024" static="true" final="true" deprecated="not deprecated" @@ -73606,7 +73606,7 @@ type="int" transient="false" volatile="false" - value="131072" + value="8" static="true" final="true" deprecated="not deprecated" @@ -73617,7 +73617,7 @@ type="int" transient="false" volatile="false" - value="2097152" + value="128" static="true" final="true" deprecated="not deprecated" @@ -73628,7 +73628,29 @@ type="int" transient="false" volatile="false" - value="196608" + value="12" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> + + + +(this), - mRecordSource, mSampleRate, mChannelCount, mAudioFormat, mNativeBufferSizeInBytes); + mRecordSource, mSampleRate, mChannels, mAudioFormat, mNativeBufferSizeInBytes); if (initResult != SUCCESS) { loge("Error code "+initResult+" when initializing native AudioRecord object."); return; // with mState == STATE_UNINITIALIZED @@ -239,6 +243,7 @@ public class AudioRecord // postconditions: // mRecordSource is valid // mChannelCount is valid + // mChannels is valid // mAudioFormat is valid // mSampleRate is valid private void audioParamCheck(int audioSource, int sampleRateInHz, @@ -264,20 +269,25 @@ public class AudioRecord //-------------- // channel config + mChannelConfiguration = channelConfig; + switch (channelConfig) { - case AudioFormat.CHANNEL_IN_DEFAULT: + case AudioFormat.CHANNEL_IN_DEFAULT: // AudioFormat.CHANNEL_CONFIGURATION_DEFAULT case AudioFormat.CHANNEL_IN_MONO: + case AudioFormat.CHANNEL_CONFIGURATION_MONO: mChannelCount = 1; - mChannelConfiguration = AudioFormat.CHANNEL_IN_MONO; + mChannels = AudioFormat.CHANNEL_IN_MONO; break; case AudioFormat.CHANNEL_IN_STEREO: + case AudioFormat.CHANNEL_CONFIGURATION_STEREO: mChannelCount = 2; - mChannelConfiguration = AudioFormat.CHANNEL_IN_STEREO; + mChannels = AudioFormat.CHANNEL_IN_STEREO; break; default: mChannelCount = 0; - mChannelConfiguration = AudioFormat.CHANNEL_INVALID; - throw (new IllegalArgumentException("Unsupported channel configuration.")); + mChannels = AudioFormat.CHANNEL_INVALID; + mChannelConfiguration = AudioFormat.CHANNEL_INVALID; + throw (new IllegalArgumentException("Unsupported channel configuration.")); } //-------------- @@ -438,11 +448,13 @@ public class AudioRecord static public int getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat) { int channelCount = 0; switch(channelConfig) { - case AudioFormat.CHANNEL_IN_DEFAULT: + case AudioFormat.CHANNEL_IN_DEFAULT: // AudioFormat.CHANNEL_CONFIGURATION_DEFAULT case AudioFormat.CHANNEL_IN_MONO: + case AudioFormat.CHANNEL_CONFIGURATION_MONO: channelCount = 1; break; case AudioFormat.CHANNEL_IN_STEREO: + case AudioFormat.CHANNEL_CONFIGURATION_STEREO: channelCount = 2; break; case AudioFormat.CHANNEL_INVALID: diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java index 7fbe9658b7c70..1e8d72f47a34f 100644 --- a/media/java/android/media/AudioTrack.java +++ b/media/java/android/media/AudioTrack.java @@ -181,9 +181,14 @@ public class AudioTrack */ private int mSampleRate = 22050; /** - * The number of input audio channels (1 is mono, 2 is stereo). + * The number of audio output channels (1 is mono, 2 is stereo). */ private int mChannelCount = 1; + /** + * The audio channel mask. + */ + private int mChannels = AudioFormat.CHANNEL_OUT_MONO; + /** * The type of the audio stream to play. See * {@link AudioManager#STREAM_VOICE_CALL}, {@link AudioManager#STREAM_SYSTEM}, @@ -266,7 +271,7 @@ public class AudioTrack // native initialization int initResult = native_setup(new WeakReference(this), - mStreamType, mSampleRate, mChannelCount, mAudioFormat, + mStreamType, mSampleRate, mChannels, mAudioFormat, mNativeBufferSizeInBytes, mDataLoadMode); if (initResult != SUCCESS) { loge("Error code "+initResult+" when initializing AudioTrack."); @@ -286,6 +291,7 @@ public class AudioTrack // postconditions: // mStreamType is valid // mChannelCount is valid + // mChannels is valid // mAudioFormat is valid // mSampleRate is valid // mDataLoadMode is valid @@ -316,19 +322,24 @@ public class AudioTrack //-------------- // channel config + mChannelConfiguration = channelConfig; + switch (channelConfig) { - case AudioFormat.CHANNEL_OUT_DEFAULT: + case AudioFormat.CHANNEL_OUT_DEFAULT: //AudioFormat.CHANNEL_CONFIGURATION_DEFAULT case AudioFormat.CHANNEL_OUT_MONO: + case AudioFormat.CHANNEL_CONFIGURATION_MONO: mChannelCount = 1; - mChannelConfiguration = AudioFormat.CHANNEL_OUT_MONO; + mChannels = AudioFormat.CHANNEL_OUT_MONO; break; case AudioFormat.CHANNEL_OUT_STEREO: + case AudioFormat.CHANNEL_CONFIGURATION_STEREO: mChannelCount = 2; - mChannelConfiguration = AudioFormat.CHANNEL_OUT_STEREO; + mChannels = AudioFormat.CHANNEL_OUT_STEREO; break; default: mChannelCount = 0; - mChannelConfiguration = AudioFormat.CHANNEL_INVALID; + mChannels = AudioFormat.CHANNEL_INVALID; + mChannelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_INVALID; throw(new IllegalArgumentException("Unsupported channel configuration.")); } @@ -546,9 +557,11 @@ public class AudioTrack int channelCount = 0; switch(channelConfig) { case AudioFormat.CHANNEL_OUT_MONO: + case AudioFormat.CHANNEL_CONFIGURATION_MONO: channelCount = 1; break; case AudioFormat.CHANNEL_OUT_STEREO: + case AudioFormat.CHANNEL_CONFIGURATION_STEREO: channelCount = 2; break; default: