Is the following code an example of polymorphism ? Thank you
/**
* Create a waveform according to audio signal intensity
*/
class WavPanel extends JPanel {
List<Byte> audioBytes;
List<Line2D.Double> lines;
public WavPanel() {
super();
setBackground(Color.black);
resetWaveform();
}
public void resetWaveform() {
audioBytes = new ArrayList<Byte>();
lines = new ArrayList<Line2D.Double>();
repaint();
}
public void addAudioByte(byte b) {
audioBytes.add(b);
}
public void createWaveForm() {
if (audioBytes.size() == 0) {
return;
}
AudioFormat format = audioInputStream.getFormat();
Dimension d = getSize();
int w = d.width;
int h = d.height - 15;
int[] audioData = null;
if (format.getSampleSizeInBits() == 16) {
int nlengthInSamples = audioBytes.size() / 2;
audioData = new int[nlengthInSamples];
if (format.isBigEndian()) {
for (int i = 0; i < nlengthInSamples; i++) {
int MSB = (int) audioBytes.get(2 * i);
int LSB = (int) audioBytes.get(2 * i + 1);
audioData[i] = MSB << 8 | (255 & LSB);
}
} else {
for (int i = 0; i < nlengthInSamples; i++) {
int LSB = (int) audioBytes.get(2 * i);
int MSB = (int) audioBytes.get(2 * i + 1);
audioData[i] = MSB << 8 | (255 & LSB);
}
}
} else if (format.getSampleSizeInBits() == 8) {
int nlengthInSamples = audioBytes.size();
audioData = new int[nlengthInSamples];
if (format.getEncoding().toString().startsWith("PCM_SIGN")) {
for (int i = 0; i < audioBytes.size(); i++) {
audioData[i] = audioBytes.get(i);
}
} else {
for (int i = 0; i < audioBytes.size(); i++) {
audioData[i] = audioBytes.get(i) - 128;
}
}
}
int frames_per_pixel = audioBytes.size() / format.getFrameSize() / w;
byte my_byte = 0;
double y_last = 0;
int numChannels = format.getChannels();
for (double x = 0; x < w && audioData != null; x++) {
int idx = (int) (frames_per_pixel * numChannels * x);
if (format.getSampleSizeInBits() == 8) {
my_byte = (byte) audioData[idx];
} else {
my_byte = (byte) (128 * audioData[idx] / 32768);
}
double y_new = (double) (h * (128 - my_byte) / 256);
lines.add(new Line2D.Double(x, y_last, x, y_new));
y_last = y_new;
}
repaint();
}
public void paint(Graphics g) {
Dimension d = getSize();
g.setColor(getBackground());
g.fillRect(0, 0, d.width, d.height);
if (audioBytes.size() == 0) {
return;
}
g.setColor(Color.LIGHT_GRAY);
for (int i = 1; i < lines.size(); i++) {
Line2D.Double line = lines.get(i);
g.drawLine((int) line.x1, (int) line.y1, (int) line.x2, (int) line.y2);
}
}
}
}