FileDocCategorySizeDatePackage
EnvReverbTest.javaAPI DocAndroid 5.1 API19563Thu Mar 12 22:22:30 GMT 2015com.android.effectstest

EnvReverbTest

public class EnvReverbTest extends android.app.Activity implements android.widget.CompoundButton.OnCheckedChangeListener, SeekBar.OnSeekBarChangeListener

Fields Summary
private static final String
TAG
private static int
NUM_PARAMS
private EffectParameter[]
mParameters
private android.media.audiofx.EnvironmentalReverb
mReverb
android.widget.ToggleButton
mOnOffButton
android.widget.ToggleButton
mReleaseButton
android.widget.ToggleButton
mAttachButton
private static HashMap
sInstances
static SimplePlayer
sPlayerController
android.widget.SeekBar
mSendLevelSeekBar
android.widget.TextView
mSendLevelDisplay
static float
sSendLevel
static boolean
sAttached
String
mSettings
Constructors Summary
public EnvReverbTest()


      
        Log.d(TAG, "contructor");
    
Methods Summary
static intexpToLin(float exp, int range)

        if (exp == 0) return 0;
        return (int)(20*range*Math.log10((double)exp)/72 + range);
    
private voidgetEffect(int session)

        synchronized (sInstances) {
            if (sInstances.containsKey(session)) {
                mReverb = sInstances.get(session);
            } else {
                try{
                    mReverb = new EnvironmentalReverb(0, session);
                } catch (IllegalArgumentException e) {
                    Log.e(TAG,"Reverb effect not supported");
                } catch (UnsupportedOperationException e) {
                    Log.e(TAG,"Reverb library not loaded");
                } catch (RuntimeException e) {
                    Log.e(TAG,"Reverb effect not found");
                }
                Log.d(TAG, "new reverb: "+mReverb);
                sInstances.put(session, mReverb);
            }
        }
        mReleaseButton.setEnabled(false);
        mOnOffButton.setEnabled(false);
        mAttachButton.setEnabled(false);
        if (mReverb != null) {
            if (mSettings != "") {
                mReverb.setProperties(new EnvironmentalReverb.Settings(mSettings));
            }
            mReleaseButton.setChecked(true);
            mReleaseButton.setEnabled(true);
            mOnOffButton.setChecked(mReverb.getEnabled());
            mOnOffButton.setEnabled(true);
            mAttachButton.setChecked(false);
            mAttachButton.setEnabled(true);
            if (sAttached) {
                mAttachButton.setChecked(true);
                sPlayerController.attachAuxEffect(mReverb.getId());
            }
        }
    
static floatlinToExp(int lin, int range)

        if (lin == 0) return 0;
        return (float)Math.pow((double)10,(double)72*(lin-range)/(20*range));
    
public voidonCheckedChanged(android.widget.CompoundButton buttonView, boolean isChecked)

        if (buttonView.getId() == R.id.rvbOnOff) {
            if (mReverb != null) {
                mReverb.setEnabled(isChecked);
                Log.d(TAG,"onCheckedChanged: rvbOnOff");
                for (int i = 0 ; i < mParameters.length; i++) {
                    mParameters[i].updateDisplay();
                }
            }
        }
        if (buttonView.getId() == R.id.rvbReleaseButton) {
            if (isChecked) {
                if (mReverb == null) {
                    getEffect(0);
                    for (int i = 0 ; i < mParameters.length; i++) {
                        mParameters[i].setEffect(mReverb);
                        mParameters[i].setEnabled(true);
                    }
                }
            } else {
                if (mReverb != null) {
                    for (int i = 0 ; i < mParameters.length; i++) {
                        mParameters[i].setEnabled(false);
                    }
                    putEffect(0);
                }
            }
        }
