Android Open Source - BluetoothRecord Single Waveform Panel






From Project

Back to project page BluetoothRecord.

License

The source code is released under:

Apache License

If you think the Android project BluetoothRecord listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.audioseparate;
import javax.swing.*;
import java.awt.*;
//  www .j  a v a 2 s  .c o  m
/**
 * Created by IntelliJ IDEA.
 * User: Jonathan Simon
 * Date: Mar 6, 2005
 * Time: 9:16:15 PM
 * To change this template use File | Settings | File Templates.
 */
public class SingleWaveformPanel extends JPanel {
    /**
   *
   */
  private static final long serialVersionUID = -133514436822003255L;
  protected static final Color BACKGROUND_COLOR = Color.WHITE;
    protected static final Color REFERENCE_LINE_COLOR = Color.BLACK;
    protected static final Color WAVEFORM_COLOR = Color.RED;


    private AudioSep helper;
    private int channelIndex;

    public SingleWaveformPanel(AudioSep helper, int channelIndex) {
        this.helper = helper;
        this.channelIndex = channelIndex;
        setBackground(BACKGROUND_COLOR);
    }

    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        int lineHeight = getHeight() / 2;
        g.setColor(REFERENCE_LINE_COLOR);
        g.drawLine(0, lineHeight, (int)getWidth(), lineHeight);

        drawWaveform(g, helper.getAudio(channelIndex));

    }

    protected void drawWaveform(Graphics g, int[] samples) {
        if (samples == null) {
            return;
        }

        int oldX = 0;
        int oldY = (int) (getHeight() / 2);
        int xIndex = 0;

        int increment = helper.getIncrement(helper.getXScaleFactor(getWidth()));
        g.setColor(WAVEFORM_COLOR);

        int t = 0;

        for (t = 0; t < increment; t += increment) {
            g.drawLine(oldX, oldY, xIndex, oldY);
            xIndex++;
            oldX = xIndex;
        }

        for (; t < samples.length; t += increment) {
            double scaleFactor = helper.getYScaleFactor(getHeight());
            double scaledSample = samples[t] * scaleFactor;
            int y = (int) ((getHeight() / 2) - (scaledSample));
            g.drawLine(oldX, oldY, xIndex, y);

            xIndex++;
            oldX = xIndex;
            oldY = y;
        }
    }
}




Java Source Code List

com.audioseparate.AudioSampleReader.java
com.audioseparate.AudioSep.java
com.audioseparate.BTConnect.java
com.audioseparate.MainActivity.java
com.audioseparate.Record.java
com.audioseparate.SingleWaveformPanel.java
com.audioseparate.WaveformPanelContainer.java
com.audioserver.BTServer.java
com.audioserver.ServerCommand.java