OpenShot Library | libopenshot  0.3.3
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 
21 namespace 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:
85  AudioWaveformer(ReaderBase* reader);
86 
91  AudioWaveformData ExtractSamples(int channel, int num_per_second, bool normalize);
92 
95  };
96 
97 }
98 
99 #endif
openshot::AudioWaveformer::~AudioWaveformer
~AudioWaveformer()
Destructor.
Definition: AudioWaveformer.cpp:27
openshot::AudioWaveformData::rms_samples
std::vector< float > rms_samples
Definition: AudioWaveformer.h:32
openshot::AudioWaveformData::resize
void resize(int total_samples)
Resize both datasets.
Definition: AudioWaveformer.h:35
openshot::AudioWaveformData::vectors
std::vector< std::vector< float > > vectors()
Return a vector of vectors (containing both datasets)
Definition: AudioWaveformer.h:63
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::AudioWaveformData::zero
void zero(int total_samples)
Zero out # of values in both datasets.
Definition: AudioWaveformer.h:41
openshot::AudioWaveformData::scale
void scale(int total_samples, float factor)
Scale # of values by some factor.
Definition: AudioWaveformer.h:47
openshot::AudioWaveformData::clear
void clear()
Clear and free memory of both datasets.
Definition: AudioWaveformer.h:55
openshot::AudioWaveformer::ExtractSamples
AudioWaveformData ExtractSamples(int channel, int num_per_second, bool normalize)
Extract audio samples from any ReaderBase class.
Definition: AudioWaveformer.cpp:33
Frame.h
Header file for Frame class.
openshot::AudioWaveformData
This struct holds the extracted waveform data (both the RMS root-mean-squared average,...
Definition: AudioWaveformer.h:29
ReaderBase.h
Header file for ReaderBase class.
openshot::AudioWaveformer
This class is used to extra audio data used for generating waveforms.
Definition: AudioWaveformer.h:79
openshot::AudioWaveformData::max_samples
std::vector< float > max_samples
Definition: AudioWaveformer.h:31
openshot::ReaderBase
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:75
openshot::AudioWaveformer::AudioWaveformer
AudioWaveformer(ReaderBase *reader)
Default constructor.
Definition: AudioWaveformer.cpp:21