processSamples method
Raw samples are processed before used following some techniques. This is to have consistent samples that can be used to draw the waveform properly.
Implementation
@protected
void processSamples() {
final rawSamples = widget.samples;
_processedSamples = rawSamples
.map((e) => absolute ? e.abs() * widget.height : e * widget.height)
.toList();
final maxNum =
_processedSamples.reduce((a, b) => math.max(a.abs(), b.abs()));
if (maxNum > 0) {
final multiplier = math.pow(maxNum, -1).toDouble();
final finalHeight = absolute ? widget.height : widget.height / 2;
final finalMultiplier = multiplier * finalHeight;
_processedSamples = _processedSamples
.map(
(e) => invert ? -e * finalMultiplier : e * finalMultiplier,
)
.toList();
}
}