Skip to content

Commit

Permalink
enhancing documentation and readability of AudioEffectsStereoEnhance
Browse files Browse the repository at this point in the history
  • Loading branch information
betalars committed Oct 23, 2024
1 parent ee434ad commit daec66d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
8 changes: 5 additions & 3 deletions doc/classes/AudioEffectStereoEnhance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
</tutorials>
<members>
<member name="pan_pullout" type="float" setter="set_pan_pullout" getter="get_pan_pullout" default="1.0">
Values greater than 1.0 increase intensity of any panning on audio passing through this effect, whereas values less than 1.0 will decrease the panning intensity. A value of 0.0 will downmix audio to mono.
</member>
<member name="surround" type="float" setter="set_surround" getter="get_surround" default="0.0">
Amplifies the difference between stereo channels, increasing or descreasing existing panning. A value of 0.0 will downmix stereo to mono. Does not affect a mono signal.
</member>
<member name="time_pullout_ms" type="float" setter="set_time_pullout" getter="get_time_pullout" default="0.0">
Widens sound stage trough phase shifting in cunjuncion with [surround]. Just delays the right channel if [surround] is 0.
</member>
<member name="surround" type="float" setter="set_surround" getter="get_surround" default="0.0">
Widens sound stage trough phase shifting in cunjuncion with [time_pullout_ms]. Just pans sound to the left channel if [time_pullout_ms] is 0.
</member>
</members>
</class>
26 changes: 13 additions & 13 deletions servers/audio/effects/audio_effect_stereo_enhance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,34 @@ void AudioEffectStereoEnhanceInstance::process(const AudioFrame *p_src_frames, A
unsigned int delay_frames = (base->time_pullout / 1000.0) * AudioServer::get_singleton()->get_mix_rate();

for (int i = 0; i < p_frame_count; i++) {
float l = p_src_frames[i].left;
float r = p_src_frames[i].right;
float left = p_src_frames[i].left;
float right = p_src_frames[i].right;

float center = (l + r) / 2.0f;
float center = (left + right) / 2.0f;

l = (center + (l - center) * intensity);
r = (center + (r - center) * intensity);
left = (center + (left - center) * intensity);
right = (center + (right - center) * intensity);

if (surround_mode) {
float val = (l + r) / 2.0;
float val = (left + right) / 2.0;

delay_ringbuff[ringbuff_pos & ringbuff_mask] = val;

float out = delay_ringbuff[(ringbuff_pos - delay_frames) & ringbuff_mask] * surround_amount;

l += out;
r += -out;
left += out;
right += -out;
} else {
float val = r;
float val = right;

delay_ringbuff[ringbuff_pos & ringbuff_mask] = val;

//r is delayed
r = delay_ringbuff[(ringbuff_pos - delay_frames) & ringbuff_mask];
//right channel is delayed
right = delay_ringbuff[(ringbuff_pos - delay_frames) & ringbuff_mask];
}

p_dst_frames[i].left = l;
p_dst_frames[i].right = r;
p_dst_frames[i].left = left;
p_dst_frames[i].right = right;
ringbuff_pos++;
}
}
Expand Down

0 comments on commit daec66d

Please sign in to comment.