• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
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 package com.google.android.exoplayer2.audio;
17 
18 import android.media.AudioTrack;
19 import android.media.audiofx.AudioEffect;
20 import androidx.annotation.Nullable;
21 
22 /**
23  * Represents auxiliary effect information, which can be used to attach an auxiliary effect to an
24  * underlying {@link AudioTrack}.
25  *
26  * <p>Auxiliary effects can only be applied if the application has the {@code
27  * android.permission.MODIFY_AUDIO_SETTINGS} permission. Apps are responsible for retaining the
28  * associated audio effect instance and releasing it when it's no longer needed. See the
29  * documentation of {@link AudioEffect} for more information.
30  */
31 public final class AuxEffectInfo {
32 
33   /** Value for {@link #effectId} representing no auxiliary effect. */
34   public static final int NO_AUX_EFFECT_ID = 0;
35 
36   /**
37    * The identifier of the effect, or {@link #NO_AUX_EFFECT_ID} if there is no effect.
38    *
39    * @see android.media.AudioTrack#attachAuxEffect(int)
40    */
41   public final int effectId;
42   /**
43    * The send level for the effect.
44    *
45    * @see android.media.AudioTrack#setAuxEffectSendLevel(float)
46    */
47   public final float sendLevel;
48 
49   /**
50    * Creates an instance with the given effect identifier and send level.
51    *
52    * @param effectId The effect identifier. This is the value returned by {@link
53    *     AudioEffect#getId()} on the effect, or {@value NO_AUX_EFFECT_ID} which represents no
54    *     effect. This value is passed to {@link AudioTrack#attachAuxEffect(int)} on the underlying
55    *     audio track.
56    * @param sendLevel The send level for the effect, where 0 represents no effect and a value of 1
57    *     is full send. If {@code effectId} is not {@value #NO_AUX_EFFECT_ID}, this value is passed
58    *     to {@link AudioTrack#setAuxEffectSendLevel(float)} on the underlying audio track.
59    */
AuxEffectInfo(int effectId, float sendLevel)60   public AuxEffectInfo(int effectId, float sendLevel) {
61     this.effectId = effectId;
62     this.sendLevel = sendLevel;
63   }
64 
65   @Override
equals(@ullable Object o)66   public boolean equals(@Nullable Object o) {
67     if (this == o) {
68       return true;
69     }
70     if (o == null || getClass() != o.getClass()) {
71       return false;
72     }
73     AuxEffectInfo auxEffectInfo = (AuxEffectInfo) o;
74     return effectId == auxEffectInfo.effectId
75         && Float.compare(auxEffectInfo.sendLevel, sendLevel) == 0;
76   }
77 
78   @Override
hashCode()79   public int hashCode() {
80     int result = 17;
81     result = 31 * result + effectId;
82     result = 31 * result + Float.floatToIntBits(sendLevel);
83     return result;
84   }
85 }
86