zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 2bee5f578cd94052a4d54be651a51b8bfab7ca4d
parent fd3ce48f49591d05f3870f192c300f42fe33522c
Author: fundamental <[email protected]>
Date:   Sat, 12 Jun 2010 11:30:32 -0400

Nio: Reducing calls to new/malloc

Diffstat:
Msrc/Nio/AudioOut.cpp | 5+++++
Msrc/Nio/AudioOut.h | 1+
Msrc/Nio/JackEngine.cpp | 6+++---
Msrc/Nio/OutMgr.cpp | 12+++++++-----
4 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/Nio/AudioOut.cpp b/src/Nio/AudioOut.cpp @@ -72,3 +72,8 @@ const Stereo<Sample> AudioOut::getNext(bool wait) //stop the samples return Stereo<Sample>(Sample(bufferSize, tmp.l()), Sample(bufferSize, tmp.r())); } + +const Stereo<REALTYPE *> AudioOut::getNextBuf() +{ + return OutMgr::getInstance().tick(bufferSize); +} diff --git a/src/Nio/AudioOut.h b/src/Nio/AudioOut.h @@ -53,6 +53,7 @@ class AudioOut : public virtual Engine /**Get the next sample for output. * (has nsamples sampled at a rate of samplerate)*/ const Stereo<Sample> getNext(bool wait = false); + const Stereo<REALTYPE *> getNextBuf(); int samplerate; int bufferSize; diff --git a/src/Nio/JackEngine.cpp b/src/Nio/JackEngine.cpp @@ -259,11 +259,11 @@ bool JackEngine::processAudio(jack_nframes_t nframes) } } - Stereo<Sample> smp = getNext(); + Stereo<REALTYPE *> smp = getNextBuf(); //Assumes smp.l().size() == nframes - memcpy(audio.portBuffs[0], smp.l().c_buf(), smp.l().size()*sizeof(REALTYPE)); - memcpy(audio.portBuffs[1], smp.r().c_buf(), smp.r().size()*sizeof(REALTYPE)); + memcpy(audio.portBuffs[0], smp.l(), bufferSize*sizeof(REALTYPE)); + memcpy(audio.portBuffs[1], smp.r(), bufferSize*sizeof(REALTYPE)); handleMidi(nframes); return true; diff --git a/src/Nio/OutMgr.cpp b/src/Nio/OutMgr.cpp @@ -118,16 +118,18 @@ void OutMgr::addSmps(REALTYPE *l, REALTYPE *r) //allow wave file to syphon off stream wave->push(Stereo<REALTYPE *>(l,r),SOUND_BUFFER_SIZE); - Stereo<Sample> smps(Sample(SOUND_BUFFER_SIZE, l), Sample(SOUND_BUFFER_SIZE, r)); - if(currentOut->getSampleRate() != SAMPLE_RATE) { //we need to resample //cout << "BAD RESAMPLING" << endl; + Stereo<Sample> smps(Sample(SOUND_BUFFER_SIZE, l), Sample(SOUND_BUFFER_SIZE, r)); smps.l().resample(SAMPLE_RATE,currentOut->getSampleRate()); smps.r().resample(SAMPLE_RATE,currentOut->getSampleRate()); + memcpy(priBuffCurrent.l(), smps.l().c_buf(), SOUND_BUFFER_SIZE*sizeof(REALTYPE)); + memcpy(priBuffCurrent.r(), smps.r().c_buf(), SOUND_BUFFER_SIZE*sizeof(REALTYPE)); + } + else { //just copy the samples + memcpy(priBuffCurrent.l(), l, SOUND_BUFFER_SIZE*sizeof(REALTYPE)); + memcpy(priBuffCurrent.r(), r, SOUND_BUFFER_SIZE*sizeof(REALTYPE)); } - - memcpy(priBuffCurrent.l(), smps.l().c_buf(), SOUND_BUFFER_SIZE*sizeof(REALTYPE)); - memcpy(priBuffCurrent.r(), smps.r().c_buf(), SOUND_BUFFER_SIZE*sizeof(REALTYPE)); priBuffCurrent.l() += SOUND_BUFFER_SIZE; priBuffCurrent.r() += SOUND_BUFFER_SIZE; stales += SOUND_BUFFER_SIZE;