Skip to content
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

CSine<> Amplitude drift #44

Open
mhetrick opened this issue Jun 23, 2016 · 4 comments
Open

CSine<> Amplitude drift #44

mhetrick opened this issue Jun 23, 2016 · 4 comments

Comments

@mhetrick
Copy link
Contributor

We're having issues with CSine<> changing amplitude very slowly over time, even with decay = -1. We're experiencing audible amplitude drift after 30+ minutes.

@mhetrick
Copy link
Contributor Author

mhetrick commented Jun 24, 2016

As a workaround, it appears that the amplitude drift doesn't occur when using CSine double.

@LancePutnam
Copy link
Owner

Yes, for very long decays, double precision is required. For no decay, since single precision may be faster (it is on all my machines), another workaround may be to normalize 'val' every so often. Since I can't think of an automatic way to prevent drift that doesn't incur extra overhead (on each sample), I've added a note to the CSine comment section.

@mhetrick
Copy link
Contributor Author

mhetrick commented Jul 2, 2016

We have no decay on ours. It runs away after 30 minutes with single precision. It turns out that double precision didn't fix it either, as it runs away after a longer period of time (even with no decay).

We'll look into automatic normalization and see if we can fix it that way without too much overhead.

@mhetrick
Copy link
Contributor Author

mhetrick commented Jul 5, 2016

Automatic normalization has fixed it for us.

However, new bug: Higher frequencies cause the sine wave to decay instead of increase in amplitude (even with decay = -1). I believe this is occurring with frequencies > (Nyquist/2.0).

Try the following:

`
#include "../AudioApp.h"
#include "Gamma/Delay.h"
#include "Gamma/Filter.h"
#include "Gamma/Oscillator.h"
using namespace gam;

typedef gam::Complex complex;

int main()
{

int counter = 0;
complex val;
CSine<float> cSine;
gam::Domain::master().spu(44100);
cSine.freq(14000);

printf("Ten Samples at init\n");

for (int i = 0; i < 10; ++i)
{
    val = cSine();
    printf("value: %f %f\n", val.real(), val.imag());
}

for (int i = 0; i < 900000000; ++i)
{
    cSine();
}

printf("Ten Samples after 900000000\n");

for (int i = 0; i < 10; ++i)
{
    val = cSine();
    printf("value: %f %f\n", val.real(), val.imag());
}

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants