2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "CAudioIODef.h"
24 using namespace tizen_media_audio;
30 CAudioInfo::CAudioInfo() :
31 __mSampleRate(MAX_SYSTEM_SAMPLERATE),
32 __mChannel(EChannel::CHANNEL_MONO),
33 __mSampleType(ESampleType::SAMPLE_TYPE_U8),
34 __mAudioType(EAudioType::AUDIO_IN_TYPE_MEDIA),
36 __mReferenceDeviceId(0),
37 __mNoiseSuppression(false) {
40 CAudioInfo::CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex) :
41 __mSampleRate(sampleRate),
43 __mSampleType(sampleType),
44 __mAudioType(audioType),
45 __mAudioIndex(audioIndex),
46 __mReferenceDeviceId(0),
47 __mNoiseSuppression(false) {
48 // Check to invalid AudioInfo
49 if (sampleRate < CAudioInfo::MIN_SYSTEM_SAMPLERATE ||
50 sampleRate > CAudioInfo::MAX_SYSTEM_SAMPLERATE)
51 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
52 "The sampleRate is invalid [sampleRate:%u]", sampleRate);
54 if (channel < CAudioInfo::EChannel::CHANNEL_MONO ||
55 channel >= CAudioInfo::EChannel::CHANNEL_MAX)
56 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
57 "The channel is invalid [channel:%u]", to_integral(channel));
59 if (sampleType < CAudioInfo::ESampleType::SAMPLE_TYPE_U8 ||
60 sampleType >= CAudioInfo::ESampleType::SAMPLE_TYPE_MAX)
61 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
62 "The sampleType is invalid [sampleType:%u]", to_integral(sampleType));
64 if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ||
65 audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX)
66 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
67 "The audioType is invalid [audioType:%u]", to_integral(audioType));
70 unsigned int CAudioInfo::getSampleRate() noexcept {
74 CAudioInfo::EChannel CAudioInfo::getChannel() noexcept {
78 CAudioInfo::ESampleType CAudioInfo::getSampleType() noexcept {
82 CAudioInfo::EAudioType CAudioInfo::getAudioType() noexcept {
86 void CAudioInfo::setAudioTypeByInputStreamType(const char* streamType) {
87 __mAudioType = convertInputStreamTypeToAudioType(streamType);
90 void CAudioInfo::setAudioTypeByOutputStreamType(const char* streamType) {
91 __mAudioType = convertOutputStreamTypeToAudioType(streamType);
94 int CAudioInfo::getAudioIndex() noexcept {
98 void CAudioInfo::setAudioIndex(int audioIndex) noexcept {
99 __mAudioIndex = audioIndex;
102 int CAudioInfo::getSampleSize() noexcept {
103 int bytes_in_sample = 0;
105 switch (__mSampleType) {
106 case ESampleType::SAMPLE_TYPE_U8:
109 case ESampleType::SAMPLE_TYPE_S16_LE:
112 case ESampleType::SAMPLE_TYPE_S24_LE:
115 case ESampleType::SAMPLE_TYPE_S24_32_LE:
116 case ESampleType::SAMPLE_TYPE_S32_LE:
120 AUDIO_IO_LOGW("As unrecognized sample type %d, let's assume S16_LE", static_cast<int>(__mSampleType));
125 return bytes_in_sample * static_cast<int>(__mChannel);
128 void CAudioInfo::bindEchoCancelReferenceDeviceId(int id) noexcept {
129 __mReferenceDeviceId = id;
132 int CAudioInfo::getEchoCancelReferenceDeviceId() noexcept {
133 return __mReferenceDeviceId;
136 void CAudioInfo::setNoiseSuppression(bool enable) noexcept {
137 __mNoiseSuppression = enable;
140 bool CAudioInfo::getNoiseSuppression() noexcept {
141 return __mNoiseSuppression;
144 const char* CAudioInfo::getConvertedStreamType() {
145 if (__mAudioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ||
146 __mAudioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX)
147 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
148 "The audioType is not supported [audioType:%u]", to_integral(__mAudioType));
150 return __STREAM_TYPE_TABLE[(unsigned int)__mAudioType];
153 CAudioInfo::EAudioType CAudioInfo::convertInputStreamTypeToAudioType(const char *streamType) {
154 for (auto i = (unsigned int)CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA;
155 i < (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA;
157 if (!strcmp(__STREAM_TYPE_TABLE[i], streamType))
158 return (CAudioInfo::EAudioType)i;
160 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
161 "The streamType of input is not supported [streamType:%s]", streamType);
164 CAudioInfo::EAudioType CAudioInfo::convertOutputStreamTypeToAudioType(const char *streamType) {
165 for (auto i = (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA;
166 i < (unsigned int)CAudioInfo::EAudioType::AUDIO_TYPE_MAX;
168 if (!strcmp(__STREAM_TYPE_TABLE[i], streamType))
169 return (CAudioInfo::EAudioType)i;
171 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
172 "The streamType of output is not supported [streamType:%s]", streamType);