21 AudioWaveformer::AudioWaveformer(
ReaderBase* new_reader) : reader(new_reader)
46 int sample_divisor = sample_rate / num_per_second;
47 int total_samples = num_per_second * (reader->
info.
duration + 1.0);
48 int extracted_index = 0;
56 data.
resize(total_samples);
57 data.
zero(total_samples);
66 float samples_max = 0.0;
67 float chunk_max = 0.0;
68 float chunk_squared_sum = 0.0;
71 int channel_count = 1;
78 shared_ptr<openshot::Frame> frame = reader->
GetFrame(f);
81 float* channels[channel_count];
82 for (
auto channel_index = 0; channel_index < reader->
info.
channels; channel_index++) {
83 if (channel == channel_index || channel == -1) {
84 channels[channel_index] = frame->GetAudioSamples(channel_index);
89 for (
auto s = 0; s < frame->GetAudioSamplesCount(); s++) {
90 for (
auto channel_index = 0; channel_index < reader->
info.
channels; channel_index++) {
91 if (channel == channel_index || channel == -1) {
92 float *samples = channels[channel_index];
93 float rms_sample_value = std::sqrt(samples[s] * samples[s]);
96 chunk_squared_sum += rms_sample_value;
97 chunk_max = std::max(chunk_max, rms_sample_value);
104 if (sample_index % sample_divisor == 0) {
105 float avg_squared_sum = chunk_squared_sum / (sample_divisor * channel_count);
107 data.
rms_samples[extracted_index] = avg_squared_sum;
111 samples_max = std::max(samples_max, chunk_max);
116 chunk_squared_sum = 0.0;
123 if (normalize && samples_max > 0.0) {
124 float scale = 1.0f / samples_max;
125 data.
scale(total_samples, scale);