1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webaudio/blink/ReverbAccumulationBuffer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 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 ReverbAccumulationBuffer_h 1.33 +#define ReverbAccumulationBuffer_h 1.34 + 1.35 +#include "nsTArray.h" 1.36 +#include "mozilla/MemoryReporting.h" 1.37 + 1.38 +namespace WebCore { 1.39 + 1.40 +typedef nsTArray<float> AudioFloatArray; 1.41 + 1.42 +// ReverbAccumulationBuffer is a circular delay buffer with one client reading from it and multiple clients 1.43 +// writing/accumulating to it at different delay offsets from the read position. The read operation will zero the memory 1.44 +// just read from the buffer, so it will be ready for accumulation the next time around. 1.45 +class ReverbAccumulationBuffer { 1.46 +public: 1.47 + ReverbAccumulationBuffer(size_t length); 1.48 + 1.49 + // This will read from, then clear-out numberOfFrames 1.50 + void readAndClear(float* destination, size_t numberOfFrames); 1.51 + 1.52 + // Each ReverbConvolverStage will accumulate its output at the appropriate delay from the read position. 1.53 + // We need to pass in and update readIndex here, since each ReverbConvolverStage may be running in 1.54 + // a different thread than the realtime thread calling ReadAndClear() and maintaining m_readIndex 1.55 + // Returns the writeIndex where the accumulation took place 1.56 + int accumulate(float* source, size_t numberOfFrames, int* readIndex, size_t delayFrames); 1.57 + 1.58 + size_t readIndex() const { return m_readIndex; } 1.59 + void updateReadIndex(int* readIndex, size_t numberOfFrames) const; 1.60 + 1.61 + size_t readTimeFrame() const { return m_readTimeFrame; } 1.62 + 1.63 + void reset(); 1.64 + 1.65 + size_t sizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const 1.66 + { 1.67 + return m_buffer.SizeOfExcludingThis(aMallocSizeOf); 1.68 + } 1.69 + 1.70 +private: 1.71 + AudioFloatArray m_buffer; 1.72 + size_t m_readIndex; 1.73 + size_t m_readTimeFrame; // for debugging (frame on continuous timeline) 1.74 +}; 1.75 + 1.76 +} // namespace WebCore 1.77 + 1.78 +#endif // ReverbAccumulationBuffer_h