summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opierec/waveform.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opierec/waveform.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/waveform.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/noncore/multimedia/opierec/waveform.cpp b/noncore/multimedia/opierec/waveform.cpp
index 9cc40b4..7c9a25f 100644
--- a/noncore/multimedia/opierec/waveform.cpp
+++ b/noncore/multimedia/opierec/waveform.cpp
@@ -1,67 +1,71 @@
1/********************************************************************** 1/**********************************************************************
2 ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2 ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3 ** 3 **
4 ** This file is part of the Qtopia Environment. 4 ** This file is part of the Qtopia Environment.
5 ** 5 **
6 ** This file may be distributed and/or modified under the terms of the 6 ** This file may be distributed and/or modified under the terms of the
7 ** GNU General Public License version 2 as published by the Free Software 7 ** GNU General Public License version 2 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.GPL included in the 8 ** Foundation and appearing in the file LICENSE.GPL included in the
9 ** packaging of this file. 9 ** packaging of this file.
10 ** 10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 ** 13 **
14 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 14 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
15 ** 15 **
16 ** Contact info@trolltech.com if any conditions of this licensing are 16 ** Contact info@trolltech.com if any conditions of this licensing are
17 ** not clear to you. 17 ** not clear to you.
18 ** 18 **
19 **********************************************************************/ 19 **********************************************************************/
20#include "waveform.h" 20#include "waveform.h"
21 21
22#include <qpainter.h> 22/* OPIE */
23#include <opie2/odebug.h>
24using namespace Opie::Core;
23 25
26/* QT */
27#include <qpainter.h>
24 28
25Waveform::Waveform( QWidget *parent, const char *name, WFlags fl ) 29Waveform::Waveform( QWidget *parent, const char *name, WFlags fl )
26 : QWidget( parent, name, fl ) 30 : QWidget( parent, name, fl )
27{ 31{
28 pixmap = 0; 32 pixmap = 0;
29 windowSize = 100; 33 windowSize = 100;
30 samplesPerPixel = 8000 / (5 * windowSize); 34 samplesPerPixel = 8000 / (5 * windowSize);
31 currentValue = 0; 35 currentValue = 0;
32 numSamples = 0; 36 numSamples = 0;
33 windowPosn = 0; 37 windowPosn = 0;
34 window = 0; 38 window = 0;
35} 39}
36 40
37 41
38void Waveform::changeSettings( int frequency, int channels ) 42void Waveform::changeSettings( int frequency, int channels )
39{ 43{
40 makePixmap(); 44 makePixmap();
41// qWarning("change waveform %d, %d", frequency, channels); 45// owarn << "change waveform " << frequency << ", " << channels << "" << oendl;
42 samplesPerPixel = frequency * channels / (5 * windowSize); 46 samplesPerPixel = frequency * channels / (5 * windowSize);
43 qWarning("Waveform::changeSettings %d", samplesPerPixel); 47 owarn << "Waveform::changeSettings " << samplesPerPixel << "" << oendl;
44 if ( !samplesPerPixel ) 48 if ( !samplesPerPixel )
45 samplesPerPixel = 1; 49 samplesPerPixel = 1;
46 currentValue = 0; 50 currentValue = 0;
47 numSamples = 0; 51 numSamples = 0;
48 windowPosn = 0; 52 windowPosn = 0;
49 draw(); 53 draw();
50} 54}
51 55
52 56
53Waveform::~Waveform() 57Waveform::~Waveform()
54{ 58{
55 if ( window ) 59 if ( window )
56 delete[] window; 60 delete[] window;
57 if ( pixmap ) 61 if ( pixmap )
58 delete pixmap; 62 delete pixmap;
59} 63}
60 64
61 65
62void Waveform::reset() 66void Waveform::reset()
63{ 67{
64 makePixmap(); 68 makePixmap();
65 currentValue = 0; 69 currentValue = 0;
66 numSamples = 0; 70 numSamples = 0;
67 windowPosn = 0; 71 windowPosn = 0;
@@ -75,49 +79,49 @@ void Waveform::newSamples( const short *buf, int len )
75 int samplesPerPixel = this->samplesPerPixel; 79 int samplesPerPixel = this->samplesPerPixel;
76 int currentValue = this->currentValue; 80 int currentValue = this->currentValue;
77 int numSamples = this->numSamples; 81 int numSamples = this->numSamples;
78 short *window = this->window; 82 short *window = this->window;
79 int windowPosn = this->windowPosn; 83 int windowPosn = this->windowPosn;
80 int windowSize = this->windowSize; 84 int windowSize = this->windowSize;
81 85
82 // Average the incoming samples to scale them to the window. 86 // Average the incoming samples to scale them to the window.
83 while ( len > 0 ) { 87 while ( len > 0 ) {
84 currentValue += *buf++; 88 currentValue += *buf++;
85 --len; 89 --len;
86 if ( ++numSamples >= samplesPerPixel ) { 90 if ( ++numSamples >= samplesPerPixel ) {
87 window[windowPosn++] = (short)(currentValue / numSamples); 91 window[windowPosn++] = (short)(currentValue / numSamples);
88 if ( windowPosn >= windowSize ) { 92 if ( windowPosn >= windowSize ) {
89 this->windowPosn = windowPosn; 93 this->windowPosn = windowPosn;
90 draw(); 94 draw();
91 windowPosn = 0; 95 windowPosn = 0;
92 } 96 }
93 numSamples = 0; 97 numSamples = 0;
94 currentValue = 0; 98 currentValue = 0;
95 } 99 }
96 } 100 }
97 101
98 // Copy the final state back to the object. 102 // Copy the final state back to the object.
99//qWarning("%d, %d, %d", currentValue, numSamples, windowPosn); 103//owarn << "" << currentValue << ", " << numSamples << ", " << windowPosn << "" << oendl;
100 this->currentValue = currentValue; 104 this->currentValue = currentValue;
101 this->numSamples = numSamples; 105 this->numSamples = numSamples;
102 this->windowPosn = windowPosn; 106 this->windowPosn = windowPosn;
103} 107}
104 108
105 109
106void Waveform::makePixmap() 110void Waveform::makePixmap()
107{ 111{
108 if ( !pixmap ) { 112 if ( !pixmap ) {
109 pixmap = new QPixmap( size() ); 113 pixmap = new QPixmap( size() );
110 windowSize = pixmap->width(); 114 windowSize = pixmap->width();
111 window = new short [windowSize]; 115 window = new short [windowSize];
112 } 116 }
113} 117}
114 118
115 119
116void Waveform::draw() 120void Waveform::draw()
117{ 121{
118 pixmap->fill( Qt::black ); 122 pixmap->fill( Qt::black );
119 QPainter painter; 123 QPainter painter;
120 painter.begin( pixmap ); 124 painter.begin( pixmap );
121 painter.setPen( Qt::green ); 125 painter.setPen( Qt::green );
122 126
123 int middle = pixmap->height() / 2; 127 int middle = pixmap->height() / 2;