OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 18 matching lines...) Expand all Loading... |
29 #ifndef ReverbAccumulationBuffer_h | 29 #ifndef ReverbAccumulationBuffer_h |
30 #define ReverbAccumulationBuffer_h | 30 #define ReverbAccumulationBuffer_h |
31 | 31 |
32 #include "platform/PlatformExport.h" | 32 #include "platform/PlatformExport.h" |
33 #include "platform/audio/AudioArray.h" | 33 #include "platform/audio/AudioArray.h" |
34 #include "wtf/Allocator.h" | 34 #include "wtf/Allocator.h" |
35 #include "wtf/Noncopyable.h" | 35 #include "wtf/Noncopyable.h" |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 // ReverbAccumulationBuffer is a circular delay buffer with one client reading f
rom it and multiple clients | 39 // ReverbAccumulationBuffer is a circular delay buffer with one client reading |
40 // writing/accumulating to it at different delay offsets from the read position.
The read operation will zero the memory | 40 // from it and multiple clients writing/accumulating to it at different delay |
41 // just read from the buffer, so it will be ready for accumulation the next time
around. | 41 // offsets from the read position. The read operation will zero the memory |
| 42 // just read from the buffer, so it will be ready for accumulation the next |
| 43 // time around. |
42 class PLATFORM_EXPORT ReverbAccumulationBuffer { | 44 class PLATFORM_EXPORT ReverbAccumulationBuffer { |
43 DISALLOW_NEW(); | 45 DISALLOW_NEW(); |
44 WTF_MAKE_NONCOPYABLE(ReverbAccumulationBuffer); | 46 WTF_MAKE_NONCOPYABLE(ReverbAccumulationBuffer); |
45 | 47 |
46 public: | 48 public: |
47 ReverbAccumulationBuffer(size_t length); | 49 ReverbAccumulationBuffer(size_t length); |
48 | 50 |
49 // This will read from, then clear-out numberOfFrames | 51 // This will read from, then clear-out numberOfFrames |
50 void readAndClear(float* destination, size_t numberOfFrames); | 52 void readAndClear(float* destination, size_t numberOfFrames); |
51 | 53 |
52 // Each ReverbConvolverStage will accumulate its output at the appropriate del
ay from the read position. | 54 // Each ReverbConvolverStage will accumulate its output at the appropriate |
53 // We need to pass in and update readIndex here, since each ReverbConvolverSta
ge may be running in | 55 // delay from the read position. We need to pass in and update readIndex |
54 // a different thread than the realtime thread calling ReadAndClear() and main
taining m_readIndex | 56 // here, since each ReverbConvolverStage may be running in a different thread |
| 57 // than the realtime thread calling ReadAndClear() and maintaining |
| 58 // m_readIndex |
55 // Returns the writeIndex where the accumulation took place | 59 // Returns the writeIndex where the accumulation took place |
56 int accumulate(float* source, | 60 int accumulate(float* source, |
57 size_t numberOfFrames, | 61 size_t numberOfFrames, |
58 int* readIndex, | 62 int* readIndex, |
59 size_t delayFrames); | 63 size_t delayFrames); |
60 | 64 |
61 size_t readIndex() const { return m_readIndex; } | 65 size_t readIndex() const { return m_readIndex; } |
62 void updateReadIndex(int* readIndex, size_t numberOfFrames) const; | 66 void updateReadIndex(int* readIndex, size_t numberOfFrames) const; |
63 | 67 |
64 size_t readTimeFrame() const { return m_readTimeFrame; } | 68 size_t readTimeFrame() const { return m_readTimeFrame; } |
65 | 69 |
66 void reset(); | 70 void reset(); |
67 | 71 |
68 private: | 72 private: |
69 AudioFloatArray m_buffer; | 73 AudioFloatArray m_buffer; |
70 size_t m_readIndex; | 74 size_t m_readIndex; |
71 size_t m_readTimeFrame; // for debugging (frame on continuous timeline) | 75 size_t m_readTimeFrame; // for debugging (frame on continuous timeline) |
72 }; | 76 }; |
73 | 77 |
74 } // namespace blink | 78 } // namespace blink |
75 | 79 |
76 #endif // ReverbAccumulationBuffer_h | 80 #endif // ReverbAccumulationBuffer_h |
OLD | NEW |