1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webaudio/blink/FFTConvolver.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,80 @@ 1.4 +/* 1.5 + * Copyright (C) 2010 Google Inc. All rights reserved. 1.6 + * 1.7 + * Redistribution and use in source and binary forms, with or without 1.8 + * modification, are permitted provided that the following conditions 1.9 + * are met: 1.10 + * 1.11 + * 1. Redistributions of source code must retain the above copyright 1.12 + * notice, this list of conditions and the following disclaimer. 1.13 + * 2. Redistributions in binary form must reproduce the above copyright 1.14 + * notice, this list of conditions and the following disclaimer in the 1.15 + * documentation and/or other materials provided with the distribution. 1.16 + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 1.17 + * its contributors may be used to endorse or promote products derived 1.18 + * from this software without specific prior written permission. 1.19 + * 1.20 + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 1.21 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1.22 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 1.23 + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 1.24 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 1.25 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 1.26 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 1.27 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.28 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 1.29 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.30 + */ 1.31 + 1.32 +#ifndef FFTConvolver_h 1.33 +#define FFTConvolver_h 1.34 + 1.35 +#include "nsTArray.h" 1.36 +#include "mozilla/FFTBlock.h" 1.37 +#include "mozilla/MemoryReporting.h" 1.38 + 1.39 +namespace WebCore { 1.40 + 1.41 +typedef nsTArray<float> AudioFloatArray; 1.42 +using mozilla::FFTBlock; 1.43 + 1.44 +class FFTConvolver { 1.45 +public: 1.46 + // fftSize must be a power of two 1.47 + FFTConvolver(size_t fftSize); 1.48 + 1.49 + // |fftKernel| must be pre-scaled for FFTBlock::GetInverseWithoutScaling(). 1.50 + // 1.51 + // For now, with multiple calls to Process(), framesToProcess MUST add up EXACTLY to fftSize / 2 1.52 + // 1.53 + // FIXME: Later, we can do more sophisticated buffering to relax this requirement... 1.54 + // 1.55 + // The input to output latency is equal to fftSize / 2 1.56 + // 1.57 + // Processing in-place is allowed... 1.58 + void process(FFTBlock* fftKernel, const float* sourceP, float* destP, size_t framesToProcess); 1.59 + 1.60 + void reset(); 1.61 + 1.62 + size_t fftSize() const { return m_frame.FFTSize(); } 1.63 + 1.64 + size_t sizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; 1.65 + size_t sizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; 1.66 + 1.67 +private: 1.68 + FFTBlock m_frame; 1.69 + 1.70 + // Buffer input until we get fftSize / 2 samples then do an FFT 1.71 + size_t m_readWriteIndex; 1.72 + AudioFloatArray m_inputBuffer; 1.73 + 1.74 + // Stores output which we read a little at a time 1.75 + AudioFloatArray m_outputBuffer; 1.76 + 1.77 + // Saves the 2nd half of the FFT buffer, so we can do an overlap-add with the 1st half of the next one 1.78 + AudioFloatArray m_lastOverlapBuffer; 1.79 +}; 1.80 + 1.81 +} // namespace WebCore 1.82 + 1.83 +#endif // FFTConvolver_h