Skip to content

Commit

Permalink
added AudioBuffer class
Browse files Browse the repository at this point in the history
  • Loading branch information
woguls committed Mar 22, 2020
1 parent d4a3d89 commit 50d8663
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile.base.mk
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ endif
# Set build and link flags

BASE_FLAGS = -Wall -Wextra -pipe -MD -MP
BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections # -fopt-info-vec-missed
BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections -fopt-info-vec-missed

ifeq ($(CPU_I386_OR_X86_64),true)
BASE_OPTS += -mtune=generic -msse -msse2
Expand Down
28 changes: 18 additions & 10 deletions src/csound-session/CsoundSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,37 @@ CsoundSession::CsoundSession(const char* orc, double framerate, uint32_t buffers
SetOption("-d");
if (CompileOrc(m_orc) == 0) {
Start();
m_ksmps = GetKsmps();
m_processedFrames = m_ksmps;
}
else {
m_result = 1;
return;
}

m_spout = GetSpout();
m_spin = GetSpin();
m_result = 0;
m_0dBFS = Get0dBFS();

buffers = new AudioBuffers(Get0dBFS(), GetKsmps(), GetSpin(), GetSpout(), GetCsound());
};
// -----------------------------------------------------------------------
// CopyBuffers
// low, high: sample numbers relative to the Distrho buffers.
void CsoundSession::CopyBuffers(const uint32_t low, const uint32_t high, const float** in, float** out) {

buffers->Copy(low, high, in, out);
}

AudioBuffers::AudioBuffers(const MYFLT zdbfs, const uint32_t ksmps, MYFLT* spin, MYFLT* spout, CSOUND * const csound) :
m_0dBFS{zdbfs},
m_ksmps{ksmps},
m_spin{spin},
m_spout{spout},
m_processedFrames{ksmps},
m_csound{csound}
{}

void AudioBuffers::Copy(const uint32_t low, const uint32_t high, const float** const in, float** const out) {
for (uint32_t frame = low; frame < high; frame++, m_processedFrames++) {
if (m_processedFrames == m_ksmps ) {
PerformKsmps();
csoundPerformKsmps(m_csound);
m_processedFrames = 0;
}

Expand All @@ -65,10 +76,7 @@ void CsoundSession::CopyBuffers(const uint32_t low, const uint32_t high, const f
m_spin[j + offset] = in[j][frame] * m_0dBFS;
}
}
}




}

END_NAMESPACE_DISTRHO
23 changes: 18 additions & 5 deletions src/csound-session/CsoundSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,35 @@

START_NAMESPACE_DISTRHO

class AudioBuffers
{
public:
AudioBuffers(const MYFLT zdbfs, const uint32_t ksmps, MYFLT* spin, MYFLT* spout, CSOUND * const csound);
void Copy(const uint32_t low, const uint32_t high, const float** const in, float** const out);

private:
const MYFLT m_0dBFS;
MYFLT * const m_spin;
MYFLT * const m_spout;
const uint32_t m_ksmps;
uint32_t m_processedFrames;
CSOUND * const m_csound;
};


class CsoundSession : public Csound
{
public:
CsoundSession(const char* orc, double framerate, uint32_t buffersize);
CsoundSession(const char* orc, const double framerate, const uint32_t buffersize);

void CopyBuffers(uint32_t low, uint32_t high, const float** in, float** out);
private:
CSOUND_PARAMS m_csParams;
String m_orc;
uint32_t m_processedFrames;
int m_result;
uint32_t m_ksmps;
MYFLT *m_spin, *m_spout;
MYFLT m_0dBFS;
AudioBuffers* buffers;
};


END_NAMESPACE_DISTRHO
#endif

0 comments on commit 50d8663

Please sign in to comment.