zynaddsubfx

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

commit 7ee08076a6cf3129b29145ca4f3a183388072a61
parent 2a06e36bad5fac63e1126a8796c01e0f7660fd1c
Author: Johannes Lorenz <johannes89@ist-einmalig.de>
Date:   Wed, 10 Jun 2015 06:53:19 +0200

Deglobalised denormalkillbuf, however, alias behaviour yet critical

Diffstat:
MTODO.txt | 8++++----
Msrc/CMakeLists.txt | 3++-
Msrc/Effects/EffectMgr.cpp | 4++--
Msrc/Misc/MiddleWare.cpp | 9+++++----
Msrc/Misc/MiddleWare.h | 2+-
Msrc/Misc/Part.cpp | 8++++----
Msrc/Misc/Util.cpp | 2--
Msrc/Misc/Util.h | 2--
Msrc/Synth/ADnote.cpp | 4++--
Msrc/Synth/SUBnote.cpp | 4++--
Asrc/globals.cpp | 38++++++++++++++++++++++++++++++++++++++
Msrc/globals.h | 19++++++++++++-------
Msrc/main.cpp | 10++--------
13 files changed, 74 insertions(+), 39 deletions(-)

diff --git a/TODO.txt b/TODO.txt @@ -12,12 +12,12 @@ in order to avoid denormalisation*/ Status: (1) -(2) -(3) +(2) will be fixed with fftw3 (?), until then maybe use separate mutex? +(3) will be fixed by fundamental (4) -(5) +(5) fixed + tested, but alias() behaviour is unclear yet (6) -(7) +(7) -> will not be fixed (should stay random) (8) fixed + tested diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt @@ -367,7 +367,7 @@ if(CompileTests) endif(CompileTests) -add_executable(zynaddsubfx main.cpp) +add_executable(zynaddsubfx main.cpp globals.cpp) #Warning: the required ordering of these to get proper linking depends upon the # phase of the moon @@ -384,6 +384,7 @@ if (DssiEnable) add_library(zynaddsubfx_dssi SHARED UI/ConnectionDummy.cpp Output/DSSIaudiooutput.cpp + globals.cpp ) target_link_libraries(zynaddsubfx_dssi diff --git a/src/Effects/EffectMgr.cpp b/src/Effects/EffectMgr.cpp @@ -297,8 +297,8 @@ void EffectMgr::out(float *smpsl, float *smpsr) return; } for(int i = 0; i < synth.buffersize; ++i) { - smpsl[i] += denormalkillbuf[i]; - smpsr[i] += denormalkillbuf[i]; + smpsl[i] += synth.denormalkillbuf[i]; + smpsr[i] += synth.denormalkillbuf[i]; efxoutl[i] = 0.0f; efxoutr[i] = 0.0f; } diff --git a/src/Misc/MiddleWare.cpp b/src/Misc/MiddleWare.cpp @@ -552,7 +552,7 @@ class MiddleWareImpl } public: - MiddleWareImpl(MiddleWare *mw, SYNTH_T synth, int prefered_port); + MiddleWareImpl(MiddleWare *mw, const SYNTH_T &synth, int prefered_port); ~MiddleWareImpl(void); void warnMemoryLeaks(void); @@ -848,12 +848,13 @@ public: string last_url, curr_url; //Synthesis Rate Parameters - const SYNTH_T synth; + const SYNTH_T& synth; PresetsStore presetsstore; }; -MiddleWareImpl::MiddleWareImpl(MiddleWare *mw, SYNTH_T synth_, int prefered_port) +MiddleWareImpl::MiddleWareImpl(MiddleWare *mw, const SYNTH_T& synth_, + int prefered_port) :parent(mw), ui(nullptr), synth(synth_) { bToU = new rtosc::ThreadLink(4096*2,1024); @@ -1287,7 +1288,7 @@ void MiddleWareImpl::warnMemoryLeaks(void) /****************************************************************************** * MidleWare Forwarding Stubs * ******************************************************************************/ -MiddleWare::MiddleWare(SYNTH_T synth, int prefered_port) +MiddleWare::MiddleWare(const SYNTH_T &synth, int prefered_port) :impl(new MiddleWareImpl(this, synth, prefered_port)) {} MiddleWare::~MiddleWare(void) diff --git a/src/Misc/MiddleWare.h b/src/Misc/MiddleWare.h @@ -11,7 +11,7 @@ class PresetsStore; class MiddleWare { public: - MiddleWare(SYNTH_T synth, int prefered_port = -1); + MiddleWare(const SYNTH_T& synth, int prefered_port = -1); ~MiddleWare(void); void updateResources(Master *m); //returns internal master pointer diff --git a/src/Misc/Part.cpp b/src/Misc/Part.cpp @@ -328,16 +328,16 @@ void Part::cleanup(bool final_) for(int k = 0; k < POLYPHONY; ++k) KillNotePos(k); for(int i = 0; i < synth.buffersize; ++i) { - partoutl[i] = final_ ? 0.0f : denormalkillbuf[i]; - partoutr[i] = final_ ? 0.0f : denormalkillbuf[i]; + partoutl[i] = final_ ? 0.0f : synth.denormalkillbuf[i]; + partoutr[i] = final_ ? 0.0f : synth.denormalkillbuf[i]; } ctl.resetall(); for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx) partefx[nefx]->cleanup(); for(int n = 0; n < NUM_PART_EFX + 1; ++n) for(int i = 0; i < synth.buffersize; ++i) { - partfxinputl[n][i] = final_ ? 0.0f : denormalkillbuf[i]; - partfxinputr[n][i] = final_ ? 0.0f : denormalkillbuf[i]; + partfxinputl[n][i] = final_ ? 0.0f : synth.denormalkillbuf[i]; + partfxinputr[n][i] = final_ ? 0.0f : synth.denormalkillbuf[i]; } } diff --git a/src/Misc/Util.cpp b/src/Misc/Util.cpp @@ -44,8 +44,6 @@ prng_t prng_state = 0x1234; Config config; -float *denormalkillbuf; - /* * Transform the velocity according the scaling parameter (velocity sensing) diff --git a/src/Misc/Util.h b/src/Misc/Util.h @@ -56,8 +56,6 @@ std::string os_pid_as_padded_string(); std::string legalizeFilename(std::string filename); -extern float *denormalkillbuf; /**<the buffer to add noise in order to avoid denormalisation*/ - extern class Config config; void invSignal(float *sig, size_t len); diff --git a/src/Synth/ADnote.cpp b/src/Synth/ADnote.cpp @@ -1434,8 +1434,8 @@ inline void ADnote::ComputeVoiceNoise(int nvoice) */ int ADnote::noteout(float *outl, float *outr) { - memcpy(outl, denormalkillbuf, synth.bufferbytes); - memcpy(outr, denormalkillbuf, synth.bufferbytes); + memcpy(outl, synth.denormalkillbuf, synth.bufferbytes); + memcpy(outr, synth.denormalkillbuf, synth.bufferbytes); if(NoteEnabled == OFF) return 0; diff --git a/src/Synth/SUBnote.cpp b/src/Synth/SUBnote.cpp @@ -491,8 +491,8 @@ void SUBnote::computecurrentparameters() */ int SUBnote::noteout(float *outl, float *outr) { - memcpy(outl, denormalkillbuf, synth.bufferbytes); - memcpy(outr, denormalkillbuf, synth.bufferbytes); + memcpy(outl, synth.denormalkillbuf, synth.bufferbytes); + memcpy(outr, synth.denormalkillbuf, synth.bufferbytes); if(NoteEnabled == OFF) return 0; diff --git a/src/globals.cpp b/src/globals.cpp @@ -0,0 +1,38 @@ +/* + ZynAddSubFX - a software synthesizer + + globals.h - it contains program settings and the program capabilities + like number of parts, of effects + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2 or later) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include "Misc/Util.h" +#include "globals.h" + +void SYNTH_T::alias() +{ + halfsamplerate_f = (samplerate_f = samplerate) / 2.0f; + buffersize_f = buffersize; + bufferbytes = buffersize * sizeof(float); + oscilsize_f = oscilsize; + + //produce denormal buf + denormalkillbuf = new float [buffersize]; + for(int i = 0; i < buffersize; ++i) + denormalkillbuf[i] = (RND - 0.5f) * 1e-16; +} diff --git a/src/globals.h b/src/globals.h @@ -254,12 +254,23 @@ enum LegatoMsg { //temporary include for synth->{samplerate/buffersize} members struct SYNTH_T { + SYNTH_T(void) :samplerate(44100), buffersize(256), oscilsize(1024) { alias(); } + ~SYNTH_T() + { + delete [] denormalkillbuf; + } + + SYNTH_T(const SYNTH_T& ) = delete; + + /** the buffer to add noise in order to avoid denormalisation */ + float *denormalkillbuf = nullptr; + /**Sampling rate*/ unsigned int samplerate; @@ -291,13 +302,7 @@ struct SYNTH_T { { return buffersize_f / samplerate_f; } - inline void alias(void) - { - halfsamplerate_f = (samplerate_f = samplerate) / 2.0f; - buffersize_f = buffersize; - bufferbytes = buffersize * sizeof(float); - oscilsize_f = oscilsize; - } + void alias(void); static float numRandom(void); //defined in Util.cpp for now }; #endif diff --git a/src/main.cpp b/src/main.cpp @@ -91,7 +91,7 @@ void sigterm_exit(int /*sig*/) /* * Program initialisation */ -void initprogram(SYNTH_T synth, int prefered_port) +void initprogram(const SYNTH_T& synth, int prefered_port) { middleware = new MiddleWare(synth, prefered_port); master = middleware->spawnMaster(); @@ -121,7 +121,6 @@ void exitprogram() delete nsm; #endif - delete [] denormalkillbuf; FFT_cleanup(); } @@ -375,11 +374,6 @@ int main(int argc, char *argv[]) return 0; } - //produce denormal buf - denormalkillbuf = new float [synth.buffersize]; - for(int i = 0; i < synth.buffersize; ++i) - denormalkillbuf[i] = (RND - 0.5f) * 1e-16; - initprogram(synth, prefered_port); if(!loadfile.empty()) { @@ -413,7 +407,7 @@ int main(int argc, char *argv[]) //Run the Nio system bool ioGood = Nio::start(); - + cerr.precision(1); cerr << std::fixed; cerr << "\nSample Rate = \t\t" << synth.samplerate << endl;