Skip to content

Commit

Permalink
Merge pull request #79 from xmos/feature/sensory
Browse files Browse the repository at this point in the history
Update Sensory adapter to be configured with operating point 12
  • Loading branch information
xluciano authored Jul 5, 2022
2 parents 32c3db7 + 50c490e commit e9bc421
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 65 deletions.
3 changes: 2 additions & 1 deletion Integration/AlexaClientSDKConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
"sampleApp": {
"displayCardsSupported":true,
"sensory": {
"modelFilePath": "${SDK_SENSORY_MODEL_FILE_PATH}"
"modelFilePath": "${SDK_SENSORY_MODEL_FILE_PATH}",
"snsrOperatingPoint": 12
}
}
}
16 changes: 0 additions & 16 deletions SampleApp/include/SampleApp/SampleApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,6 @@ class SampleApplication {
avsCommon::sdkInterfaces::ChannelVolumeInterface::Type speakerType);
};

#ifdef SENSORY_OP_POINT
/**
* Set Sensory operating point value
*/
static void setSensoryOpPoint(int value) {
m_sensoryOpPoint = value;
}
#endif

#ifdef XMOS_AVS_TESTS
/**
* Set flag to indicate if the audio is streamed from a file.
Expand Down Expand Up @@ -346,13 +337,6 @@ class SampleApplication {
std::shared_ptr<acsdkAuthorization::lwa::LWAAuthorizationAdapter> m_lwaAdapter;
#endif

#ifdef SENSORY_OP_POINT
/*
* Operating point of the Sensory KWD engine.
*/
static int m_sensoryOpPoint;
#endif

#ifdef XMOS_AVS_TESTS
/**
* Write to file instead of a real audio device.
Expand Down
7 changes: 0 additions & 7 deletions SampleApp/src/SampleApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::ApplicationMediaInterf
namespace alexaClientSDK {
namespace sampleApp {

#ifdef SENSORY_OP_POINT
int SampleApplication::m_sensoryOpPoint = 0;
#endif

#ifdef XMOS_AVS_TESTS
bool SampleApplication::m_isFileStream = false;
#endif
Expand Down Expand Up @@ -684,9 +680,6 @@ std::unique_ptr<SampleApplication> SampleApplication::create(
const std::string& logLevel,
std::shared_ptr<avsCommon::sdkInterfaces::diagnostics::DiagnosticsInterface> diagnostics) {
auto clientApplication = std::unique_ptr<SampleApplication>(new SampleApplication);
#ifdef SENSORY_OP_POINT
alexaClientSDK::kwd::AbstractKeywordDetector::setSensoryOpPoint(SampleApplication::m_sensoryOpPoint);
#endif
#ifdef XMOS_AVS_TESTS
alexaClientSDK::mediaPlayer::MediaPlayer::setIsFileStream(m_isFileStream);
PortAudioMicrophoneWrapper::setIsFileStream(m_isFileStream);
Expand Down
7 changes: 0 additions & 7 deletions SampleApp/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ bool usesOptStyleArgs(int argc, char* argv[]) {
int main(int argc, char* argv[]) {
std::vector<std::string> configFiles;
std::string logLevel;
#ifdef SENSORY_OP_POINT
int sensoryOpPoint = 5;
#endif
#ifdef XMOS_AVS_TESTS
bool isFileStream = false;
#endif
Expand Down Expand Up @@ -111,10 +108,6 @@ int main(int argc, char* argv[]) {

do {

#ifdef SENSORY_OP_POINT
SampleApplication::setSensoryOpPoint(sensoryOpPoint);
#endif

#ifdef XMOS_AVS_TESTS
SampleApplication::setIsFileStream(isFileStream);
#endif
Expand Down
16 changes: 15 additions & 1 deletion applications/acsdkSensoryAdapter/acsdkKWD/src/KWDComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ static const std::string TAG{"SensoryKWDComponent"};
static const std::string SAMPLE_APP_CONFIG_ROOT_KEY("sampleApp");
static const std::string SENSORY_CONFIG_ROOT_KEY("sensory");
static const std::string SENSORY_MODEL_FILE_PATH("modelFilePath");

#ifdef SENSORY_OP_POINT
static const std::string SENSORY_SNSR_OPERATING_POINT("snsrOperatingPoint");
#endif // SENSORY_OP_POINT
static std::shared_ptr<acsdkKWDImplementations::AbstractKeywordDetector> createAbstractKeywordDetector(
const std::shared_ptr<avsCommon::avs::AudioInputStream>& stream,
const std::shared_ptr<avsCommon::utils::AudioFormat>& audioFormat,
Expand All @@ -48,11 +50,23 @@ static std::shared_ptr<acsdkKWDImplementations::AbstractKeywordDetector> createA
[SENSORY_CONFIG_ROOT_KEY];
if (config) {
config.getString(SENSORY_MODEL_FILE_PATH, &modelFilePath);
#ifdef SENSORY_OP_POINT
uint32_t operatingPoint = 0;
config.getUint32(SENSORY_SNSR_OPERATING_POINT, &operatingPoint);
SensoryKeywordDetector::setSnsrOperatingPoint(operatingPoint);
#endif // SENSORY_OP_POINT
}
if (modelFilePath.empty()) {
ACSDK_ERROR(LX("createFailed").d("reason", "emptyModelFilePath"));
return nullptr;
}
#ifdef SENSORY_OP_POINT
if (m_snsrOperatingPoint==0) {
ACSDK_ERROR(LX("createFailed").d("reason", "zeroSnsrOperatingPoint"));
return nullptr;
}
#endif // SENSORY_OP_POINT

return kwd::SensoryKeywordDetector::create(
stream, audioFormat, keywordNotifier, keywordDetectorStateNotifier, modelFilePath);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ namespace kwd {
static const std::string SAMPLE_APP_CONFIG_ROOT_KEY("sampleApp");
static const std::string SENSORY_CONFIG_ROOT_KEY("sensory");
static const std::string SENSORY_MODEL_FILE_PATH("modelFilePath");

#ifdef SENSORY_OP_POINT
static const std::string SENSORY_SNSR_OPERATING_POINT("snsrOperatingPoint");
#endif // SENSORY_OP_POINT
std::unique_ptr<acsdkKWDImplementations::AbstractKeywordDetector> createSensoryKWDAdapter(
std::shared_ptr<avsCommon::avs::AudioInputStream> stream,
avsCommon::utils::AudioFormat audioFormat,
Expand All @@ -43,6 +45,12 @@ std::unique_ptr<acsdkKWDImplementations::AbstractKeywordDetector> createSensoryK
[SENSORY_CONFIG_ROOT_KEY];
if (config) {
config.getString(SENSORY_MODEL_FILE_PATH, &modelFilePath);
#ifdef SENSORY_OP_POINT
uint32_t operatingPoint = 0;
config.getUint32(SENSORY_SNSR_OPERATING_POINT, &operatingPoint);
SensoryKeywordDetector::setSnsrOperatingPoint(operatingPoint);
#endif // SENSORY_OP_POINT

}
return kwd::SensoryKeywordDetector::create(
stream, audioFormat, keyWordObservers, keyWordDetectorStateObservers, modelFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ class SensoryKeywordDetector : public acsdkKWDImplementations::AbstractKeywordDe
*/
~SensoryKeywordDetector() override;

