xref: /aosp_15_r20/external/webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2014 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 #ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_RESAMPLE_INPUT_AUDIO_FILE_H_
12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_RESAMPLE_INPUT_AUDIO_FILE_H_
13 
14 #include <string>
15 
16 #include "absl/strings/string_view.h"
17 #include "common_audio/resampler/include/resampler.h"
18 #include "modules/audio_coding/neteq/tools/input_audio_file.h"
19 
20 namespace webrtc {
21 namespace test {
22 
23 // Class for handling a looping input audio file with resampling.
24 class ResampleInputAudioFile : public InputAudioFile {
25  public:
26   ResampleInputAudioFile(absl::string_view file_name,
27                          int file_rate_hz,
28                          bool loop_at_end = true)
InputAudioFile(file_name,loop_at_end)29       : InputAudioFile(file_name, loop_at_end),
30         file_rate_hz_(file_rate_hz),
31         output_rate_hz_(-1) {}
32   ResampleInputAudioFile(absl::string_view file_name,
33                          int file_rate_hz,
34                          int output_rate_hz,
35                          bool loop_at_end = true)
InputAudioFile(file_name,loop_at_end)36       : InputAudioFile(file_name, loop_at_end),
37         file_rate_hz_(file_rate_hz),
38         output_rate_hz_(output_rate_hz) {}
39 
40   ResampleInputAudioFile(const ResampleInputAudioFile&) = delete;
41   ResampleInputAudioFile& operator=(const ResampleInputAudioFile&) = delete;
42 
43   bool Read(size_t samples, int output_rate_hz, int16_t* destination);
44   bool Read(size_t samples, int16_t* destination) override;
45   void set_output_rate_hz(int rate_hz);
46 
47  private:
48   const int file_rate_hz_;
49   int output_rate_hz_;
50   Resampler resampler_;
51 };
52 
53 }  // namespace test
54 }  // namespace webrtc
55 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_RESAMPLE_INPUT_AUDIO_FILE_H_
56