|
1 /* This file is part of the KDE project. |
|
2 |
|
3 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
|
5 This library is free software: you can redistribute it and/or modify |
|
6 it under the terms of the GNU Lesser General Public License as published by |
|
7 the Free Software Foundation, either version 2.1 or 3 of the License. |
|
8 |
|
9 This library is distributed in the hope that it will be useful, |
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 GNU Lesser General Public License for more details. |
|
13 |
|
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/>. |
|
16 |
|
17 */ |
|
18 |
|
19 #include "audioequalizer.h" |
|
20 |
|
21 QT_BEGIN_NAMESPACE |
|
22 |
|
23 using namespace Phonon; |
|
24 using namespace Phonon::MMF; |
|
25 |
|
26 /*! \class MMF::AudioEqualizer |
|
27 \internal |
|
28 */ |
|
29 |
|
30 AudioEqualizer::AudioEqualizer(QObject *parent) : AbstractAudioEffect::AbstractAudioEffect(parent, createParams()) |
|
31 { |
|
32 } |
|
33 |
|
34 void AudioEqualizer::parameterChanged(const int pid, |
|
35 const QVariant &value) |
|
36 { |
|
37 // There is no way to return an error from this function, so we just |
|
38 // have to trap and ignore exceptions. |
|
39 TRAP_IGNORE(static_cast<CAudioEqualizer *>(m_effect.data())->SetBandLevelL(pid, value.toInt())); |
|
40 } |
|
41 |
|
42 bool AudioEqualizer::activateOn(CPlayerType *player) |
|
43 { |
|
44 CAudioEqualizer *ptr = 0; |
|
45 QT_TRAP_THROWING(ptr = CAudioEqualizer::NewL(*player)); |
|
46 m_effect.reset(ptr); |
|
47 |
|
48 return true; |
|
49 } |
|
50 |
|
51 QList<EffectParameter> AudioEqualizer::createParams() |
|
52 { |
|
53 QList<EffectParameter> retval; |
|
54 |
|
55 // We temporarily create an AudioPlayer, and run the effect on it, so |
|
56 // we can extract the readonly data we need. |
|
57 AudioPlayer dummyPlayer; |
|
58 |
|
59 CAudioEqualizer *eqPtr = 0; |
|
60 QT_TRAP_THROWING(eqPtr = CAudioEqualizer::NewL(*dummyPlayer.player());) |
|
61 QScopedPointer<CAudioEqualizer> e(eqPtr); |
|
62 |
|
63 TInt32 dbMin; |
|
64 TInt32 dbMax; |
|
65 e->DbLevelLimits(dbMin, dbMax); |
|
66 |
|
67 const int bandCount = e->NumberOfBands(); |
|
68 |
|
69 for (int i = 0; i < bandCount; ++i) { |
|
70 const qint32 hz = e->CenterFrequency(i); |
|
71 |
|
72 const qint32 defVol = e->BandLevel(i); |
|
73 |
|
74 retval.append(EffectParameter(i, |
|
75 tr("Frequency band, %1 Hz").arg(hz), |
|
76 EffectParameter::LogarithmicHint, |
|
77 QVariant(qint32(defVol)), |
|
78 QVariant(qint32(dbMin)), |
|
79 QVariant(qint32(dbMax)), |
|
80 QVariantList(), |
|
81 QString())); |
|
82 } |
|
83 |
|
84 return retval; |
|
85 } |
|
86 |
|
87 QT_END_NAMESPACE |