/**
* Set the operating point of the SNSR engine.
*
* @param value Value of the SNSR operating point.
* @return void
*/
static void setSnsrOperatingPoint(int value) {
m_snsrOperatingPoint = value;
};

private:
/**
* Constructor.
Expand Down Expand Up @@ -170,6 +180,13 @@ class SensoryKeywordDetector : public acsdkKWDImplementations::AbstractKeywordDe
/// The Sensory handle.
SnsrSession m_session;

#ifdef SENSORY_OP_POINT
/**
* The SNSR operating point to be set in the keyword engine
*/
static uint32_t m_snsrOperatingPoint;
#endif // SENSORY_OP_POINT

/**
* The max number of samples to push into the underlying engine per iteration. This will be determined based on the
* sampling rate of the audio data passed in.
Expand Down
11 changes: 4 additions & 7 deletions applications/acsdkSensoryAdapter/src/SensoryKeywordDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ namespace kwd {

using namespace avsCommon::utils::logger;

#ifdef SENSORY_OP_POINT
int AbstractKeywordDetector::m_sensoryOpPoint = 0;
#endif

/// String to identify log entries originating from this file.
static const std::string TAG("SensoryKeywordDetector");

Expand Down Expand Up @@ -339,7 +335,7 @@ bool SensoryKeywordDetector::setUpRuntimeSettings(SnsrSession* session) {
}

#ifdef SENSORY_OP_POINT
result = snsrSetInt(*session, SNSR_OPERATING_POINT, AbstractKeywordDetector::m_sensoryOpPoint);
result = snsrSetInt(*session, SNSR_OPERATING_POINT, m_snsrOperatingPoint);
if (result != SNSR_RC_OK)
{
ACSDK_ERROR(LX("setUpRuntimeSettingsFailed")
Expand All @@ -356,9 +352,10 @@ bool SensoryKeywordDetector::setUpRuntimeSettings(SnsrSession* session) {
.d("error", getSensoryDetails(*session, result)));
return false;
}
printf("Sensory operating point = %d\n",op);
ACSDK_INFO(LX("setUpRuntimeSettings")
.d("operating point",op));
#endif // SENSORY_OP_POINT
return true;
#endif// SENSORY_OP_POINT
}

void SensoryKeywordDetector::detectionLoop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ class AbstractKeywordDetector {
* Destructor.
*/
virtual ~AbstractKeywordDetector() = default;
#ifdef SENSORY_OP_POINT
/**
* Set Sensory operating point value
*/
static void setSensoryOpPoint(int value) {
m_sensoryOpPoint = value;
}
#endif

