mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-21 16:37:12 +01:00
Add triangle waveform to Tone Generator.
This commit is contained in:
committed by
Paul Licameli
parent
5126ea4105
commit
7d3d8fcf86
@@ -56,6 +56,7 @@ enum kWaveforms
|
|||||||
kSquare,
|
kSquare,
|
||||||
kSawtooth,
|
kSawtooth,
|
||||||
kSquareNoAlias,
|
kSquareNoAlias,
|
||||||
|
kTriangle,
|
||||||
nWaveforms
|
nWaveforms
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -64,7 +65,8 @@ static const EnumValueSymbol kWaveStrings[nWaveforms] =
|
|||||||
{ XO("Sine") },
|
{ XO("Sine") },
|
||||||
{ XO("Square") },
|
{ XO("Square") },
|
||||||
{ XO("Sawtooth") },
|
{ XO("Sawtooth") },
|
||||||
{ XO("Square, no alias") }
|
{ XO("Square, no alias") },
|
||||||
|
{ XO("Triangle") }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define keys, defaults, minimums, and maximums for the effect parameters
|
// Define keys, defaults, minimums, and maximums for the effect parameters
|
||||||
@@ -225,6 +227,16 @@ size_t EffectToneGen::ProcessBlock(float **WXUNUSED(inBlock), float **outBlock,
|
|||||||
case kSawtooth:
|
case kSawtooth:
|
||||||
f = (2.0 * modf(mPositionInCycles / mSampleRate + 0.5, &throwaway)) - 1.0;
|
f = (2.0 * modf(mPositionInCycles / mSampleRate + 0.5, &throwaway)) - 1.0;
|
||||||
break;
|
break;
|
||||||
|
case kTriangle:
|
||||||
|
f = modf(mPositionInCycles / mSampleRate, &throwaway);
|
||||||
|
if(f < 0.25) {
|
||||||
|
f *= 4.0;
|
||||||
|
} else if(f > 0.75) {
|
||||||
|
f = (f - 1.0) * 4.0;
|
||||||
|
} else { /* f >= 0.25 || f <= 0.75 */
|
||||||
|
f = (0.5 - f) * 4.0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case kSquareNoAlias: // Good down to 110Hz @ 44100Hz sampling.
|
case kSquareNoAlias: // Good down to 110Hz @ 44100Hz sampling.
|
||||||
//do fundamental (k=1) outside loop
|
//do fundamental (k=1) outside loop
|
||||||
b = (1.0 + cos((pre2PI * BlendedFrequency) / mSampleRate)) / pre4divPI; //scaling
|
b = (1.0 + cos((pre2PI * BlendedFrequency) / mSampleRate)) / pre4divPI; //scaling
|
||||||
|
|||||||
Reference in New Issue
Block a user