source: trunk/demos/spectrum/app/spectrum.h@ 769

Last change on this file since 769 was 769, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.3 sources from branches/vendor/nokia/qt.

File size: 5.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the examples of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:BSD$
10** You may use this file under the terms of the BSD license as follows:
11**
12** "Redistribution and use in source and binary forms, with or without
13** modification, are permitted provided that the following conditions are
14** met:
15** * Redistributions of source code must retain the above copyright
16** notice, this list of conditions and the following disclaimer.
17** * Redistributions in binary form must reproduce the above copyright
18** notice, this list of conditions and the following disclaimer in
19** the documentation and/or other materials provided with the
20** distribution.
21** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22** the names of its contributors may be used to endorse or promote
23** products derived from this software without specific prior written
24** permission.
25**
26** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef SPECTRUM_H
42#define SPECTRUM_H
43
44#include <QtCore/qglobal.h>
45#include "utils.h"
46#include "fftreal_wrapper.h" // For FFTLengthPowerOfTwo
47
48//-----------------------------------------------------------------------------
49// Constants
50//-----------------------------------------------------------------------------
51
52// Number of audio samples used to calculate the frequency spectrum
53const int SpectrumLengthSamples = PowerOfTwo<FFTLengthPowerOfTwo>::Result;
54
55// Number of bands in the frequency spectrum
56const int SpectrumNumBands = 10;
57
58// Lower bound of first band in the spectrum
59const qreal SpectrumLowFreq = 0.0; // Hz
60
61// Upper band of last band in the spectrum
62const qreal SpectrumHighFreq = 1000.0; // Hz
63
64// Waveform window size in microseconds
65const qint64 WaveformWindowDuration = 500 * 1000;
66
67// Length of waveform tiles in bytes
68// Ideally, these would match the QAudio*::bufferSize(), but that isn't
69// available until some time after QAudio*::start() has been called, and we
70// need this value in order to initialize the waveform display.
71// We therefore just choose a sensible value.
72const int WaveformTileLength = 4096;
73
74// Fudge factor used to calculate the spectrum bar heights
75const qreal SpectrumAnalyserMultiplier = 0.15;
76
77// Disable message timeout
78const int NullMessageTimeout = -1;
79
80
81//-----------------------------------------------------------------------------
82// Types and data structures
83//-----------------------------------------------------------------------------
84
85enum WindowFunction {
86 NoWindow,
87 HannWindow
88};
89
90const WindowFunction DefaultWindowFunction = HannWindow;
91
92struct Tone {
93 Tone(qreal freq = 0.0, qreal amp = 0.0)
94 : frequency(freq), amplitude(amp)
95 { }
96
97 // Start and end frequencies for swept tone generation
98 qreal frequency;
99
100 // Amplitude in range [0.0, 1.0]
101 qreal amplitude;
102};
103
104struct SweptTone {
105 SweptTone(qreal start = 0.0, qreal end = 0.0, qreal amp = 0.0)
106 : startFreq(start), endFreq(end), amplitude(amp)
107 { Q_ASSERT(end >= start); }
108
109 SweptTone(const Tone &tone)
110 : startFreq(tone.frequency), endFreq(tone.frequency), amplitude(tone.amplitude)
111 { }
112
113 // Start and end frequencies for swept tone generation
114 qreal startFreq;
115 qreal endFreq;
116
117 // Amplitude in range [0.0, 1.0]
118 qreal amplitude;
119};
120
121
122//-----------------------------------------------------------------------------
123// Macros
124//-----------------------------------------------------------------------------
125
126// Macro which connects a signal to a slot, and which causes application to
127// abort if the connection fails. This is intended to catch programming errors
128// such as mis-typing a signal or slot name. It is necessary to write our own
129// macro to do this - the following idiom
130// Q_ASSERT(connect(source, signal, receiver, slot));
131// will not work because Q_ASSERT compiles to a no-op in release builds.
132
133#define CHECKED_CONNECT(source, signal, receiver, slot) \
134 if(!connect(source, signal, receiver, slot)) \
135 qt_assert_x(Q_FUNC_INFO, "CHECKED_CONNECT failed", __FILE__, __LINE__);
136
137// Handle some dependencies between macros defined in the .pro file
138
139#ifdef DISABLE_WAVEFORM
140#undef SUPERIMPOSE_PROGRESS_ON_WAVEFORM
141#endif
142
143#endif // SPECTRUM_H
144
Note: See TracBrowser for help on using the repository browser.