Java Code Examples for android.media.audiofx.Visualizer#getCaptureSizeRange()

The following examples show how to use android.media.audiofx.Visualizer#getCaptureSizeRange() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: MainActivity.java    From MusicVisualization with Apache License 2.0 4 votes vote down vote up
private void start() {
    int captureSize = Visualizer.getCaptureSizeRange()[1];
    captureSize = captureSize > 512 ? 512 : captureSize;

    /*
      Setup texture view
     */
    final TextureView textureView = new TextureView(this);
    mContainerView.addView(textureView);
    textureView.setSurfaceTextureListener(mRender = new VisualizerRenderer(this, captureSize / 2));
    textureView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(
                View v, int left, int top, int right, int bottom,
                int oldLeft, int oldTop, int oldRight, int oldBottom) {

            mRender.onSurfaceTextureSizeChanged(null, v.getWidth(), v.getHeight());
        }
    });
    textureView.requestLayout();

    mRender.setSceneController(mSceneController = new SceneController() {
        @Override
        public void onSetup(Context context, int audioTextureId, int textureWidth) {
            mSceneList = new ArrayList<>();
            GLScene defaultScene = new BasicSpectrumScene(context, audioTextureId, textureWidth);
            mSceneList.add(Pair.create("Basic Spectrum", defaultScene));
            mSceneList.add(Pair.create("Circle Spectrum", new CircSpectrumScene(context, audioTextureId, textureWidth)));
            mSceneList.add(Pair.create("Enhanced Spectrum", new EnhancedSpectrumScene(context, audioTextureId, textureWidth)));
            mSceneList.add(Pair.create("Input Sound", new InputSoundScene(context, audioTextureId, textureWidth)));
            mSceneList.add(Pair.create("Sa2Wave", new Sa2WaveScene(context, audioTextureId, textureWidth)));
            mSceneList.add(Pair.create("Waves Remix", new WavesRemixScene(context, audioTextureId, textureWidth)));
            mSceneList.add(Pair.create("Rainbow Spectrum", new RainbowSpectrumScene(context, audioTextureId, textureWidth)));
            mSceneList.add(Pair.create("Chlast", new ChlastScene(context, audioTextureId, textureWidth)));
            mSceneList.add(Pair.create("Origin Texture", new OriginScene(context, audioTextureId, textureWidth)));

            changeScene(defaultScene);

            invalidateOptionsMenu();
        }
    });

    /*
      Setup media player and play music
     */
    mPlayer = MediaPlayer.create(this, R.raw.music);
    mPlayer.setLooping(true);
    mPlayer.start();

    mVisualizer = new Visualizer(mPlayer.getAudioSessionId());
    mVisualizer.setCaptureSize(captureSize);
    mVisualizer.setDataCaptureListener(this, Visualizer.getMaxCaptureRate(), true, true);
    // Start capturing
    mVisualizer.setEnabled(true);
}
 
Example 10
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();
}