U
U
urmi tilek uulu2015-11-16 10:59:39
Java
urmi tilek uulu, 2015-11-16 10:59:39

How to make good music rendering?

Good day to all!
I am trying to render a music file. I don't know if I'm calling it right but I mean 51103b507699475ba6ce6c84ee00c09a.png
when the line dances to the music :D.
Everything works but not qualitatively, I do not like it. I do this: then I
public class VisualizerView extends View
override the method

@Override
    protected void onDraw(Canvas canvas) {

I take bytes[] from the music file and draw based on this
. For example:
for (int i = 0; i < bytes.length - 1; i++) {
            mPoints[i * 4] = rect.width() * i / (bytes.length - 1);
            mPoints[i * 4 + 1] = rect.height() / 2
                    + ((byte) (bytes[i] + 128)) * (rect.height() / 2) / 128;
            mPoints[i * 4 + 2] = rect.width() * (i + 1) / (bytes.length - 1);
            mPoints[i * 4 + 3] = rect.height() / 2
                    + ((byte) (bytes[i + 1] + 128)) * (rect.height() / 2)
                    / 128;
        }
        canvas.drawLines(mPoints, mPaint);

but it does not work very smoothly, does not have time to draw.
So, are there easier ways to implement this? To work faster.
Thanks!!!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Perelygin, 2015-11-16
@urma

The problem is that you are taking bytes[] in an encoded format. For such a thing - you need to write a decoder yourself in the native space, and do playback, skipping the decoded (you can get it using some codec, for example, for mp3 - lime) bytes through the buffer, drawing the picture you need along the way.

A
Alexander Wolf, 2015-11-16
@mannaro

tsya.ru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question