⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audiochart.java

📁 java+eclipse做的TTPlayer
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (wLeft > 1.0f) {            wLeft = 1.0f;        }        if (wRight > 1.0f) {            wRight = 1.0f;        }        //      vuAverage += ( ( wLeft + wRight ) / 2.0f );        //      vuSamples++;        //        //      if ( vuSamples > 128 ) {        //          vuSamples /= 2.0f;        //          vuAverage /= 2.0f;        //      }        if (wLeft >= (oldLeft - wSadfrr)) {            oldLeft = wLeft;        } else {            oldLeft -= wSadfrr;            if (oldLeft < 0) {                oldLeft = 0;            }        }        if (wRight >= (oldRight - wSadfrr)) {            oldRight = wRight;        } else {            oldRight -= wSadfrr;            if (oldRight < 0) {                oldRight = 0;            }        }        int wHeight = (height >> 1) - 24;        drawVolumeMeterBar(pGrp, 16, 16, (int) (oldLeft * (float) (width - 32)), wHeight);        //      drawVolumeMeterBar( pGrp, 16, wHeight + 22, (int)( ( vuAverage / vuSamples ) * (float)( width - 32 ) ), 4 );        drawVolumeMeterBar(pGrp, 16, wHeight + 32, (int) (oldRight * (float) (width - 32)), wHeight);    //      pGrp.fillRect( 16, 16, (int)( oldLeft  * (float)( width - 32 ) ), wHeight );    //      pGrp.fillRect( 16, 64, (int)( oldRight * (float)( width - 32 ) ), wHeight );    }    private void drawSpectrumAnalyserBar(Graphics pGraphics, int pX, int pY, int pWidth, int pHeight, int band) {        float c = 0;        for (int a = pY; a >= pY - pHeight; a -= barOffset) {            c += saColorScale;            if (c < spectrumAnalyserColors.length) {                pGraphics.setColor(spectrumAnalyserColors[(int) c]);            }            pGraphics.fillRect(pX, a, pWidth, 1);        }        if ((peakColor != null) && (peaksEnabled == true)) {            pGraphics.setColor(peakColor);            if (pHeight > peaks[band]) {                peaks[band] = pHeight;                peaksDelay[band] = peakDelay;            } else {                peaksDelay[band]--;                if (peaksDelay[band] < 0) {                    peaks[band]--;                }                if (peaks[band] < 0) {                    peaks[band] = 0;                }            }            pGraphics.fillRect(pX, pY - peaks[band], pWidth, 1);        }    }    private void drawVolumeMeterBar(Graphics pGraphics, int pX, int pY, int pWidth, int pHeight) {        float c = 0;        for (int a = pX; a <= pX + pWidth; a += 2) {            c += vuColorScale;            if (c < 256.0f) {                pGraphics.setColor(spectrumAnalyserColors[(int) c]);            }            pGraphics.fillRect(a, pY, 1, pHeight);        }    }    private synchronized Image getDoubleBuffer() {        if (bi == null || (bi.getWidth(null) != getSize().width || bi.getHeight(null) != getSize().height)) {            width = getSize().width;            height = getSize().height;            height_2 = height >> 1;            computeColorScale();            bi = getGraphicsConfiguration().createCompatibleVolatileImage(width, height);        }        return bi;    }    public static Color[] getDefaultSpectrumAnalyserColors() {        Color[] wColors = new Color[256];        for (int a = 0; a < 128; a++) {            wColors[a] = new Color(0, (a >> 1) + 192, 0);        }        for (int a = 0; a < 64; a++) {            wColors[a + 128] = new Color(a << 2, 255, 0);        }        for (int a = 0; a < 64; a++) {            wColors[a + 192] = new Color(255, 255 - (a << 2), 0);        }        return wColors;    }    /**     * @return Returns the current display mode, DISPLAY_MODE_SCOPE or DISPLAY_MODE_SPECTRUM_ANALYSER.     */    public int getDisplayMode() {        return displayMode;    }    /**     * @return Returns the current number of bands displayed by the spectrum analyser.     */    public int getSpectrumAnalyserBandCount() {        return saBands;    }    /**     * @return Returns the decay rate of the spectrum analyser's bands.     */    public float getSpectrumAnalyserDecay() {        return saDecay;    }    /**     * @return Returns the color the scope is rendered in.     */    public Color getScopeColor() {        return scopeColor;    }    /**     * @return Returns the color scale used to render the spectrum analyser bars.     */    public Color[] getSpectrumAnalyserColors() {        return spectrumAnalyserColors;    }    private void initialize() {        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);        setBackground(DEFAULT_BACKGROUND_COLOR);        prepareDisplayToggleListener();        setSpectrumAnalyserBandCount(DEFAULT_SPECTRUM_ANALYSER_BAND_COUNT);        setSpectrumAnalyserFFTSampleSize(DEFAULT_SPECTRUM_ANALYSER_FFT_SAMPLE_SIZE);    }    /**     * @return Returns 'true' if "Frames Per Second" are being calculated and displayed.     */    public boolean isShowingFPS() {        return showFPS;    }    public void paintComponent(Graphics pGraphics) {        if (displayMode == DISPLAY_MODE_OFF) {            return;        }        if (dspStarted) {            pGraphics.drawImage(getDoubleBuffer(), 0, 0, null);        } else {            super.paintComponent(pGraphics);        }    }    private void prepareDisplayToggleListener() {        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));        addMouseListener(new MouseAdapter() {            public void mousePressed(MouseEvent pEvent) {                if (pEvent.getButton() == MouseEvent.BUTTON1) {                    if (displayMode + 1 > 2) {                        displayMode = 0;                    } else {                        displayMode++;                    }                    Config.getConfig().setAudioChartDisplayMode(displayMode);                    repaint();                }            }        });    }    /* (non-Javadoc)     * @see kj.dsp.KJDigitalSignalProcessor#process(float[], float[], float)     */    public synchronized void process(float[] pLeft, float[] pRight, float pFrameRateRatioHint) {        if (displayMode == DISPLAY_MODE_OFF) {            return;        }        Graphics wGrp = getDoubleBuffer().getGraphics();        wGrp.setColor(getBackground());        wGrp.fillRect(0, 0, getSize().width, getSize().height);        switch (displayMode) {            case DISPLAY_MODE_SCOPE:                drawScope(wGrp, stereoMerge(pLeft, pRight));                break;            case DISPLAY_MODE_SPECTRUM_ANALYSER:                drawSpectrumAnalyser(wGrp, stereoMerge(pLeft, pRight), pFrameRateRatioHint);                break;            case DISPLAY_MODE_OFF:                drawVUMeter(wGrp, pLeft, pRight, pFrameRateRatioHint);                break;        }        // -- Show FPS if necessary.                if (showFPS) {            // -- Calculate FPS.            if (System.currentTimeMillis() >= lfu + 1000) {                lfu = System.currentTimeMillis();                fp = fc;                fc = 0;            }            fc++;            wGrp.setColor(Color.yellow);            wGrp.drawString("FPS: " + fp + " (FRRH: " + pFrameRateRatioHint + ")", 0, height - 1);        }        if (getGraphics() != null) {            getGraphics().drawImage(getDoubleBuffer(), 0, 0, null);        }    //      repaint();    //      try {    //          EventQueue.invokeLater( new AWTPaintSynchronizer() );    //      } catch ( Exception pEx ) {    //          // -- Ignore exception.    //          pEx.printStackTrace();    //      }    }    /**     * Sets the current display mode.     *     * @param pMode Must be either DISPLAY_MODE_SCOPE or DISPLAY_MODE_SPECTRUM_ANALYSER.     */    public synchronized void setDisplayMode(int pMode) {        displayMode = pMode;    }    /**     * Sets the color of the scope.     *     * @param pColor     */    public synchronized void setScopeColor(Color pColor) {        scopeColor = pColor;    }    /**     * When 'true' is passed as a parameter, will overlay the "Frames Per Seconds"     * achieved by the component.     *     * @param pState     */    public synchronized void setShowFPS(boolean pState) {        showFPS = pState;    }    /**     * Sets the numbers of bands rendered by the spectrum analyser.     *     * @param pCount Cannot be more than half the "FFT sample size".     */    public synchronized void setSpectrumAnalyserBandCount(int pCount) {        saBands = pCount;        peaks = new int[saBands];        peaksDelay = new int[saBands];        computeSAMultiplier();    }    /**     * Sets the spectrum analyser band decay rate.     *     * @param pDecay Must be a number between 0.0 and 1.0 exclusive.     */    public synchronized void setSpectrumAnalyserDecay(float pDecay) {        if ((pDecay >= MIN_SPECTRUM_ANALYSER_DECAY) && (pDecay <= MAX_SPECTRUM_ANALYSER_DECAY)) {            saDecay = pDecay;        } else {            saDecay = DEFAULT_SPECTRUM_ANALYSER_DECAY;        }    }    /**     * Sets the spectrum analyser color scale.     *     * @param pColors Any amount of colors may be used. Must not be null.     */    public synchronized void setSpectrumAnalyserColors(Color[] pColors) {        spectrumAnalyserColors = pColors;        computeColorScale();    }    /**     * Sets the FFT sample size to be just for calculating the spectrum analyser     * values. The default is 512.     *     * @param pSize Cannot be more than the size of the sample provided by the DSP.     */    public synchronized void setSpectrumAnalyserFFTSampleSize(int pSize) {        saFFTSampleSize = pSize;        fft = new KJFFT(saFFTSampleSize);        old_FFT = new float[saFFTSampleSize];        computeSAMultiplier();    }    private float[] stereoMerge(float[] pLeft, float[] pRight) {        for (int a = 0; a < pLeft.length; a++) {            pLeft[a] = (pLeft[a] + pRight[a]) / 2.0f;        }        return pLeft;    }    /*public void update(Graphics pGraphics)    {    // -- Prevent AWT from clearing background.    paint(pGraphics);    }*/}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -