Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/modules/audio_processing/test/fake_rec_device_linear.h" | |
| 12 | |
| 13 #include "webrtc/base/logging.h" | |
| 14 | |
| 15 namespace webrtc { | |
| 16 namespace test { | |
| 17 | |
| 18 FakeRecordingDeviceLinear::FakeRecordingDeviceLinear(int initial_mic_level) | |
| 19 : FakeRecordingDevice(initial_mic_level) {} | |
| 20 | |
| 21 FakeRecordingDeviceLinear::~FakeRecordingDeviceLinear() = default; | |
| 22 | |
| 23 void FakeRecordingDeviceLinear::ModifySampleInt16(int16_t* sample) { | |
| 24 float sample_f = static_cast<float>(*sample); | |
| 25 rtc::Optional<int> undo_level = undo_mic_level(); | |
| 26 | |
| 27 // Virtually restore the unmodified microphone level. | |
| 28 if (undo_level) { | |
| 29 if (*undo_level == 0) { | |
| 30 LOG(LS_INFO) << "undo level is zero, cannot undo mic level"; | |
| 31 } else { | |
| 32 sample_f = ClipSampleInt16( | |
| 33 sample_f * 255.0f / static_cast<float>(*undo_level)); | |
| 34 } | |
| 35 } | |
|
AleBzk
2017/05/17 11:52:24
Let's continue the discussion about clipping betwe
| |
| 36 | |
| 37 // Simulate the mic gain. | |
| 38 *sample = ClipSampleInt16( | |
| 39 sample_f * static_cast<float>(mic_level()) / 255.0f); | |
| 40 } | |
| 41 | |
| 42 void FakeRecordingDeviceLinear::ModifySampleFloat(float* sample) { | |
| 43 rtc::Optional<int> undo_level = undo_mic_level(); | |
| 44 | |
| 45 // Virtually restore the unmodified microphone level. | |
| 46 if (undo_level) { | |
| 47 if (*undo_level == 0) { | |
| 48 LOG(LS_INFO) << "undo level is zero, cannot undo mic level"; | |
| 49 } else { | |
| 50 *sample = ClipSampleFloat( | |
| 51 *sample * 255.0f / static_cast<float>(*undo_level)); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 // Simulate the mic gain. | |
| 56 *sample = ClipSampleFloat(*sample * static_cast<float>(mic_level()) / 255.0f); | |
| 57 } | |
| 58 | |
| 59 } // namespace test | |
| 60 } // namespace webrtc | |
| OLD | NEW |