FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
RSAlgorithmicVerb/Source/EarlyReflections.cpp at main · reillypascal/RSAlgorithmicVerb · GitHub
reillypascal
/
RSAlgorithmicVerb
Public
Notifications
You must be signed in to change notification settings
Fork
7
Star
73
Code
Issues
4
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
RSAlgorithmicVerb
/
Source
/
EarlyReflections.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
163 lines (131 loc) · 5.75 KB
Breadcrumbs
RSAlgorithmicVerb
/
Source
/
EarlyReflections.cpp
Copy path
File metadata and controls
163 lines (131 loc) · 5.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
FIR-based early reflections with 6 taps and HRTF for binaural stereo. Based on Dattorro
#
include
"
EarlyReflections.h
"
EarlyReflections::EarlyReflections
() = default;
EarlyReflections::~EarlyReflections
() =
default
;
void
EarlyReflections::prepare
(
const
juce::dsp::ProcessSpec& spec)
{
juce::dsp::ProcessSpec monoSpec;
monoSpec.
sampleRate
= spec.
sampleRate
;
monoSpec.
maximumBlockSize
= spec.
maximumBlockSize
;
monoSpec.
numChannels
=
1
;
earlyReflectionsDelayLine.
prepare
(monoSpec);
//
leftHRTFDelay.prepare(monoSpec);
//
rightHRTFDelay.prepare(monoSpec);
//
leftHRTFFilter.prepare(monoSpec);
//
rightHRTFFilter.prepare(monoSpec);
hrtfDelays.
resize
(spec.
numChannels
);
hrtfFilters.
resize
(spec.
numChannels
);
channelOutputs.
resize
(spec.
numChannels
,
0.0
);
for
(
auto
& delay : hrtfDelays)
{
delay.
prepare
(monoSpec);
delay.
setMaximumDelayInSamples
(
441
);
}
for
(
auto
& filter : hrtfFilters)
filter.
prepare
(monoSpec);
}
void
EarlyReflections::processBlock
(juce::AudioBuffer<
float
>& buffer, juce::MidiBuffer& midiMessages)
{
juce::ScopedNoDenormals noDenormals;
int
numSamples = buffer.
getNumSamples
();
int
numChannels = buffer.
getNumChannels
();
juce::AudioBuffer<
float
>
monoBuffer
(
1
, numSamples);
monoBuffer.
clear
();
monoBuffer.
copyFrom
(
0
,
0
, buffer,
0
,
0
, numSamples);
if
(numChannels >
1
)
{
monoBuffer.
addFrom
(
0
,
0
, buffer,
1
,
0
, numSamples);
monoBuffer.
applyGain
(
0
.
5f
);
}
//
leftHRTFDelay.setDelay(35);
//
rightHRTFDelay.setDelay(35);
for
(
auto
& delay : hrtfDelays)
delay.
setDelay
(
35
);
auto
* channelData = monoBuffer.
getWritePointer
(
0
);
for
(
int
sample =
0
; sample < numSamples; ++sample)
{
earlyReflectionsDelayLine.
pushSample
(
0
, channelData[sample]);
for
(
int
channel =
0
; channel < numChannels; ++channel)
{
for
(
int
delTime =
0
; delTime < hrtfDelayTimes.
size
(); ++delTime)
{
//
sum 3 left/ 3 right taps (interleaved w/ each other)
//
channel % 2 because could be many channels, but only 2 lists of delay times
channelOutputs[channel] = earlyReflectionsDelayLine.
getSampleAtDelay
(
0
, hrtfDelayTimes[channel %
2
][delTime] * parameters.
roomSize
) *
initialLevel *
pow
(parameters.
decayTime
, delTime);
}
}
for
(
int
channel =
0
; channel < numChannels; ++channel)
{
if
(!monoFlag)
{
//
right into left HRTF and vice versa
hrtfDelays[channel].
pushSample
(
0
, channelOutputs[(channel +
1
) % numChannels]);
//
filter HRTFs and add to outputs
channelOutputs[channel] += hrtfFilters[channel].
processSample
(
0
, hrtfDelays[channel].
popSample
(
0
));
}
//
outputs into original stereo buffer
buffer.
setSample
(
0
, sample, channelOutputs[channel]);
}
}
//
for (int sample = 0; sample < numSamples; ++sample)
//
{
//
earlyReflectionsDelayLine.pushSample(0, channelData[sample]);
//
// sum left 3 taps
//
channel0Output = earlyReflectionsDelayLine.getSampleAtDelay(0, 441 * parameters.roomSize) * initialLevel;
//
channel0Output += earlyReflectionsDelayLine.getSampleAtDelay(0, 2929 * parameters.roomSize) * initialLevel *
//
parameters.decayTime; channel0Output += earlyReflectionsDelayLine.getSampleAtDelay(0, 6319 *
//
parameters.roomSize) * initialLevel * pow(parameters.decayTime, 2);
//
// sum right 3 taps (interleaved w/ left)
//
channel1Output = earlyReflectionsDelayLine.getSampleAtDelay(0, 1191 * parameters.roomSize) * initialLevel;
//
channel1Output += earlyReflectionsDelayLine.getSampleAtDelay(0, 3948 * parameters.roomSize) * initialLevel *
//
parameters.decayTime; channel1Output += earlyReflectionsDelayLine.getSampleAtDelay(0, 9462 *
//
parameters.roomSize) * initialLevel * pow(parameters.decayTime, 2);
//
if (!monoFlag)
//
{
//
// right into left HRTF and vice versa
//
leftHRTFDelay.pushSample(0, channel1Output);
//
rightHRTFDelay.pushSample(0, channel0Output);
//
// filter HRTFs and add to outputs
//
channel0Output += leftHRTFFilter.processSample(0, leftHRTFDelay.popSample(0));
//
channel1Output += rightHRTFFilter.processSample(0, rightHRTFDelay.popSample(0));
//
}
//
// outputs into original stereo buffer
//
for (int destChannel = 0; destChannel < numChannels; ++destChannel)
//
{
//
if (destChannel == 0)
//
buffer.setSample(0, sample, channel0Output);
//
else if (destChannel == 1)
//
buffer.setSample(1, sample, channel1Output);
//
}
//
}
}
void
EarlyReflections::reset
()
{
earlyReflectionsDelayLine.
reset
();
for
(
auto
& delay : hrtfDelays)
delay.
reset
();
for
(
auto
& filter : hrtfFilters)
filter.
reset
();
//
leftHRTFDelay.reset();
//
rightHRTFDelay.reset();
//
leftHRTFFilter.reset();
//
rightHRTFFilter.reset();
}
ReverbProcessorParameters&
EarlyReflections::getParameters
()
{
return
parameters;
}
void
EarlyReflections::setParameters
(
const
ReverbProcessorParameters& params)
{
if
(!(params == parameters))
{
parameters = params;
parameters.
roomSize
=
scale
(parameters.
roomSize
,
0
.
0f
,
1
.
0f
,
0
.
25f
,
1
.
75f
);
}
}
void
EarlyReflections::setMonoFlag
(
const
bool
newMonoFlag)
{
monoFlag = newMonoFlag;
}
Back
|
FazBrowse Home
|
New Git URL