Question

I'm using the Visualizer class to create visualizations for an AudioTrack. The problem is associating the Visualizer to the AudioTrack modifies the audio output, it sounds "brighter" and louder, almost as if the Visualizer bytes were being added to the track playback.

When the visualizer is setEnabled(false) or release()'d, the audio returns to normal. Setting the audio session Id to "0" (the output mix) does not cause this problem, however this solution is not acceptable for my application.

How can I associate an AudioTrack to a Visualizer without modifying the audio output?

Here is code for attaching:

public void link(int audioSessionId)
    {

        mVisualizer = new Visualizer(audioSessionId);
        mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);

        // Pass through Visualizer data to VisualizerView
        Visualizer.OnDataCaptureListener captureListener = new Visualizer.OnDataCaptureListener()
        {
            @Override
            public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes,
                    int samplingRate)
            {
                updateVisualizer(bytes);
            }

            @Override
            public void onFftDataCapture(Visualizer visualizer, byte[] bytes,
                    int samplingRate)
            {
                updateVisualizerFFT(bytes);
            }
        };

        mVisualizer.setDataCaptureListener(captureListener,
                Visualizer.getMaxCaptureRate(), true, true);

        // Enabled Visualizer and disable when we're done with the stream
        mVisualizer.setEnabled(true);
    }

All the updateVisualizer() methods do is invalidate() the view and redraw it. No possible modification there.

Possible Android bug? I've noticed this behavior in another visualization app.

Was it helpful?

Solution

This problem was caused by Beats Audio on my HTC device. With it turned off, it doesn't happen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top