2 * Copyright (C) 2010, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #ifndef RealtimeAnalyser_h
26 #define RealtimeAnalyser_h
28 #include "platform/audio/AudioArray.h"
29 #include "platform/audio/FFTFrame.h"
30 #include "wtf/Forward.h"
31 #include "wtf/Noncopyable.h"
32 #include "wtf/OwnPtr.h"
38 class RealtimeAnalyser FINAL {
39 WTF_MAKE_NONCOPYABLE(RealtimeAnalyser);
43 size_t fftSize() const { return m_fftSize; }
44 bool setFftSize(size_t);
46 unsigned frequencyBinCount() const { return m_fftSize / 2; }
48 void setMinDecibels(double k) { m_minDecibels = k; }
49 double minDecibels() const { return m_minDecibels; }
51 void setMaxDecibels(double k) { m_maxDecibels = k; }
52 double maxDecibels() const { return m_maxDecibels; }
54 void setSmoothingTimeConstant(double k) { m_smoothingTimeConstant = k; }
55 double smoothingTimeConstant() const { return m_smoothingTimeConstant; }
57 void getFloatFrequencyData(Float32Array*);
58 void getByteFrequencyData(Uint8Array*);
59 void getFloatTimeDomainData(Float32Array*);
60 void getByteTimeDomainData(Uint8Array*);
62 // The audio thread writes input data here.
63 void writeInput(AudioBus*, size_t framesToProcess);
65 static const double DefaultSmoothingTimeConstant;
66 static const double DefaultMinDecibels;
67 static const double DefaultMaxDecibels;
69 static const unsigned DefaultFFTSize;
70 static const unsigned MinFFTSize;
71 static const unsigned MaxFFTSize;
72 static const unsigned InputBufferSize;
75 // The audio thread writes the input audio here.
76 AudioFloatArray m_inputBuffer;
77 unsigned m_writeIndex;
80 OwnPtr<FFTFrame> m_analysisFrame;
83 // doFFTAnalysis() stores the floating-point magnitude analysis data here.
84 AudioFloatArray m_magnitudeBuffer;
85 AudioFloatArray& magnitudeBuffer() { return m_magnitudeBuffer; }
87 // A value between 0 and 1 which averages the previous version of m_magnitudeBuffer with the current analysis magnitude data.
88 double m_smoothingTimeConstant;
90 // The range used when converting when using getByteFrequencyData().
95 } // namespace WebCore
97 #endif // RealtimeAnalyser_h