audio_loop.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_LOOP_H_
  11. #define MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_LOOP_H_
  12. #include <memory>
  13. #include <string>
  14. #include "api/array_view.h"
  15. #include "rtc_base/constructor_magic.h"
  16. namespace webrtc {
  17. namespace test {
  18. // Class serving as an infinite source of audio, realized by looping an audio
  19. // clip.
  20. class AudioLoop {
  21. public:
  22. AudioLoop()
  23. : next_index_(0), loop_length_samples_(0), block_length_samples_(0) {}
  24. virtual ~AudioLoop() {}
  25. // Initializes the AudioLoop by reading from |file_name|. The loop will be no
  26. // longer than |max_loop_length_samples|, if the length of the file is
  27. // greater. Otherwise, the loop length is the same as the file length.
  28. // The audio will be delivered in blocks of |block_length_samples|.
  29. // Returns false if the initialization failed, otherwise true.
  30. bool Init(const std::string file_name,
  31. size_t max_loop_length_samples,
  32. size_t block_length_samples);
  33. // Returns a (pointer,size) pair for the next block of audio. The size is
  34. // equal to the |block_length_samples| Init() argument.
  35. rtc::ArrayView<const int16_t> GetNextBlock();
  36. private:
  37. size_t next_index_;
  38. size_t loop_length_samples_;
  39. size_t block_length_samples_;
  40. std::unique_ptr<int16_t[]> audio_array_;
  41. RTC_DISALLOW_COPY_AND_ASSIGN(AudioLoop);
  42. };
  43. } // namespace test
  44. } // namespace webrtc
  45. #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_LOOP_H_