| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 void AudioChannel::scale(float scale) { | 44 void AudioChannel::scale(float scale) { |
| 45 if (isSilent()) | 45 if (isSilent()) |
| 46 return; | 46 return; |
| 47 | 47 |
| 48 vsmul(data(), 1, &scale, mutableData(), 1, length()); | 48 vsmul(data(), 1, &scale, mutableData(), 1, length()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void AudioChannel::copyFrom(const AudioChannel* sourceChannel) { | 51 void AudioChannel::copyFrom(const AudioChannel* sourceChannel) { |
| 52 bool isSafe = (sourceChannel && sourceChannel->length() >= length()); | 52 bool isSafe = (sourceChannel && sourceChannel->length() >= length()); |
| 53 ASSERT(isSafe); | 53 DCHECK(isSafe); |
| 54 if (!isSafe) | 54 if (!isSafe) |
| 55 return; | 55 return; |
| 56 | 56 |
| 57 if (sourceChannel->isSilent()) { | 57 if (sourceChannel->isSilent()) { |
| 58 zero(); | 58 zero(); |
| 59 return; | 59 return; |
| 60 } | 60 } |
| 61 memcpy(mutableData(), sourceChannel->data(), sizeof(float) * length()); | 61 memcpy(mutableData(), sourceChannel->data(), sizeof(float) * length()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void AudioChannel::copyFromRange(const AudioChannel* sourceChannel, | 64 void AudioChannel::copyFromRange(const AudioChannel* sourceChannel, |
| 65 unsigned startFrame, | 65 unsigned startFrame, |
| 66 unsigned endFrame) { | 66 unsigned endFrame) { |
| 67 // Check that range is safe for reading from sourceChannel. | 67 // Check that range is safe for reading from sourceChannel. |
| 68 bool isRangeSafe = sourceChannel && startFrame < endFrame && | 68 bool isRangeSafe = sourceChannel && startFrame < endFrame && |
| 69 endFrame <= sourceChannel->length(); | 69 endFrame <= sourceChannel->length(); |
| 70 ASSERT(isRangeSafe); | 70 DCHECK(isRangeSafe); |
| 71 if (!isRangeSafe) | 71 if (!isRangeSafe) |
| 72 return; | 72 return; |
| 73 | 73 |
| 74 if (sourceChannel->isSilent() && isSilent()) | 74 if (sourceChannel->isSilent() && isSilent()) |
| 75 return; | 75 return; |
| 76 | 76 |
| 77 // Check that this channel has enough space. | 77 // Check that this channel has enough space. |
| 78 size_t rangeLength = endFrame - startFrame; | 78 size_t rangeLength = endFrame - startFrame; |
| 79 bool isRangeLengthSafe = rangeLength <= length(); | 79 bool isRangeLengthSafe = rangeLength <= length(); |
| 80 ASSERT(isRangeLengthSafe); | 80 DCHECK(isRangeLengthSafe); |
| 81 if (!isRangeLengthSafe) | 81 if (!isRangeLengthSafe) |
| 82 return; | 82 return; |
| 83 | 83 |
| 84 const float* source = sourceChannel->data(); | 84 const float* source = sourceChannel->data(); |
| 85 float* destination = mutableData(); | 85 float* destination = mutableData(); |
| 86 | 86 |
| 87 if (sourceChannel->isSilent()) { | 87 if (sourceChannel->isSilent()) { |
| 88 if (rangeLength == length()) | 88 if (rangeLength == length()) |
| 89 zero(); | 89 zero(); |
| 90 else | 90 else |
| 91 memset(destination, 0, sizeof(float) * rangeLength); | 91 memset(destination, 0, sizeof(float) * rangeLength); |
| 92 } else | 92 } else |
| 93 memcpy(destination, source + startFrame, sizeof(float) * rangeLength); | 93 memcpy(destination, source + startFrame, sizeof(float) * rangeLength); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void AudioChannel::sumFrom(const AudioChannel* sourceChannel) { | 96 void AudioChannel::sumFrom(const AudioChannel* sourceChannel) { |
| 97 bool isSafe = sourceChannel && sourceChannel->length() >= length(); | 97 bool isSafe = sourceChannel && sourceChannel->length() >= length(); |
| 98 ASSERT(isSafe); | 98 DCHECK(isSafe); |
| 99 if (!isSafe) | 99 if (!isSafe) |
| 100 return; | 100 return; |
| 101 | 101 |
| 102 if (sourceChannel->isSilent()) | 102 if (sourceChannel->isSilent()) |
| 103 return; | 103 return; |
| 104 | 104 |
| 105 if (isSilent()) | 105 if (isSilent()) |
| 106 copyFrom(sourceChannel); | 106 copyFrom(sourceChannel); |
| 107 else | 107 else |
| 108 vadd(data(), 1, sourceChannel->data(), 1, mutableData(), 1, length()); | 108 vadd(data(), 1, sourceChannel->data(), 1, mutableData(), 1, length()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 float AudioChannel::maxAbsValue() const { | 111 float AudioChannel::maxAbsValue() const { |
| 112 if (isSilent()) | 112 if (isSilent()) |
| 113 return 0; | 113 return 0; |
| 114 | 114 |
| 115 float max = 0; | 115 float max = 0; |
| 116 | 116 |
| 117 vmaxmgv(data(), 1, &max, length()); | 117 vmaxmgv(data(), 1, &max, length()); |
| 118 | 118 |
| 119 return max; | 119 return max; |
| 120 } | 120 } |
| 121 | 121 |
| 122 } // namespace blink | 122 } // namespace blink |
| OLD | NEW |