Add effect methods information to AudioInfo
[platform/core/api/audio-io.git] / include / CAudioInfo.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __TIZEN_MEDIA_AUDIO__IO_CAUDIO_INFO_H__
18 #define __TIZEN_MEDIA_AUDIO__IO_CAUDIO_INFO_H__
19
20
21 #ifdef __cplusplus
22
23 #include <type_traits>
24 #include <string>
25 #include <sound_manager.h>
26 #include <sound_manager_internal.h>
27
28 namespace tizen_media_audio {
29
30     template<typename E>
31     constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type {
32         return static_cast<typename std::underlying_type<E>::type>(e);
33     }
34
35     /**
36      * Audio Information
37      */
38     class CAudioInfo {
39     public:
40         enum class EChannel : unsigned int {
41             CHANNEL_MONO = 1,               /**< 1 channel, mono */
42             CHANNEL_STEREO,                 /**< 2 channel, stereo */
43             CHANNEL_MULTI_3,                /**< 3 channel */
44             CHANNEL_MULTI_4,                /**< 4 channel */
45             CHANNEL_MULTI_5,                /**< 5 channel */
46             CHANNEL_MULTI_6,                /**< 6 channel */
47             CHANNEL_MULTI_7,                /**< 7 channel */
48             CHANNEL_MULTI_8,                /**< 8 channel */
49             CHANNEL_MULTI_9,                /**< 9 channel */
50             CHANNEL_MULTI_10,               /**< 10 channel */
51             CHANNEL_MULTI_11,               /**< 11 channel */
52             CHANNEL_MULTI_12,               /**< 12 channel */
53             CHANNEL_MULTI_13,               /**< 13 channel */
54             CHANNEL_MULTI_14,               /**< 14 channel */
55             CHANNEL_MULTI_15,               /**< 15 channel */
56             CHANNEL_MULTI_16,               /**< 16 channel */
57             CHANNEL_MAX
58         };
59
60         enum class ESampleType : unsigned int {
61             SAMPLE_TYPE_U8 = 1,             /**< Unsigned 8-bit audio samples */
62             SAMPLE_TYPE_S16_LE,             /**< Signed 16-bit audio samples */
63             SAMPLE_TYPE_S24_LE,             /**< Signed 24-bit audio samples */
64             SAMPLE_TYPE_S24_32_LE,          /**< Signed 24-bit packed in 32-bit audio samples */
65             SAMPLE_TYPE_S32_LE,             /**< Signed 32-bit audio samples */
66             SAMPLE_TYPE_MAX
67         };
68
69         enum class EAudioType : unsigned int {
70             /* Input Type */
71             AUDIO_IN_TYPE_MEDIA = 0,
72             //AUDIO_IN_TYPE_SYSTEM,
73             //AUDIO_IN_TYPE_ALARM,
74             //AUDIO_IN_TYPE_NOTIFICATION,
75             //AUDIO_IN_TYPE_EMERGENCY,
76             //AUDIO_IN_TYPE_VOICE_INFORMATION,
77             AUDIO_IN_TYPE_VOICE_RECOGNITION,
78             //AUDIO_IN_TYPE_RINGTONE_VOIP,
79             AUDIO_IN_TYPE_VOIP,
80             AUDIO_IN_TYPE_MEDIA_EXTERNAL_ONLY,
81             //AUDIO_IN_TYPE_RINGTONE_CALL,
82             //AUDIO_IN_TYPE_VOICE_CALL,
83             //AUDIO_IN_TYPE_VIDEO_CALL,
84             //AUDIO_IN_TYPE_RADIO,
85             AUDIO_IN_TYPE_LOOPBACK,
86             AUDIO_IN_TYPE_VOICE_RECOGNITION_SERVICE,
87             //AUDIO_IN_TYPE_MEDIA_NETWORK_SOURCE,
88
89             /* Output Type */
90             AUDIO_OUT_TYPE_MEDIA,
91             AUDIO_OUT_TYPE_SYSTEM,
92             AUDIO_OUT_TYPE_ALARM,
93             AUDIO_OUT_TYPE_NOTIFICATION,
94             AUDIO_OUT_TYPE_EMERGENCY,
95             AUDIO_OUT_TYPE_VOICE_INFORMATION,
96             //AUDIO_OUT_TYPE_VOICE_RECOGNITION,
97             AUDIO_OUT_TYPE_RINGTONE_VOIP,
98             AUDIO_OUT_TYPE_VOIP,
99             AUDIO_OUT_TYPE_MEDIA_EXTERNAL_ONLY,
100             AUDIO_OUT_TYPE_RINGTONE_CALL,
101             //AUDIO_OUT_TYPE_VOICE_CALL,
102             //AUDIO_OUT_TYPE_VIDEO_CALL,
103             //AUDIO_OUT_TYPE_RADIO,
104             //AUDIO_OUT_TYPE_LOOPBACK,
105             //AUDIO_OUT_TYPE_VOICE_RECOGNITION_SERVICE,
106             AUDIO_OUT_TYPE_MEDIA_NETWORK_SOURCE,
107
108             AUDIO_TYPE_MAX
109         };
110
111         enum class EAudioIOState : unsigned int {
112             AUDIO_IO_STATE_NONE,      /**< Audio-io handle is not created */
113             AUDIO_IO_STATE_IDLE,      /**< Audio-io handle is created, but not prepared */
114             AUDIO_IO_STATE_RUNNING,   /**< Audio-io handle is ready and the stream is running */
115             AUDIO_IO_STATE_PAUSED,    /**< Audio-io handle is ready and the stream is paused */
116             AUDIO_IO_STATE_MAX
117         };
118
119         enum class EAudioDirection : unsigned int {
120             AUDIO_DIRECTION_IN,       /**< Audio direction input */
121             AUDIO_DIRECTION_OUT,      /**< Audio direction output */
122             AUDIO_DIRECTION_MAX
123         };
124
125         static constexpr auto MIN_SYSTEM_SAMPLERATE = 8000;
126         static constexpr auto MAX_SYSTEM_SAMPLERATE = 192000;
127
128         static constexpr auto MIN_RECORD_VOLUME = 0.0;
129         static constexpr auto MAX_RECORD_VOLUME = 2.0;
130         static constexpr auto DEFAULT_RECORD_VOLUME = 1.0;
131
132         /* Constructors */
133         CAudioInfo();
134         CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex);
135         virtual ~CAudioInfo() = default;
136
137         /* Setter & Getter */
138         unsigned int getSampleRate() noexcept;
139         EChannel getChannel() noexcept;
140         ESampleType getSampleType() noexcept;
141         EAudioType getAudioType() noexcept;
142         int getAudioIndex() noexcept;
143         void setAudioIndex(int audioIndex) noexcept;
144         int getSampleSize() noexcept;
145
146         void setEffectMethod(int method) noexcept;
147         std::string getEffectMethod() noexcept;
148
149         void setEffectMethodWithReference(sound_effect_method_with_reference_e method, int id) noexcept;
150         std::pair<std::string, int> getEffectMethodWithReference() noexcept;
151
152         /* Setter & Getter Utilities */
153         const char* getConvertedStreamType();
154         void setAudioTypeByInputStreamType(const char* streamType);
155         void setAudioTypeByOutputStreamType(const char* streamType);
156
157     private:
158         const char *__STREAM_TYPE_TABLE[(unsigned int)EAudioType::AUDIO_TYPE_MAX] = {
159             /* Input Type */
160             "media",                  /**< AUDIO_IN_TYPE_MEDIA */
161             //"system",               /**< AUDIO_IN_TYPE_SYSTEM */
162             //"alarm",                /**< AUDIO_IN_TYPE_ALARM */
163             //"notification",         /**< AUDIO_IN_TYPE_NOTIFICATION */
164             //"emergency",            /**< AUDIO_IN_TYPE_EMERGENCY */
165             //"voice-information",    /**< AUDIO_IN_TYPE_VOICE_INFORMATION */
166             "voice-recognition",      /**< AUDIO_IN_TYPE_VOICE_RECOGNITION */
167             //"ringtone-voip",        /**< AUDIO_IN_TYPE_RINGTONE_VOIP */
168             "voip",                   /**< AUDIO_IN_TYPE_VOIP */
169             "ext-media",              /**< AUDIO_IN_TYPE_MEDIA_EXTERNAL_ONLY */
170             //"ringtone-call",        /**< AUDIO_IN_TYPE_RINGTONE_CALL */
171             //"call-voice",           /**< AUDIO_IN_TYPE_VOICE_CALL */
172             //"call-video",           /**< AUDIO_IN_TYPE_VIDEO_CALL */
173             //"radio",                /**< AUDIO_IN_TYPE_RADIO */
174             "loopback-mirroring",     /**< AUDIO_IN_TYPE_LOOPBACK */
175             "voice-recognition-service",     /**< AUDIO_IN_TYPE_VOICE_RECOGNITION_SERVICE */
176             //"network-source-media", /**< AUDIO_IN_TYPE_MEDIA_NETWORK_SOURCE */
177
178             /* Output Type */
179             "media",                  /**< AUDIO_OUT_TYPE_MEDIA */
180             "system",                 /**< AUDIO_OUT_TYPE_SYSTEM */
181             "alarm",                  /**< AUDIO_OUT_TYPE_ALARM */
182             "notification",           /**< AUDIO_OUT_TYPE_NOTIFICATION */
183             "emergency",              /**< AUDIO_OUT_TYPE_EMERGENCY */
184             "voice-information",      /**< AUDIO_OUT_TYPE_VOICE_INFORMATION */
185             //"voice-recognition",    /**< AUDIO_OUT_TYPE_VOICE_RECOGNITION */
186             "ringtone-voip",          /**< AUDIO_OUT_TYPE_RINGTONE_VOIP */
187             "voip",                   /**< AUDIO_OUT_TYPE_VOIP */
188             "ext-media",              /**< AUDIO_OUT_TYPE_MEDIA_EXTERNAL_ONLY */
189             "ringtone-call",          /**< AUDIO_OUT_TYPE_RINGTONE_CALL */
190             //"call-voice",           /**< AUDIO_OUT_TYPE_VOICE_CALL */
191             //"call-video",           /**< AUDIO_OUT_TYPE_VIDEO_CALL */
192             //"radio",                /**< AUDIO_OUT_TYPE_RADIO */
193             //"loopback-mirroring",   /**< AUDIO_OUT_TYPE_LOOPBACK */
194             //"voice-recognition-service",/**< AUDIO_OUT_TYPE_VOICE_RECOGNITION_SERVICE */
195             "network-source-media",   /**< AUDIO_OUT_TYPE_MEDIA_NETWORK_SOURCE */
196         };
197
198         EAudioType convertInputStreamTypeToAudioType(const char *streamType);
199         EAudioType convertOutputStreamTypeToAudioType(const char *streamType);
200
201         unsigned int __mSampleRate;
202         EChannel     __mChannel;
203         ESampleType  __mSampleType;
204         EAudioType   __mAudioType;
205         int          __mAudioIndex;
206
207         sound_effect_method_with_reference_e    __mEffectMethodWithReference;
208         int                                     __mEffectMethodReferenceDeviceId;
209         int                                     __mEffectMethod;
210
211     };
212
213
214 } /* namespace tizen_media_audio */
215
216 #endif
217 #endif /* __TIZEN_MEDIA_AUDIO__IO_CAUDIO_INFO_H__ */