I have the following code, which I've got from an example at Github (1):
private void drawWaveform(Canvas canvas) {
canvas.drawColor(Color.BLACK);
float width = getWidth();
float height = getHeight();
float centerY = height / 2;
// We draw the history from oldest to newest so that the older audio data is further back
// and darker than the most recent data.
int colorDelta = 255 / (HISTORY_SIZE + 1);
int brightness = colorDelta;
for (short[] buffer : mAudioData) {
mPaint.setColor(Color.argb(brightness, 128, 255, 192));
float lastX = -1;
float lastY = -1;
// For efficiency, we don't draw all of the samples in the buffer, but only the ones
// that align with pixel boundaries.
for (int x = 0; x < width; x++) {
int index = (int) ((x / width) * buffer.length);
short sample = buffer[index];
float y = (sample / MAX_AMPLITUDE_TO_DRAW) * centerY + centerY;
if (lastX != -1) {
canvas.drawLine(lastX, lastY, x, y, mPaint);
}
lastX = x;
lastY = y;
}
brightness += colorDelta;//muda o brilho da proxima onda a ser desenhada
}
}
So I understood that it takes the parameter HISTORY_SIZE = 6 in this examples, so it draws 6 waveforms in the screen, with different brigthness in each one, to create a fade-out effect.
I won't need this effect in my project. What I actually need is to draw the first wave until the point (width/HISTORY_SIZE) and then start drawing the second wave from the last point drawed in the first wave.
So each wave are a different short[] array in my LinkedList.
I could try to simplify and change the HISTORY_SIZE for 2, but I just don't seem to know how to edit my start and end point.
With the code I showed you, it is always starting the next wave from the point (-1,-1).
How do I change that?
It's probably very basic stuff, but I haven't really found a post related to this issue.
Sorry if this post is unnappropriate and thanks for your time.
Aucun commentaire:
Enregistrer un commentaire