Modify noise suppression functionality
[platform/core/api/audio-io.git] / src / cpp / CAudioInfo.cpp
index f35f3f4..f5d2666 100644 (file)
@@ -32,7 +32,9 @@ CAudioInfo::CAudioInfo() :
     __mChannel(EChannel::CHANNEL_MONO),
     __mSampleType(ESampleType::SAMPLE_TYPE_U8),
     __mAudioType(EAudioType::AUDIO_IN_TYPE_MEDIA),
-    __mAudioIndex(-1) {
+    __mAudioIndex(-1),
+    __mReferenceDeviceId(0),
+    __mNoiseSuppression(false) {
 }
 
 CAudioInfo::CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex) :
@@ -40,7 +42,9 @@ CAudioInfo::CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sa
     __mChannel(channel),
     __mSampleType(sampleType),
     __mAudioType(audioType),
-    __mAudioIndex(audioIndex) {
+    __mAudioIndex(audioIndex),
+    __mReferenceDeviceId(0),
+    __mNoiseSuppression(false) {
     // Check to invalid AudioInfo
     if (sampleRate < CAudioInfo::MIN_SYSTEM_SAMPLERATE ||
         sampleRate > CAudioInfo::MAX_SYSTEM_SAMPLERATE)
@@ -121,6 +125,39 @@ int CAudioInfo::getSampleSize() noexcept {
     return bytes_in_sample * static_cast<int>(__mChannel);
 }
 
+void CAudioInfo::bindEchoCancelReferenceDeviceId(int id, sound_acoustic_echo_cancel_type_e type) {
+    if (type == SOUND_ACOUSTIC_ECHO_CANCEL_VOICE_CALL)
+        __mProcessorProperty += "webrtc,";
+    else if (type == SOUND_ACOUSTIC_ECHO_CANCEL_REFERENCE_COPY)
+        __mProcessorProperty += "reference_copy,";
+    else
+        THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
+                               "The echo cancel is not supported [type:%d]", type);
+
+    __mReferenceDeviceId = id;
+}
+
+int CAudioInfo::getEchoCancelReferenceDeviceId() noexcept {
+    return __mReferenceDeviceId;
+}
+
+void CAudioInfo::setNoiseSuppression(bool enable, sound_noise_suppression_type_e type) {
+    if (type == SOUND_NOISE_SUPPRESSION_VOICE_CALL) {
+        __mProcessorProperty += "rnnoise,";
+    } else if (type == SOUND_NOISE_SUPPRESSION_VOICE_RECOGNITION) {
+        __mProcessorProperty += "pse,";
+    } else {
+        THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
+                               "The noise suppression type is not supported [type:%d]", type);
+    }
+
+    __mNoiseSuppression = enable;
+}
+
+std::string& CAudioInfo::getProcessorProperty() noexcept {
+    return __mProcessorProperty;
+}
+
 const char* CAudioInfo::getConvertedStreamType() {
     if (__mAudioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ||
         __mAudioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX)
@@ -150,4 +187,4 @@ CAudioInfo::EAudioType CAudioInfo::convertOutputStreamTypeToAudioType(const char
     }
     THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
                            "The streamType of output is not supported [streamType:%s]", streamType);
-}
\ No newline at end of file
+}