Éanna Ó Catháin | c6ab02a | 2021-04-07 14:35:25 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #define CATCH_CONFIG_MAIN |
| 7 | #include <catch.hpp> |
| 8 | #include <limits> |
| 9 | |
| 10 | #include "AudioCapture.hpp" |
| 11 | |
| 12 | TEST_CASE("Test capture of audio file") |
| 13 | { |
| 14 | std::string testResources = TEST_RESOURCE_DIR; |
| 15 | REQUIRE(testResources != ""); |
| 16 | std::string file = testResources + "/" + "myVoiceIsMyPassportVerifyMe04.wav"; |
| 17 | asr::AudioCapture capture; |
| 18 | std::vector<float> audioData = capture.LoadAudioFile(file); |
| 19 | capture.InitSlidingWindow(audioData.data(), audioData.size(), 47712, 16000); |
| 20 | |
| 21 | std::vector<float> firstAudioBlock = capture.Next(); |
| 22 | float actual1 = firstAudioBlock.at(0); |
| 23 | float actual2 = firstAudioBlock.at(47000); |
| 24 | CHECK(std::to_string(actual1) == "0.000352"); |
| 25 | CHECK(std::to_string(actual2) == "-0.056441"); |
| 26 | CHECK(firstAudioBlock.size() == 47712); |
| 27 | |
| 28 | CHECK(capture.HasNext() == true); |
| 29 | |
| 30 | std::vector<float> secondAudioBlock = capture.Next(); |
| 31 | float actual3 = secondAudioBlock.at(0); |
| 32 | float actual4 = secondAudioBlock.at(47000); |
| 33 | CHECK(std::to_string(actual3) == "0.102077"); |
| 34 | CHECK(std::to_string(actual4) == "0.000194"); |
| 35 | CHECK(capture.HasNext() == true); |
| 36 | |
| 37 | std::vector<float> thirdAudioBlock = capture.Next(); |
| 38 | float actual5 = thirdAudioBlock.at(0); |
| 39 | float actual6 = thirdAudioBlock.at(33500); |
| 40 | float actual7 = thirdAudioBlock.at(33600); |
| 41 | CHECK(std::to_string(actual5) == "-0.076416"); |
| 42 | CHECK(std::to_string(actual6) == "-0.000275"); |
| 43 | CHECK(std::to_string(actual7) == "0.000000"); |
| 44 | CHECK(capture.HasNext() == false); |
| 45 | } |
| 46 | |
| 47 | TEST_CASE("Test sliding window of audio capture") |
| 48 | { |
| 49 | std::string testResources = TEST_RESOURCE_DIR; |
| 50 | REQUIRE(testResources != ""); |
| 51 | std::string file = testResources + "/" + "myVoiceIsMyPassportVerifyMe04.wav"; |
| 52 | asr::AudioCapture capture; |
| 53 | std::vector<float> audioData = capture.LoadAudioFile(file); |
| 54 | capture.InitSlidingWindow(audioData.data(), audioData.size(), 47712, 16000); |
| 55 | capture.Next(); |
| 56 | capture.Next(); |
| 57 | |
| 58 | CHECK(capture.HasNext() == true); |
| 59 | capture.Next(); |
| 60 | CHECK(capture.HasNext() == false); |
| 61 | } |