Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 33c437df authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Rename mChannels to mChannelMask to avoid ambiguity

This clarifies that it's a channel mask, as opposed to a count.

Also no need to initialize the field in the declaration,
as it's initialized in the constructor.

Include channel mask in error logs.

Change-Id: Ifc02668cf922dc8826a9fb042b3ca52fad377ba6
parent d5af2381
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -156,18 +156,19 @@ static sp<AudioRecord> setAudioRecord(JNIEnv* env, jobject thiz, const sp<AudioR
// ----------------------------------------------------------------------------
static int
android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
        jint source, jint sampleRateInHertz, jint channels,
        jint source, jint sampleRateInHertz, jint channelMask,
                // Java channel masks map directly to the native definition
        jint audioFormat, jint buffSizeInBytes, jintArray jSession)
{
    //ALOGV(">> Entering android_media_AudioRecord_setup");
    //ALOGV("sampleRate=%d, audioFormat=%d, channels=%x, buffSizeInBytes=%d",
    //     sampleRateInHertz, audioFormat, channels,     buffSizeInBytes);
    //ALOGV("sampleRate=%d, audioFormat=%d, channel mask=%x, buffSizeInBytes=%d",
    //     sampleRateInHertz, audioFormat, channelMask, buffSizeInBytes);

    if (!audio_is_input_channel(channels)) {
        ALOGE("Error creating AudioRecord: channel count is not 1 or 2.");
    if (!audio_is_input_channel(channelMask)) {
        ALOGE("Error creating AudioRecord: channel mask %#x is not valid.", channelMask);
        return AUDIORECORD_ERROR_SETUP_INVALIDCHANNELMASK;
    }
    uint32_t nbChannels = popcount(channels);
    uint32_t nbChannels = popcount(channelMask);

    // compare the format against the Java constants
    if ((audioFormat != javaAudioRecordFields.PCM16)
@@ -226,7 +227,7 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
    lpRecorder->set((audio_source_t) source,
        sampleRateInHertz,
        format,        // word length, PCM
        channels,
        channelMask,
        frameCount,
        recorderCallback,// callback_t
        lpCallbackData,// void* user
+1 −1
Original line number Diff line number Diff line
@@ -218,7 +218,7 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
    uint32_t nativeChannelMask = ((uint32_t)javaChannelMask) >> 2;

    if (!audio_is_output_channel(nativeChannelMask)) {
        ALOGE("Error creating AudioTrack: invalid channel mask.");
        ALOGE("Error creating AudioTrack: invalid channel mask %#x.", javaChannelMask);
        return AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK;
    }

+8 −8
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ public class AudioRecord
    /**
     * The audio channel mask
     */
    private int mChannels = AudioFormat.CHANNEL_IN_MONO;
    private int mChannelMask;
    /**
     * The encoding of the audio samples.
     * @see AudioFormat#ENCODING_PCM_8BIT
@@ -228,7 +228,7 @@ public class AudioRecord
        //TODO: update native initialization when information about hardware init failure
        //      due to capture device already open is available.
        int initResult = native_setup( new WeakReference<AudioRecord>(this),
                mRecordSource, mSampleRate, mChannels, mAudioFormat, mNativeBufferSizeInBytes,
                mRecordSource, mSampleRate, mChannelMask, mAudioFormat, mNativeBufferSizeInBytes,
                session);
        if (initResult != SUCCESS) {
            loge("Error code "+initResult+" when initializing native AudioRecord object.");
@@ -246,7 +246,7 @@ public class AudioRecord
    // postconditions:
    //    mRecordSource is valid
    //    mChannelCount is valid
    //    mChannels is valid
    //    mChannelMask is valid
    //    mAudioFormat is valid
    //    mSampleRate is valid
    private void audioParamCheck(int audioSource, int sampleRateInHz,
@@ -277,20 +277,20 @@ public class AudioRecord
        case AudioFormat.CHANNEL_IN_MONO:
        case AudioFormat.CHANNEL_CONFIGURATION_MONO:
            mChannelCount = 1;
            mChannels = AudioFormat.CHANNEL_IN_MONO;
            mChannelMask = AudioFormat.CHANNEL_IN_MONO;
            break;
        case AudioFormat.CHANNEL_IN_STEREO:
        case AudioFormat.CHANNEL_CONFIGURATION_STEREO:
            mChannelCount = 2;
            mChannels = AudioFormat.CHANNEL_IN_STEREO;
            mChannelMask = AudioFormat.CHANNEL_IN_STEREO;
            break;
        case (AudioFormat.CHANNEL_IN_FRONT | AudioFormat.CHANNEL_IN_BACK):
            mChannelCount = 2;
            mChannels = channelConfig;
            mChannelMask = channelConfig;
            break;
        default:
            mChannelCount = 0;
            mChannels = AudioFormat.CHANNEL_INVALID;
            mChannelMask = AudioFormat.CHANNEL_INVALID;
            throw (new IllegalArgumentException("Unsupported channel configuration."));
        }

@@ -386,7 +386,7 @@ public class AudioRecord
     * and {@link AudioFormat#CHANNEL_IN_STEREO}.
     */
    public int getChannelConfiguration() {
        return mChannels;
        return mChannelMask;
    }

    /**