#include <stdio.h>
+#include <string.h>
#include "CAudioIODef.h"
__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) throw(CAudioError) :
+CAudioInfo::CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex) :
__mSampleRate(sampleRate),
__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) {
- 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);
}
-int CAudioInfo::getAudioIndex() {
+void CAudioInfo::setAudioTypeByOutputStreamType(const char* streamType) {
+ __mAudioType = convertOutputStreamTypeToAudioType(streamType);
+}
+
+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);
+}
+
+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);
- return bytes_in_sample * number_of_channel;
+ __mReferenceDeviceId = id;
}
-void CAudioInfo::convertAudioType2StreamType(CAudioInfo::EAudioType audioType, char **streamType) {
- if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) {
+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 audioType is not supported [audioType:%u]", to_integral(audioType));
+ "The noise suppression type is not supported [type:%d]", type);
}
- *streamType = (char *)__STREAM_TYPE_TABLE[(unsigned int)audioType];
- return;
+
+ __mNoiseSuppression = enable;
}
-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;
- }
- }
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The streamType of input is not supported [streamType:%s]", streamType);
- return;
+std::string& CAudioInfo::getProcessorProperty() noexcept {
+ return __mProcessorProperty;
}
-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;
- }
+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(__mAudioType));
+
+ return __STREAM_TYPE_TABLE[(unsigned int)__mAudioType];
+}
+
+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 output 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);
}
+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);
+}