OpenShot Library | libopenshot 0.3.3
Loading...
Searching...
No Matches
AudioWaveformer.h
Go to the documentation of this file.
1
9// Copyright (c) 2008-2022 OpenShot Studios, LLC
10//
11// SPDX-License-Identifier: LGPL-3.0-or-later
12
13#ifndef OPENSHOT_WAVEFORMER_H
14#define OPENSHOT_WAVEFORMER_H
15
16#include "ReaderBase.h"
17#include "Frame.h"
18#include <vector>
19
20
21namespace openshot {
22
30 {
31 std::vector<float> max_samples;
32 std::vector<float> rms_samples;
33
35 void resize(int total_samples) {
36 max_samples.resize(total_samples);
37 rms_samples.resize(total_samples);
38 }
39
41 void zero(int total_samples) {
42 std::fill(max_samples.begin(), max_samples.end(), 0);
43 std::fill(rms_samples.begin(), rms_samples.end(), 0);
44 }
45
47 void scale(int total_samples, float factor) {
48 for (auto s = 0; s < total_samples; s++) {
49 max_samples[s] *= factor;
50 rms_samples[s] *= factor;
51 }
52 }
53
55 void clear() {
56 max_samples.clear();
57 max_samples.shrink_to_fit();
58 rms_samples.clear();
59 rms_samples.shrink_to_fit();
60 }
61
63 std::vector<std::vector<float>> vectors() {
64 std::vector<std::vector<float>> output;
65 output.push_back(max_samples);
66 output.push_back(rms_samples);
67 return output;
68 }
69 };
70
80 private:
81 ReaderBase* reader;
82
83 public:
86
91 AudioWaveformData ExtractSamples(int channel, int num_per_second, bool normalize);
92
95 };
96
97}
98
99#endif
Header file for Frame class.
Header file for ReaderBase class.
This class is used to extra audio data used for generating waveforms.
AudioWaveformData ExtractSamples(int channel, int num_per_second, bool normalize)
Extract audio samples from any ReaderBase class.
This abstract class is the base class, used by all readers in libopenshot.
Definition ReaderBase.h:76
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
This struct holds the extracted waveform data (both the RMS root-mean-squared average,...
void resize(int total_samples)
Resize both datasets.
std::vector< float > rms_samples
std::vector< float > max_samples
void zero(int total_samples)
Zero out # of values in both datasets.
std::vector< std::vector< float > > vectors()
Return a vector of vectors (containing both datasets)
void scale(int total_samples, float factor)
Scale # of values by some factor.
void clear()
Clear and free memory of both datasets.