]> git.sesse.net Git - kdenlive/blob - testingArea/audioCorrelationInfo.cpp
1d33aee10fff4513d50a70312ad019325f069245
[kdenlive] / testingArea / audioCorrelationInfo.cpp
1 #include "audioCorrelationInfo.h"
2 #include <iostream>
3
4 AudioCorrelationInfo::AudioCorrelationInfo(int mainSize, int subSize) :
5     m_mainSize(mainSize),
6     m_subSize(subSize),
7     m_max(-1)
8 {
9     m_correlationVector = new int64_t[m_mainSize+m_subSize+1];
10 }
11
12 AudioCorrelationInfo::~AudioCorrelationInfo()
13 {
14     delete m_correlationVector;
15 }
16
17 int AudioCorrelationInfo::size() const
18 {
19     return m_mainSize+m_subSize+1;
20 }
21
22 void AudioCorrelationInfo::setMax(int64_t max)
23 {
24     m_max = max;
25 }
26
27 int64_t AudioCorrelationInfo::max() const
28 {
29     Q_ASSERT(m_max > 0);
30     if (m_max <= 0) {
31         int width = size();
32         int64_t max = 0;
33         for (int i = 0; i < width; i++) {
34             if (m_correlationVector[i] > max) {
35                 max = m_correlationVector[i];
36             }
37         }
38         Q_ASSERT(max > 0);
39         return max;
40     }
41     return m_max;
42 }
43
44 int AudioCorrelationInfo::maxIndex() const
45 {
46     int64_t max = 0;
47     int index = 0;
48     int width = size();
49
50     for (int i = 0; i < width; i++) {
51         if (m_correlationVector[i] > max) {
52             max = m_correlationVector[i];
53             index = i;
54         }
55     }
56
57     return index;
58 }
59
60 int64_t* AudioCorrelationInfo::correlationVector()
61 {
62     return m_correlationVector;
63 }
64
65 QImage AudioCorrelationInfo::toImage(int height) const
66 {
67     int width = size();
68     int64_t maxVal = max();
69
70     QImage img(width, height, QImage::Format_ARGB32);
71     img.fill(qRgb(255,255,255));
72
73     int val;
74
75     for (int x = 0; x < width; x++) {
76         val = m_correlationVector[x]/double(maxVal)*img.height();
77         for (int y = img.height()-1; y > img.height() - val - 1; y--) {
78             img.setPixel(x, y, qRgb(50, 50, 50));
79         }
80     }
81
82     return img;
83 }