-
Notifications
You must be signed in to change notification settings - Fork 29
Reverb wrapping bugfix #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
djtuBIG-MaliceX
wants to merge
3
commits into
oxesoft:master
Choose a base branch
from
djtuBIG-MaliceX:bugfix/reverbwrapping
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,5 +160,5 @@ enum | |
| #endif | ||
|
|
||
| #ifdef _WIN32 | ||
| #define snprintf _snprintf | ||
| //#define snprintf _snprintf | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |
|
|
||
| #include "constants.h" | ||
| #include "reverb.h" | ||
| #include <math.h> | ||
| #include <string.h> | ||
| #include <cmath> | ||
| #include <cstring> | ||
| #include <climits> | ||
|
|
||
| void CReverb::Init() | ||
| { | ||
|
|
@@ -48,7 +49,7 @@ void CReverb::Init() | |
| b1 = 0; | ||
| } | ||
|
|
||
| void CReverb::SetPar(char param, float value) | ||
| void CReverb::SetPar(char param, double value) | ||
| { | ||
| switch (param) | ||
| { | ||
|
|
@@ -64,20 +65,21 @@ void CReverb::SetPar(char param, float value) | |
| } | ||
| } | ||
|
|
||
| void CReverb::CalcCoefLowPass(float frequencia) | ||
| void CReverb::CalcCoefLowPass(double frequencia) | ||
| { | ||
| float w = 2.0f * sr; | ||
| float fCut = 2.0f * PI * Key2Frequency(frequencia * MAXFREQFLT); | ||
| float Norm = 1.0f / (fCut + w); | ||
| double w = 2.0f * sr; | ||
| double fCut = 2.0f * PI * Key2Frequency(frequencia * MAXFREQFLT); | ||
| double Norm = 1.0f / (fCut + w); | ||
| b1 = lrintf((w - fCut) * Norm * 32768.f); | ||
| a0 = a1 = lrintf( fCut * Norm * 32768.f); | ||
| } | ||
|
|
||
| void CReverb::Process(int *b, int size) | ||
| { | ||
| int i = 0; | ||
| int ent = 0; | ||
| int aux = 0; | ||
| int i = 0; | ||
| long ent = 0; | ||
| long aux = 0; | ||
| long smp = 0; | ||
| int retorno = (int)(ti * 127.f); | ||
| if (REVDAant != da) | ||
| { | ||
|
|
@@ -87,46 +89,53 @@ void CReverb::Process(int *b, int size) | |
| for (i=0;i<size;i++) | ||
| { | ||
| ent = b[i]; | ||
| b[i] = 0; | ||
| smp = 0; | ||
| // comb 1 | ||
| b[i] += bcomb1[icomb1]; | ||
| smp += bcomb1[icomb1]; | ||
| bcomb1[icomb1] = ent + ((bcomb1[icomb1] * retorno)/128); | ||
| if (++icomb1>=TAMCOMB1) icomb1 = 0; | ||
| // comb 2 | ||
| b[i] += bcomb2[icomb2]; | ||
| smp += bcomb2[icomb2]; | ||
| bcomb2[icomb2] = ent + ((bcomb2[icomb2] * retorno)/128); | ||
| if (++icomb2>=TAMCOMB2) icomb2 = 0; | ||
| // comb 3 | ||
| b[i] += bcomb3[icomb3]; | ||
| smp += bcomb3[icomb3]; | ||
| bcomb3[icomb3] = ent + ((bcomb3[icomb3] * retorno)/128); | ||
| if (++icomb3>=TAMCOMB3) icomb3 = 0; | ||
| // comb 4 | ||
| b[i] += bcomb4[icomb4]; | ||
| smp += bcomb4[icomb4]; | ||
| bcomb4[icomb4] = ent + ((bcomb4[icomb4] * retorno)/128); | ||
| if (++icomb4>=TAMCOMB4) icomb4 = 0; | ||
| // allpass 1 | ||
| aux = ballp1[iallp1]; | ||
| ballp1[iallp1] = ((aux * retorno)/128) + b[i]; | ||
| b[i] = aux - ((ballp1[iallp1] * retorno)/128); | ||
| ballp1[iallp1] = ((aux * retorno)/128) + smp; | ||
| smp = aux - ((ballp1[iallp1] * retorno)/128); | ||
| if (++iallp1>=TAMALLP1) iallp1 = 0; | ||
| // allpass 2 | ||
| aux = ballp2[iallp2]; | ||
| ballp2[iallp2] = ((aux * retorno)/128) + b[i]; | ||
| ballp2[iallp2] = ((aux * retorno)/128) + smp; | ||
| b[i] = aux - ((ballp2[iallp2] * retorno)/128); | ||
| if (++iallp2>=TAMALLP2) iallp2 = 0; | ||
| // DC filter | ||
| ou0 = b[i] - in1 + ((ou0*32674)/32768); | ||
| in1 = b[i]; | ||
| b[i] = ou0>>2; | ||
| ou0 = smp - in1 + (((double)ou0*32674)/32768); | ||
| in1 = smp; | ||
| smp = ou0>>2; | ||
|
|
||
| b[i] = (smp > INT_MAX) ? INT_MAX : | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking more work might be needed to prevent double-clipping. |
||
| (smp < INT_MIN) ? INT_MIN : | ||
| smp; | ||
| } | ||
| if (REVDAant < 1.f) | ||
| { | ||
| for (i=0;i<size;i++) | ||
| { | ||
| smp = b[i]; | ||
| // low pass filter | ||
| ou0l = ((b[i] * a0)/32768) + ((in1l * a1)/32768) + ((ou0l * b1)/32768); | ||
| in1l = b[i]; | ||
| b[i] = ou0l; | ||
| ou0l = ((smp * a0)/32768) + ((in1l * a1)/32768) + ((ou0l * b1)/32768); | ||
| in1l = smp; | ||
| b[i] = (ou0l > INT_MAX) ? INT_MAX : | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, this may contribute to double-clipping. |
||
| (ou0l < INT_MIN) ? INT_MIN : | ||
| ou0l; | ||
| } | ||
| } | ||
| state = ACTIVE; | ||
|
|
@@ -139,7 +148,7 @@ char CReverb::GetState() | |
| return state; | ||
| } | ||
|
|
||
| inline float CReverb::Key2Frequency(float valor) | ||
| inline double CReverb::Key2Frequency(double valor) | ||
| { | ||
| return C0 * powf(2.0f, valor / 12.0f); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to comment this out as it was failing to build under MSYS2 MinGW-w64. This seems like a dirty hack anyway that likely no longer applies with more recent versions of MinGW-w64 GCC compiler suite.