android.media.audiofx.Visualizer Java Examples

The following examples show how to use android.media.audiofx.Visualizer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardVisualizer.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized int getFft(byte[] fft) throws IllegalStateException {
    if (fft == null)
        return Visualizer.ERROR_BAD_VALUE;

    // workaround: Fix mState variable
    mVisualizer.setEnabled(mVisualizer.getEnabled());

    getCaptureSizeAndUpdateField();

    if (fft.length != mCaptureSize) {
        // NOTE: To avoid app crash in native layer...
        return IVisualizer.ERROR_BAD_VALUE;
    }

    return mVisualizer.getFft(fft);
}
 
Example #2
Source File: StandardVisualizer.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized int getWaveForm(byte[] waveform) throws IllegalStateException {
    if (waveform == null)
        return Visualizer.ERROR_BAD_VALUE;

    // workaround: Fix mState variable
    mVisualizer.setEnabled(mVisualizer.getEnabled());

    getCaptureSizeAndUpdateField();

    if (waveform.length != mCaptureSize) {
        // NOTE: To avoid app crash in native layer...
        return IVisualizer.ERROR_BAD_VALUE;
    }

    return mVisualizer.getWaveForm(waveform);
}
 
Example #3
Source File: HQVisualizerTestCase.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private void checkSetCaptureSizeWhenEnabledWithValidParameters(
        IBasicMediaPlayer player) {
    IHQVisualizer visualizer = null;

    try {
        visualizer = createVisualizer(player);

        int[] range = Visualizer.getCaptureSizeRange();

        assertEquals(IHQVisualizer.SUCCESS, visualizer.setEnabled(true));
        assertTrue(visualizer.getEnabled());

        for (int value = range[0] * 2; value <= range[1]; value *= 2) {
            checkSetCaptureSizeIllegalStateException(visualizer, value);
        }
    } finally {
        releaseQuietly(visualizer);
    }
}
 
Example #4
Source File: VisualizerShadowChanger.java    From PlayWidget with MIT License 6 votes vote down vote up
@Override
public void onFftDataCapture(Visualizer visualizer, byte[] fft, int samplingRate) {
    int dataSize = fft.length / 2 - 1;
    for (int i = 0; i < SOUND_INDEX_COEFFICIENTS.length; i++) {
        int index = (int) (SOUND_INDEX_COEFFICIENTS[i] * dataSize);
        byte real = fft[2 * index];
        byte imag = fft[2 * index + 1];
        long magnitudeSquare = real * real + imag * imag;
        magnitudeSquare = (long) Math.sqrt(magnitudeSquare);
        float dbs = magnitudeToDb(magnitudeSquare);
        float dbPercentage = dbs / MAX_DB_VALUE;
        if (dbPercentage > 1.0f) {
            dbPercentage = 1.0f;
        }
        mDbsPercentagesConcrete[i] = mDbsPercentagesConcrete[i] * FILTRATION_ALPHA + dbPercentage * FILTRATION_BETA;
    }

    changeShadow(mDbsPercentagesConcrete[0], mDbsPercentagesConcrete[1], mDbsPercentagesConcrete[2]);

}
 
Example #5
Source File: HQVisualizerTestCase.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private void checkSetCaptureSizeWithVaildParameters(IBasicMediaPlayer player) {
    IHQVisualizer visualizer = null;

    try {
        visualizer = createVisualizer(player);

        int[] range = Visualizer.getCaptureSizeRange();

        assertFalse(visualizer.getEnabled());

        for (int value = range[0] * 2; value <= range[1]; value *= 2) {
            checkSetCaptureSizeSUCCESS(visualizer, value);
        }
    } finally {
        releaseQuietly(visualizer);
    }
}
 
