]> git.sesse.net Git - kdenlive/commitdiff
Audio spectrum: Show overdriving (overmodulation) by colorizing the spectrum
authorSimon A. Eugster <simon.eu@gmail.com>
Sat, 15 Jan 2011 19:24:34 +0000 (19:24 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Sat, 15 Jan 2011 19:24:34 +0000 (19:24 +0000)
svn path=/trunk/kdenlive/; revision=5326

kdenlive-mindmap.svg
src/audioscopes/audiospectrum.cpp
src/audioscopes/audiospectrum.h

index c8c5347766cf97e907ed43e723266eb5d9d1f62d..3b754c75afe8110d0d15604db9090485dc1f8637 100644 (file)
        inkscape:vp_y="0 : 1000 : 0"
        inkscape:vp_x="0 : 0.5 : 1"
        sodipodi:type="inkscape:persp3d" />
+    <inkscape:perspective
+       id="perspective3834"
+       inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
+       inkscape:vp_z="1 : 0.5 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_x="0 : 0.5 : 1"
+       sodipodi:type="inkscape:persp3d" />
   </defs>
   <sodipodi:namedview
      id="base"
      borderopacity="1.0"
      inkscape:pageopacity="0"
      inkscape:pageshadow="2"
-     inkscape:zoom="0.49497475"
-     inkscape:cx="7848.5254"
-     inkscape:cy="5017.1078"
+     inkscape:zoom="0.7"
+     inkscape:cx="11758.763"
+     inkscape:cy="4407.2705"
      inkscape:document-units="px"
      inkscape:current-layer="layer3"
      showgrid="false"
          id="tspan11223-6"
          x="-4473.2314"
          y="-1229.5742">STABILITY</tspan></text>
+    <text
+       sodipodi:linespacing="100%"
+       id="text3868"
+       y="538.66272"
+       x="4985.834"
+       style="font-size:288px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:100%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;opacity:0.2017544;color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans Bold"
+       xml:space="preserve"><tspan
+         y="538.66272"
+         x="4985.834"
+         id="tspan3870"
+         sodipodi:role="line">GENERAL</tspan></text>
   </g>
   <g
      inkscape:groupmode="layer"
          x="899.27069"
          id="tspan3286"
          sodipodi:role="line">Keyboard Shortcuts</tspan></text>
+    <text
+       xml:space="preserve"
+       style="font-size:144px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;opacity:0.2017544;color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans Bold"
+       x="4260.4497"
+       y="-1274.8326"
+       id="text3852"
+       sodipodi:linespacing="125%"><tspan
+         sodipodi:role="line"
+         id="tspan3854"
+         x="4260.4497"
+         y="-1274.8326">UI</tspan></text>
   </g>
   <g
      inkscape:groupmode="layer"
          sodipodi:role="line"
          id="tspan13417-2-7"
          x="-2251.8438"
-         y="2730.7996">Color safety (TV) tdisplay</tspan></text>
+         y="2730.7996">Color safety (TV) display</tspan></text>
     <text
        xml:space="preserve"
        style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;color:#000000;fill:#eeeeee;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
          sodipodi:role="line"
          id="tspan13264-5-0-1-1-6"
          x="-1491.0187"
-         y="28.033258">Low-Resolution preview</tspan></text>
+         y="28.033258">Low-Resolution preview</tspan><tspan
+         sodipodi:role="line"
+         x="-1491.0187"
+         y="58.033257"
+         id="tspan3880">(Proxy Clips)</tspan></text>
     <text
        xml:space="preserve"
        style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;color:#000000;fill:#eeeeee;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
          id="tspan3294"
          x="1620.6732"
          y="1.675822">Support workflow</tspan></text>
+    <use
+       height="6765.7144"
+       width="14148.571"
+       transform="translate(10772.758,-4844.9441)"
+       id="use4239-5"
+       xlink:href="#path3261"
+       y="0"
+       x="0" />
+    <text
+       sodipodi:linespacing="125%"
+       id="text3848"
+       y="-1475.5615"
+       x="2193.2241"
+       style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;color:#000000;fill:#eeeeee;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
+       xml:space="preserve"><tspan
+         id="tspan3850"
+         y="-1475.5615"
+         x="2193.2241"
+         sodipodi:role="line">Display both monitors (clip/project) to compare results</tspan></text>
+    <text
+       sodipodi:linespacing="125%"
+       id="text3856"
+       y="-1203.4962"
+       x="4411.6221"
+       style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;color:#000000;fill:#eeeeee;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
+       xml:space="preserve"><tspan
+         id="tspan3858"
+         y="-1203.4962"
+         x="4411.6221"
+         sodipodi:role="line">Hide clip names</tspan></text>
+    <text
+       sodipodi:linespacing="125%"
+       id="text3860"
+       y="4036.4453"
+       x="982.38702"
+       style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;color:#000000;fill:#eeeeee;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
+       xml:space="preserve"><tspan
+         id="tspan3862"
+         y="4036.4453"
+         x="982.38702"
+         sodipodi:role="line">Set audio track to general sound level</tspan></text>
+    <text
+       sodipodi:linespacing="125%"
+       id="text3864"
+       y="4177.1982"
+       x="1280.7074"
+       style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;color:#000000;fill:#eeeeee;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
+       xml:space="preserve"><tspan
+         id="tspan3866"
+         y="4177.1982"
+         x="1280.7074"
+         sodipodi:role="line">Split audio and video by default when adding a clip to the timeline</tspan></text>
+    <text
+       sodipodi:linespacing="125%"
+       id="text3874"
+       y="159.74539"
+       x="5255.332"
+       style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;color:#000000;fill:#eeeeee;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
+       xml:space="preserve"><tspan
+         y="159.74539"
+         x="5255.332"
+         id="tspan3876"
+         sodipodi:role="line">Nested tracks</tspan><tspan
+         y="189.74539"
+         x="5255.332"
+         sodipodi:role="line"
+         id="tspan3878">(similar to adding a .kdenlive file as clip to the timeline)</tspan></text>
+    <text
+       xml:space="preserve"
+       style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;color:#000000;fill:#eeeeee;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
+       x="6559.6177"
+       y="268.31683"
+       id="text3882"
+       sodipodi:linespacing="125%"><tspan
+         id="tspan3886"
+         sodipodi:role="line"
+         x="6559.6177"
+         y="268.31683">EDL (Edit Decision List)</tspan></text>
   </g>
 </svg>
index 27f4c0a267f0fdddf881bbbfe9a0640e38bfddfa..2d0bb243d36595864f6d79462403400ba9bace8f 100644 (file)
 #include <QDebug>
 #endif
 
+// (defined in the header file)
+#ifdef DETECT_OVERMODULATION
+#include <limits>
+#include <cmath>
+#endif
+
 // Draw lines instead of single pixels.
 // This is about 25 % faster, especially when enlarging the scope to e.g. 1680x1050 px.
 #define AUDIOSPEC_LINES
@@ -44,6 +50,7 @@ AudioSpectrum::AudioSpectrum(QWidget *parent) :
     ,m_timeTotal(0)
     ,m_showTotal(0)
   #endif
+  ,colorizeFactor(0)
 {
     ui = new Ui::AudioSpectrum_UI;
     ui->setupUi(this);
@@ -158,6 +165,34 @@ QImage AudioSpectrum::renderAudioScope(uint, const QVector<int16_t> audioFrame,
         QTime start = QTime::currentTime();
 
 
+#ifdef DETECT_OVERMODULATION
+        bool overmodulated = false;
+        int overmodulateCount = 0;
+
+        for (int i = 0; i < audioFrame.size(); i++) {
+            if (
+                    audioFrame[i] == std::numeric_limits<int16_t>::max()
+                    || audioFrame[i] == std::numeric_limits<int16_t>::min()) {
+                overmodulateCount++;
+                if (overmodulateCount > 3) {
+                    overmodulated = true;
+                    break;
+                }
+            }
+        }
+        if (overmodulated) {
+            colorizeFactor = 1;
+        } else {
+            if (colorizeFactor > 0) {
+                colorizeFactor -= .08;
+                if (colorizeFactor < 0) {
+                    colorizeFactor = 0;
+                }
+            }
+        }
+#endif
+
+
         // Determine the window size to use. It should be
         // * not bigger than the number of samples actually available
         // * divisible by 2
@@ -203,11 +238,26 @@ QImage AudioSpectrum::renderAudioScope(uint, const QVector<int16_t> audioFrame,
         const uint h = m_innerScopeRect.height();
         const uint leftDist = m_innerScopeRect.left() - m_scopeRect.left();
         const uint topDist = m_innerScopeRect.top() - m_scopeRect.top();
+        QColor spectrumColor(AbstractScopeWidget::colDarkWhite);
         int yMax;
 
+#ifdef DETECT_OVERMODULATION
+        if (colorizeFactor > 0) {
+            QColor col = AbstractScopeWidget::colHighlightDark;
+            QColor spec = spectrumColor;
+            float f = std::sin(M_PI_2 * colorizeFactor);
+            spectrumColor = QColor(
+                        (int) (f * col.red() + (1-f) * spec.red()),
+                        (int) (f * col.green() + (1-f) * spec.green()),
+                        (int) (f * col.blue() + (1-f) * spec.blue()),
+                        spec.alpha()
+                        );
+        }
+#endif
+
 #ifdef AUDIOSPEC_LINES
         QPainter davinci(&spectrum);
-        davinci.setPen(AbstractScopeWidget::penThin);
+        davinci.setPen(QPen(QBrush(spectrumColor.rgba()), 1, Qt::SolidLine));
 #endif
 
         for (uint i = 0; i < w; i++) {
@@ -221,7 +271,7 @@ QImage AudioSpectrum::renderAudioScope(uint, const QVector<int16_t> audioFrame,
             davinci.drawLine(leftDist + i, topDist + h-1, leftDist + i, topDist + h-1 - yMax);
 #else
             for (int y = 0; y < yMax && y < (int)h; y++) {
-                spectrum.setPixel(leftDist + i, topDist + h-y-1, qRgba(225, 182, 255, 255));
+                spectrum.setPixel(leftDist + i, topDist + h-y-1, spectrumColor.rgba());
             }
 #endif
         }
@@ -296,13 +346,6 @@ QImage AudioSpectrum::renderHUD(uint)
         QPainter davinci(&hud);
         davinci.setPen(AbstractScopeWidget::penLight);
 
-        int _dw = m_innerScopeRect.width();
-        int _dh = m_innerScopeRect.height();
-        int _dld = m_innerScopeRect.width() + leftDist + textDistX;
-        int _dtd = topDist+ m_innerScopeRect.height() + 6;
-        int _fw = AbstractScopeWidget::geometry().width();
-        int _fh = AbstractScopeWidget::geometry().height();
-
         int y;
         for (int db = -dbDiff; db > m_dBmin; db -= dbDiff) {
             y = topDist + m_innerScopeRect.height() * ((float)db)/(m_dBmin - m_dBmax);
index 78d6cbc5680691b5f9989a771499d0c1247e2b61..a0d8d2943d1a70bec5b0744b1c32161676f0273a 100644 (file)
@@ -20,6 +20,9 @@
 // Enables debugging
 //#define DEBUG_AUDIOSPEC
 
+// Show overmodulation
+#define DETECT_OVERMODULATION
+
 #include <QtCore>
 #include <QVector>
 #include <QHash>
@@ -83,6 +86,8 @@ private:
     /** The user has chosen a custom frequency. */
     bool m_customFreq;
 
+    float colorizeFactor;
+
 #ifdef DEBUG_AUDIOSPEC
     long m_timeTotal;
     long m_showTotal;