protected:
/**
Expand Down Expand Up @@ -150,14 +142,6 @@ class AbstractKeywordDetector {
*/
static bool isByteswappingRequired(avsCommon::utils::AudioFormat audioFormat);

#ifdef SENSORY_OP_POINT

/*
* Operating point of the Sensory KWD engine.
*/
static int m_sensoryOpPoint;
#endif

private:
/**
* The notifier to notify observers of key word detections.
Expand Down
7 changes: 6 additions & 1 deletion tools/Install/pi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ show_help() {
echo 'Optional parameters'
echo ' -G Flag to enable keyword detector on GPIO interrupt'
echo ' -H Flag to enable keyword detector on HID event'
echo ' -S Flag to enable Sensory keyword detector'
echo ' -h Display this help and exit'
}
OPTIONS=GHh
OPTIONS=GHSh
while getopts "$OPTIONS" opt ; do
case $opt in
G )
Expand All @@ -41,6 +42,10 @@ while getopts "$OPTIONS" opt ; do
H )
HID_KEY_WORD_DETECTOR_FLAG="ON"
;;
S )
SENSORY_KEY_WORD_DETECTOR_FLAG="ON"
;;

h )
show_help
exit 1
Expand Down
17 changes: 9 additions & 8 deletions tools/Install/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ show_help() {
echo ' -i <user-pin> PKCS#11 user pin to access key object functions.'
echo ' -k <key-name> PKCS#11 key object label.'
echo ' -x <xmos-device-type> XMOS device to setup: possible values are xvf3100, xvf3500, xvf3510, xvf3600-slave, xvf3600-master, or xvf3610, default is xvf3510'
echo ' -g Flag to enable keyword detector on GPIO interrupt'
echo ' -G Flag to enable keyword detector on GPIO interrupt'
echo ' -H Flag to enable keyword detector on HID interrupt'
echo ' -S Flag to enable Sensory keyword detector'
echo ' -h Display this help and exit'
}

Expand All @@ -157,7 +159,7 @@ XMOS_TAG=$2

shift 2

OPTIONS=s:a:d:hp:k:i:t:m:x:GHh
OPTIONS=s:a:d:hp:k:i:t:m:x:GHSh
while getopts "$OPTIONS" opt ; do
case $opt in
s )
Expand Down Expand Up @@ -186,6 +188,9 @@ while getopts "$OPTIONS" opt ; do
H )
HID_KEY_WORD_DETECTOR_FLAG="-H"
;;
S )
SENSORY_KEY_WORD_DETECTOR_FLAG="-S"
;;
h )
show_help
exit 1
Expand Down Expand Up @@ -331,12 +336,8 @@ AUTOSTART_SESSION="avsrun"
AUTOSTART_DIR=$HOME/.config/lxsession/LXDE-pi
AUTOSTART=$AUTOSTART_DIR/autostart
AVSRUN_CMD="lxterminal -t avsrun -e \"$BUILD_PATH/SampleApp/src/SampleApp $OUTPUT_CONFIG_FILE "
if [ -n "$SENSORY_KEY_WORD_DETECTOR_FLAG" ]; then
AVSRUN_CMD+="$THIRD_PARTY_PATH/alexa-rpi/models NONE 12 \$*" #$* is for passing any extra arguments to Sampleapp through .avsrun-startup.sh shell script
else
AVSRUN_CMD+="NONE"
fi
AVSRUN_CMD+="\" &"
AVSRUN_CMD+="NONE\" &"

STARTUP_SCRIPT=$CURRENT_DIR/.avsrun-startup.sh
if [ ! -f $AUTOSTART ]; then
mkdir -p $AUTOSTART_DIR
Expand Down

0 comments on commit e9bc421

Please sign in to comment.