Example #6
Source File: VisualizerTestCase.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private void checkSetCaptureSizeWithVaildParameters(IBasicMediaPlayer player) {
    IVisualizer visualizer = null;

    try {
        visualizer = createVisualizer(player);

        int[] range = Visualizer.getCaptureSizeRange();

        assertFalse(visualizer.getEnabled());

        for (int value = range[0] * 2; value <= range[1]; value *= 2) {
            checkSetCaptureSizeSUCCESS(visualizer, value);
        }
    } finally {
        releaseQuietly(visualizer);
    }
}
 
Example #7
Source File: VisualizerTestCase.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private void checkSetCaptureSizeWhenEnabledWithValidParameters(
        IBasicMediaPlayer player) {
    IVisualizer visualizer = null;

    try {
        visualizer = createVisualizer(player);

        int[] range = Visualizer.getCaptureSizeRange();

        assertEquals(IVisualizer.SUCCESS, visualizer.setEnabled(true));
        assertTrue(visualizer.getEnabled());

        for (int value = range[0] * 2; value <= range[1]; value *= 2) {
            checkSetCaptureSizeIllegalStateException(visualizer, value);
        }
    } finally {
        releaseQuietly(visualizer);
    }
}
 
Example #8
Source File: VisualizerCompatKitKat.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public int getMeasurementPeakRmsCompat(Visualizer visualizer,
        IVisualizer.MeasurementPeakRms measurement) {
    Visualizer.MeasurementPeakRms tmp = new Visualizer.MeasurementPeakRms();
    int result = visualizer.getMeasurementPeakRms(tmp);

    measurement.mPeak = tmp.mPeak;
    measurement.mRms = tmp.mRms;

    return result;
}
 
Example #9
Source File: StandardVisualizer.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
public StandardVisualizer(Context context, int audioSession) {
    mVisualizer = new Visualizer(audioSession);

    getCaptureSizeAndUpdateField();

    // NOTE:
    // Default implementation always tells the sampling rate is 44100000 mHz
    // but actually that is not correct!
    mCorrectSamplingRate = AudioSystemUtils.getProperties(context).outputSampleRate * 1000;
}
 
Example #10
Source File: StandardVisualizer.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onWaveFormDataCapture(Visualizer visualizer, byte[] waveform, int samplingRate) {
    final StandardVisualizer holder = mHolder.get();

    if (holder != null) {
        mListener.onWaveFormDataCapture(holder, waveform, mCorrectSamplingRate);
    }
}
 
Example #11
Source File: StandardVisualizer.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onFftDataCapture(Visualizer visualizer, byte[] fft, int samplingRate) {
    final StandardVisualizer holder = mHolder.get();

    if (holder != null) {
        mListener.onFftDataCapture(holder, fft, mCorrectSamplingRate);
    }
}
 
Example #12
Source File: HQVisualizerTestCase.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
private void checkSetCaptureSizeWhenEnabledWithInvalidParameters(
        IBasicMediaPlayer player) {
    IHQVisualizer visualizer = null;

    try {
        visualizer = createVisualizer(player);

        int[] range = Visualizer.getCaptureSizeRange();

        assertEquals(IHQVisualizer.SUCCESS, visualizer.setEnabled(true));
        assertTrue(visualizer.getEnabled());

        // minimum / 2
        checkSetCaptureSizeIllegalStateException(visualizer, range[0] / 2);

        // maximum * 2
        checkSetCaptureSizeIllegalStateException(visualizer, range[1] * 2);

        // minimum + 1 (not power of two)
        assertFalse(isPowOfTwo(range[0] + 1));
        checkSetCaptureSizeIllegalStateException(visualizer, range[0] + 1);

        // maximum - 1 (not power of two)
        assertFalse(isPowOfTwo(range[1] - 1));
        checkSetCaptureSizeIllegalStateException(visualizer, range[1] - 1);

        // medium (not power of two)
        int mid = (range[0] * 2) - 1;
        assertRange((range[0] + 1), (range[1] - 1), mid);
        assertFalse(isPowOfTwo(mid));
        checkSetCaptureSizeIllegalStateException(visualizer, mid);
    } finally {
        releaseQuietly(visualizer);
    }
}
 
