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

Commit 896a7f5f authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Clean up throws in AudioRecord and AudioTrack

Remove dead assignments to member fields in constructor prior to throw.
Execution doesn't continue execution, so no need to initialize fields.

throw doesn't need parentheses.

Fix indentation.

Change-Id: I2bf1b8bfa2c836e53a41eea67552cba40dc6fd43
parent 474daa2b
Loading
Loading
Loading
Loading
+14 −19
Original line number Original line Diff line number Diff line
@@ -256,19 +256,17 @@ public class AudioRecord
        // audio source
        // audio source
        if ( (audioSource < MediaRecorder.AudioSource.DEFAULT) ||
        if ( (audioSource < MediaRecorder.AudioSource.DEFAULT) ||
             (audioSource > MediaRecorder.getAudioSourceMax()) )  {
             (audioSource > MediaRecorder.getAudioSourceMax()) )  {
            throw (new IllegalArgumentException("Invalid audio source."));
            throw new IllegalArgumentException("Invalid audio source.");
        } else {
            mRecordSource = audioSource;
        }
        }
        mRecordSource = audioSource;


        //--------------
        //--------------
        // sample rate
        // sample rate
        if ( (sampleRateInHz < 4000) || (sampleRateInHz > 48000) ) {
        if ( (sampleRateInHz < 4000) || (sampleRateInHz > 48000) ) {
            throw (new IllegalArgumentException(sampleRateInHz
            throw new IllegalArgumentException(sampleRateInHz
                    + "Hz is not a supported sample rate."));
                    + "Hz is not a supported sample rate.");
        } else {
            mSampleRate = sampleRateInHz;
        }
        }
        mSampleRate = sampleRateInHz;


        //--------------
        //--------------
        // channel config
        // channel config
@@ -289,9 +287,7 @@ public class AudioRecord
            mChannelMask = channelConfig;
            mChannelMask = channelConfig;
            break;
            break;
        default:
        default:
            mChannelCount = 0;
            throw new IllegalArgumentException("Unsupported channel configuration.");
            mChannelMask = AudioFormat.CHANNEL_INVALID;
            throw (new IllegalArgumentException("Unsupported channel configuration."));
        }
        }


        //--------------
        //--------------
@@ -305,9 +301,8 @@ public class AudioRecord
            mAudioFormat = audioFormat;
            mAudioFormat = audioFormat;
            break;
            break;
        default:
        default:
            mAudioFormat = AudioFormat.ENCODING_INVALID;
            throw new IllegalArgumentException("Unsupported sample encoding."
        throw (new IllegalArgumentException("Unsupported sample encoding."
                    + " Should be ENCODING_PCM_8BIT or ENCODING_PCM_16BIT.");
                + " Should be ENCODING_PCM_8BIT or ENCODING_PCM_16BIT."));
        }
        }
    }
    }


@@ -324,7 +319,7 @@ public class AudioRecord
        int frameSizeInBytes = mChannelCount
        int frameSizeInBytes = mChannelCount
            * (mAudioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2);
            * (mAudioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2);
        if ((audioBufferSize % frameSizeInBytes != 0) || (audioBufferSize < 1)) {
        if ((audioBufferSize % frameSizeInBytes != 0) || (audioBufferSize < 1)) {
            throw (new IllegalArgumentException("Invalid audio buffer size."));
            throw new IllegalArgumentException("Invalid audio buffer size.");
        }
        }


        mNativeBufferSizeInBytes = audioBufferSize;
        mNativeBufferSizeInBytes = audioBufferSize;
