Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rendering the entire waveform data is not necissary and it becomes very slow when your waveform data is long #232

Closed
ty1135 opened this issue Jul 5, 2023 · 2 comments · Fixed by #243
Labels
bug Something isn't working

Comments

@ty1135
Copy link

ty1135 commented Jul 5, 2023

rerendering only the visible is enough

@ujas-m-simformsolutions
Copy link
Collaborator

@ty1135 That is what I have done for duration labels but how do suggest to approach this for waveform data?

@ujas-m-simformsolutions ujas-m-simformsolutions added the enhancement New feature or request label Jul 14, 2023
@ty1135
Copy link
Author

ty1135 commented Jul 16, 2023

void paintWave(Canvas canvas, Size size) {
// barWidth * (1 + spacingRatio) * pixelsPerSecond * visibleDuration.inSeconds = size.width
final visiblePixels = pixelsPerSecond! * visibleDuration.inSeconds;
final barWidth = size.width / ((1 + spacingRatio) * visiblePixels);
final spacing = barWidth * spacingRatio;
//
final secondsPerPixel = 1 / pixelsPerSecond!;
final microSecondsPerPixel = secondsPerPixel * 1000 * 1000;
final index = visibleStart ~/ microSecondsPerPixel;

final remainder = visibleStart % microSecondsPerPixel;
final offset = remainder / microSecondsPerPixel * (barWidth + spacing);

defaultPaint.strokeWidth = barWidth;

if (waveFormData != null) {
  for (int i = index;
      i <= index + visiblePixels && i < waveFormData!.length;
      i++) {
    double x = (spacing + barWidth) * (i - index) - offset + spacing;
    Offset bottom = Offset(x, scaleY(waveFormData![2 * i], size.height));
    Offset top = Offset(x, scaleY(waveFormData![2 * i + 1], size.height));
    canvas.drawLine(bottom, top, defaultPaint);
  }
}

}

@ujas-m-simformsolutions ujas-m-simformsolutions added bug Something isn't working and removed enhancement New feature or request labels Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants