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