| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // Uninitialized state - for parameter recalculation. | 44 // Uninitialized state - for parameter recalculation. |
| 45 m_lastFilterStageRatio = -1; | 45 m_lastFilterStageRatio = -1; |
| 46 m_lastAnchor = -1; | 46 m_lastAnchor = -1; |
| 47 m_lastFilterStageGain = -1; | 47 m_lastFilterStageGain = -1; |
| 48 | 48 |
| 49 setNumberOfChannels(numberOfChannels); | 49 setNumberOfChannels(numberOfChannels); |
| 50 initializeParameters(); | 50 initializeParameters(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void DynamicsCompressor::setParameterValue(unsigned parameterID, float value) { | 53 void DynamicsCompressor::setParameterValue(unsigned parameterID, float value) { |
| 54 ASSERT(parameterID < ParamLast); | 54 DCHECK_LT(parameterID, static_cast<unsigned>(ParamLast)); |
| 55 if (parameterID < ParamLast) | 55 if (parameterID < ParamLast) |
| 56 m_parameters[parameterID] = value; | 56 m_parameters[parameterID] = value; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void DynamicsCompressor::initializeParameters() { | 59 void DynamicsCompressor::initializeParameters() { |
| 60 // Initializes compressor to default values. | 60 // Initializes compressor to default values. |
| 61 | 61 |
| 62 m_parameters[ParamThreshold] = -24; // dB | 62 m_parameters[ParamThreshold] = -24; // dB |
| 63 m_parameters[ParamKnee] = 30; // dB | 63 m_parameters[ParamKnee] = 30; // dB |
| 64 m_parameters[ParamRatio] = 12; // unit-less | 64 m_parameters[ParamRatio] = 12; // unit-less |
| (...skipping 12 matching lines...) Expand all Loading... |
| 77 m_parameters[ParamFilterAnchor] = 15000 / nyquist(); | 77 m_parameters[ParamFilterAnchor] = 15000 / nyquist(); |
| 78 | 78 |
| 79 m_parameters[ParamPostGain] = 0; // dB | 79 m_parameters[ParamPostGain] = 0; // dB |
| 80 m_parameters[ParamReduction] = 0; // dB | 80 m_parameters[ParamReduction] = 0; // dB |
| 81 | 81 |
| 82 // Linear crossfade (0 -> 1). | 82 // Linear crossfade (0 -> 1). |
| 83 m_parameters[ParamEffectBlend] = 1; | 83 m_parameters[ParamEffectBlend] = 1; |
| 84 } | 84 } |
| 85 | 85 |
| 86 float DynamicsCompressor::parameterValue(unsigned parameterID) { | 86 float DynamicsCompressor::parameterValue(unsigned parameterID) { |
| 87 ASSERT(parameterID < ParamLast); | 87 DCHECK_LT(parameterID, static_cast<unsigned>(ParamLast)); |
| 88 return m_parameters[parameterID]; | 88 return m_parameters[parameterID]; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void DynamicsCompressor::process(const AudioBus* sourceBus, | 91 void DynamicsCompressor::process(const AudioBus* sourceBus, |
| 92 AudioBus* destinationBus, | 92 AudioBus* destinationBus, |
| 93 unsigned framesToProcess) { | 93 unsigned framesToProcess) { |
| 94 // Though numberOfChannels is retrived from destinationBus, we still name it | 94 // Though numberOfChannels is retrived from destinationBus, we still name it |
| 95 // numberOfChannels instead of numberOfDestinationChannels. It's because we | 95 // numberOfChannels instead of numberOfDestinationChannels. It's because we |
| 96 // internally match sourceChannels's size to destinationBus by channel | 96 // internally match sourceChannels's size to destinationBus by channel |
| 97 // up/down mix. Thus we need numberOfChannels | 97 // up/down mix. Thus we need numberOfChannels |
| 98 // to do the loop work for both m_sourceChannels and m_destinationChannels. | 98 // to do the loop work for both m_sourceChannels and m_destinationChannels. |
| 99 | 99 |
| 100 unsigned numberOfChannels = destinationBus->numberOfChannels(); | 100 unsigned numberOfChannels = destinationBus->numberOfChannels(); |
| 101 unsigned numberOfSourceChannels = sourceBus->numberOfChannels(); | 101 unsigned numberOfSourceChannels = sourceBus->numberOfChannels(); |
| 102 | 102 |
| 103 ASSERT(numberOfChannels == m_numberOfChannels && numberOfSourceChannels); | 103 DCHECK_EQ(numberOfChannels, m_numberOfChannels); |
| 104 DCHECK(numberOfSourceChannels); |
| 104 | 105 |
| 105 if (numberOfChannels != m_numberOfChannels || !numberOfSourceChannels) { | 106 if (numberOfChannels != m_numberOfChannels || !numberOfSourceChannels) { |
| 106 destinationBus->zero(); | 107 destinationBus->zero(); |
| 107 return; | 108 return; |
| 108 } | 109 } |
| 109 | 110 |
| 110 switch (numberOfChannels) { | 111 switch (numberOfChannels) { |
| 111 case 2: // stereo | 112 case 2: // stereo |
| 112 m_sourceChannels[0] = sourceBus->channel(0)->data(); | 113 m_sourceChannels[0] = sourceBus->channel(0)->data(); |
| 113 | 114 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 185 |
| 185 void DynamicsCompressor::setNumberOfChannels(unsigned numberOfChannels) { | 186 void DynamicsCompressor::setNumberOfChannels(unsigned numberOfChannels) { |
| 186 m_sourceChannels = wrapArrayUnique(new const float*[numberOfChannels]); | 187 m_sourceChannels = wrapArrayUnique(new const float*[numberOfChannels]); |
| 187 m_destinationChannels = wrapArrayUnique(new float*[numberOfChannels]); | 188 m_destinationChannels = wrapArrayUnique(new float*[numberOfChannels]); |
| 188 | 189 |
| 189 m_compressor.setNumberOfChannels(numberOfChannels); | 190 m_compressor.setNumberOfChannels(numberOfChannels); |
| 190 m_numberOfChannels = numberOfChannels; | 191 m_numberOfChannels = numberOfChannels; |
| 191 } | 192 } |
| 192 | 193 |
| 193 } // namespace blink | 194 } // namespace blink |
| OLD | NEW |