Skip to content

Commit 3b59e26

Browse files
author
Hannes Barfuss
committed
Control inputs for delay are now working.
1 parent 521330b commit 3b59e26

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

Assets/Scripts/Delay/delaySignalGenerator.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public enum Param : int
3333
private float[] p = new float[(int)Param.P_N];
3434
private bool shouldClear = false;
3535

36-
private float[] cTimeBuffer = new float[2] { 0, 0 };
37-
private float[] cFeedbackBuffer = new float[2] { 0, 0 };
36+
private float[] cTimeBuffer = new float[0];
37+
private float[] cFeedbackBuffer = new float[0];
3838
private float cTime;
3939
private float cFeedback;
4040

@@ -54,10 +54,10 @@ public void SetParam(float value, int param)
5454
switch(param)
5555
{
5656
case (int)Param.P_TIME:
57-
p[param] = Utils.map(Mathf.Pow(value, 3), 0, 1, MIN_TIME * AudioSettings.outputSampleRate, MAX_TIME * AudioSettings.outputSampleRate);
57+
p[param] = value; //this is finally set in process method
5858
break;
5959
case (int)Param.P_FEEDBACK:
60-
p[param] = Utils.map(value, 0, 1, MIN_FEEDBACK, MAX_FEEDBACK);
60+
p[param] = value; //this is finally set in process method
6161
break;
6262
case (int)Param.P_WET:
6363
p[param] = Utils.dbToLin( Utils.map(value, 0, 1, MIN_WET, MAX_WET, 0.8f) );
@@ -101,11 +101,6 @@ public override void processBuffer(float[] buffer, double dspTime, int channels)
101101
shouldClear = false;
102102
}
103103

104-
Delay_SetParam(p[(int)Param.P_TIME], (int)Param.P_TIME, x);
105-
Delay_SetParam(p[(int)Param.P_FEEDBACK], (int)Param.P_FEEDBACK, x);
106-
Delay_SetParam(p[(int)Param.P_WET], (int)Param.P_WET, x);
107-
Delay_SetParam(p[(int)Param.P_DRY], (int)Param.P_DRY, x);
108-
109104
if (input != null)
110105
{
111106
input.processBuffer(buffer, dspTime, channels);
@@ -125,6 +120,11 @@ public override void processBuffer(float[] buffer, double dspTime, int channels)
125120
cFeedback = cFeedbackBuffer[0];
126121
}
127122

123+
Delay_SetParam(Utils.map(Mathf.Pow(Mathf.Clamp01(p[(int)Param.P_TIME] + cTime), 3), 0, 1, MIN_TIME * AudioSettings.outputSampleRate, MAX_TIME * AudioSettings.outputSampleRate), (int)Param.P_TIME, x);
124+
Delay_SetParam(Utils.map(Mathf.Clamp01(p[(int)Param.P_FEEDBACK] + cFeedback), 0, 1, MIN_FEEDBACK, MAX_FEEDBACK), (int)Param.P_FEEDBACK, x);
125+
Delay_SetParam(p[(int)Param.P_WET], (int)Param.P_WET, x);
126+
Delay_SetParam(p[(int)Param.P_DRY], (int)Param.P_DRY, x);
127+
128128
//We need to process the delay even if there is currently no input,
129129
//bc there could be unconsumed samples from a previous input left in the delay line.
130130
//To optimize, we could store the timestamp when the last input connection was removed.
Binary file not shown.

SoundStageNative/Delay.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
#define DELAY_MAXVECTORSIZE 4096
99

10-
#define DELAY_MAXTIME 96000 //in samples
11-
#define DELAY_MINTIME 512 //in bucket brigade mode, shorter delay means more oversampling, so we have to set a reasonable limit.
12-
1310
enum DelayParams
1411
{
1512
P_TIME,
@@ -21,9 +18,9 @@ enum DelayParams
2118

2219
void Delay_ProcessPitchShift(float buffer[], int n, int channels, float cTime, float cFeedback, DelayData* x)
2320
{
24-
/* Prepare */
25-
int time = cTime != 0 ? (x->maxTime - x->time) * cTime : x->time;
26-
float feedback = cFeedback != 0 ? (1.0f - x->feedback) * cFeedback : x->feedback;
21+
// Prepare
22+
int time = x->time;
23+
float feedback = x->feedback;
2724

2825
assert(time > 0);
2926

@@ -33,7 +30,7 @@ void Delay_ProcessPitchShift(float buffer[], int n, int channels, float cTime, f
3330
if(channels > 1)
3431
_fDeinterleave(buffer, buffer, n, channels);
3532

36-
/* Process delay */
33+
// Process delay
3734
int m;
3835
int r = nPerChannel;
3936
float* bufOffset = buffer;
@@ -57,7 +54,7 @@ void Delay_ProcessPitchShift(float buffer[], int n, int channels, float cTime, f
5754
r -= m;
5855
}
5956

60-
/* Finalize */
57+
// Finalize
6158
if(channels > 1)
6259
{
6360
for(int i = 1; i < channels; i++)

SoundStageNative/Delay.h

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "main.h"
55
#include "RingBuffer.h"
6+
#include "CompressedRingBuffer.h"
67

78
struct DelayData
89
{

0 commit comments

Comments
 (0)