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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 BiquadProcessor::~BiquadProcessor() { | 48 BiquadProcessor::~BiquadProcessor() { |
49 if (isInitialized()) | 49 if (isInitialized()) |
50 uninitialize(); | 50 uninitialize(); |
51 } | 51 } |
52 | 52 |
53 std::unique_ptr<AudioDSPKernel> BiquadProcessor::createKernel() { | 53 std::unique_ptr<AudioDSPKernel> BiquadProcessor::createKernel() { |
54 return wrapUnique(new BiquadDSPKernel(this)); | 54 return wrapUnique(new BiquadDSPKernel(this)); |
55 } | 55 } |
56 | 56 |
57 void BiquadProcessor::checkForDirtyCoefficients() { | 57 void BiquadProcessor::checkForDirtyCoefficients() { |
58 // Deal with smoothing / de-zippering. Start out assuming filter parameters ar
e not changing. | 58 // Deal with smoothing / de-zippering. Start out assuming filter parameters |
| 59 // are not changing. |
59 | 60 |
60 // The BiquadDSPKernel objects rely on this value to see if they need to re-co
mpute their internal filter coefficients. | 61 // The BiquadDSPKernel objects rely on this value to see if they need to |
| 62 // re-compute their internal filter coefficients. |
61 m_filterCoefficientsDirty = false; | 63 m_filterCoefficientsDirty = false; |
62 m_hasSampleAccurateValues = false; | 64 m_hasSampleAccurateValues = false; |
63 | 65 |
64 if (m_parameter1->hasSampleAccurateValues() || | 66 if (m_parameter1->hasSampleAccurateValues() || |
65 m_parameter2->hasSampleAccurateValues() || | 67 m_parameter2->hasSampleAccurateValues() || |
66 m_parameter3->hasSampleAccurateValues() || | 68 m_parameter3->hasSampleAccurateValues() || |
67 m_parameter4->hasSampleAccurateValues()) { | 69 m_parameter4->hasSampleAccurateValues()) { |
68 m_filterCoefficientsDirty = true; | 70 m_filterCoefficientsDirty = true; |
69 m_hasSampleAccurateValues = true; | 71 m_hasSampleAccurateValues = true; |
70 } else { | 72 } else { |
71 if (m_hasJustReset) { | 73 if (m_hasJustReset) { |
72 // Snap to exact values first time after reset, then smooth for subsequent
changes. | 74 // Snap to exact values first time after reset, then smooth for subsequent |
| 75 // changes. |
73 m_parameter1->resetSmoothedValue(); | 76 m_parameter1->resetSmoothedValue(); |
74 m_parameter2->resetSmoothedValue(); | 77 m_parameter2->resetSmoothedValue(); |
75 m_parameter3->resetSmoothedValue(); | 78 m_parameter3->resetSmoothedValue(); |
76 m_parameter4->resetSmoothedValue(); | 79 m_parameter4->resetSmoothedValue(); |
77 m_filterCoefficientsDirty = true; | 80 m_filterCoefficientsDirty = true; |
78 m_hasJustReset = false; | 81 m_hasJustReset = false; |
79 } else { | 82 } else { |
80 // Smooth all of the filter parameters. If they haven't yet converged to t
heir target value then mark coefficients as dirty. | 83 // Smooth all of the filter parameters. If they haven't yet converged to |
| 84 // their target value then mark coefficients as dirty. |
81 bool isStable1 = m_parameter1->smooth(); | 85 bool isStable1 = m_parameter1->smooth(); |
82 bool isStable2 = m_parameter2->smooth(); | 86 bool isStable2 = m_parameter2->smooth(); |
83 bool isStable3 = m_parameter3->smooth(); | 87 bool isStable3 = m_parameter3->smooth(); |
84 bool isStable4 = m_parameter4->smooth(); | 88 bool isStable4 = m_parameter4->smooth(); |
85 if (!(isStable1 && isStable2 && isStable3 && isStable4)) | 89 if (!(isStable1 && isStable2 && isStable3 && isStable4)) |
86 m_filterCoefficientsDirty = true; | 90 m_filterCoefficientsDirty = true; |
87 } | 91 } |
88 } | 92 } |
89 } | 93 } |
90 | 94 |
91 void BiquadProcessor::process(const AudioBus* source, | 95 void BiquadProcessor::process(const AudioBus* source, |
92 AudioBus* destination, | 96 AudioBus* destination, |
93 size_t framesToProcess) { | 97 size_t framesToProcess) { |
94 if (!isInitialized()) { | 98 if (!isInitialized()) { |
95 destination->zero(); | 99 destination->zero(); |
96 return; | 100 return; |
97 } | 101 } |
98 | 102 |
99 // Synchronize with possible dynamic changes to the impulse response. | 103 // Synchronize with possible dynamic changes to the impulse response. |
100 MutexTryLocker tryLocker(m_processLock); | 104 MutexTryLocker tryLocker(m_processLock); |
101 if (!tryLocker.locked()) { | 105 if (!tryLocker.locked()) { |
102 // Can't get the lock. We must be in the middle of changing something. | 106 // Can't get the lock. We must be in the middle of changing something. |
103 destination->zero(); | 107 destination->zero(); |
104 return; | 108 return; |
105 } | 109 } |
106 | 110 |
107 checkForDirtyCoefficients(); | 111 checkForDirtyCoefficients(); |
108 | 112 |
109 // For each channel of our input, process using the corresponding BiquadDSPKer
nel into the output channel. | 113 // For each channel of our input, process using the corresponding |
| 114 // BiquadDSPKernel into the output channel. |
110 for (unsigned i = 0; i < m_kernels.size(); ++i) | 115 for (unsigned i = 0; i < m_kernels.size(); ++i) |
111 m_kernels[i]->process(source->channel(i)->data(), | 116 m_kernels[i]->process(source->channel(i)->data(), |
112 destination->channel(i)->mutableData(), | 117 destination->channel(i)->mutableData(), |
113 framesToProcess); | 118 framesToProcess); |
114 } | 119 } |
115 | 120 |
116 void BiquadProcessor::setType(FilterType type) { | 121 void BiquadProcessor::setType(FilterType type) { |
117 if (type != m_type) { | 122 if (type != m_type) { |
118 m_type = type; | 123 m_type = type; |
119 reset(); // The filter state must be reset only if the type has changed. | 124 reset(); // The filter state must be reset only if the type has changed. |
120 } | 125 } |
121 } | 126 } |
122 | 127 |
123 void BiquadProcessor::getFrequencyResponse(int nFrequencies, | 128 void BiquadProcessor::getFrequencyResponse(int nFrequencies, |
124 const float* frequencyHz, | 129 const float* frequencyHz, |
125 float* magResponse, | 130 float* magResponse, |
126 float* phaseResponse) { | 131 float* phaseResponse) { |
127 // Compute the frequency response on a separate temporary kernel | 132 // Compute the frequency response on a separate temporary kernel |
128 // to avoid interfering with the processing running in the audio | 133 // to avoid interfering with the processing running in the audio |
129 // thread on the main kernels. | 134 // thread on the main kernels. |
130 | 135 |
131 std::unique_ptr<BiquadDSPKernel> responseKernel = | 136 std::unique_ptr<BiquadDSPKernel> responseKernel = |
132 wrapUnique(new BiquadDSPKernel(this)); | 137 wrapUnique(new BiquadDSPKernel(this)); |
133 responseKernel->getFrequencyResponse(nFrequencies, frequencyHz, magResponse, | 138 responseKernel->getFrequencyResponse(nFrequencies, frequencyHz, magResponse, |
134 phaseResponse); | 139 phaseResponse); |
135 } | 140 } |
136 | 141 |
137 } // namespace blink | 142 } // namespace blink |
OLD | NEW |