Example #13
Source File: HQVisualizerTestCase.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
private void checkSetCaptureSizeWithInvalidParameters(
        IBasicMediaPlayer player) {
    IHQVisualizer visualizer = null;

    try {
        visualizer = createVisualizer(player);

        int[] range = Visualizer.getCaptureSizeRange();

        assertFalse(visualizer.getEnabled());

        // minimum / 2
        checkSetCaptureSizeERROR_BAD_VALUE(visualizer, range[0] / 2);

        // maximum * 2
        checkSetCaptureSizeERROR_BAD_VALUE(visualizer, range[1] * 2);

        // minimum + 1 (not power of two)
        assertFalse(isPowOfTwo(range[0] + 1));
        checkSetCaptureSizeERROR_BAD_VALUE(visualizer, range[0] + 1);

        // maximum - 1 (not power of two)
        assertFalse(isPowOfTwo(range[1] - 1));
        checkSetCaptureSizeERROR_BAD_VALUE(visualizer, range[1] - 1);

        // medium (not power of two)
        int mid = (range[0] * 2) - 1;
        assertRange((range[0] + 1), (range[1] - 1), mid);
        assertFalse(isPowOfTwo(mid));
        checkSetCaptureSizeERROR_BAD_VALUE(visualizer, mid);
    } finally {
        releaseQuietly(visualizer);
    }
}
 
Example #14
Source File: VisualizerTestCase.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
private void checkSetCaptureSizeWhenEnabledWithInvalidParameters(
        IBasicMediaPlayer player) {
    IVisualizer visualizer = null;

    try {
        visualizer = createVisualizer(player);

        int[] range = Visualizer.getCaptureSizeRange();

        assertEquals(IVisualizer.SUCCESS, visualizer.setEnabled(true));
        assertTrue(visualizer.getEnabled());

        // minimum / 2
        checkSetCaptureSizeIllegalStateException(visualizer, range[0] / 2);

        // maximum * 2
        checkSetCaptureSizeIllegalStateException(visualizer, range[1] * 2);

        // minimum + 1 (not power of two)
        assertFalse(isPowOfTwo(range[0] + 1));
        checkSetCaptureSizeIllegalStateException(visualizer, range[0] + 1);

        // maximum - 1 (not power of two)
        assertFalse(isPowOfTwo(range[1] - 1));
        checkSetCaptureSizeIllegalStateException(visualizer, range[1] - 1);

        // medium (not power of two)
        int mid = (range[0] * 2) - 1;
        assertRange((range[0] + 1), (range[1] - 1), mid);
        assertFalse(isPowOfTwo(mid));
        checkSetCaptureSizeIllegalStateException(visualizer, mid);
    } finally {
        releaseQuietly(visualizer);
    }
}
 
Example #15
Source File: VisualizerTestCase.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
private void checkSetCaptureSizeWithInvalidParameters(
        IBasicMediaPlayer player) {
    IVisualizer visualizer = null;

    try {
        visualizer = createVisualizer(player);

        int[] range = Visualizer.getCaptureSizeRange();

        assertFalse(visualizer.getEnabled());

        // minimum / 2
        checkSetCaptureSizeERROR_BAD_VALUE(visualizer, range[0] / 2);

        // maximum * 2
        checkSetCaptureSizeERROR_BAD_VALUE(visualizer, range[1] * 2);

        // minimum + 1 (not power of two)
        assertFalse(isPowOfTwo(range[0] + 1));
        checkSetCaptureSizeERROR_BAD_VALUE(visualizer, range[0] + 1);

        // maximum - 1 (not power of two)
        assertFalse(isPowOfTwo(range[1] - 1));
        checkSetCaptureSizeERROR_BAD_VALUE(visualizer, range[1] - 1);

        // medium (not power of two)
        int mid = (range[0] * 2) - 1;
        assertRange((range[0] + 1), (range[1] - 1), mid);
        assertFalse(isPowOfTwo(mid));
        checkSetCaptureSizeERROR_BAD_VALUE(visualizer, mid);
    } finally {
        releaseQuietly(visualizer);
    }
}
 
