1 // 2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #pragma once 7 8 #include <string> 9 #include <iostream> 10 #include <cmath> 11 #include <vector> 12 #include <exception> 13 14 #include "SlidingWindow.hpp" 15 16 namespace audio 17 { 18 19 /** 20 * @brief Class used to capture the audio data loaded from file, and to provide a method of 21 * extracting correctly positioned and appropriately sized audio windows 22 * 23 */ 24 class AudioCapture 25 { 26 public: 27 28 SlidingWindow<const float> m_window; 29 30 /** 31 * @brief Default constructor 32 */ 33 AudioCapture() = default; 34 35 /** 36 * @brief Function to load the audio data captured from the 37 * input file to memory. 38 */ 39 static std::vector<float> LoadAudioFile(std::string filePath); 40 41 /** 42 * @brief Function to initialize the sliding window. This will set its position in memory, its 43 * window size and its stride. 44 */ 45 void InitSlidingWindow(float* data, size_t dataSize, int minSamples, size_t stride); 46 47 /** 48 * Checks whether there is another block of audio in memory to read 49 */ 50 bool HasNext(); 51 52 /** 53 * Retrieves the next block of audio if its available 54 */ 55 std::vector<float> Next(); 56 }; 57 } // namespace audio