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.
17 #ifndef __TIZEN_MEDIA_AUDIO__IO_CAUDIO_INFO_H__
18 #define __TIZEN_MEDIA_AUDIO__IO_CAUDIO_INFO_H__
23 #include <type_traits>
28 #include <sound_manager.h>
29 #include <sound_manager_internal.h>
31 namespace tizen_media_audio {
34 constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type {
35 return static_cast<typename std::underlying_type<E>::type>(e);
43 enum class EChannel : unsigned int {
44 CHANNEL_MONO = 1, /**< 1 channel, mono */
45 CHANNEL_STEREO, /**< 2 channel, stereo */
46 CHANNEL_MULTI_3, /**< 3 channel */
47 CHANNEL_MULTI_4, /**< 4 channel */
48 CHANNEL_MULTI_5, /**< 5 channel */
49 CHANNEL_MULTI_6, /**< 6 channel */
50 CHANNEL_MULTI_7, /**< 7 channel */
51 CHANNEL_MULTI_8, /**< 8 channel */
52 CHANNEL_MULTI_9, /**< 9 channel */
53 CHANNEL_MULTI_10, /**< 10 channel */
54 CHANNEL_MULTI_11, /**< 11 channel */
55 CHANNEL_MULTI_12, /**< 12 channel */
56 CHANNEL_MULTI_13, /**< 13 channel */
57 CHANNEL_MULTI_14, /**< 14 channel */
58 CHANNEL_MULTI_15, /**< 15 channel */
59 CHANNEL_MULTI_16, /**< 16 channel */
63 enum class ESampleType : unsigned int {
64 SAMPLE_TYPE_U8 = 1, /**< Unsigned 8-bit audio samples */
65 SAMPLE_TYPE_S16_LE, /**< Signed 16-bit audio samples */
66 SAMPLE_TYPE_S24_LE, /**< Signed 24-bit audio samples */
67 SAMPLE_TYPE_S24_32_LE, /**< Signed 24-bit packed in 32-bit audio samples */
68 SAMPLE_TYPE_S32_LE, /**< Signed 32-bit audio samples */
72 enum class EAudioType : unsigned int {
74 AUDIO_IN_TYPE_MEDIA = 0,
75 //AUDIO_IN_TYPE_SYSTEM,
76 //AUDIO_IN_TYPE_ALARM,
77 //AUDIO_IN_TYPE_NOTIFICATION,
78 //AUDIO_IN_TYPE_EMERGENCY,
79 //AUDIO_IN_TYPE_VOICE_INFORMATION,
80 AUDIO_IN_TYPE_VOICE_RECOGNITION,
81 //AUDIO_IN_TYPE_RINGTONE_VOIP,
83 AUDIO_IN_TYPE_MEDIA_EXTERNAL_ONLY,
84 //AUDIO_IN_TYPE_RINGTONE_CALL,
85 //AUDIO_IN_TYPE_VOICE_CALL,
86 //AUDIO_IN_TYPE_VIDEO_CALL,
87 //AUDIO_IN_TYPE_RADIO,
88 AUDIO_IN_TYPE_LOOPBACK,
89 AUDIO_IN_TYPE_VOICE_RECOGNITION_SERVICE,
90 //AUDIO_IN_TYPE_MEDIA_NETWORK_SOURCE,
94 AUDIO_OUT_TYPE_SYSTEM,
96 AUDIO_OUT_TYPE_NOTIFICATION,
97 AUDIO_OUT_TYPE_EMERGENCY,
98 AUDIO_OUT_TYPE_VOICE_INFORMATION,
99 //AUDIO_OUT_TYPE_VOICE_RECOGNITION,
100 AUDIO_OUT_TYPE_RINGTONE_VOIP,
102 AUDIO_OUT_TYPE_MEDIA_EXTERNAL_ONLY,
103 AUDIO_OUT_TYPE_RINGTONE_CALL,
104 //AUDIO_OUT_TYPE_VOICE_CALL,
105 //AUDIO_OUT_TYPE_VIDEO_CALL,
106 //AUDIO_OUT_TYPE_RADIO,
107 //AUDIO_OUT_TYPE_LOOPBACK,
108 //AUDIO_OUT_TYPE_VOICE_RECOGNITION_SERVICE,
109 AUDIO_OUT_TYPE_MEDIA_NETWORK_SOURCE,
114 enum class EAudioIOState : unsigned int {
115 AUDIO_IO_STATE_NONE, /**< Audio-io handle is not created */
116 AUDIO_IO_STATE_IDLE, /**< Audio-io handle is created, but not prepared */
117 AUDIO_IO_STATE_RUNNING, /**< Audio-io handle is ready and the stream is running */
118 AUDIO_IO_STATE_PAUSED, /**< Audio-io handle is ready and the stream is paused */
122 enum class EAudioDirection : unsigned int {
123 AUDIO_DIRECTION_IN, /**< Audio direction input */
124 AUDIO_DIRECTION_OUT, /**< Audio direction output */
128 static constexpr auto MIN_SYSTEM_SAMPLERATE = 8000;
129 static constexpr auto MAX_SYSTEM_SAMPLERATE = 192000;
131 static constexpr auto MIN_RECORD_VOLUME = 0.0;
132 static constexpr auto MAX_RECORD_VOLUME = 2.0;
133 static constexpr auto DEFAULT_RECORD_VOLUME = 1.0;
135 /* Constructor & Destructor */
136 CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex);
137 virtual ~CAudioInfo() = default;
139 /* Audio Specification */
140 std::tuple<ESampleType, unsigned int, EChannel> getSpec() const noexcept;
141 int getSampleSize() const noexcept;
143 /* Stream Properties */
144 void setAudioIndex(int audioIndex) noexcept;
145 void setAudioTypeByInputStreamType(const char* streamType);
146 void setAudioTypeByOutputStreamType(const char* streamType);
147 EAudioType getAudioType() const noexcept;
148 std::pair<const char*, int> getStreamProperties() const;
151 void setEffectMethod(int method) noexcept;
152 std::string getEffectMethod() const noexcept;
154 void setEffectMethodWithReference(sound_effect_method_with_reference_e method, int id) noexcept;
155 std::pair<std::string, int> getEffectMethodWithReference() const noexcept;
158 size_t msToBytes(size_t milliseconds) const noexcept;
159 size_t bytesToMs(size_t bytes) const noexcept;
162 const char *__STREAM_TYPE_TABLE[(unsigned int)EAudioType::AUDIO_TYPE_MAX] = {
164 "media", /**< AUDIO_IN_TYPE_MEDIA */
165 //"system", /**< AUDIO_IN_TYPE_SYSTEM */
166 //"alarm", /**< AUDIO_IN_TYPE_ALARM */
167 //"notification", /**< AUDIO_IN_TYPE_NOTIFICATION */
168 //"emergency", /**< AUDIO_IN_TYPE_EMERGENCY */
169 //"voice-information", /**< AUDIO_IN_TYPE_VOICE_INFORMATION */
170 "voice-recognition", /**< AUDIO_IN_TYPE_VOICE_RECOGNITION */
171 //"ringtone-voip", /**< AUDIO_IN_TYPE_RINGTONE_VOIP */
172 "voip", /**< AUDIO_IN_TYPE_VOIP */
173 "ext-media", /**< AUDIO_IN_TYPE_MEDIA_EXTERNAL_ONLY */
174 //"ringtone-call", /**< AUDIO_IN_TYPE_RINGTONE_CALL */
175 //"call-voice", /**< AUDIO_IN_TYPE_VOICE_CALL */
176 //"call-video", /**< AUDIO_IN_TYPE_VIDEO_CALL */
177 //"radio", /**< AUDIO_IN_TYPE_RADIO */
178 "loopback-mirroring", /**< AUDIO_IN_TYPE_LOOPBACK */
179 "voice-recognition-service", /**< AUDIO_IN_TYPE_VOICE_RECOGNITION_SERVICE */
180 //"network-source-media", /**< AUDIO_IN_TYPE_MEDIA_NETWORK_SOURCE */
183 "media", /**< AUDIO_OUT_TYPE_MEDIA */
184 "system", /**< AUDIO_OUT_TYPE_SYSTEM */
185 "alarm", /**< AUDIO_OUT_TYPE_ALARM */
186 "notification", /**< AUDIO_OUT_TYPE_NOTIFICATION */
187 "emergency", /**< AUDIO_OUT_TYPE_EMERGENCY */
188 "voice-information", /**< AUDIO_OUT_TYPE_VOICE_INFORMATION */
189 //"voice-recognition", /**< AUDIO_OUT_TYPE_VOICE_RECOGNITION */
190 "ringtone-voip", /**< AUDIO_OUT_TYPE_RINGTONE_VOIP */
191 "voip", /**< AUDIO_OUT_TYPE_VOIP */
192 "ext-media", /**< AUDIO_OUT_TYPE_MEDIA_EXTERNAL_ONLY */
193 "ringtone-call", /**< AUDIO_OUT_TYPE_RINGTONE_CALL */
194 //"call-voice", /**< AUDIO_OUT_TYPE_VOICE_CALL */
195 //"call-video", /**< AUDIO_OUT_TYPE_VIDEO_CALL */
196 //"radio", /**< AUDIO_OUT_TYPE_RADIO */
197 //"loopback-mirroring", /**< AUDIO_OUT_TYPE_LOOPBACK */
198 //"voice-recognition-service",/**< AUDIO_OUT_TYPE_VOICE_RECOGNITION_SERVICE */
199 "network-source-media", /**< AUDIO_OUT_TYPE_MEDIA_NETWORK_SOURCE */
202 EAudioType convertInputStreamTypeToAudioType(const char *streamType);
203 EAudioType convertOutputStreamTypeToAudioType(const char *streamType);
205 unsigned int __mSampleRate { MAX_SYSTEM_SAMPLERATE };
206 EChannel __mChannel { EChannel::CHANNEL_MAX };
207 ESampleType __mSampleType { ESampleType::SAMPLE_TYPE_MAX };
208 EAudioType __mAudioType { EAudioType::AUDIO_TYPE_MAX };
209 int __mAudioIndex { -1 };
211 std::optional<sound_effect_method_with_reference_e>
212 __mEffectMethodWithReference;
213 int __mEffectMethodReferenceDeviceId { 0 };
214 int __mEffectMethod { 0 };
218 } /* namespace tizen_media_audio */
221 #endif /* __TIZEN_MEDIA_AUDIO__IO_CAUDIO_INFO_H__ */