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;
124 float scale = 1.0f / samples_max;
125 data.
scale(total_samples, scale);
float duration
Length of time (in seconds)
This abstract class is the base class, used by all readers in libopenshot.
bool has_video
Determines if this file has a video stream.
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t number)=0
bool has_audio
Determines if this file has an audio stream.
int64_t video_length
The number of frames in the video stream.
openshot::ReaderInfo info
Information about the current media file.
This namespace is the default namespace for all code in the openshot library.
int channels
The number of audio channels used in the audio stream.
virtual void Open()=0
Open the reader (and start consuming resources, such as images or video files)
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
virtual bool IsOpen()=0
Determine if reader is open or closed.