@@ -509,8 +504,8 @@ public class AudioRecord
    public void startRecording()
    public void startRecording()
    throws IllegalStateException {
    throws IllegalStateException {
        if (mState != STATE_INITIALIZED) {
        if (mState != STATE_INITIALIZED) {
            throw(new IllegalStateException("startRecording() called on an "
            throw new IllegalStateException("startRecording() called on an "
                    +"uninitialized AudioRecord."));
                    + "uninitialized AudioRecord.");
        }
        }


        // start recording
        // start recording
@@ -531,8 +526,8 @@ public class AudioRecord
    public void startRecording(MediaSyncEvent syncEvent)
    public void startRecording(MediaSyncEvent syncEvent)
    throws IllegalStateException {
    throws IllegalStateException {
        if (mState != STATE_INITIALIZED) {
        if (mState != STATE_INITIALIZED) {
            throw(new IllegalStateException("startRecording() called on an "
            throw new IllegalStateException("startRecording() called on an "
                    +"uninitialized AudioRecord."));
                    + "uninitialized AudioRecord.");
        }
        }


        // start recording
        // start recording
@@ -550,7 +545,7 @@ public class AudioRecord
    public void stop()
    public void stop()
    throws IllegalStateException {
    throws IllegalStateException {
        if (mState != STATE_INITIALIZED) {
        if (mState != STATE_INITIALIZED) {
            throw(new IllegalStateException("stop() called on an uninitialized AudioRecord."));
            throw new IllegalStateException("stop() called on an uninitialized AudioRecord.");
        }
        }


        // stop recording
        // stop recording
+5 −13
Original line number Original line Diff line number Diff line
@@ -371,18 +371,16 @@ public class AudioTrack
           && (streamType != AudioManager.STREAM_BLUETOOTH_SCO)
           && (streamType != AudioManager.STREAM_BLUETOOTH_SCO)
           && (streamType != AudioManager.STREAM_DTMF)) {
           && (streamType != AudioManager.STREAM_DTMF)) {
            throw new IllegalArgumentException("Invalid stream type.");
            throw new IllegalArgumentException("Invalid stream type.");
        } else {
            mStreamType = streamType;
        }
        }
        mStreamType = streamType;


        //--------------
        //--------------
        // sample rate, note these values are subject to change
        // sample rate, note these values are subject to change
        if ( (sampleRateInHz < 4000) || (sampleRateInHz > 48000) ) {
        if ( (sampleRateInHz < 4000) || (sampleRateInHz > 48000) ) {
            throw new IllegalArgumentException(sampleRateInHz
            throw new IllegalArgumentException(sampleRateInHz
                    + "Hz is not a supported sample rate.");
                    + "Hz is not a supported sample rate.");
        } else {
            mSampleRate = sampleRateInHz;
        }
        }
        mSampleRate = sampleRateInHz;


        //--------------
        //--------------
        // channel config
        // channel config
@@ -403,15 +401,11 @@ public class AudioTrack
        default:
        default:
            if (!isMultichannelConfigSupported(channelConfig)) {
            if (!isMultichannelConfigSupported(channelConfig)) {
                // input channel configuration features unsupported channels
                // input channel configuration features unsupported channels
                mChannelCount = 0;
                mChannels = AudioFormat.CHANNEL_INVALID;
                mChannelConfiguration = AudioFormat.CHANNEL_INVALID;
                throw new IllegalArgumentException("Unsupported channel configuration.");
                throw new IllegalArgumentException("Unsupported channel configuration.");
            } else {
            }
            mChannels = channelConfig;
            mChannels = channelConfig;
            mChannelCount = Integer.bitCount(channelConfig);
            mChannelCount = Integer.bitCount(channelConfig);
        }
        }
        }


        //--------------
        //--------------
        // audio format
        // audio format
@@ -424,7 +418,6 @@ public class AudioTrack
            mAudioFormat = audioFormat;
            mAudioFormat = audioFormat;
            break;
            break;
        default:
        default:
            mAudioFormat = AudioFormat.ENCODING_INVALID;
            throw new IllegalArgumentException("Unsupported sample encoding."
            throw new IllegalArgumentException("Unsupported sample encoding."
                + " Should be ENCODING_PCM_8BIT or ENCODING_PCM_16BIT.");
                + " Should be ENCODING_PCM_8BIT or ENCODING_PCM_16BIT.");
        }
        }
@@ -433,9 +426,8 @@ public class AudioTrack
        // audio load mode
        // audio load mode
        if ( (mode != MODE_STREAM) && (mode != MODE_STATIC) ) {
        if ( (mode != MODE_STREAM) && (mode != MODE_STATIC) ) {
            throw new IllegalArgumentException("Invalid mode.");
            throw new IllegalArgumentException("Invalid mode.");
        } else {
            mDataLoadMode = mode;
        }
        }
        mDataLoadMode = mode;
    }
    }


    /**
    /**