forked from alexa/avs-device-sdk
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update XMOS adapter classes to comply with v1.26.0
- Loading branch information
Showing
13 changed files
with
230 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
add_definitions("-DACSDK_LOG_MODULE=GPIOKeywordDetector") | ||
add_library(GPIO SHARED | ||
|
||
add_library(GPIO | ||
GPIOKeywordDetector.cpp) | ||
|
||
target_include_directories(GPIO PUBLIC | ||
"${KWD_SOURCE_DIR}/include" | ||
"${XMOS_SOURCE_DIR}/include" | ||
"${GPIO_SOURCE_DIR}/../XMOS/include" | ||
"${GPIO_SOURCE_DIR}/include") | ||
|
||
target_link_libraries(GPIO XMOS KWD AVSCommon wiringPi) | ||
target_link_libraries(GPIO | ||
XMOS | ||
acsdkKWDImplementations | ||
acsdkKWDInterfaces | ||
AVSCommon | ||
wiringPi) | ||
|
||
# install target | ||
asdk_install() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (c) 2021 XMOS LIMITED. This Software is subject to the terms of the | ||
// Copyright (c) 2021-2022 XMOS LIMITED. This Software is subject to the terms of the | ||
// XMOS Public License: Version 1 | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
@@ -21,6 +21,7 @@ | |
#include <chrono> | ||
#include <dirent.h> | ||
|
||
#include <acsdkKWDImplementations/KWDNotifierFactories.h> | ||
#include <AVSCommon/Utils/Logger/Logger.h> | ||
|
||
#include "HID/HIDKeywordDetector.h" | ||
|
@@ -138,26 +139,52 @@ bool HIDKeywordDetector::openDevice() { | |
return true; | ||
} | ||
|
||
// Deprecated create method. | ||
std::unique_ptr<HIDKeywordDetector> HIDKeywordDetector::create( | ||
std::shared_ptr<AudioInputStream> stream, | ||
avsCommon::utils::AudioFormat audioFormat, | ||
std::unordered_set<std::shared_ptr<KeyWordObserverInterface>> keyWordObservers, | ||
std::unordered_set<std::shared_ptr<KeyWordDetectorStateObserverInterface>> keyWordDetectorStateObservers, | ||
std::chrono::milliseconds msToPushPerIteration) { | ||
// Create Notifiers to be used instead of the observers. | ||
This comment has been minimized.
Sorry, something went wrong. |
||
auto keywordNotifier = acsdkKWDImplementations::KWDNotifierFactories::createKeywordNotifier(); | ||
for (auto kwObserver : keyWordObservers) { | ||
keywordNotifier->addObserver(kwObserver); | ||
} | ||
|
||
auto keywordDetectorStateNotifier = | ||
acsdkKWDImplementations::KWDNotifierFactories::createKeywordDetectorStateNotifier(); | ||
for (auto kwdStateObserver : keyWordDetectorStateObservers) { | ||
keywordDetectorStateNotifier->addObserver(kwdStateObserver); | ||
} | ||
|
||
return create( | ||
stream, | ||
std::make_shared<avsCommon::utils::AudioFormat>(audioFormat), | ||
keywordNotifier, | ||
keywordDetectorStateNotifier, | ||
msToPushPerIteration); | ||
} | ||
|
||
std::unique_ptr<HIDKeywordDetector> HIDKeywordDetector::create( | ||
std::shared_ptr<avsCommon::avs::AudioInputStream> stream, | ||
const std::shared_ptr<avsCommon::utils::AudioFormat>& audioFormat, | ||
const std::shared_ptr<acsdkKWDInterfaces::KeywordNotifierInterface> keywordNotifier, | ||
const std::shared_ptr<acsdkKWDInterfaces::KeywordDetectorStateNotifierInterface> keywordDetectorStateNotifier, | ||
std::chrono::milliseconds msToPushPerIteration) { | ||
if (!stream) { | ||
ACSDK_ERROR(LX("createFailed").d("reason", "nullStream")); | ||
return nullptr; | ||
} | ||
|
||
// TODO: ACSDK-249 - Investigate cpu usage of converting bytes between endianness and if it's not too much, do it. | ||
if (isByteswappingRequired(audioFormat)) { | ||
if (isByteswappingRequired(*audioFormat)) { | ||
This comment has been minimized.
Sorry, something went wrong.
mbanth
|
||
ACSDK_ERROR(LX("createFailed").d("reason", "endianMismatch")); | ||
return nullptr; | ||
} | ||
|
||
std::unique_ptr<HIDKeywordDetector> detector(new HIDKeywordDetector( | ||
stream, keyWordObservers, keyWordDetectorStateObservers, audioFormat)); | ||
stream, keywordNotifier, keywordDetectorStateNotifier, *audioFormat)); | ||
|
||
if (!detector->init()) { | ||
ACSDK_ERROR(LX("createFailed").d("reason", "initDetectorFailed")); | ||
|
@@ -169,17 +196,16 @@ std::unique_ptr<HIDKeywordDetector> HIDKeywordDetector::create( | |
|
||
HIDKeywordDetector::HIDKeywordDetector( | ||
std::shared_ptr<AudioInputStream> stream, | ||
std::unordered_set<std::shared_ptr<KeyWordObserverInterface>> keyWordObservers, | ||
std::unordered_set<std::shared_ptr<KeyWordDetectorStateObserverInterface>> keyWordDetectorStateObservers, | ||
std::shared_ptr<acsdkKWDInterfaces::KeywordNotifierInterface> keywordNotifier, | ||
std::shared_ptr<acsdkKWDInterfaces::KeywordDetectorStateNotifierInterface> keywordDetectorStateNotifier, | ||
avsCommon::utils::AudioFormat audioFormat, | ||
std::chrono::milliseconds msToPushPerIteration) : | ||
XMOSKeywordDetector(stream, keyWordObservers, keyWordDetectorStateObservers, audioFormat, msToPushPerIteration) { | ||
XMOSKeywordDetector(stream, keywordNotifier, keywordDetectorStateNotifier, audioFormat, msToPushPerIteration) { | ||
} | ||
|
||
HIDKeywordDetector::~HIDKeywordDetector() { | ||
} | ||
|
||
|
||
bool HIDKeywordDetector::init() { | ||
if (XMOSKeywordDetector::init()) { | ||
m_detectionThread = std::thread(&HIDKeywordDetector::detectionLoop, this); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.1 FATAL_ERROR) | ||
project(XMOS LANGUAGES CXX) | ||
|
||
add_subdirectory("src") | ||
include(${AVS_CMAKE_BUILD}/BuildDefaults.cmake) | ||
|
||
# set(TARGET_KWD_LIB "acsdkXMOSAdapter" PARENT_SCOPE) | ||
|
||
if(HID_KEY_WORD_DETECTOR) | ||
add_subdirectory("HID") | ||
endif() | ||
if(GPIO_KEY_WORD_DETECTOR) | ||
add_subdirectory("GPIO") | ||
endif() | ||
add_subdirectory("src") |
Oops, something went wrong.
It looks like the creation of Notifiers and registration of Observers to Notifiers is duplicated in GPIOKeywordDetector and HIDKeywordDetector. Since this functionality does not differ between these two classes, there should be a way to perform it in only one place with no duplication. That place may be XMOSKeywordDetector or it may be that this functionality already exists in the underlying Amazon class that XMOSKeywordDetector is derived from.