2 * Copyright (c) 2016 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.
18 using Native = Interop.AudioEffect;
20 namespace Tizen.Multimedia
23 /// Provides the ability to control the audio effects for <see cref="Multimedia.Player"/>.
25 public class AudioEffect
27 private readonly EqualizerBand[] _bands;
29 internal AudioEffect(Player owner)
33 bool available = false;
35 Native.EqualizerIsAvailable(Player.Handle, out available).
36 ThrowIfFailed("Failed to initialize the AudioEffect");
38 IsAvailable = available;
40 if (IsAvailable == false)
46 Native.GetEqualizerBandsCount(Player.Handle, out count).
47 ThrowIfFailed("Failed to initialize the AudioEffect");
51 Native.GetEqualizerLevelRange(Player.Handle, out min, out max).
52 ThrowIfFailed("Failed to initialize the AudioEffect");
55 BandLevelRange = new Range(min, max);
57 _bands = new EqualizerBand[count];
61 /// Gets a <see cref="EqualizerBand"/> at the specified index.
63 /// <param name="index">The index of the band to get.</param>
64 /// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
65 /// <exception cref="ArgumentOutOfRangeException">
66 /// index is less than zero.\n
68 /// index is equal to or greater than <see cref="Count"/>.
70 public EqualizerBand this[int index]
74 Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
75 Player.ValidateNotDisposed();
77 if (index < 0 || Count <= index)
79 throw new ArgumentOutOfRangeException(nameof(index), index,
80 $"Valid index is 0 <= x < { nameof(Count) } ");
83 if (_bands[index] == null)
85 _bands[index] = new EqualizerBand(this, index);
87 Log.Info(PlayerLog.Tag, "get equalizer band : " + _bands[index]);
93 /// Clears the equalizer effect.
95 /// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
98 Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
99 Player.ValidateNotDisposed();
101 Native.EqualizerClear(Player.Handle).
102 ThrowIfFailed("Failed to clear equalizer effect");
103 Log.Debug(PlayerLog.Tag, PlayerLog.Leave);
107 /// Get the number of items.
109 public int Count { get; }
112 /// Get the band level range of the bands in dB.
114 public Range BandLevelRange { get; }
117 /// Gets the value whether the AudioEffect is available or not.
119 public bool IsAvailable { get; }
122 /// Gets the player that this AudioEffect belongs to.
124 public Player Player { get; }