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 /// <since_tizen> 3 </since_tizen>
26 public class AudioEffect
28 private readonly EqualizerBand[] _bands;
30 internal AudioEffect(Player owner)
34 if (IsAvailable== false)
39 _bands = new EqualizerBand[Count];
43 /// Gets a <see cref="EqualizerBand"/> at the specified index.
45 /// <param name="index">The index of the band to get.</param>
46 /// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
47 /// <exception cref="ArgumentOutOfRangeException">
48 /// <pramref name="index"/> is less than zero.<br/>
50 /// <paramref name="index"/> is equal to or greater than <see cref="Count"/>.
52 /// <exception cref="InvalidOperationException">
53 /// If audio offload is enabled by calling <see cref="AudioOffload.IsEnabled"/>. (Since tizen 6.0)
55 /// <since_tizen> 3 </since_tizen>
56 public EqualizerBand this[int index]
60 Player.ValidateNotDisposed();
61 Player.AudioOffload.CheckDisabled();
63 if (index < 0 || Count <= index)
65 throw new ArgumentOutOfRangeException(nameof(index), index,
66 $"Valid index is 0 <= x < { nameof(Count) } ");
69 if (_bands[index] == null)
71 _bands[index] = new EqualizerBand(this, index);
73 Log.Info(PlayerLog.Tag, "get equalizer band : " + _bands[index]);
79 /// Clears the equalizer effect.
81 /// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
82 /// <exception cref="InvalidOperationException">
83 /// If audio offload is enabled by calling <see cref="AudioOffload.IsEnabled"/>. (Since tizen 6.0)
85 /// <since_tizen> 3 </since_tizen>
88 Player.ValidateNotDisposed();
89 Player.AudioOffload.CheckDisabled();
91 Native.EqualizerClear(Player.Handle).
92 ThrowIfFailed(Player, "Failed to clear equalizer effect");
96 /// Gets the number of items.
98 /// <exception cref="InvalidOperationException">
99 /// If audio offload is enabled by calling <see cref="AudioOffload.IsEnabled"/>. (Since tizen 6.0)
101 /// <since_tizen> 3 </since_tizen>
106 Player.AudioOffload.CheckDisabled();
108 Native.GetEqualizerBandsCount(Player.Handle, out var count).
109 ThrowIfFailed(Player, "Failed to initialize the AudioEffect");
116 /// Gets the range of band level in dB.
118 /// <exception cref="InvalidOperationException">
119 /// If audio offload is enabled by calling <see cref="AudioOffload.IsEnabled"/>. (Since tizen 6.0)
121 /// <since_tizen> 3 </since_tizen>
122 public Range BandLevelRange
126 Player.AudioOffload.CheckDisabled();
128 Native.GetEqualizerLevelRange(Player.Handle, out var min, out var max).
129 ThrowIfFailed(Player, "Failed to initialize the AudioEffect");
131 return new Range(min, max);
136 /// Gets the value whether the AudioEffect is available or not.
138 /// <exception cref="InvalidOperationException">
139 /// If audio offload is enabled by calling <see cref="AudioOffload.IsEnabled"/>. (Since tizen 6.0)
141 /// <since_tizen> 3 </since_tizen>
142 public bool IsAvailable
146 Player.AudioOffload.CheckDisabled();
148 Native.EqualizerIsAvailable(Player.Handle, out var available).
149 ThrowIfFailed(Player, "Failed to initialize the AudioEffect");
155 /// Gets the player that this AudioEffect belongs to.
157 /// <since_tizen> 3 </since_tizen>
158 public Player Player { get; }