Skip to content

Commit

Permalink
Micro code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
olehxch committed Aug 18, 2016
1 parent 0f8ad75 commit bf1d0f4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Source/IWave.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class IWave
IWave() : level(0.0), frequency(0.0), phase(0.0), sampleRate(44100.0) {};
~IWave() {};

void setParams(double level, double freq, double phase) {
this->level = level;
this->frequency = freq;
this->phase = phase;
void setParams(double plevel, double pfreq, double pphase) {
this->level = plevel;
this->frequency = pfreq;
this->phase = pphase;
};

double nextSample(double t, int len) {
Expand Down
18 changes: 9 additions & 9 deletions Source/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ class MainContentComponent : public AudioAppComponent
monoBuffer = new float[samplesPerBlockExpected] {0};
}

void mixWaves(double t, float* monoBuffer, int numSamples) {
void mixWaves(float* pmonoBuffer, int numSamples) {
Random random;

// generate sin wave in mono
for (int sample = 0; sample < numSamples; ++sample) {
float sine = sineWaveOsc.nextSample(m_time, numSamples);
float square = squareWaveOsc.nextSample(m_time, numSamples);
float saw = sawWaveOsc.nextSample(m_time, numSamples);
float triangle = triangleWaveOsc.nextSample(m_time, numSamples);
double sine = sineWaveOsc.nextSample(m_time, numSamples);
double square = squareWaveOsc.nextSample(m_time, numSamples);
double saw = sawWaveOsc.nextSample(m_time, numSamples);
double triangle = triangleWaveOsc.nextSample(m_time, numSamples);

monoBuffer[sample] = sine + square + saw + triangle;
pmonoBuffer[sample] = sine + square + saw + triangle;
m_time += m_deltaTime;
}
}
Expand All @@ -94,7 +94,7 @@ class MainContentComponent : public AudioAppComponent
}

std::fill(monoBuffer, monoBuffer + bufferToFill.numSamples, 0);
mixWaves(m_time, monoBuffer, bufferToFill.numSamples);
mixWaves(monoBuffer, bufferToFill.numSamples);

// iterate over all available output channels
for (int channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel)
Expand Down Expand Up @@ -154,8 +154,8 @@ class MainContentComponent : public AudioAppComponent
SpectralViewComponent spectralView;

// Your private member variables go here...
float m_time;
float m_deltaTime;
double m_time;
double m_deltaTime;
float *monoBuffer;

bool m_isInitialized = false;
Expand Down
2 changes: 1 addition & 1 deletion Source/WaveformViewComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void WaveformViewComponent::fillBuffer(float *buffer, int len) {
lines.clear();

int pos = 0;
int scale = 100.0;
int scale = 200.0;
for (int i = 0; i < len - 1; i++) {
float cur = buffer[i] * scale;
float next = buffer[i + 1] * scale;
Expand Down

0 comments on commit bf1d0f4

Please sign in to comment.