-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStereoSpread.cpp
More file actions
60 lines (47 loc) · 1.29 KB
/
StereoSpread.cpp
File metadata and controls
60 lines (47 loc) · 1.29 KB
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
//
// Created by Ragnar Hrafnkelsson on 01/11/2015.
// Copyright © 2015 Reactify. All rights reserved.
//
#include "StereoSpread.h"
StereoSpread::StereoSpread() : width(1.f)
{
printf("StereoSpread Loaded \n");
}
StereoSpread::~StereoSpread()
{
}
void StereoSpread::setWidth(float w)
{
if (w < 0.f) w = 0.f; if (w > 1.f) w = 1.f;
width = w;
printf("Set Width: %f \n", width);
}
// http://musicdsp.org/showArchiveComment.php?ArchiveID=256
void StereoSpread::process(float **inBuffers, float **outBuffers, const int bufferSize)
{
// calculate scale coefficient
float coef_S = width * 0.5f;
float* inLeft = inBuffers[0];
float* inRight = inBuffers[1];
float* outLeft = outBuffers[0];
float* outRight = outBuffers[1];
for (int i = 0; i < bufferSize; i++)
{
float m = (inLeft[i] + inRight[i]) * 0.5f;
float s = (inRight[i] - inLeft[i]) * coef_S;
outLeft[i] = m - s;
outRight[i] = m + s;
}
}
void StereoSpread::process_inline(float *inBuffer, float *outBuffer, const int bufferSize)
{
// calculate scale coefficient
float coef_S = width * 0.5f;
for (int i = 0; i < bufferSize * 2; i++)
{
float m = (inBuffer[i] + inBuffer[i + bufferSize]) * 0.5f;
float s = (inBuffer[i + bufferSize] - inBuffer[i]) * coef_S;
outBuffer[i] = m - s;
outBuffer[i + bufferSize] = m + s;
}
}