|
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 <QObject> |
|
20 #include <QCoreApplication> |
|
21 |
|
22 #include <AudioEqualizerBase.h> |
|
23 #include <BassBoostBase.h> |
|
24 #include <DistanceAttenuationBase.h> |
|
25 #include <DopplerBase.h> |
|
26 #include <EnvironmentalReverbBase.h> |
|
27 #include <ListenerOrientationBase.h> |
|
28 #include <LocationBase.h> |
|
29 #include <LoudnessBase.h> |
|
30 #include <SourceOrientationBase.h> |
|
31 #include <StereoWideningBase.h> |
|
32 |
|
33 #include "audioequalizer.h" |
|
34 #include "bassboost.h" |
|
35 |
|
36 #include "effectfactory.h" |
|
37 |
|
38 QT_BEGIN_NAMESPACE |
|
39 |
|
40 using namespace Phonon; |
|
41 using namespace Phonon::MMF; |
|
42 |
|
43 /*! \class MMF::EffectFactory |
|
44 \internal |
|
45 */ |
|
46 |
|
47 QHash<QByteArray, QVariant> EffectFactory::constructEffectDescription(const QString &name, |
|
48 const QString &description) |
|
49 { |
|
50 QHash<QByteArray, QVariant> retval; |
|
51 |
|
52 retval.insert("name", name); |
|
53 retval.insert("description", description); |
|
54 retval.insert("available", true); |
|
55 |
|
56 return retval; |
|
57 } |
|
58 |
|
59 |
|
60 QHash<QByteArray, QVariant> EffectFactory::audioEffectDescriptions(AbstractAudioEffect::Type type) |
|
61 { |
|
62 switch (type) |
|
63 { |
|
64 case AbstractAudioEffect::EffectAudioEqualizer: |
|
65 return constructEffectDescription(QCoreApplication::translate("Phonon::MMF::EffectFactory", "audio equalizer"), "Audio equalizer."); |
|
66 case AbstractAudioEffect::EffectBassBoost: |
|
67 return constructEffectDescription(QCoreApplication::translate("Phonon::MMF::EffectFactory", "Bass boost"), "Bass boost."); |
|
68 case AbstractAudioEffect::EffectDistanceAttenuation: |
|
69 return constructEffectDescription(QCoreApplication::translate("Phonon::MMF::EffectFactory", "Distance Attenuation"), "Distance Attenuation."); |
|
70 case AbstractAudioEffect::EffectEnvironmentalReverb: |
|
71 return constructEffectDescription(QCoreApplication::translate("Phonon::MMF::EffectFactory", "Environmental Reverb"), "Environmental Reverb."); |
|
72 case AbstractAudioEffect::EffectListenerOrientation: |
|
73 return constructEffectDescription(QCoreApplication::translate("Phonon::MMF::EffectFactory", "Environmental Reverb"), "Environmental Reverb."); |
|
74 case AbstractAudioEffect::EffectLoudness: |
|
75 return constructEffectDescription(QCoreApplication::translate("Phonon::MMF::EffectFactory", "Loudness"), "Loudness."); |
|
76 case AbstractAudioEffect::EffectSourceOrientation: |
|
77 return constructEffectDescription(QCoreApplication::translate("Phonon::MMF::EffectFactory", "Source Orientation"), "Source Orientation."); |
|
78 case AbstractAudioEffect::EffectStereoWidening: |
|
79 return constructEffectDescription(QCoreApplication::translate("Phonon::MMF::EffectFactory", "Stereo Widening"), "Stereo Widening."); |
|
80 } |
|
81 |
|
82 Q_ASSERT_X(false, Q_FUNC_INFO, "Unknown effect type."); |
|
83 return QHash<QByteArray, QVariant>(); |
|
84 } |
|
85 |
|
86 AbstractAudioEffect *EffectFactory::createAudioEffect(AbstractAudioEffect::Type type, |
|
87 QObject *parent) |
|
88 { |
|
89 Q_ASSERT(parent); |
|
90 |
|
91 switch (type) |
|
92 { |
|
93 case AbstractAudioEffect::EffectBassBoost: |
|
94 return new BassBoost(parent); |
|
95 case AbstractAudioEffect::EffectAudioEqualizer: |
|
96 return new AudioEqualizer(parent); |
|
97 case AbstractAudioEffect::EffectDistanceAttenuation: |
|
98 case AbstractAudioEffect::EffectEnvironmentalReverb: |
|
99 case AbstractAudioEffect::EffectListenerOrientation: |
|
100 case AbstractAudioEffect::EffectLoudness: |
|
101 case AbstractAudioEffect::EffectSourceOrientation: |
|
102 case AbstractAudioEffect::EffectStereoWidening: |
|
103 ; |
|
104 } |
|
105 |
|
106 Q_ASSERT_X(false, Q_FUNC_INFO, "Unknown effect."); |
|
107 return 0; |
|
108 } |
|
109 |
|
110 template<typename TEffect> |
|
111 bool isEffectSupported() |
|
112 { |
|
113 AudioPlayer audioPlayer; |
|
114 |
|
115 QScopedPointer<TEffect> eff; |
|
116 TRAPD(errorCode, eff.reset(TEffect::NewL(*audioPlayer.player()))); |
|
117 |
|
118 return errorCode != KErrNone; |
|
119 } |
|
120 |
|
121 QList<int> EffectFactory::effectIndexes() |
|
122 { |
|
123 QList<int> retval; |
|
124 |
|
125 if (isEffectSupported<CAudioEqualizer>()) |
|
126 retval.append(AbstractAudioEffect::EffectAudioEqualizer); |
|
127 |
|
128 if (isEffectSupported<CBassBoost>()) |
|
129 retval.append(AbstractAudioEffect::EffectBassBoost); |
|
130 |
|
131 /* We haven't implemented these yet. |
|
132 if (isEffectSupported<CDistanceAttenuation>()) |
|
133 retval.append(AbstractAudioEffect::EffectDistanceAttenuation); |
|
134 |
|
135 if (isEffectSupported<CEnvironmentalReverb>()) |
|
136 retval.append(AbstractAudioEffect::EffectEnvironmentalReverb); |
|
137 |
|
138 if (isEffectSupported<CLoudness>()) |
|
139 retval.append(AbstractAudioEffect::EffectLoudness); |
|
140 |
|
141 if (isEffectSupported<CListenerOrientation>()) |
|
142 retval.append(AbstractAudioEffect::EffectListenerOrientation); |
|
143 |
|
144 if (isEffectSupported<CSourceOrientation>()) |
|
145 retval.append(AbstractAudioEffect::EffectSourceOrientation); |
|
146 |
|
147 if (isEffectSupported<CStereoWidening>()) |
|
148 retval.append(AbstractAudioEffect::EffectStereoWidening); |
|
149 */ |
|
150 |
|
151 return retval; |
|
152 } |
|
153 |
|
154 QT_END_NAMESPACE |
|
155 |