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

Fixes to utilities.cpp and audio_buffer.cpp/h #216

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/audio_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AudioBuffer {
}
}

bool checkForDiscontinuitiy(int threshold) const;
bool checkForDiscontinuity(int threshold) const;

int m_writePointer;

Expand Down
6 changes: 4 additions & 2 deletions src/audio_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ void AudioBuffer::destroy() {
m_bufferSize = 0;
}

bool AudioBuffer::checkForDiscontinuitiy(int threshold) const {
for (int i = 0; i < m_bufferSize - 1; ++i) {
bool AudioBuffer::checkForDiscontinuity(int threshold) const {
int i = 0;
int m_bufferSizeMinusOne = m_bufferSize - 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be a minor optimization when debugging, but most modern compilers will do this optimization for us. I don't think there's a benefit unless the termination condition includes calling a function.

for (; i < m_bufferSizeMinusOne; ++i) {
const int i0 = getBufferIndex(i + m_writePointer);
const int i1 = getBufferIndex(i0 + 1);

Expand Down
14 changes: 2 additions & 12 deletions src/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@

#include <cmath>

double modularDistance(double a0, double b0, double mod) {
double a, b;
if (a0 < b0) {
a = a0;
b = b0;
}
else {
a = b0;
b = a0;
}

return std::fmin(b - a, a + mod - b);
double modularDistance(double a, double b, double mod) {
return (a < b) ? std::fmin(b - a, a + mod - b) : std::fmin(a - b, b + mod - a);
}

double positiveMod(double x, double mod) {
Expand Down