Alejandro Acuña
2024-08-12 1876e65234c20209001178705cfa50d8f9ded67a
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
// Limiter.cpp: implementation of the Limiter class.
//
//////////////////////////////////////////////////////////////////////
 
#include "AudioSample.h"
#include "AudioSampleManager.h"
#include "DSP/VolumeLimiter.h"
#include "Limiter.h"
 
using namespace std;
 
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
 
Limiter::Limiter(double threshold = -8.0, double lossIncrement = 0.075, double lossDecrement = -0.00075)
{
    char subFacilityName[100];
    sprintf(subFacilityName, "Limiter:%x", this);
    tracer.SetSubFacilityName(subFacilityName);
    SetTraceLevel();
    volumeLimiter = new VolumeLimiter(threshold, lossIncrement, lossDecrement);
}
 
Limiter::~Limiter()
{
    if (volumeLimiter)
    {
        delete volumeLimiter;
    }
}
 
int
Limiter::SetTraceLevel()
{
    long SystemMask = 0;
    if ((SystemMask = GetRegKeyLong(HKEY_CURRENT_USER, "Software\\Cisco Systems\\MTC\\Tracing", "AllComponents", 0x0)) == 0)
    {
        SystemMask = GetRegKeyLong(HKEY_CURRENT_USER, "Software\\Cisco Systems\\MTC\\Tracing", "Limiter", 0x100000);
    }
    tracer.SetSystemMask(SystemMask);
    return 0;
}
 
int
Limiter::SetParameters(double threshold, double lossIncrement, double lossDecrement)
{
    if (volumeLimiter)
    {
        delete volumeLimiter;
        volumeLimiter = NULL;
    }
    volumeLimiter = new VolumeLimiter(threshold, lossIncrement, lossDecrement);
    return 0;
}
 
int
Limiter::TransformAudioSamples(std::vector<std::pair<AudioSample *, AudioSource *> > &data, AudioSample **ppAudioSample)
{
    int result = 0;
    AudioSample *inSample = NULL;
    if (data.size() > 0)
    {
        inSample = data[0].first;
    }
 
    if (inSample)
    {
        inSample->AddRef(this);
        WAVEFORMATEX sampleFormat;
        inSample->GetFormat(&sampleFormat);
        int numSamples = (inSample->DataSize() * 8) / sampleFormat.wBitsPerSample;
        volumeLimiter->LimitVolume((short *)(inSample->Data()), numSamples);    
    }
    *ppAudioSample = inSample;
    return result;
}