Skip to content

Commit ab68ec9

Browse files
committed
Alias: Self test with naive saw 1.
1 parent 4467d42 commit ab68ec9

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/Alias.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct Alias : Module {
162162
for (int i = 0; i < 3; i++) {
163163
const float target = targetFrequencies[i];
164164
const float targetLogP = std::log(target / startFreq) / std::log(endFreq / startFreq);
165-
const int targetStep = std::round(targetLogP * (STEPS - 1));
165+
const int targetStep = int(std::round(targetLogP * (STEPS - 1)));
166166

167167
if (step == targetStep) {
168168
idealFreq = target;
@@ -232,7 +232,7 @@ struct Alias : Module {
232232
bool crossedZero = false;
233233
if (sweepPhase >= 1.0f) {
234234
sweepPhase -= 1.0f;
235-
crossedZero = true; // The wave wrapped perfectly around 0!
235+
crossedZero = true; // The wave wrapped around 0
236236
}
237237

238238
// state
@@ -252,9 +252,16 @@ struct Alias : Module {
252252
} else if (currentState == RECORD) {
253253
// Record the stable signal
254254
audioBuffer[bufferIndex] = inputs[RETURN_INPUT].getVoltage() * 0.2f;
255+
256+
constexpr bool NAIVETEST = true;
257+
if (mode && NAIVETEST) {
258+
// make a naive saw for testing large amount of aliasing
259+
audioBuffer[bufferIndex] = (sweepPhase*2.0f)-1.0f;
260+
}
261+
255262
bufferIndex++;
256263

257-
// When buffer is full, do the math!
264+
// When buffer is full, do the fft
258265
if (bufferIndex >= FFT_SIZE) {
259266
// remove DC offset, this must be done before FFT
260267

@@ -359,7 +366,7 @@ struct Alias : Module {
359366
for (int i = 0; i < 3; i++) {
360367
const float target = targetFrequencies[i];
361368
const float targetLogP = std::log(target / startFreq) / std::log(END_HZ / startFreq);
362-
const int targetStep = std::round(targetLogP * (STEPS - 1));
369+
const int targetStep = int(std::round(targetLogP * (STEPS - 1)));
363370

364371
if (currentStep >= targetStep - 1 && currentStep <= targetStep + 1) {
365372
// If this is the first time entering the window, or if we found a worse dB

0 commit comments

Comments
 (0)