2013-09-17 08:38:02 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-06-09 08:10:28 +00:00
|
|
|
#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_LOOP_H_
|
|
|
|
|
#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_LOOP_H_
|
2013-09-17 08:38:02 +00:00
|
|
|
|
2016-02-14 09:28:33 -08:00
|
|
|
#include <memory>
|
2013-09-17 08:38:02 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
2017-09-04 05:43:17 -07:00
|
|
|
#include "webrtc/api/array_view.h"
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/rtc_base/constructormagic.h"
|
2013-09-17 08:38:02 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
// Class serving as an infinite source of audio, realized by looping an audio
|
|
|
|
|
// clip.
|
|
|
|
|
class AudioLoop {
|
|
|
|
|
public:
|
|
|
|
|
AudioLoop()
|
|
|
|
|
: next_index_(0),
|
|
|
|
|
loop_length_samples_(0),
|
2014-04-25 23:10:28 +00:00
|
|
|
block_length_samples_(0) {
|
2013-09-17 08:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ~AudioLoop() {}
|
|
|
|
|
|
|
|
|
|
// Initializes the AudioLoop by reading from |file_name|. The loop will be no
|
|
|
|
|
// longer than |max_loop_length_samples|, if the length of the file is
|
|
|
|
|
// greater. Otherwise, the loop length is the same as the file length.
|
|
|
|
|
// The audio will be delivered in blocks of |block_length_samples|.
|
|
|
|
|
// Returns false if the initialization failed, otherwise true.
|
|
|
|
|
bool Init(const std::string file_name, size_t max_loop_length_samples,
|
|
|
|
|
size_t block_length_samples);
|
|
|
|
|
|
2015-11-06 01:21:35 -08:00
|
|
|
// Returns a (pointer,size) pair for the next block of audio. The size is
|
|
|
|
|
// equal to the |block_length_samples| Init() argument.
|
|
|
|
|
rtc::ArrayView<const int16_t> GetNextBlock();
|
2013-09-17 08:38:02 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
size_t next_index_;
|
|
|
|
|
size_t loop_length_samples_;
|
|
|
|
|
size_t block_length_samples_;
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<int16_t[]> audio_array_;
|
2013-09-17 08:38:02 +00:00
|
|
|
|
2015-09-16 05:37:44 -07:00
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(AudioLoop);
|
2013-09-17 08:38:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|
2014-06-09 08:10:28 +00:00
|
|
|
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_LOOP_H_
|