Release 4.0.0-preview1-00201
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.MediaPlayer / Player / EqualizerBand.cs
1 /*
2  * Copyright (c) 2016 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 using System;
18 using System.Diagnostics;
19 using Native = Interop.AudioEffect;
20
21 namespace Tizen.Multimedia
22 {
23
24     /// <summary>
25     /// Represents an equalizer band of <see cref="AudioEffect"/>.
26     /// </summary>
27     public class EqualizerBand
28     {
29         private readonly AudioEffect _owner;
30         private readonly int _index;
31
32         internal EqualizerBand(AudioEffect owner, int index)
33         {
34             Debug.Assert(owner != null);
35
36             _owner = owner;
37             _index = index;
38
39             int frequency = 0;
40             int range = 0;
41
42             Native.GetEqualizerBandFrequency(_owner.Player.Handle, _index, out frequency).
43                 ThrowIfFailed("Failed to initialize equalizer band");
44
45             Native.GetEqualizerBandFrequencyRange(_owner.Player.Handle, _index, out range).
46                 ThrowIfFailed("Failed to initialize equalizer band");
47
48             Frequency = frequency;
49             FrequencyRange = range;
50             Log.Debug(PlayerLog.Tag, "frequency : " + frequency + ", range : " + range);
51         }
52
53         /// <summary>
54         /// Sets or gets the gain for the equalizer band.
55         /// </summary>
56         /// <param name="value">The value indicating new gain in decibel(dB).</param>
57         /// <exception cref="ObjectDisposedException">The player that this EqualizerBand belongs to has already been disposed of.</exception>
58         /// <exception cref="ArgumentOutOfRangeException">
59         ///     <paramref name="value"/> is not inside of <see cref="AudioEffect.BandLevelRange"/>.
60         /// </exception>
61         public int Level
62         {
63             get
64             {
65                 _owner.Player.ValidateNotDisposed();
66
67                 int value = 0;
68                 Native.GetEqualizerBandLevel(_owner.Player.Handle, _index, out value).
69                     ThrowIfFailed("Failed to get the level of the equalizer band");
70                 Log.Info(PlayerLog.Tag, "get level : " + value);
71                 return value;
72             }
73             set
74             {
75                 _owner.Player.ValidateNotDisposed();
76
77                 if (value < _owner.BandLevelRange.Min || _owner.BandLevelRange.Max < value)
78                 {
79                     Log.Error(PlayerLog.Tag, "invalid level : " + value);
80                     throw new ArgumentOutOfRangeException(nameof(value), value,
81                         $"valid value range is { nameof(AudioEffect.BandLevelRange) }." +
82                         $"but got {value}.");
83                 }
84
85                 Native.SetEqualizerBandLevel(_owner.Player.Handle, _index, value).
86                     ThrowIfFailed("Failed to set the level of the equalizer band");
87             }
88         }
89
90
91         /// <summary>
92         /// Gets the frequency in the dB.
93         /// </summary>
94         public int Frequency { get; }
95
96         /// <summary>
97         /// Gets the frequency range in the dB.
98         /// </summary>
99         public int FrequencyRange { get; }
100
101     }
102 }