mirror of
https://github.com/cookiengineer/audacity
synced 2026-01-11 23:25:53 +01:00
bug 635:fix generate chirp for log square no alias. Patch by Steve Daulton.
This commit is contained in:
@@ -142,6 +142,8 @@ bool EffectToneGen::MakeTone(float *buffer, sampleCount len)
|
|||||||
double throwaway = 0; //passed to modf but never used
|
double throwaway = 0; //passed to modf but never used
|
||||||
sampleCount i;
|
sampleCount i;
|
||||||
double f = 0.0;
|
double f = 0.0;
|
||||||
|
double a,b;
|
||||||
|
int k;
|
||||||
|
|
||||||
double BlendedFrequency;
|
double BlendedFrequency;
|
||||||
double BlendedAmplitude;
|
double BlendedAmplitude;
|
||||||
@@ -187,8 +189,17 @@ bool EffectToneGen::MakeTone(float *buffer, sampleCount len)
|
|||||||
case 2: //sawtooth
|
case 2: //sawtooth
|
||||||
f = (2 * modf(mPositionInCycles/mCurRate+0.5f, &throwaway)) -1.0f;
|
f = (2 * modf(mPositionInCycles/mCurRate+0.5f, &throwaway)) -1.0f;
|
||||||
break;
|
break;
|
||||||
default:
|
case 3: //square, no alias. Good down to 110Hz @ 44100Hz sampling.
|
||||||
break;
|
//do fundamental (k=1) outside loop
|
||||||
|
b = (1. + cos((pre2PI * BlendedFrequency)/mCurRate))/pre4divPI; //scaling
|
||||||
|
f = (float) pre4divPI * sin(pre2PI * mPositionInCycles/mCurRate);
|
||||||
|
for(k=3; (k<200) && (k * BlendedFrequency < mCurRate/2.); k+=2)
|
||||||
|
{
|
||||||
|
//Hanning Window in freq domain
|
||||||
|
a = 1. + cos((pre2PI * k * BlendedFrequency)/mCurRate);
|
||||||
|
//calc harmonic, apply window, scale to amplitude of fundamental
|
||||||
|
f += (float) a * sin(pre2PI * mPositionInCycles/mCurRate * k)/(b*k);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// insert value in buffer
|
// insert value in buffer
|
||||||
buffer[i] = BlendedAmplitude * f;
|
buffer[i] = BlendedAmplitude * f;
|
||||||
@@ -201,8 +212,6 @@ bool EffectToneGen::MakeTone(float *buffer, sampleCount len)
|
|||||||
} else {
|
} else {
|
||||||
// this for regular case, linear interpolation
|
// this for regular case, linear interpolation
|
||||||
BlendedFrequency = frequency[0] + frequencyQuantum * mSample;
|
BlendedFrequency = frequency[0] + frequencyQuantum * mSample;
|
||||||
double a,b;
|
|
||||||
int k;
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
switch (waveform) {
|
switch (waveform) {
|
||||||
@@ -226,10 +235,6 @@ bool EffectToneGen::MakeTone(float *buffer, sampleCount len)
|
|||||||
//calc harmonic, apply window, scale to amplitude of fundamental
|
//calc harmonic, apply window, scale to amplitude of fundamental
|
||||||
f += (float) a * sin(pre2PI * mPositionInCycles/mCurRate * k)/(b*k);
|
f += (float) a * sin(pre2PI * mPositionInCycles/mCurRate * k)/(b*k);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
// insert value in buffer
|
// insert value in buffer
|
||||||
buffer[i] = BlendedAmplitude * f;
|
buffer[i] = BlendedAmplitude * f;
|
||||||
|
|||||||
Reference in New Issue
Block a user