//        if (buttonView.getId() == R.id.rvbBypass) {
//            // REVERB_PARAM_BYPASS parametervalue is 11 in EffectEnvironmentalReverApi.h
//            if (mReverb != null) {
//                if (isChecked) {
//                    mReverb.setParameter((int)11, (int)1);
//                } else {
//                    mReverb.setParameter((int)11, (int)0);
//                }
//            }
//        }
        if (buttonView.getId() == R.id.attachButton) {
            if (mReverb != null) {
                if (isChecked) {
                    sPlayerController.attachAuxEffect(mReverb.getId());
                    sAttached = true;
                } else {
                    sPlayerController.attachAuxEffect(0);
                    sAttached = false;
                }
            }
        }
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);
        Log.d(TAG, "onCreate");
        SeekBar seekBar;
        TextView textView;
        ToggleButton button;
        setContentView(R.layout.envreverbtest);

        ImageView playPause = (ImageView) findViewById(R.id.playPause1);
        ImageView stop = (ImageView) findViewById(R.id.stop1);
        textView = (TextView) findViewById(R.id.sessionText);
        if (sPlayerController == null) {
            sPlayerController = new SimplePlayer(this, R.id.playPause1, playPause,
                    R.id.stop1, stop, textView,
                    R.raw.mp3_sample, AudioManager.STREAM_MUSIC, 0);
        } else {
            sPlayerController.set(this, R.id.playPause1, playPause,
                    R.id.stop1, stop, textView,
                    AudioManager.STREAM_MUSIC, 0);
        }

        // send level
        mSendLevelSeekBar = (SeekBar)findViewById(R.id.sendLevelSeekBar);
        mSendLevelDisplay = (TextView)findViewById(R.id.sendLevelValue);
        mSendLevelSeekBar.setMax(100);
        mSendLevelSeekBar.setOnSeekBarChangeListener(this);
        mSendLevelSeekBar.setProgress(expToLin(sSendLevel,100));
        sPlayerController.setAuxEffectSendLevel(sSendLevel);

        mOnOffButton = (ToggleButton)findViewById(R.id.rvbOnOff);
        mReleaseButton = (ToggleButton)findViewById(R.id.rvbReleaseButton);
        mAttachButton = (ToggleButton)findViewById(R.id.attachButton);

        getEffect(0);

        if (mReverb != null) {
            mOnOffButton.setOnCheckedChangeListener(this);
            mReleaseButton.setOnCheckedChangeListener(this);
            mAttachButton.setOnCheckedChangeListener(this);

//            button = (ToggleButton)findViewById(R.id.rvbBypass);
//            button.setChecked(false);
//            button.setOnCheckedChangeListener(this);

            // Room level
            seekBar = (SeekBar)findViewById(R.id.rvbParam1SeekBar);
            textView = (TextView)findViewById(R.id.rvbParam1Value);
            mParameters[0] = new RoomLevelParam(mReverb, seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[0]);

            // Room HF level
            seekBar = (SeekBar)findViewById(R.id.rvbParam2SeekBar);
            textView = (TextView)findViewById(R.id.rvbParam2Value);
            mParameters[1] = new RoomHFLevelParam(mReverb, seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[1]);

            // Decay time
            seekBar = (SeekBar)findViewById(R.id.rvbParam3SeekBar);
            textView = (TextView)findViewById(R.id.rvbParam3Value);
            mParameters[2] = new DecayTimeParam(mReverb, seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[2]);

            // Decay HF ratio
            seekBar = (SeekBar)findViewById(R.id.rvbParam4SeekBar);
            textView = (TextView)findViewById(R.id.rvbParam4Value);
            mParameters[3] = new DecayHFRatioParam(mReverb, seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[3]);

            // Reflections level
            seekBar = (SeekBar)findViewById(R.id.rvbParam5SeekBar);
            textView = (TextView)findViewById(R.id.rvbParam5Value);
            mParameters[4] = new ReflectionsLevelParam(mReverb, seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[4]);

            // Reflections delay
            seekBar = (SeekBar)findViewById(R.id.rvbParam6SeekBar);
            textView = (TextView)findViewById(R.id.rvbParam6Value);
            mParameters[5] = new ReflectionsDelayParam(mReverb, seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[5]);

            // Reverb level
            seekBar = (SeekBar)findViewById(R.id.rvbParam7SeekBar);
            textView = (TextView)findViewById(R.id.rvbParam7Value);
            mParameters[6] = new ReverbLevelParam(mReverb, seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[6]);

            // Reverb delay
            seekBar = (SeekBar)findViewById(R.id.rvbParam8SeekBar);
            textView = (TextView)findViewById(R.id.rvbParam8Value);
            mParameters[7] = new ReverbDelayParam(mReverb, seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[7]);

            // Diffusion
            seekBar = (SeekBar)findViewById(R.id.rvbParam9SeekBar);
            textView = (TextView)findViewById(R.id.rvbParam9Value);
            mParameters[8] = new DiffusionParam(mReverb, seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[8]);

            // Density
            seekBar = (SeekBar)findViewById(R.id.rvbParam10SeekBar);
            textView = (TextView)findViewById(R.id.rvbParam10Value);
            mParameters[9] = new DensityParam(mReverb, seekBar, textView);
            seekBar.setOnSeekBarChangeListener(mParameters[9]);
        }
    
public voidonPause()

        super.onPause();
    
public voidonProgressChanged(android.widget.SeekBar seekBar, int progress, boolean fromTouch)


        if (seekBar != mSendLevelSeekBar) {
            Log.e(TAG, "onProgressChanged called with wrong seekBar");
            return;
        }

        sSendLevel = linToExp(progress,100);
        if (fromTouch) {
            sPlayerController.setAuxEffectSendLevel(sSendLevel);
        }
        String text = Float.toString(sSendLevel);
        mSendLevelDisplay.setText(text);
        if (!fromTouch) {
            seekBar.setProgress(progress);
        }
    
public voidonResume()

        super.onResume();
        Log.d(TAG, "onResume");
    
public voidonStartTrackingTouch(android.widget.SeekBar seekBar)

    
public voidonStopTrackingTouch(android.widget.SeekBar seekBar)

    
private voidputEffect(int session)

        mOnOffButton.setChecked(false);
        mOnOffButton.setEnabled(false);
        mAttachButton.setChecked(false);
        mAttachButton.setEnabled(false);
        synchronized (sInstances) {
            if (mReverb != null) {
                mSettings = mReverb.getProperties().toString();
                mReverb.release();
                Log.d(TAG,"Reverb released, settings: "+mSettings);
                mReverb = null;
                sInstances.remove(session);
            }
        }