Éanna Ó Catháin | c6ab02a | 2021-04-07 14:35:25 +0100 | [diff] [blame] | 1 | // |
George Gekov | 23c2627 | 2021-08-16 11:32:10 +0100 | [diff] [blame] | 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
Éanna Ó Catháin | c6ab02a | 2021-04-07 14:35:25 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include <string> |
| 9 | #include <iostream> |
George Gekov | 23c2627 | 2021-08-16 11:32:10 +0100 | [diff] [blame] | 10 | #include <cmath> |
Éanna Ó Catháin | c6ab02a | 2021-04-07 14:35:25 +0100 | [diff] [blame] | 11 | #include <vector> |
Éanna Ó Catháin | c6ab02a | 2021-04-07 14:35:25 +0100 | [diff] [blame] | 12 | #include <exception> |
| 13 | |
| 14 | #include "SlidingWindow.hpp" |
| 15 | |
George Gekov | 23c2627 | 2021-08-16 11:32:10 +0100 | [diff] [blame] | 16 | namespace audio |
Éanna Ó Catháin | c6ab02a | 2021-04-07 14:35:25 +0100 | [diff] [blame] | 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; |
Éanna Ó Catháin | c6ab02a | 2021-04-07 14:35:25 +0100 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * @brief Default constructor |
| 32 | */ |
George Gekov | 23c2627 | 2021-08-16 11:32:10 +0100 | [diff] [blame] | 33 | AudioCapture() = default; |
Éanna Ó Catháin | c6ab02a | 2021-04-07 14:35:25 +0100 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * @brief Function to load the audio data captured from the |
| 37 | * input file to memory. |
| 38 | */ |
George Gekov | 23c2627 | 2021-08-16 11:32:10 +0100 | [diff] [blame] | 39 | static std::vector<float> LoadAudioFile(std::string filePath); |
Éanna Ó Catháin | c6ab02a | 2021-04-07 14:35:25 +0100 | [diff] [blame] | 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 | }; |
George Gekov | 23c2627 | 2021-08-16 11:32:10 +0100 | [diff] [blame] | 57 | } // namespace audio |