1 /* 2 * Copyright (c) 2017 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 #include "modules/audio_processing/test/conversational_speech/wavreader_factory.h" 12 13 #include <cstddef> 14 15 #include "api/array_view.h" 16 #include "common_audio/wav_file.h" 17 #include "rtc_base/checks.h" 18 19 namespace webrtc { 20 namespace test { 21 namespace { 22 23 using conversational_speech::WavReaderInterface; 24 25 class WavReaderAdaptor final : public WavReaderInterface { 26 public: WavReaderAdaptor(const std::string & filepath)27 explicit WavReaderAdaptor(const std::string& filepath) 28 : wav_reader_(filepath) {} 29 ~WavReaderAdaptor() override = default; 30 ReadFloatSamples(rtc::ArrayView<float> samples)31 size_t ReadFloatSamples(rtc::ArrayView<float> samples) override { 32 return wav_reader_.ReadSamples(samples.size(), samples.begin()); 33 } 34 ReadInt16Samples(rtc::ArrayView<int16_t> samples)35 size_t ReadInt16Samples(rtc::ArrayView<int16_t> samples) override { 36 return wav_reader_.ReadSamples(samples.size(), samples.begin()); 37 } 38 SampleRate() const39 int SampleRate() const override { return wav_reader_.sample_rate(); } 40 NumChannels() const41 size_t NumChannels() const override { return wav_reader_.num_channels(); } 42 NumSamples() const43 size_t NumSamples() const override { return wav_reader_.num_samples(); } 44 45 private: 46 WavReader wav_reader_; 47 }; 48 49 } // namespace 50 51 namespace conversational_speech { 52 53 WavReaderFactory::WavReaderFactory() = default; 54 55 WavReaderFactory::~WavReaderFactory() = default; 56 Create(const std::string & filepath) const57std::unique_ptr<WavReaderInterface> WavReaderFactory::Create( 58 const std::string& filepath) const { 59 return std::unique_ptr<WavReaderAdaptor>(new WavReaderAdaptor(filepath)); 60 } 61 62 } // namespace conversational_speech 63 } // namespace test 64 } // namespace webrtc 65