Skip to content

Commit

Permalink
audiovisualwaveform: removed templates
Browse files Browse the repository at this point in the history
I'm not sure if this will make any difference performance-wise,
but we don't need them anymore so yeah.
  • Loading branch information
itsmattkc committed Apr 14, 2021
1 parent 3ffb2fd commit 6b7412a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
25 changes: 9 additions & 16 deletions app/audio/audiovisualwaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ AudioVisualWaveform::Sample AudioVisualWaveform::GetSummaryFromTime(const ration

AudioVisualWaveform::Sample AudioVisualWaveform::SumSamples(const float *samples, int nb_samples, int nb_channels)
{
return SumSamplesInternal(samples, nb_samples, nb_channels);
AudioVisualWaveform::Sample summed_samples(nb_channels);

for (int i=0;i<nb_samples;i++) {
ExpandMinMax(summed_samples[i%nb_channels], samples[i]);
}

return summed_samples;
}

AudioVisualWaveform::Sample AudioVisualWaveform::SumSamples(SampleBufferPtr samples, int start_index, int length)
Expand All @@ -229,7 +235,7 @@ AudioVisualWaveform::Sample AudioVisualWaveform::SumSamples(SampleBufferPtr samp

for (int i=start_index; i<end_index; i++) {
for (int channel=0; channel<samples->audio_params().channel_count(); channel++) {
ExpandMinMax<float>(summed_samples[channel], samples->data(channel)[i]);
ExpandMinMax(summed_samples[channel], samples->data(channel)[i]);
}
}

Expand Down Expand Up @@ -369,20 +375,7 @@ std::map<rational, AudioVisualWaveform::Sample>::const_iterator AudioVisualWavef
return using_mipmap;
}

template<typename T>
AudioVisualWaveform::Sample AudioVisualWaveform::SumSamplesInternal(const T *samples, int nb_samples, int nb_channels)
{
AudioVisualWaveform::Sample summed_samples(nb_channels);

for (int i=0;i<nb_samples;i++) {
ExpandMinMax<T>(summed_samples[i%nb_channels], samples[i]);
}

return summed_samples;
}

template<typename T>
void AudioVisualWaveform::ExpandMinMax(AudioVisualWaveform::SamplePerChannel &sum, T value)
void AudioVisualWaveform::ExpandMinMax(AudioVisualWaveform::SamplePerChannel &sum, float value)
{
if (value < sum.min) {
sum.min = value;
Expand Down
6 changes: 1 addition & 5 deletions app/audio/audiovisualwaveform.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ class AudioVisualWaveform {
static void DrawWaveform(QPainter* painter, const QRect &rect, const double &scale, const AudioVisualWaveform& samples, const rational &start_time);

private:
template <typename T>
static Sample SumSamplesInternal(const T* samples, int nb_samples, int nb_channels);

template <typename T>
static void ExpandMinMax(SamplePerChannel &sum, T value);
static void ExpandMinMax(SamplePerChannel &sum, float value);

void OverwriteSamplesFromBuffer(SampleBufferPtr samples, int sample_rate, const rational& start, double target_rate, Sample &data, int &start_index, int &samples_length);

Expand Down

0 comments on commit 6b7412a

Please sign in to comment.