fixed hardcoded half-height to match any image height
This commit is contained in:
parent
a1b69e13bd
commit
34ce9bdc59
1 changed files with 4 additions and 4 deletions
|
@ -68,10 +68,10 @@ impl Waveform {
|
|||
}
|
||||
// Set function scoped last rows
|
||||
if previous_left_row.0 != self.rgba.height as usize && previous_left_row.1 != 0 {
|
||||
last_rows.0 = if (previous_left_row.0 as f32 - 128f32).abs() < (previous_left_row.1 as f32 - 128f32).abs() {previous_left_row.0} else {previous_left_row.1};
|
||||
last_rows.0 = if (previous_left_row.0 as f32 - (self.rgba.height/2) as f32).abs() < (previous_left_row.1 as f32 - (self.rgba.height/2) as f32).abs() {previous_left_row.0} else {previous_left_row.1};
|
||||
}
|
||||
if previous_right_row.0 != self.rgba.height as usize && previous_right_row.1 != 0 {
|
||||
last_rows.1 = if (previous_right_row.0 as f32 - 128f32).abs() < (previous_right_row.1 as f32 - 128f32).abs() {previous_right_row.0} else {previous_right_row.1};
|
||||
last_rows.1 = if (previous_right_row.0 as f32 - (self.rgba.height/2) as f32).abs() < (previous_right_row.1 as f32 - (self.rgba.height/2) as f32).abs() {previous_right_row.0} else {previous_right_row.1};
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -84,7 +84,7 @@ impl Waveform {
|
|||
// LEFT CHANNEL
|
||||
let column_values : &[f32] = &left_samples[x*left_column_width..(x+1)*left_column_width];
|
||||
let column_average : f32 = (column_values.iter().cloned().reduce(|acc, v| acc+v).unwrap_or(0f32) / column_values.len() as f32).clamp(-0.99, 0.99);
|
||||
let row = (128f32 - (column_average * 128f32)).round() as usize;
|
||||
let row = ((self.rgba.height/2) as f32 - (column_average * (self.rgba.height/2) as f32)).round() as usize;
|
||||
|
||||
// Draw vertical lines from last row
|
||||
let range : Vec<usize> = if row <= last_rows.0 {(row..=last_rows.0).collect()} else {(last_rows.0..=row).rev().collect()};
|
||||
|
@ -98,7 +98,7 @@ impl Waveform {
|
|||
// RIGHT CHANNEL
|
||||
let column_values : &[f32] = &right_samples[x*right_column_width..(x+1)*right_column_width];
|
||||
let column_average : f32 = (column_values.iter().cloned().reduce(|acc, v| acc+v).unwrap_or(0f32) / column_values.len() as f32).clamp(-0.99, 0.99);
|
||||
let row = (128f32 - (column_average * 128f32)).round() as usize;
|
||||
let row = ((self.rgba.height/2) as f32 - (column_average * (self.rgba.height/2) as f32)).round() as usize;
|
||||
|
||||
// Draw vertical lines from last row
|
||||
let range : Vec<usize> = if row <= last_rows.1 {(row..=last_rows.1).collect()} else {(last_rows.1..=row).rev().collect()};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue