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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 void BiquadProcessor::process(const AudioBus* source, AudioBus* destination, siz
e_t framesToProcess) | 87 void BiquadProcessor::process(const AudioBus* source, AudioBus* destination, siz
e_t framesToProcess) |
88 { | 88 { |
89 if (!isInitialized()) { | 89 if (!isInitialized()) { |
90 destination->zero(); | 90 destination->zero(); |
91 return; | 91 return; |
92 } | 92 } |
93 | 93 |
| 94 // Synchronize with possible dynamic changes to the impulse response. |
| 95 MutexTryLocker tryLocker(m_processLock); |
| 96 if (!tryLocker.locked()) { |
| 97 // Can't get the lock. We must be in the middle of changing something. |
| 98 destination->zero(); |
| 99 return; |
| 100 } |
| 101 |
94 checkForDirtyCoefficients(); | 102 checkForDirtyCoefficients(); |
95 | 103 |
96 // For each channel of our input, process using the corresponding BiquadDSPK
ernel into the output channel. | 104 // For each channel of our input, process using the corresponding BiquadDSPK
ernel into the output channel. |
97 for (unsigned i = 0; i < m_kernels.size(); ++i) | 105 for (unsigned i = 0; i < m_kernels.size(); ++i) |
98 m_kernels[i]->process(source->channel(i)->data(), destination->channel(i
)->mutableData(), framesToProcess); | 106 m_kernels[i]->process(source->channel(i)->data(), destination->channel(i
)->mutableData(), framesToProcess); |
99 } | 107 } |
100 | 108 |
101 void BiquadProcessor::setType(FilterType type) | 109 void BiquadProcessor::setType(FilterType type) |
102 { | 110 { |
103 if (type != m_type) { | 111 if (type != m_type) { |
104 m_type = type; | 112 m_type = type; |
105 reset(); // The filter state must be reset only if the type has changed. | 113 reset(); // The filter state must be reset only if the type has changed. |
106 } | 114 } |
107 } | 115 } |
108 | 116 |
109 void BiquadProcessor::getFrequencyResponse(int nFrequencies, const float* freque
ncyHz, float* magResponse, float* phaseResponse) | 117 void BiquadProcessor::getFrequencyResponse(int nFrequencies, const float* freque
ncyHz, float* magResponse, float* phaseResponse) |
110 { | 118 { |
111 // Compute the frequency response on a separate temporary kernel | 119 // Compute the frequency response on a separate temporary kernel |
112 // to avoid interfering with the processing running in the audio | 120 // to avoid interfering with the processing running in the audio |
113 // thread on the main kernels. | 121 // thread on the main kernels. |
114 | 122 |
115 std::unique_ptr<BiquadDSPKernel> responseKernel = wrapUnique(new BiquadDSPKe
rnel(this)); | 123 std::unique_ptr<BiquadDSPKernel> responseKernel = wrapUnique(new BiquadDSPKe
rnel(this)); |
116 responseKernel->getFrequencyResponse(nFrequencies, frequencyHz, magResponse,
phaseResponse); | 124 responseKernel->getFrequencyResponse(nFrequencies, frequencyHz, magResponse,
phaseResponse); |
117 } | 125 } |
118 | 126 |
119 } // namespace blink | 127 } // namespace blink |
120 | 128 |
OLD | NEW |