10f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent/*
20f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * Copyright (C) 2011 The Android Open Source Project
30f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent *
40f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
50f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * you may not use this file except in compliance with the License.
60f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * You may obtain a copy of the License at
70f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent *
80f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
90f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent *
100f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * Unless required by applicable law or agreed to in writing, software
110f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
120f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * See the License for the specific language governing permissions and
140f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * limitations under the License.
150f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */
160f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent
170f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurentpackage android.media.audiofx;
180f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent
190f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent/**
200f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * Automatic Gain Control (AGC).
210f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * <p>Automatic Gain Control (AGC) is an audio pre-processing which automatically normalizes the
220f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * output of the captured signal by boosting or lowering input from the microphone to match a preset
230f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * level so that that the output signal level is virtually constant.
240f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * AGC can be used by applications where the input signal dynamic range is not important but where
250f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * a constant strong capture level is desired.
260f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * <p>An application creates a AutomaticGainControl object to instantiate and control an AGC
270f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * engine in the audio framework.
280f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * <p>To attach the AutomaticGainControl to a particular {@link android.media.AudioRecord},
290f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * specify the audio session ID of this AudioRecord when constructing the AutomaticGainControl.
300f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * The audio session is retrieved by calling
310f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * {@link android.media.AudioRecord#getAudioSessionId()} on the AudioRecord instance.
320f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * <p>On some devices, an AGC can be inserted by default in the capture path by the platform
330f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * according to the {@link android.media.MediaRecorder.AudioSource} used. The application can
340f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * query which pre-processings are currently applied to an AudioRecord instance by calling
350f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * {@link android.media.audiofx.AudioEffect#queryPreProcessings(int)} with the audio session of the
360f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * AudioRecord.
370f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * <p>See {@link android.media.audiofx.AudioEffect} class for more details on
380f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * controlling audio effects.
390f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent * @hide
400f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent */
410f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent
420f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurentpublic class AutomaticGainControl extends AudioEffect {
430f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent
440f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent    private final static String TAG = "AutomaticGainControl";
450f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent
460f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent    /**
470f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     * Class constructor.
480f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     * <p> The application must catch exceptions when creating an AutomaticGainControl as the
490f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     * constructor is not guarantied to succeed:
500f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     * <ul>
510f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     *  <li>IllegalArgumentException is thrown if the device does not implement an AGC</li>
520f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     *  <li>UnsupportedOperationException is thrown is the resources allocated to audio
530f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     *  pre-procesing are currently exceeded.</li>
540f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     * </ul>
550f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     *
560f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     * @param audioSession system wide unique audio session identifier. The AutomaticGainControl
570f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     * will be applied to the AudioRecord with the same audio session.
580f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     *
590f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     * @throws java.lang.IllegalArgumentException
600f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     * @throws java.lang.UnsupportedOperationException
610f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     * @throws java.lang.RuntimeException
620f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent     */
630f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent    public AutomaticGainControl(int audioSession)
640f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent            throws IllegalArgumentException, UnsupportedOperationException, RuntimeException {
650f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent        super(EFFECT_TYPE_AGC, EFFECT_TYPE_NULL, 0, audioSession);
660f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent    }
670f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent}
68