sinusoidal_linear_chirp_source.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. // Modified from the Chromium original here:
  11. // src/media/base/sinc_resampler_unittest.cc
  12. #ifndef COMMON_AUDIO_RESAMPLER_SINUSOIDAL_LINEAR_CHIRP_SOURCE_H_
  13. #define COMMON_AUDIO_RESAMPLER_SINUSOIDAL_LINEAR_CHIRP_SOURCE_H_
  14. #include "common_audio/resampler/sinc_resampler.h"
  15. #include "rtc_base/constructor_magic.h"
  16. namespace webrtc {
  17. // Fake audio source for testing the resampler. Generates a sinusoidal linear
  18. // chirp (http://en.wikipedia.org/wiki/Chirp) which can be tuned to stress the
  19. // resampler for the specific sample rate conversion being used.
  20. class SinusoidalLinearChirpSource : public SincResamplerCallback {
  21. public:
  22. // |delay_samples| can be used to insert a fractional sample delay into the
  23. // source. It will produce zeros until non-negative time is reached.
  24. SinusoidalLinearChirpSource(int sample_rate,
  25. size_t samples,
  26. double max_frequency,
  27. double delay_samples);
  28. ~SinusoidalLinearChirpSource() override {}
  29. void Run(size_t frames, float* destination) override;
  30. double Frequency(size_t position);
  31. private:
  32. enum { kMinFrequency = 5 };
  33. int sample_rate_;
  34. size_t total_samples_;
  35. double max_frequency_;
  36. double k_;
  37. size_t current_index_;
  38. double delay_samples_;
  39. RTC_DISALLOW_COPY_AND_ASSIGN(SinusoidalLinearChirpSource);
  40. };
  41. } // namespace webrtc
  42. #endif // COMMON_AUDIO_RESAMPLER_SINUSOIDAL_LINEAR_CHIRP_SOURCE_H_