File: stereo.cc

package info (click to toggle)
ste-plugins 0.0.2-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 168 kB
  • sloc: cpp: 578; makefile: 35
file content (145 lines) | stat: -rw-r--r-- 3,333 bytes parent folder | download | duplicates (3)
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
// -----------------------------------------------------------------------
//
//  Copyright (C) 2010-2014 Fons Adriaensen <fons@linuxaudio.org>
//    
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program 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 General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// -----------------------------------------------------------------------


#include <stdio.h>
#include <math.h>
#include "stereo.h"



void Ladspa_Stwidth::setport (unsigned long port, LADSPA_Data *data)
{
    _port [port] = data;
}


void Ladspa_Stwidth::active (bool act)
{
}


void Ladspa_Stwidth::runproc (unsigned long frames, bool add)
{
    float *inpL = _port [A_INPL];
    float *inpR = _port [A_INPR];
    float *outL = _port [A_OUTL];
    float *outR = _port [A_OUTR];
    float b = _port [C_IPBAL][0];
    float w = _port [C_WIDTH][0];
    float gL, gR, dL, dR, dw, xL, xR, s, d;

    gR = powf (10.0f, 0.05f * b);
    gL = 1.0f / gR;
    dL = (gL - _gL) / frames;
    dR = (gR - _gR) / frames;
    if (fabsf (dL) < 1e-6f) dL = 0;
    if (fabsf (dR) < 1e-6f) dR = 0;
    gL = _gL;
    gR = _gR;

    dw = (w - _w) / frames;
    if (fabsf (dw) < 1e-6f) dw = 0;
    w = _w;

    while (frames--)
    {
	gR += dR;
	gL += dL;
	w  += dw;
	xL = *inpL++ * gL;
	xR = *inpR++ * gR;
	s = xL + xR;
	d = xL - xR;
	*outL++ = 0.5f * (s + w * d);
	*outR++ = 0.5f * (s - w * d);
    }
    
    _gL = gL;
    _gR = gR;
    _w = w;
}



void Ladspa_Stpanner::setport (unsigned long port, LADSPA_Data *data)
{
    _port [port] = data;
}


void Ladspa_Stpanner::active (bool act)
{
}


void Ladspa_Stpanner::runproc (unsigned long frames, bool add)
{
    float *inpL = _port [A_INPL];
    float *inpR = _port [A_INPR];
    float *outL = _port [A_OUTL];
    float *outR = _port [A_OUTR];
    float b = _port [C_IPBAL][0];
    float lp = _port [C_LPAN][0];
    float rp = _port [C_RPAN][0];

    float gLL, gLR, gRL, gRR;
    float dLL, dLR, dRL, dRR;
    float xL, xR;

    xL = (1 - b) * (5 + b) / 40;
    xR = (1 + b) * (5 - b) / 40;
    gLL = xL * (1 - lp) * (5 + lp);
    gLR = xL * (1 + lp) * (5 - lp);
    gRL = xR * (1 - rp) * (5 + rp);
    gRR = xR * (1 + rp) * (5 - rp);

    dLL = (gLL - _gLL) / frames;
    if (fabsf (dLL) < 1e-6f) dLL = 0;
    dLR = (gLR - _gLR) / frames;
    if (fabsf (dLR) < 1e-6f) dLR = 0;
    dRL = (gRL - _gRL) / frames;
    if (fabsf (dRL) < 1e-6f) dRL = 0;
    dRR = (gRR - _gRR) / frames;
    if (fabsf (dRR) < 1e-6f) dRR = 0;

    gLL = _gLL;
    gLR = _gLR;
    gRL = _gRL;
    gRR = _gRR;
    while (frames--)
    {
	gLL += dLL;
	gLR += dLR;
	gRL += dRL;
	gRR += dRR;
	xL = *inpL++;
	xR = *inpR++;
	*outL++ = gLL * xL + gRL * xR;
	*outR++ = gLR * xL + gRR * xR;
    }
    _gLL = gLL;
    _gLR = gLR;
    _gRL = gRL;
    _gRR = gRR;
}