summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/phonon/mmf/environmentalreverb.cpp
blob: 4a6ce2947e1d91b836f6c9ab54ff5a21db0f65f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*  This file is part of the KDE project.

Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).

This library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 or 3 of the License.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this library.  If not, see <http://www.gnu.org/licenses/>.

*/

#include <EnvironmentalReverbBase.h>
#include "environmentalreverb.h"

QT_BEGIN_NAMESPACE

using namespace Phonon;
using namespace Phonon::MMF;

/*! \class MMF::EnvironmentalReverb
  \internal
*/

// Define functions which depend on concrete native effect class name
PHONON_MMF_DEFINE_EFFECT_FUNCTIONS(EnvironmentalReverb)

enum Parameters
{
    DecayHFRatio = AbstractAudioEffect::ParameterBase,
    DecayTime,
    Density,
    Diffusion,
    ReflectionsDelay,
    ReflectionsLevel,
    ReverbDelay,
    ReverbLevel,
    RoomHFLevel,
    RoomLevel
};

EnvironmentalReverb::EnvironmentalReverb(QObject *parent, const QList<EffectParameter>& parameters)
    :   AbstractAudioEffect::AbstractAudioEffect(parent, parameters)
{

}

int EnvironmentalReverb::effectParameterChanged(const EffectParameter &param,
                                      const QVariant &value)
{
    const qreal externalLevel = value.toReal();
    const int internalLevel = param.toInternalValue(externalLevel);

    TInt err = 0;

    switch(param.id()) {
    case DecayHFRatio:
        TRAP(err, concreteEffect()->SetDecayHFRatioL(internalLevel));
        break;
    case DecayTime:
        TRAP(err, concreteEffect()->SetDecayTimeL(internalLevel));
        break;
    case Density:
        TRAP(err, concreteEffect()->SetDensityL(internalLevel));
        break;
    case Diffusion:
        TRAP(err, concreteEffect()->SetDiffusionL(internalLevel));
        break;
    case ReflectionsDelay:
        TRAP(err, concreteEffect()->SetReflectionsDelayL(internalLevel));
        break;
    case ReflectionsLevel:
        TRAP(err, concreteEffect()->SetReflectionsLevelL(internalLevel));
        break;
    case ReverbDelay:
        TRAP(err, concreteEffect()->SetReverbDelayL(internalLevel));
        break;
    case ReverbLevel:
        TRAP(err, concreteEffect()->SetReverbLevelL(internalLevel));
        break;
    case RoomHFLevel:
        TRAP(err, concreteEffect()->SetRoomHFLevelL(internalLevel));
        break;
    case RoomLevel:
        TRAP(err, concreteEffect()->SetRoomLevelL(internalLevel));
        break;
    default:
        Q_ASSERT_X(false, Q_FUNC_INFO, "Unknown parameter");
    }

    return err;
}


//-----------------------------------------------------------------------------
// Static functions
//-----------------------------------------------------------------------------

const char* EnvironmentalReverb::description()
{
    return "Reverb";
}

// Internal helper function
Phonon::MMF::EffectParameter createParameter(int id, const QString &name,
    int defaultValue, int minValue, int maxValue,
    Phonon::EffectParameter::Hint hint = Phonon::EffectParameter::IntegerHint)
{
    const qreal externalDefaultValue =
        Phonon::MMF::EffectParameter::toExternalValue
            (defaultValue, minValue, maxValue);

    Phonon::MMF::EffectParameter param(id, name, hint,
        /* defaultValue */       QVariant(externalDefaultValue),
        /* minimumValue */       QVariant(qreal(-1.0)),
        /* maximumValue */       QVariant(qreal(+1.0)));

    param.setInternalRange(minValue, maxValue);
    return param;
}

bool EnvironmentalReverb::getParameters(CMdaAudioOutputStream *stream,
    QList<EffectParameter>& parameters)
{
    bool supported = false;

    QScopedPointer<CEnvironmentalReverb> effect;
    TRAPD(err, effect.reset(CEnvironmentalReverb::NewL(*stream)));

    if (KErrNone == err) {
        supported = true;

        TInt32 min, max;
        TUint32 umin, umax;

        // DecayHFRatio
	// Ratio of high-frequency decay time to the value specified by
	// DecayTime.
        effect->DecayHFRatioRange(umin, umax);
        parameters.append(createParameter(
            DecayHFRatio, tr("Decay HF ratio (%)"), effect->DecayHFRatio(),
            umin, umax));

        // DecayTime
	// Time over which reverberation is diminished.
        effect->DecayTimeRange(umin, umax);
        parameters.append(createParameter(
            DecayTime, tr("Decay time (ms)"), effect->DecayTime(),
            umin, umax));

        // Density
	// Delay between first and subsequent reflections.
	// Note that the S60 platform documentation does not make clear
	// the distinction between this value and the Diffusion value.
        parameters.append(createParameter(
            Density, tr("Density (%)"), effect->Density(), 0, 100));

        // Diffusion
	// Delay between first and subsequent reflections.
	// Note that the S60 platform documentation does not make clear
	// the distinction between this value and the Density value.
        parameters.append(createParameter(
            Diffusion, tr("Diffusion (%)"), effect->Diffusion(), 0, 100));

        // ReflectionsDelay
	// Amount of delay between the arrival the direct path from the
	// source and the arrival of the first reflection.
        parameters.append(createParameter(
            ReflectionsDelay, tr("Reflections delay (ms)"),
            effect->ReflectionsDelay(), 0, effect->ReflectionsDelayMax()));

        // ReflectionsLevel
	// Amplitude of reflections.  This value is corrected by the RoomLevel
        // to give the final reflection amplitude.
	effect->ReflectionLevelRange(min, max);
        parameters.append(createParameter(
            ReflectionsLevel, tr("Reflections level (mB)"),
            effect->ReflectionsLevel(),
            min, max, EffectParameter::LogarithmicHint));

        // ReverbDelay
	// Amount of time between arrival of the first reflection and start of
	// the late reverberation.
        parameters.append(createParameter(
            ReverbDelay, tr("Reverb delay (ms)"), effect->ReverbDelay(),
            0, effect->ReverbDelayMax()));

        // ReverbLevel
	// Amplitude of reverberations.  This value is corrected by the
	// RoomLevel to give the final reverberation amplitude.
        effect->ReverbLevelRange(min, max);
        parameters.append(createParameter(
            ReverbLevel, tr("Reverb level (mB)"), effect->ReverbLevel(),
            min, max, EffectParameter::LogarithmicHint));

        // RoomHFLevel
	// Amplitude of low-pass filter used to attenuate the high frequency
	// component of reflected sound.
        effect->RoomHFLevelRange(min, max);
        parameters.append(createParameter(
            RoomHFLevel, tr("Room HF level"), effect->RoomHFLevel(),
            min, max));

        // RoomLevel
	// Master volume control for all reflected sound.
        effect->RoomLevelRange(min, max);
        parameters.append(createParameter(
            RoomLevel, tr("Room level (mB)"), effect->RoomLevel(),
            min, max, EffectParameter::LogarithmicHint));
    }

    return supported;
}

QT_END_NAMESPACE