Skip to content

Commit

Permalink
SERXIONE-3552: Changes in TTS thunder plugin for volume control on BRCM
Browse files Browse the repository at this point in the history
Reason for change: Primary volume control on BRCM platform
Test Procedure: Mentioned in ticket
Risks: Low

Signed-off-by: vdinak240 <[email protected]>
  • Loading branch information
vdinak240 committed Apr 5, 2024
1 parent 87c498d commit 33b4298
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
4 changes: 3 additions & 1 deletion TextToSpeech/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ set(AUDIO_CLIENT_LIB "")
if (BUILD_AMLOGIC)
set(AUDIO_CLIENT_LIB "audio_client")
elseif (BUILD_REALTEK)
set(AUDIO_CLIENT_LIB "RtkHALMisc")
set(AUDIO_CLIENT_LIB "RtkHALMisc")
elseif (BUILD_BROADCOM)
set(AUDIO_CLIENT_LIB "nxclient")
endif()

target_include_directories(${MODULE_NAME} PRIVATE ../helpers ${GSTREAMER_INCLUDES})
Expand Down
60 changes: 52 additions & 8 deletions TextToSpeech/impl/TTSSpeaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ TTSSpeaker::TTSSpeaker(TTSConfiguration &config) :
m_pcmAudioEnabled(false),
#if defined(PLATFORM_AMLOGIC)
m_audio_dev(NULL),
#elif defined(PLATFORM_BROADCOM)
m_inNexus(false),
#endif
m_ensurePipeline(false),
m_busWatch(0),
Expand All @@ -383,9 +385,15 @@ TTSSpeaker::~TTSSpeaker() {
m_busThread = false;
m_pcmAudioEnabled = false;
#if defined(PLATFORM_AMLOGIC)
if(m_audio_dev){
audio_hw_unload_interface(m_audio_dev);
m_audio_dev = NULL;
if(m_audio_dev) {
audio_hw_unload_interface(m_audio_dev);
m_audio_dev = NULL;
}
#elif defined(PLATFORM_BROADCOM)
if(m_inNexus) {
NxClient_Uninit();
TTSLOG_INFO("Nexus deinit");
m_inNexus = false;
}
#endif
m_condition.notify_one();
Expand Down Expand Up @@ -615,6 +623,27 @@ bool TTSSpeaker::loadInitAudioDev()
TTSLOG_INFO("Amlogic audio device loaded, can control mix gain");
return true;
}
#elif defined(PLATFORM_BROADCOM)
bool TTSSpeaker::loadInitNexus()
{
if (m_inNexus) return true;

NxClient_JoinSettings joinSettings;

NxClient_GetDefaultJoinSettings(&joinSettings);
snprintf(joinSettings.name, NXCLIENT_MAX_NAME, "%s", "TTS_Speaker");
NEXUS_Error rc = NxClient_Join(&joinSettings);
if (!(( rc == NEXUS_SUCCESS )))
{
TTSLOG_ERROR("could not join Nexus");
return false;
}

TTSLOG_INFO("Nexus Joined");
m_inNexus = true;

return true;
}
#endif
/*
* Control gain of
Expand Down Expand Up @@ -665,6 +694,21 @@ void TTSSpeaker::setMixGain(MixGain gain, int volume)
}
#elif defined(PLATFORM_REALTEK)
hal_set_audio_volume(volume);
#elif defined(PLATFORM_BROADCOM)
if (gain == MIXGAIN_PRIM) {
#if defined(NXCLIENT_MAIN_AUDIO_DECODER_VOLUME_SUPPORT)
NxClient_AudioSettings audioSettings;
if(!loadInitNexus())
{
TTSLOG_ERROR("BRCM could not Init Nexus");
return;
}
TTSLOG_WARNING("BRCM setMixGain gain=%d volume=%d",gain,volume);
NxClient_GetAudioSettings(&audioSettings);
audioSettings.primaryDecoderVolume = volume;
NxClient_SetAudioSettings(&audioSettings);
#endif
}
#endif
}

Expand Down Expand Up @@ -991,7 +1035,7 @@ void TTSSpeaker::play(string url, SpeechData &data, bool authrequired, string to

gst_element_set_state(m_pipeline, GST_STATE_PLAYING);

#if defined(PLATFORM_AMLOGIC) || defined(PLATFORM_REALTEK)
#if defined(PLATFORM_AMLOGIC) || defined(PLATFORM_REALTEK) || defined(PLATFORM_BROADCOM)
setMixGain(MIXGAIN_PRIM,data.primVolDuck);
#endif
TTSLOG_VERBOSE("Speaking.... ( %d, \"%s\")", data.id, data.text.c_str());
Expand Down Expand Up @@ -1101,7 +1145,7 @@ void TTSSpeaker::GStreamerThreadFunc(void *ctx) {

// when not speaking, set primary mixgain back to default.
if(speaker->m_flushed || speaker->m_networkError || !speaker->m_pipeline || speaker->m_pipelineError) {
#if defined(PLATFORM_AMLOGIC) || defined(PLATFORM_REALTEK)
#if defined(PLATFORM_AMLOGIC) || defined(PLATFORM_REALTEK) || defined(PLATFORM_BROADCOM)
speaker->setMixGain(MIXGAIN_PRIM,100);
#endif
}
Expand All @@ -1113,7 +1157,7 @@ void TTSSpeaker::GStreamerThreadFunc(void *ctx) {
else if(!speaker->m_pipeline || speaker->m_pipelineError)
data.client->playbackerror(data.id, data.callsign);
else {
#if defined(PLATFORM_AMLOGIC) || defined(PLATFORM_REALTEK)
#if defined(PLATFORM_AMLOGIC) || defined(PLATFORM_REALTEK) || defined(PLATFORM_BROADCOM)
speaker->setMixGain(MIXGAIN_PRIM,100);
#endif
data.client->spoke(data.id, data.callsign, data.text);
Expand Down Expand Up @@ -1209,7 +1253,7 @@ bool TTSSpeaker::handleMessage(GstMessage *message) {
if(m_isPaused) {
m_isPaused = false;
// -12db is almost 25%
#if defined(PLATFORM_AMLOGIC) || defined(PLATFORM_REALTEK)
#if defined(PLATFORM_AMLOGIC) || defined(PLATFORM_REALTEK) || defined(PLATFORM_BROADCOM)
setMixGain(MIXGAIN_PRIM,m_currentSpeech->primVolDuck);
#endif
m_clientSpeaking->resumed(m_currentSpeech->id, m_currentSpeech->callsign);
Expand All @@ -1221,7 +1265,7 @@ bool TTSSpeaker::handleMessage(GstMessage *message) {
} else if (oldstate == GST_STATE_PLAYING && newstate == GST_STATE_PAUSED) {
std::lock_guard<std::mutex> lock(m_stateMutex);
if(m_clientSpeaking && m_isPaused) {
#if defined(PLATFORM_AMLOGIC) || defined(PLATFORM_REALTEK)
#if defined(PLATFORM_AMLOGIC) || defined(PLATFORM_REALTEK) || defined(PLATFORM_BROADCOM)
setMixGain(MIXGAIN_PRIM,100);
#endif
m_clientSpeaking->paused(m_currentSpeech->id, m_currentSpeech->callsign);
Expand Down
9 changes: 8 additions & 1 deletion TextToSpeech/impl/TTSSpeaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
#if defined(PLATFORM_AMLOGIC)
#include "audio_if.h"
#elif defined(PLATFORM_REALTEK)
#include "RtkHALMisc.h"
#include "RtkHALMisc.h"
#elif defined(PLATFORM_BROADCOM)
#include <nexus_config.h>
#include <nxclient.h>
#endif
// --- //

Expand Down Expand Up @@ -152,6 +155,8 @@ class TTSSpeaker {
bool m_pcmAudioEnabled;
#if defined(PLATFORM_AMLOGIC)
audio_hw_device_t *m_audio_dev;
#elif defined(PLATFORM_BROADCOM)
bool m_inNexus;
#endif
enum MixGain {
MIXGAIN_PRIM,
Expand All @@ -167,6 +172,8 @@ class TTSSpeaker {

#if defined(PLATFORM_AMLOGIC)
bool loadInitAudioDev();
#elif defined(PLATFORM_BROADCOM)
bool loadInitNexus();
#endif
void setMixGain(MixGain gain, int val);
static void GStreamerThreadFunc(void *ctx);
Expand Down

0 comments on commit 33b4298

Please sign in to comment.