Example #16
Source File: EqualizerView.java    From Sky31Radio with Apache License 2.0 5 votes vote down vote up
public void linkPlayer(int sessionId){
    Timber.d("linkPlayer, session id: %d", sessionId);
    visualizer = new Visualizer(sessionId);
    if(!visualizer.getEnabled()){
        visualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
    }
    visualizer.setDataCaptureListener(dataCaptureListener, Visualizer.getMaxCaptureRate() / 2, true, true);
    visualizer.setEnabled(true);
}
 
Example #17
Source File: VisualizerCompatBase.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
public int getMeasurementPeakRmsCompat(Visualizer visualizer,
        IVisualizer.MeasurementPeakRms measurement) {
    if (measurement != null) {
        measurement.mPeak = -9600; // -96 dB
        measurement.mRms = -9600; // -96 dB
    }
    return IVisualizer.SUCCESS;
}
 
Example #18
Source File: VisualizerCompatBase.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
public int getMeasurementModeCompat(Visualizer visualizer) throws IllegalStateException {
    return IVisualizer.MEASUREMENT_MODE_NONE;
}
 
Example #19
Source File: VisualizerCompatBase.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
public int setMeasurementModeCompat(Visualizer visualizer, int mode)
        throws IllegalStateException {
    return IVisualizer.SUCCESS;
}
 
Example #20
Source File: VisualizerCompatBase.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
public int setScalingModeCompat(Visualizer visualizer, int mode) throws IllegalStateException {
    return IVisualizer.SUCCESS;
}
 
Example #21
Source File: VisualizerCompatBase.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
public int getScalingModeCompat(Visualizer visualizer) throws IllegalStateException {
    // NOTE:
    // Normalization is always applied on prior to Jelly Bean devices.
    return IVisualizer.SCALING_MODE_NORMALIZED;
}
 
Example #22
Source File: VisualizerCompatKitKat.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public int getScalingModeCompat(Visualizer visualizer) throws IllegalStateException {
    return visualizer.getScalingMode();
}
 
Example #23
Source File: VisualizerCompatKitKat.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public int setScalingModeCompat(Visualizer visualizer, int mode) throws IllegalStateException {
    return visualizer.setScalingMode(mode);
}
 
Example #24
Source File: VisualizerCompatKitKat.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public int getMeasurementModeCompat(Visualizer visualizer) throws IllegalStateException {
    return visualizer.getMeasurementMode();
}
 
Example #25
Source File: VisualizerCompatKitKat.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public int setMeasurementModeCompat(Visualizer visualizer, int mode)
        throws IllegalStateException {
    return visualizer.setMeasurementMode(mode);
}
 
Example #26
Source File: VisualizerCompatJB.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public int setScalingModeCompat(Visualizer visualizer, int mode) throws IllegalStateException {
    return visualizer.setScalingMode(mode);
}
 
Example #27
Source File: StandardVisualizer.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized int getMaxCaptureRate() throws IllegalStateException {
    throwIllegalStateExceptionIfReleased();
    return android.media.audiofx.Visualizer.getMaxCaptureRate();
}
 
Example #28
Source File: StandardVisualizer.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized int[] getCaptureSizeRange() throws IllegalStateException {
    throwIllegalStateExceptionIfReleased();
    return android.media.audiofx.Visualizer.getCaptureSizeRange();
}
 
Example #29
Source File: StandardVisualizer.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
public static int sGetMaxCaptureRate() {
    return Visualizer.getMaxCaptureRate();
}
 
Example #30
Source File: StandardVisualizer.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
public static int[] sGetCaptureSizeRange() {
    return Visualizer.getCaptureSizeRange();
}