andrew@webrtc.org | 8fc05fe | 2013-04-26 14:56:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | // Modified from the Chromium original here: |
| 12 | // src/media/base/sinc_resampler_unittest.cc |
| 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #ifndef COMMON_AUDIO_RESAMPLER_SINUSOIDAL_LINEAR_CHIRP_SOURCE_H_ |
| 15 | #define COMMON_AUDIO_RESAMPLER_SINUSOIDAL_LINEAR_CHIRP_SOURCE_H_ |
andrew@webrtc.org | 8fc05fe | 2013-04-26 14:56:51 +0000 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "common_audio/resampler/sinc_resampler.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 18 | #include "rtc_base/constructor_magic.h" |
andrew@webrtc.org | 8fc05fe | 2013-04-26 14:56:51 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | // Fake audio source for testing the resampler. Generates a sinusoidal linear |
| 23 | // chirp (http://en.wikipedia.org/wiki/Chirp) which can be tuned to stress the |
| 24 | // resampler for the specific sample rate conversion being used. |
| 25 | class SinusoidalLinearChirpSource : public SincResamplerCallback { |
| 26 | public: |
| 27 | // |delay_samples| can be used to insert a fractional sample delay into the |
| 28 | // source. It will produce zeros until non-negative time is reached. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 29 | SinusoidalLinearChirpSource(int sample_rate, |
| 30 | size_t samples, |
| 31 | double max_frequency, |
| 32 | double delay_samples); |
andrew@webrtc.org | 8fc05fe | 2013-04-26 14:56:51 +0000 | [diff] [blame] | 33 | |
Mirko Bonadei | 91df091 | 2018-07-17 11:08:15 +0200 | [diff] [blame] | 34 | ~SinusoidalLinearChirpSource() override {} |
andrew@webrtc.org | 8fc05fe | 2013-04-26 14:56:51 +0000 | [diff] [blame] | 35 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 36 | void Run(size_t frames, float* destination) override; |
andrew@webrtc.org | 8fc05fe | 2013-04-26 14:56:51 +0000 | [diff] [blame] | 37 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 38 | double Frequency(size_t position); |
andrew@webrtc.org | 8fc05fe | 2013-04-26 14:56:51 +0000 | [diff] [blame] | 39 | |
| 40 | private: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 41 | enum { kMinFrequency = 5 }; |
andrew@webrtc.org | 8fc05fe | 2013-04-26 14:56:51 +0000 | [diff] [blame] | 42 | |
Peter Kasting | f045e4d | 2015-06-10 21:15:38 -0700 | [diff] [blame] | 43 | int sample_rate_; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 44 | size_t total_samples_; |
andrew@webrtc.org | 8fc05fe | 2013-04-26 14:56:51 +0000 | [diff] [blame] | 45 | double max_frequency_; |
| 46 | double k_; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 47 | size_t current_index_; |
andrew@webrtc.org | 8fc05fe | 2013-04-26 14:56:51 +0000 | [diff] [blame] | 48 | double delay_samples_; |
| 49 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 50 | RTC_DISALLOW_COPY_AND_ASSIGN(SinusoidalLinearChirpSource); |
andrew@webrtc.org | 8fc05fe | 2013-04-26 14:56:51 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | } // namespace webrtc |
| 54 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 55 | #endif // COMMON_AUDIO_RESAMPLER_SINUSOIDAL_LINEAR_CHIRP_SOURCE_H_ |