#include <stdio.h>
+#include <string.h>
#include "CAudioIODef.h"
+#include <sound_manager.h>
+#include <sound_manager_internal.h>
using namespace std;
using namespace tizen_media_audio;
__mChannel(EChannel::CHANNEL_MONO),
__mSampleType(ESampleType::SAMPLE_TYPE_U8),
__mAudioType(EAudioType::AUDIO_IN_TYPE_MEDIA),
- __mAudioIndex(-1) {
+ __mAudioIndex(-1),
+ __mEffectMethodWithReference((sound_effect_method_with_reference_e)0),
+ __mEffectMethodReferenceDeviceId(0),
+ __mEffectMethod(0) {
}
CAudioInfo::CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex) :
__mChannel(channel),
__mSampleType(sampleType),
__mAudioType(audioType),
- __mAudioIndex(audioIndex) {
+ __mAudioIndex(audioIndex),
+ __mEffectMethodWithReference((sound_effect_method_with_reference_e)0),
+ __mEffectMethodReferenceDeviceId(0),
+ __mEffectMethod(0) {
// Check to invalid AudioInfo
- if (sampleRate < CAudioInfo::MIN_SYSTEM_SAMPLERATE || sampleRate > CAudioInfo::MAX_SYSTEM_SAMPLERATE) {
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The sampleRate is invalid [sampleRate:%u]", sampleRate);
- }
-
- if (channel < CAudioInfo::EChannel::CHANNEL_MONO || channel >= CAudioInfo::EChannel::CHANNEL_MAX) {
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The channel is invalid [channel:%u]", to_integral(channel));
- }
-
- if (sampleType < CAudioInfo::ESampleType::SAMPLE_TYPE_U8 || sampleType >= CAudioInfo::ESampleType::SAMPLE_TYPE_MAX) {
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The sampleType is invalid [sampleType:%u]", to_integral(sampleType));
- }
-
- if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) {
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The audioType is invalid [audioType:%u]", to_integral(audioType));
- }
+ if (sampleRate < CAudioInfo::MIN_SYSTEM_SAMPLERATE ||
+ sampleRate > CAudioInfo::MAX_SYSTEM_SAMPLERATE)
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
+ "The sampleRate is invalid [sampleRate:%u]", sampleRate);
+
+ if (channel < CAudioInfo::EChannel::CHANNEL_MONO ||
+ channel >= CAudioInfo::EChannel::CHANNEL_MAX)
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
+ "The channel is invalid [channel:%u]", to_integral(channel));
+
+ if (sampleType < CAudioInfo::ESampleType::SAMPLE_TYPE_U8 ||
+ sampleType >= CAudioInfo::ESampleType::SAMPLE_TYPE_MAX)
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
+ "The sampleType is invalid [sampleType:%u]", to_integral(sampleType));
+
+ if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ||
+ audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX)
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
+ "The audioType is invalid [audioType:%u]", to_integral(audioType));
}
-unsigned int CAudioInfo::getSampleRate() {
+unsigned int CAudioInfo::getSampleRate() noexcept {
return __mSampleRate;
}
-CAudioInfo::EChannel CAudioInfo::getChannel() {
+CAudioInfo::EChannel CAudioInfo::getChannel() noexcept {
return __mChannel;
}
-CAudioInfo::ESampleType CAudioInfo::getSampleType() {
+CAudioInfo::ESampleType CAudioInfo::getSampleType() noexcept {
return __mSampleType;
}
-CAudioInfo::EAudioType CAudioInfo::getAudioType() {
+CAudioInfo::EAudioType CAudioInfo::getAudioType() noexcept {
return __mAudioType;
}
-void CAudioInfo::setAudioType(CAudioInfo::EAudioType audioType) {
- __mAudioType = audioType;
- return;
+void CAudioInfo::setAudioTypeByInputStreamType(const char* streamType) {
+ __mAudioType = convertInputStreamTypeToAudioType(streamType);
+}
+
+void CAudioInfo::setAudioTypeByOutputStreamType(const char* streamType) {
+ __mAudioType = convertOutputStreamTypeToAudioType(streamType);
}
-int CAudioInfo::getAudioIndex() {
+int CAudioInfo::getAudioIndex() noexcept {
return __mAudioIndex;
}
-void CAudioInfo::setAudioIndex(int audioIndex) {
+void CAudioInfo::setAudioIndex(int audioIndex) noexcept {
__mAudioIndex = audioIndex;
- return;
}
-int CAudioInfo::getSampleSize() {
+int CAudioInfo::getSampleSize() noexcept {
int bytes_in_sample = 0;
- int number_of_channel = 0;
switch (__mSampleType) {
case ESampleType::SAMPLE_TYPE_U8:
case ESampleType::SAMPLE_TYPE_S16_LE:
bytes_in_sample = 2;
break;
+ case ESampleType::SAMPLE_TYPE_S24_LE:
+ bytes_in_sample = 3;
+ break;
+ case ESampleType::SAMPLE_TYPE_S24_32_LE:
+ case ESampleType::SAMPLE_TYPE_S32_LE:
+ bytes_in_sample = 4;
+ break;
default:
AUDIO_IO_LOGW("As unrecognized sample type %d, let's assume S16_LE", static_cast<int>(__mSampleType));
bytes_in_sample = 2;
break;
}
- switch (__mChannel) {
- case EChannel::CHANNEL_MONO:
- number_of_channel = 1;
- break;
- case EChannel::CHANNEL_STEREO:
- number_of_channel = 2;
- break;
- default:
- AUDIO_IO_LOGW("As unrecognized channel %d, let's assume STEREO", static_cast<int>(__mChannel));
- number_of_channel = 2;
- break;
- }
+ return bytes_in_sample * static_cast<int>(__mChannel);
+}
- return bytes_in_sample * number_of_channel;
+void CAudioInfo::setEffectMethod(int method) noexcept {
+ __mEffectMethod = method;
}
-void CAudioInfo::convertAudioType2StreamType(CAudioInfo::EAudioType audioType, char **streamType) {
- if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) {
+std::string CAudioInfo::getEffectMethod() noexcept {
+ std::string method;
+
+ if (__mEffectMethod & SOUND_EFFECT_NOISE_SUPPRESSION_VOIP)
+ method += "ns-rnnoise,";
+
+ if (__mEffectMethod & SOUND_EFFECT_NOISE_SUPPRESSION_VOICE_RECOGNITION)
+ method += "ns-pse,";
+
+ if (__mEffectMethod & SOUND_EFFECT_NOISE_SUPPRESSION_DOORBELL)
+ method += "ns-srid,";
+
+ if (__mEffectMethod & SOUND_EFFECT_AUTOMATIC_GAIN_CONTROL_CAPTURE)
+ method += "agc-speex,";
+
+ return method;
+}
+
+void CAudioInfo::setEffectMethodWithReference(sound_effect_method_with_reference_e method, int id) noexcept {
+ __mEffectMethodWithReference = method;
+ __mEffectMethodReferenceDeviceId = id;
+}
+
+std::pair<std::string, int> CAudioInfo::getEffectMethodWithReference() noexcept {
+ std::string method;
+
+ if (__mEffectMethodWithReference == SOUND_EFFECT_REFERENCE_COPY)
+ method += "reference_copy,";
+ else if (__mEffectMethodWithReference == SOUND_EFFECT_ACOUSTIC_ECHO_CANCEL_SPEEX)
+ method += "aec-speex,";
+ else if (__mEffectMethodWithReference == SOUND_EFFECT_ACOUSTIC_ECHO_CANCEL_WEBRTC)
+ method += "aec-webrtc,";
+
+ return make_pair(method, __mEffectMethodReferenceDeviceId);
+}
+
+const char* CAudioInfo::getConvertedStreamType() {
+ if (__mAudioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ||
+ __mAudioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
- "The audioType is not supported [audioType:%u]", to_integral(audioType));
- }
- *streamType = (char *)__STREAM_TYPE_TABLE[(unsigned int)audioType];
- return;
+ "The audioType is not supported [audioType:%u]", to_integral(__mAudioType));
+
+ return __STREAM_TYPE_TABLE[(unsigned int)__mAudioType];
}
-void CAudioInfo::convertInputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType) {
- for (unsigned int i = (unsigned int)CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ; i < (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA ; i++) {
- if (!strcmp((char *)__STREAM_TYPE_TABLE[i], streamType)) {
- *audioType = (CAudioInfo::EAudioType)i;
- return;
- }
+CAudioInfo::EAudioType CAudioInfo::convertInputStreamTypeToAudioType(const char *streamType) {
+ for (auto i = (unsigned int)CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA;
+ i < (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA;
+ i++) {
+ if (!strcmp(__STREAM_TYPE_TABLE[i], streamType))
+ return (CAudioInfo::EAudioType)i;
}
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The streamType of input is not supported [streamType:%s]", streamType);
- return;
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
+ "The streamType of input is not supported [streamType:%s]", streamType);
}
-void CAudioInfo::convertOutputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType) {
- for (unsigned int i = (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA ; i < (unsigned int)CAudioInfo::EAudioType::AUDIO_TYPE_MAX ; i++) {
- if (!strcmp((char *)__STREAM_TYPE_TABLE[i], streamType)) {
- *audioType = (CAudioInfo::EAudioType)i;
- return;
- }
+CAudioInfo::EAudioType CAudioInfo::convertOutputStreamTypeToAudioType(const char *streamType) {
+ for (auto i = (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA;
+ i < (unsigned int)CAudioInfo::EAudioType::AUDIO_TYPE_MAX;
+ i++) {
+ if (!strcmp(__STREAM_TYPE_TABLE[i], streamType))
+ return (CAudioInfo::EAudioType)i;
}
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The streamType of output is not supported [streamType:%s]", streamType);
- return;
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
+ "The streamType of output is not supported [streamType:%s]", streamType);
}
-