• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_INPUT_AUDIO_FILE_H_
12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_INPUT_AUDIO_FILE_H_
13 
14 #include <stdio.h>
15 
16 #include <string>
17 
18 #include "rtc_base/constructor_magic.h"
19 
20 namespace webrtc {
21 namespace test {
22 
23 // Class for handling a looping input audio file.
24 class InputAudioFile {
25  public:
26   explicit InputAudioFile(const std::string file_name, bool loop_at_end = true);
27 
28   virtual ~InputAudioFile();
29 
30   // Reads |samples| elements from source file to |destination|. Returns true
31   // if the read was successful, otherwise false. If the file end is reached,
32   // the file is rewound and reading continues from the beginning.
33   // The output |destination| must have the capacity to hold |samples| elements.
34   virtual bool Read(size_t samples, int16_t* destination);
35 
36   // Fast-forwards (|samples| > 0) or -backwards (|samples| < 0) the file by the
37   // indicated number of samples. Just like Read(), Seek() starts over at the
38   // beginning of the file if the end is reached. However, seeking backwards
39   // past the beginning of the file is not possible.
40   virtual bool Seek(int samples);
41 
42   // Creates a multi-channel signal from a mono signal. Each sample is repeated
43   // |channels| times to create an interleaved multi-channel signal where all
44   // channels are identical. The output |destination| must have the capacity to
45   // hold samples * channels elements. Note that |source| and |destination| can
46   // be the same array (i.e., point to the same address).
47   static void DuplicateInterleaved(const int16_t* source,
48                                    size_t samples,
49                                    size_t channels,
50                                    int16_t* destination);
51 
52  private:
53   FILE* fp_;
54   const bool loop_at_end_;
55   RTC_DISALLOW_COPY_AND_ASSIGN(InputAudioFile);
56 };
57 
58 }  // namespace test
59 }  // namespace webrtc
60 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_INPUT_AUDIO_FILE_H_
61