新增sample转db函数
This commit is contained in:
parent
d325dc51bf
commit
f3e3d44ce8
@ -118,9 +118,12 @@ void draw_mixer_track(uint32_t delta_sample_count, mixer_track* track, int32_t i
|
||||
});
|
||||
sample_t peak = std::abs(*peak_it);
|
||||
|
||||
float peak_db = sample_to_db(peak);
|
||||
float peak_db_percent = db_to_percent(peak_db);
|
||||
|
||||
// update peak
|
||||
if (peak > peak_info.peak) {
|
||||
peak_info.peak = peak;
|
||||
if (peak_db_percent > peak_info.peak) {
|
||||
peak_info.peak = peak_db_percent;
|
||||
peak_info.left_time = volume_bar_peak_duration;
|
||||
} else {
|
||||
peak_info.left_time -= delta_time;
|
||||
@ -130,7 +133,7 @@ void draw_mixer_track(uint32_t delta_sample_count, mixer_track* track, int32_t i
|
||||
}
|
||||
}
|
||||
|
||||
sample_value.push_back(peak);
|
||||
sample_value.push_back(peak_db_percent);
|
||||
sample_peak.push_back(peak_info.peak);
|
||||
}
|
||||
draw_volume_bar(volume_bar_id.c_str(), widget_height, sample_value, sample_peak);
|
||||
|
@ -1,9 +1,20 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
#include "extern.h"
|
||||
|
||||
class mixer_track;
|
||||
|
||||
inline sample_t sample_to_db(sample_t sample) {
|
||||
return 20.0f * log10f(sample);
|
||||
}
|
||||
|
||||
// convert db(-60db, 10db) to percent in range [0, 1]
|
||||
inline float db_to_percent(float db) {
|
||||
return (db + 60.0f) / 70.0f;
|
||||
}
|
||||
|
||||
void vertical_text(const char* text);
|
||||
|
||||
void draw_instrument_track();
|
||||
|
Loading…
x
Reference in New Issue
Block a user