src/3rdparty/phonon/mmf/audioequalizer.cpp
changeset 7 f7bc934e204c
parent 0 1918ee327afb
child 33 3e2da88830cd
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
    14 You should have received a copy of the GNU Lesser General Public License
    14 You should have received a copy of the GNU Lesser General Public License
    15 along with this library.  If not, see <http://www.gnu.org/licenses/>.
    15 along with this library.  If not, see <http://www.gnu.org/licenses/>.
    16 
    16 
    17 */
    17 */
    18 
    18 
       
    19 #include <AudioEqualizerBase.h>
    19 #include "audioequalizer.h"
    20 #include "audioequalizer.h"
    20 
    21 
    21 QT_BEGIN_NAMESPACE
    22 QT_BEGIN_NAMESPACE
    22 
    23 
    23 using namespace Phonon;
    24 using namespace Phonon;
    25 
    26 
    26 /*! \class MMF::AudioEqualizer
    27 /*! \class MMF::AudioEqualizer
    27   \internal
    28   \internal
    28 */
    29 */
    29 
    30 
    30 AudioEqualizer::AudioEqualizer(QObject *parent) : AbstractAudioEffect::AbstractAudioEffect(parent, createParams())
    31 // Define functions which depend on concrete native effect class name
       
    32 PHONON_MMF_DEFINE_EFFECT_FUNCTIONS(AudioEqualizer)
       
    33 
       
    34 AudioEqualizer::AudioEqualizer(QObject *parent, const QList<EffectParameter>& parameters)
       
    35     :   AbstractAudioEffect::AbstractAudioEffect(parent, parameters)
    31 {
    36 {
       
    37 
    32 }
    38 }
    33 
    39 
    34 void AudioEqualizer::parameterChanged(const int pid,
    40 int AudioEqualizer::effectParameterChanged(const EffectParameter &param,
    35                                       const QVariant &value)
    41                                       const QVariant &value)
    36 {
    42 {
    37     // There is no way to return an error from this function, so we just
    43     const int band = param.id() - ParameterBase + 1;
    38     // have to trap and ignore exceptions.
    44 
    39     TRAP_IGNORE(static_cast<CAudioEqualizer *>(m_effect.data())->SetBandLevelL(pid, value.toInt()));
    45     const qreal externalLevel = value.toReal();
       
    46     const int internalLevel = param.toInternalValue(externalLevel);
       
    47 
       
    48     TRAPD(err, concreteEffect()->SetBandLevelL(band, internalLevel));
       
    49     return err;
    40 }
    50 }
    41 
    51 
    42 bool AudioEqualizer::activateOn(CPlayerType *player)
    52 
       
    53 //-----------------------------------------------------------------------------
       
    54 // Static functions
       
    55 //-----------------------------------------------------------------------------
       
    56 
       
    57 const char* AudioEqualizer::description()
    43 {
    58 {
    44     CAudioEqualizer *ptr = 0;
    59     return "Audio equalizer";
    45     QT_TRAP_THROWING(ptr = CAudioEqualizer::NewL(*player));
       
    46     m_effect.reset(ptr);
       
    47 
       
    48     return true;
       
    49 }
    60 }
    50 
    61 
    51 QList<EffectParameter> AudioEqualizer::createParams()
    62 bool AudioEqualizer::getParameters(CMdaAudioOutputStream *stream,
       
    63     QList<EffectParameter>& parameters)
    52 {
    64 {
    53     QList<EffectParameter> retval;
    65     bool supported = false;
    54 
    66 
    55     // We temporarily create an AudioPlayer, and run the effect on it, so
    67     QScopedPointer<CAudioEqualizer> effect;
    56     // we can extract the readonly data we need.
    68     TRAPD(err, effect.reset(CAudioEqualizer::NewL(*stream)));
    57     AudioPlayer dummyPlayer;
       
    58 
    69 
    59     CAudioEqualizer *eqPtr = 0;
    70     if (KErrNone == err) {
    60     QT_TRAP_THROWING(eqPtr = CAudioEqualizer::NewL(*dummyPlayer.player());)
    71         supported = true;
    61     QScopedPointer<CAudioEqualizer> e(eqPtr);
       
    62 
    72 
    63     TInt32 dbMin;
    73         TInt32 dbMin;
    64     TInt32 dbMax;
    74         TInt32 dbMax;
    65     e->DbLevelLimits(dbMin, dbMax);
    75         effect->DbLevelLimits(dbMin, dbMax);
    66 
    76 
    67     const int bandCount = e->NumberOfBands();
    77         const int bandCount = effect->NumberOfBands();
    68 
    78 
    69     for (int i = 0; i < bandCount; ++i) {
    79         for (int i = 0; i < bandCount; ++i) {
    70         const qint32 hz = e->CenterFrequency(i);
    80             // For some reason, band IDs are 1-based, as opposed to the
       
    81             // 0-based indices used in just about other Symbian API...!
       
    82             const int band = i + 1;
    71 
    83 
    72         const qint32 defVol = e->BandLevel(i);
    84             const qint32 hz = effect->CenterFrequency(band);
    73 
    85 
    74         retval.append(EffectParameter(i,
    86             // We pass a floating-point parameter range of -1.0 to +1.0 for
    75                                       tr("Frequency band, %1 Hz").arg(hz),
    87             // each band in order to work around a limitation in
    76                                       EffectParameter::LogarithmicHint,
    88             // Phonon::EffectWidget.  See documentation of EffectParameter
    77                                       QVariant(qint32(defVol)),
    89             // for more details.
    78                                       QVariant(qint32(dbMin)),
    90             EffectParameter param(
    79                                       QVariant(qint32(dbMax)),
    91                  /* parameterId */        ParameterBase + i,
    80                                       QVariantList(),
    92                  /* name */               tr("%1 Hz").arg(hz),
    81                                       QString()));
    93                  /* hints */              EffectParameter::LogarithmicHint,
       
    94                  /* defaultValue */       QVariant(qreal(0.0)),
       
    95                  /* minimumValue */       QVariant(qreal(-1.0)),
       
    96                  /* maximumValue */       QVariant(qreal(+1.0)));
       
    97 
       
    98             param.setInternalRange(dbMin, dbMax);
       
    99             parameters.append(param);
       
   100         }
    82     }
   101     }
    83 
   102 
    84     return retval;
   103     return supported;
    85 }
   104 }
    86 
   105 
    87 QT_END_NAMESPACE
   106 QT_END_NAMESPACE