blob: 7fcbaa08214c6f595d3475fd6262aebe12aaa96e [file] [log] [blame]
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020014#ifndef COMMON_AUDIO_RESAMPLER_SINUSOIDAL_LINEAR_CHIRP_SOURCE_H_
15#define COMMON_AUDIO_RESAMPLER_SINUSOIDAL_LINEAR_CHIRP_SOURCE_H_
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "common_audio/resampler/sinc_resampler.h"
18#include "rtc_base/constructormagic.h"
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000019
20namespace 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.
25class 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.
Peter Kastingdce40cf2015-08-24 14:52:23 -070029 SinusoidalLinearChirpSource(int sample_rate, size_t samples,
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000030 double max_frequency, double delay_samples);
31
32 virtual ~SinusoidalLinearChirpSource() {}
33
Peter Kastingdce40cf2015-08-24 14:52:23 -070034 void Run(size_t frames, float* destination) override;
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000035
Peter Kastingdce40cf2015-08-24 14:52:23 -070036 double Frequency(size_t position);
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000037
38 private:
39 enum {
40 kMinFrequency = 5
41 };
42
Peter Kastingf045e4d2015-06-10 21:15:38 -070043 int sample_rate_;
Peter Kastingdce40cf2015-08-24 14:52:23 -070044 size_t total_samples_;
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000045 double max_frequency_;
46 double k_;
Peter Kastingdce40cf2015-08-24 14:52:23 -070047 size_t current_index_;
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000048 double delay_samples_;
49
henrikg3c089d72015-09-16 05:37:44 -070050 RTC_DISALLOW_COPY_AND_ASSIGN(SinusoidalLinearChirpSource);
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000051};
52
53} // namespace webrtc
54
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020055#endif // COMMON_AUDIO_RESAMPLER_SINUSOIDAL_LINEAR_CHIRP_SOURCE_H_