blob: a57cbfef02e510106742122e7ae0d9a6d110fd83 [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"
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000018
19namespace webrtc {
20
21// Fake audio source for testing the resampler. Generates a sinusoidal linear
22// chirp (http://en.wikipedia.org/wiki/Chirp) which can be tuned to stress the
23// resampler for the specific sample rate conversion being used.
24class SinusoidalLinearChirpSource : public SincResamplerCallback {
25 public:
Artem Titov96315752021-07-26 12:15:29 +020026 // `delay_samples` can be used to insert a fractional sample delay into the
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000027 // source. It will produce zeros until non-negative time is reached.
Yves Gerey665174f2018-06-19 15:03:05 +020028 SinusoidalLinearChirpSource(int sample_rate,
29 size_t samples,
30 double max_frequency,
31 double delay_samples);
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000032
Mirko Bonadei91df0912018-07-17 11:08:15 +020033 ~SinusoidalLinearChirpSource() override {}
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000034
Artem Titov6cae2d52022-01-26 15:01:10 +000035 SinusoidalLinearChirpSource(const SinusoidalLinearChirpSource&) = delete;
36 SinusoidalLinearChirpSource& operator=(const SinusoidalLinearChirpSource&) =
37 delete;
38
Peter Kastingdce40cf2015-08-24 14:52:23 -070039 void Run(size_t frames, float* destination) override;
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000040
Peter Kastingdce40cf2015-08-24 14:52:23 -070041 double Frequency(size_t position);
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000042
43 private:
Yves Gerey665174f2018-06-19 15:03:05 +020044 enum { kMinFrequency = 5 };
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000045
Peter Kastingf045e4d2015-06-10 21:15:38 -070046 int sample_rate_;
Peter Kastingdce40cf2015-08-24 14:52:23 -070047 size_t total_samples_;
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000048 double max_frequency_;
49 double k_;
Peter Kastingdce40cf2015-08-24 14:52:23 -070050 size_t current_index_;
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000051 double delay_samples_;
andrew@webrtc.org8fc05fe2013-04-26 14:56:51 +000052};
53
54} // namespace webrtc
55
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020056#endif // COMMON_AUDIO_RESAMPLER_SINUSOIDAL_LINEAR_CHIRP_SOURCE_H_