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

Commit 2db73305 authored by Eric Laurent's avatar Eric Laurent Committed by Android Git Automerger
Browse files

am dfded35b: Merge "Added automated tests for reverb audio effect." into gingerbread

Merge commit 'dfded35b' into gingerbread-plus-aosp

* commit 'dfded35b':
  Added automated tests for reverb audio effect.
parents 9509a0ce dfded35b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -27,7 +27,9 @@ import com.android.mediaframeworktest.functional.MediaPlayerInvokeTest;
import com.android.mediaframeworktest.functional.MediaAudioManagerTest;
import com.android.mediaframeworktest.functional.MediaAudioEffectTest;
import com.android.mediaframeworktest.functional.MediaBassBoostTest;
import com.android.mediaframeworktest.functional.MediaEnvReverbTest;
import com.android.mediaframeworktest.functional.MediaEqualizerTest;
import com.android.mediaframeworktest.functional.MediaPresetReverbTest;
import com.android.mediaframeworktest.functional.MediaVirtualizerTest;
import com.android.mediaframeworktest.functional.MediaVisualizerTest;
import junit.framework.TestSuite;
@@ -62,7 +64,9 @@ public class MediaFrameworkTestRunner extends InstrumentationTestRunner {
        suite.addTestSuite(MediaAudioManagerTest.class);
        suite.addTestSuite(MediaAudioEffectTest.class);
        suite.addTestSuite(MediaBassBoostTest.class);
        suite.addTestSuite(MediaEnvReverbTest.class);
        suite.addTestSuite(MediaEqualizerTest.class);
        suite.addTestSuite(MediaPresetReverbTest.class);
        suite.addTestSuite(MediaVirtualizerTest.class);
        suite.addTestSuite(MediaVisualizerTest.class);
        return suite;
+106 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.mediaframeworktest.functional;

import android.media.Visualizer;
import android.util.Log;

/**
 * The EnergyProbe class provides audio signal energy measurements based on the FFT returned
 * by the Visualizer class. The measure is qualitative and not quantitative in that the returned
 * value has no unit and is just proportional to the amount of energy present around the
 * specified frequency.
 */

public class EnergyProbe {
    private String TAG = "EnergyProbe";

    private static int CAPTURE_SIZE = 1024;
    private static int MEASURE_COUNT = 5;
    private static int AVERAGE_COUNT = 3;

    private Visualizer mVisualizer = null;
    private int mMaxFrequency = 0;
    private int mCapturePeriodMs;
    private byte[] mFft = new byte[CAPTURE_SIZE];

    public EnergyProbe(int session) {
        try {
            mVisualizer = new Visualizer(session);
            if (mVisualizer != null) {
                mVisualizer.setCaptureSize(CAPTURE_SIZE);
                mMaxFrequency = mVisualizer.getSamplingRate() / 2000;
                mCapturePeriodMs = 1000000 / mVisualizer.getMaxCaptureRate();
            }
        } catch (UnsupportedOperationException e) {
            Log.e(TAG, "Error creating visualizer");
        } catch (IllegalStateException e) {
            Log.e(TAG, "Error configuring visualizer");
        }
    }

    public int capture(int freq) throws InterruptedException {
        int energy = 0;
        int count = 0;

        if (freq > mMaxFrequency) {
            return 0;
        }

        if (mVisualizer != null) {
            try {
                mVisualizer.setEnabled(true);
                for (int i = 0; i < MEASURE_COUNT; i++) {
                    if (mVisualizer.getFft(mFft) == Visualizer.SUCCESS) {
                        if (freq == mMaxFrequency) {
                            energy += (int)mFft[0] * (int)mFft[0];
                        } else {
                            int bin = 2 * (freq * CAPTURE_SIZE / mMaxFrequency / 2);
                            if (bin < 2) bin = 2;
                            int tmp = 0;
                            int j;
                            for (j = 0;
                                 (j < AVERAGE_COUNT) && ((bin + 2 * j) < CAPTURE_SIZE);
                                 j++) {
                                tmp += (int)mFft[bin + 2 * j] * (int)mFft[bin + 2 * j] +
                                       (int)mFft[bin + 2 * j + 1] * (int)mFft[bin + 2 * j + 1];
                            }
                            // j is always != 0
                            energy += tmp/j;
                        }
                        count++;
                    }
                    Thread.sleep(mCapturePeriodMs);
                }
                mVisualizer.setEnabled(false);
            } catch (IllegalStateException e) {
                Log.e(TAG, "Error capturing audio");
            }
        }
        if (count == 0) {
            return 0;
        }
        return energy/count;
    }

    public void release() {
        if (mVisualizer != null) {
            mVisualizer.release();
            mVisualizer = null;
        }
    }
}
+1 −47
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ import java.util.UUID;
 */
public class MediaBassBoostTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> {
    private String TAG = "MediaBassBoostTest";
    private final static int MIN_ENERGY_RATIO_2 = 4;
    private final static int MIN_ENERGY_RATIO_2 = 3;
    private final static short TEST_STRENGTH = 500;

    private BassBoost mBassBoost = null;
@@ -259,52 +259,6 @@ public class MediaBassBoostTest extends ActivityInstrumentationTestCase2<MediaFr
    // private methods
    //----------------------------------

    private class EnergyProbe {
        Visualizer mVisualizer = null;
        private byte[] mFft = new byte[1024];

        public EnergyProbe(int session) {
            mVisualizer = new Visualizer(session);
            mVisualizer.setCaptureSize(1024);
        }

        public int capture(int freq) throws InterruptedException {
            int energy = 0;
            int count = 0;
            if (mVisualizer != null) {
                mVisualizer.setEnabled(true);
                for (int i = 0; i < 10; i++) {
                    if (mVisualizer.getFft(mFft) == Visualizer.SUCCESS) {
                        // TODO: check speex FFT as it seems to return only the number of points
                        // correspondong to valid part of the spectrum (< Fs).
                        // e.g., if the number of points is 1024, it covers the frequency range
                        // 0 to 22050 instead of 0 to 44100 as expected from an FFT.
                        int bin = freq / (22050 / 1024);
                        int tmp = 0;
                        for (int j = bin-2; j < bin+3; j++) {
                            tmp += (int)mFft[j] * (int)mFft[j];
                        }
                        energy += tmp/5;
                        count++;
                    }
                    Thread.sleep(50);
                }
                mVisualizer.setEnabled(false);
            }
            if (count == 0) {
                return 0;
            }
            return energy/count;
        }

        public void release() {
            if (mVisualizer != null) {
                mVisualizer.release();
                mVisualizer = null;
            }
        }
    }

    private void getBassBoost(int session) {
         if (mBassBoost == null || session != mSession) {
             if (session != mSession && mBassBoost != null) {
+508 −0

File added.

Preview size limit exceeded, changes collapsed.

+0 −46
Original line number Diff line number Diff line
@@ -322,52 +322,6 @@ public class MediaEqualizerTest extends ActivityInstrumentationTestCase2<MediaFr
    // private methods
    //----------------------------------

    private class EnergyProbe {
        Visualizer mVisualizer = null;
        private byte[] mFft = new byte[1024];

        public EnergyProbe(int session) {
            mVisualizer = new Visualizer(session);
            mVisualizer.setCaptureSize(1024);
        }

        public int capture(int freq) throws InterruptedException {
            int energy = 0;
            int count = 0;
            if (mVisualizer != null) {
                mVisualizer.setEnabled(true);
                for (int i = 0; i < 10; i++) {
                    if (mVisualizer.getFft(mFft) == Visualizer.SUCCESS) {
                        // TODO: check speex FFT as it seems to return only the number of points
                        // correspondong to valid part of the spectrum (< Fs).
                        // e.g., if the number of points is 1024, it covers the frequency range
                        // 0 to 22050 instead of 0 to 44100 as expected from an FFT.
                        int bin = freq / (22050 / 1024);
                        int tmp = 0;
                        for (int j = bin-2; j < bin+3; j++) {
                            tmp += (int)mFft[j] * (int)mFft[j];
                        }
                        energy += tmp/5;
                        count++;
                    }
                    Thread.sleep(50);
                }
                mVisualizer.setEnabled(false);
            }
            if (count == 0) {
                return 0;
            }
            return energy/count;
        }

        public void release() {
            if (mVisualizer != null) {
                mVisualizer.release();
                mVisualizer = null;
            }
        }
    }

    private void getEqualizer(int session) {
         if (mEqualizer == null || session != mSession) {
             if (session != mSession && mEqualizer != null) {
Loading