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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 , m_accumulationBuffer(accumulationBuffer) | 49 , m_accumulationBuffer(accumulationBuffer) |
50 , m_accumulationReadIndex(0) | 50 , m_accumulationReadIndex(0) |
51 , m_inputReadIndex(0) | 51 , m_inputReadIndex(0) |
52 , m_impulseResponseLength(responseLength) | 52 , m_impulseResponseLength(responseLength) |
53 { | 53 { |
54 ASSERT(impulseResponse); | 54 ASSERT(impulseResponse); |
55 ASSERT(accumulationBuffer); | 55 ASSERT(accumulationBuffer); |
56 | 56 |
57 m_fftKernel.doPaddedFFT(impulseResponse + stageOffset, stageLength); | 57 m_fftKernel.doPaddedFFT(impulseResponse + stageOffset, stageLength); |
58 m_convolver = adoptPtr(new FFTConvolver(fftSize)); | 58 m_convolver = adoptPtr(new FFTConvolver(fftSize)); |
59 m_temporaryBuffer.resize(renderSliceSize); | 59 m_temporaryBuffer.allocate(renderSliceSize); |
60 | 60 |
61 // The convolution stage at offset stageOffset needs to have a corresponding
delay to cancel out the offset. | 61 // The convolution stage at offset stageOffset needs to have a corresponding
delay to cancel out the offset. |
62 size_t totalDelay = stageOffset + reverbTotalLatency; | 62 size_t totalDelay = stageOffset + reverbTotalLatency; |
63 | 63 |
64 // But, the FFT convolution itself incurs fftSize / 2 latency, so subtract t
his out... | 64 // But, the FFT convolution itself incurs fftSize / 2 latency, so subtract t
his out... |
65 size_t halfSize = fftSize / 2; | 65 size_t halfSize = fftSize / 2; |
66 ASSERT(totalDelay >= halfSize); | 66 ASSERT(totalDelay >= halfSize); |
67 if (totalDelay >= halfSize) | 67 if (totalDelay >= halfSize) |
68 totalDelay -= halfSize; | 68 totalDelay -= halfSize; |
69 | 69 |
70 // We divide up the total delay, into pre and post delay sections so that we
can schedule at exactly the moment when the FFT will happen. | 70 // We divide up the total delay, into pre and post delay sections so that we
can schedule at exactly the moment when the FFT will happen. |
71 // This is coordinated with the other stages, so they don't all do their FFT
s at the same time... | 71 // This is coordinated with the other stages, so they don't all do their FFT
s at the same time... |
72 int maxPreDelayLength = std::min(halfSize, totalDelay); | 72 int maxPreDelayLength = std::min(halfSize, totalDelay); |
73 m_preDelayLength = totalDelay > 0 ? renderPhase % maxPreDelayLength : 0; | 73 m_preDelayLength = totalDelay > 0 ? renderPhase % maxPreDelayLength : 0; |
74 if (m_preDelayLength > totalDelay) | 74 if (m_preDelayLength > totalDelay) |
75 m_preDelayLength = 0; | 75 m_preDelayLength = 0; |
76 | 76 |
77 m_postDelayLength = totalDelay - m_preDelayLength; | 77 m_postDelayLength = totalDelay - m_preDelayLength; |
78 m_preReadWriteIndex = 0; | 78 m_preReadWriteIndex = 0; |
79 m_framesProcessed = 0; // total frames processed so far | 79 m_framesProcessed = 0; // total frames processed so far |
80 | 80 |
81 m_preDelayBuffer.resize(m_preDelayLength < fftSize ? fftSize : m_preDelayLen
gth); | 81 m_preDelayBuffer.allocate(m_preDelayLength < fftSize ? fftSize : m_preDelayL
ength); |
82 } | 82 } |
83 | 83 |
84 void ReverbConvolverStage::processInBackground(ReverbConvolver* convolver, size_
t framesToProcess) | 84 void ReverbConvolverStage::processInBackground(ReverbConvolver* convolver, size_
t framesToProcess) |
85 { | 85 { |
86 ReverbInputBuffer* inputBuffer = convolver->inputBuffer(); | 86 ReverbInputBuffer* inputBuffer = convolver->inputBuffer(); |
87 float* source = inputBuffer->directReadFrom(&m_inputReadIndex, framesToProce
ss); | 87 float* source = inputBuffer->directReadFrom(&m_inputReadIndex, framesToProce
ss); |
88 process(source, framesToProcess); | 88 process(source, framesToProcess); |
89 } | 89 } |
90 | 90 |
91 void ReverbConvolverStage::process(float* source, size_t framesToProcess) | 91 void ReverbConvolverStage::process(float* source, size_t framesToProcess) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 m_convolver->reset(); | 156 m_convolver->reset(); |
157 m_preDelayBuffer.zero(); | 157 m_preDelayBuffer.zero(); |
158 m_accumulationReadIndex = 0; | 158 m_accumulationReadIndex = 0; |
159 m_inputReadIndex = 0; | 159 m_inputReadIndex = 0; |
160 m_framesProcessed = 0; | 160 m_framesProcessed = 0; |
161 } | 161 } |
162 | 162 |
163 } // namespace WebCore | 163 } // namespace WebCore |
164 | 164 |
165 #endif // ENABLE(WEB_AUDIO) | 165 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |