zynaddsubfx

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

commit 7540c6b46e2e6158a38464aeb9a8b35fefc3c9a9
parent fb7eef5ba9bdf4ac25a100f60125c9774d37a5b0
Author: fundamental <[email protected]>
Date:   Sat,  9 Jul 2011 14:35:18 -0400

Pruning code from static analysis

Static analysis performed with cppcheck and clang

Diffstat:
Msrc/DSP/SVFilter.cpp | 5+++++
Msrc/Effects/Phaser.h | 1-
Msrc/Effects/Reverb.cpp | 10++++------
Msrc/Misc/Bank.cpp | 13++++++-------
Msrc/Misc/Bank.h | 2+-
Msrc/Misc/Part.cpp | 10+++-------
Msrc/Misc/Stereo.h | 1-
Msrc/Nio/AlsaEngine.cpp | 2+-
Msrc/Nio/AlsaEngine.h | 2+-
Msrc/Nio/AudioOut.h | 2+-
Msrc/Nio/EngineMgr.h | 3++-
Msrc/Nio/MidiIn.h | 13+++++++------
Msrc/Nio/OutMgr.cpp | 1+
Msrc/Nio/OutMgr.h | 2--
Msrc/Params/PresetsStore.cpp | 2+-
Msrc/Params/PresetsStore.h | 2+-
Msrc/Seq/MIDIFile.cpp | 10++++------
Msrc/Seq/MIDIFile.h | 4----
Msrc/Synth/ADnote.cpp | 16++--------------
Msrc/Synth/Envelope.cpp | 3++-
Msrc/Synth/Envelope.h | 3+--
Msrc/Synth/OscilGen.cpp | 2+-
Msrc/Synth/PADnote.cpp | 3---
Msrc/Synth/SUBnote.cpp | 2--
Msrc/Synth/SUBnote.h | 3---
Msrc/Synth/SynthNote.cpp | 3++-
Msrc/Synth/SynthNote.h | 3---
Msrc/Tests/AdNoteTest.h | 8+++++++-
Msrc/Tests/SubNoteTest.h | 1-
Msrc/UI/PartUI.fl | 2+-
Msrc/main.cpp | 1+
31 files changed, 55 insertions(+), 80 deletions(-)

diff --git a/src/DSP/SVFilter.cpp b/src/DSP/SVFilter.cpp @@ -23,6 +23,8 @@ #include <cmath> #include <cstdio> #include <cstring> +#include <cassert> +#include <err.h> #include "../Misc/Util.h" #include "SVFilter.h" @@ -31,6 +33,7 @@ SVFilter::SVFilter(unsigned char Ftype, REALTYPE Fq, unsigned char Fstages) { + assert(Ftype<4); stages = Fstages; type = Ftype; freq = Ffreq; @@ -144,6 +147,8 @@ void SVFilter::singlefilterout(REALTYPE *smp, fstage &x, parameters &par) case 3: out = &x.notch; break; + default: + errx(1, "Impossible SVFilter type encountered [%d]", type); } for(int i = 0; i < SOUND_BUFFER_SIZE; i++) { diff --git a/src/Effects/Phaser.h b/src/Effects/Phaser.h @@ -58,7 +58,6 @@ class Phaser:public Effect unsigned char Poutsub; //if I wish to subtract the output instead of adding unsigned char Pphase; unsigned char Phyper; //lfo^2 -- converts tri into hyper-sine - unsigned char Pbarber; //Enable parber pole phasing unsigned char Panalog; //Control parameters diff --git a/src/Effects/Reverb.cpp b/src/Effects/Reverb.cpp @@ -240,10 +240,8 @@ void Reverb::settime(unsigned char Ptime) void Reverb::setlohidamp(unsigned char Plohidamp) { - REALTYPE x; - if(Plohidamp < 64) - Plohidamp = 64; //remove this when the high part from lohidamp will be added + Plohidamp = 64; //remove this when the high part from lohidamp will be added this->Plohidamp = Plohidamp; if(Plohidamp == 64) { @@ -255,7 +253,7 @@ void Reverb::setlohidamp(unsigned char Plohidamp) lohidamptype = 1; if(Plohidamp > 64) lohidamptype = 2; - x = fabs((REALTYPE)(Plohidamp - 64) / 64.1); + REALTYPE x = fabs((REALTYPE)(Plohidamp - 64) / 64.1); lohifb = x * x; } } @@ -322,7 +320,7 @@ void Reverb::setlpf(unsigned char Plpf) void Reverb::settype(unsigned char Ptype) { const int NUM_TYPES = 3; - int combtunings[NUM_TYPES][REV_COMBS] = { + const int combtunings[NUM_TYPES][REV_COMBS] = { //this is unused (for random) {0, 0, 0, 0, 0, 0, 0, 0 }, //Freeverb by Jezar at Dreampoint @@ -330,7 +328,7 @@ void Reverb::settype(unsigned char Ptype) //Freeverb by Jezar at Dreampoint //duplicate {1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617 } }; - int aptunings[NUM_TYPES][REV_APS] = { + const int aptunings[NUM_TYPES][REV_APS] = { //this is unused (for random) {0, 0, 0, 0 }, //Freeverb by Jezar at Dreampoint diff --git a/src/Misc/Bank.cpp b/src/Misc/Bank.cpp @@ -82,7 +82,7 @@ string Bank::getnamenumbered(unsigned int ninstrument) /* * Changes the name of an instrument (and the filename) */ -void Bank::setname(unsigned int ninstrument, string newname, int newslot) +void Bank::setname(unsigned int ninstrument, const string &newname, int newslot) { if(emptyslot(ninstrument)) return; @@ -248,7 +248,6 @@ int Bank::loadbank(string bankdirname) */ int Bank::newbank(string newbankdirname) { - int result; string bankdir; bankdir = config.cfg.bankRootDirList[0]; @@ -258,16 +257,16 @@ int Bank::newbank(string newbankdirname) bankdir += newbankdirname; #if OS_WINDOWS - result = mkdir(bankdir.c_str()); + if(mkdir(bankdir.c_str()) < 0) + return -1; #elif OS_LINUX || OS_CYGWIN - result = mkdir(bankdir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if(mkdir(bankdir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) + return -1; #else #warning Undefined OS #endif - if(result < 0) - return -1; - string tmpfilename = bankdir + '/' + FORCE_BANK_DIR_FILE; + const string tmpfilename = bankdir + '/' + FORCE_BANK_DIR_FILE; FILE *tmpfile = fopen(tmpfilename.c_str(), "w+"); fclose(tmpfile); diff --git a/src/Misc/Bank.h b/src/Misc/Bank.h @@ -42,7 +42,7 @@ class Bank ~Bank(); std::string getname(unsigned int ninstrument); std::string getnamenumbered(unsigned int ninstrument); - void setname(unsigned int ninstrument, const std::string newname, int newslot); //if newslot==-1 then this is ignored, else it will be put on that slot + void setname(unsigned int ninstrument, const std::string &newname, int newslot); //if newslot==-1 then this is ignored, else it will be put on that slot bool isPADsynth_used(unsigned int ninstrument); /**returns true when slot is empty*/ diff --git a/src/Misc/Part.cpp b/src/Misc/Part.cpp @@ -773,9 +773,10 @@ void Part::setkeylimit(unsigned char Pkeylimit) || (partnote[i].status == KEY_RELASED_AND_SUSTAINED)) notecount++; - int oldestnotepos = -1, maxtime = 0; + int oldestnotepos = -1; if(notecount > keylimit) { //find out the oldest note for(int i = 0; i < POLIPHONY; i++) { + int maxtime = 0; if(((partnote[i].status == KEY_PLAYING) || (partnote[i].status == KEY_RELASED_AND_SUSTAINED)) && (partnote[i].time > maxtime)) { @@ -821,12 +822,7 @@ void Part::RunNote(unsigned int k) REALTYPE *tmpoutr = getTmpBuffer(); REALTYPE *tmpoutl = getTmpBuffer(); - if((*note)->ready) - (*note)->noteout(&tmpoutl[0], &tmpoutr[0]); - else { - memset(tmpoutl, 0, sizeof(REALTYPE) * SOUND_BUFFER_SIZE); - memset(tmpoutr, 0, sizeof(REALTYPE) * SOUND_BUFFER_SIZE); - } + (*note)->noteout(&tmpoutl[0], &tmpoutr[0]); if((*note)->finished()) { delete (*note); diff --git a/src/Misc/Stereo.h b/src/Misc/Stereo.h @@ -30,7 +30,6 @@ struct Stereo /**Initializes Stereo with left and right set to val * @param val the value for both channels*/ Stereo(const T &val); - Stereo() {}; ~Stereo() {} Stereo<T> &operator=(const Stereo<T> &smp); diff --git a/src/Nio/AlsaEngine.cpp b/src/Nio/AlsaEngine.cpp @@ -233,7 +233,7 @@ void AlsaEngine::stopMidi() snd_seq_close(handle); } -short *AlsaEngine::interleave(const Stereo<REALTYPE *> smps) +short *AlsaEngine::interleave(const Stereo<REALTYPE *> &smps) { /**\todo TODO fix repeated allocation*/ short *shortInterleaved = audio.buffer; diff --git a/src/Nio/AlsaEngine.h b/src/Nio/AlsaEngine.h @@ -57,7 +57,7 @@ class AlsaEngine : public AudioOut, MidiIn bool openAudio(); void stopAudio(); - short *interleave(const Stereo<REALTYPE *> smps); + short *interleave(const Stereo<REALTYPE *> &smps); struct { std::string device; diff --git a/src/Nio/AudioOut.h b/src/Nio/AudioOut.h @@ -24,7 +24,7 @@ #define AUDIO_OUT_H #include "../Misc/Stereo.h" -#include "../Samples/Sample.h" +#include "../globals.h" #include "Engine.h" class AudioOut : public virtual Engine diff --git a/src/Nio/EngineMgr.h b/src/Nio/EngineMgr.h @@ -10,8 +10,9 @@ class MidiIn; class AudioOut; class OutMgr; /**Container/Owner of the long lived Engines*/ -struct EngineMgr +class EngineMgr { + public: static EngineMgr &getInstance(); ~EngineMgr(); diff --git a/src/Nio/MidiIn.h b/src/Nio/MidiIn.h @@ -28,13 +28,14 @@ #include "Engine.h" /**This class is inherited by all the Midi input classes*/ -struct MidiIn : public virtual Engine +class MidiIn : public virtual Engine { - /**Enables or disables driver based upon value*/ - virtual void setMidiEn(bool nval)=0; - /**Returns if driver is initialized*/ - virtual bool getMidiEn() const=0; - static void midiProcess(unsigned char head, unsigned char num, unsigned char value); + public: + /**Enables or disables driver based upon value*/ + virtual void setMidiEn(bool nval)=0; + /**Returns if driver is initialized*/ + virtual bool getMidiEn() const=0; + static void midiProcess(unsigned char head, unsigned char num, unsigned char value); }; #endif diff --git a/src/Nio/OutMgr.cpp b/src/Nio/OutMgr.cpp @@ -8,6 +8,7 @@ #include "WavEngine.h" #include "../Misc/Master.h" #include "../Misc/Util.h"//for set_realtime() +#include "../Samples/Sample.h"//for resampling using namespace std; diff --git a/src/Nio/OutMgr.h b/src/Nio/OutMgr.h @@ -3,7 +3,6 @@ #include "../globals.h" #include "../Misc/Stereo.h" -#include "../Samples/Sample.h" //deprecated #include <list> #include <string> #include <semaphore.h> @@ -55,7 +54,6 @@ class OutMgr /**Buffer*/ Stereo<REALTYPE *> priBuf; //buffer for primary drivers Stereo<REALTYPE *> priBuffCurrent; //current array accessor - Stereo<Sample> smps; /**Deprecated TODO Remove*/ REALTYPE *outl; REALTYPE *outr; diff --git a/src/Params/PresetsStore.cpp b/src/Params/PresetsStore.cpp @@ -88,7 +88,7 @@ bool PresetsStore::presetstruct::operator<(const presetstruct &b) const } -void PresetsStore::rescanforpresets(string type) +void PresetsStore::rescanforpresets(const string &type) { //std::cout << "Scanning For Presets" << std::endl; //std::cout << "Of Type: " << type << std::endl; diff --git a/src/Params/PresetsStore.h b/src/Params/PresetsStore.h @@ -52,7 +52,7 @@ class PresetsStore }; std::vector<presetstruct> presets; - void rescanforpresets(const std::string type); + void rescanforpresets(const std::string &type); private: struct { diff --git a/src/Seq/MIDIFile.cpp b/src/Seq/MIDIFile.cpp @@ -22,6 +22,7 @@ #include <stdio.h> #include <string.h> +#include <stdint.h> #include "MIDIFile.h" @@ -235,8 +236,7 @@ void MIDIFile::parsenoteoff(char ntrack, char chan, unsigned int dt) unsigned char note; note = getbyte(); - unsigned char noteoff_velocity = getbyte(); //unused by zynaddsubfx - noteoff_velocity = 0; + (void) getbyte(); //Read in unused noteoff_velocity if(chan >= NUM_MIDI_CHANNELS) return; @@ -346,7 +346,6 @@ void MIDIFile::clearmidifile() midifilesize = 0; midifilek = 0; midieof = false; - data.tick = 0.05; } unsigned char MIDIFile::getbyte() @@ -394,14 +393,13 @@ unsigned short int MIDIFile::getint16() unsigned int MIDIFile::getvarint32() { unsigned long result = 0; - unsigned char b; - /// printf("\n[start]"); if((result = getbyte()) & 0x80) { result &= 0x7f; + uint8_t b; do { - b = getbyte(); + b = getbyte(); result = (result << 7) + (b & 0x7f); } while(b & 0x80); } diff --git a/src/Seq/MIDIFile.h b/src/Seq/MIDIFile.h @@ -83,10 +83,6 @@ class MIDIFile //skip some bytes void skipnbytes(int n); - - struct { - double tick; //how many seconds one tick has - } data; }; #endif diff --git a/src/Synth/ADnote.cpp b/src/Synth/ADnote.cpp @@ -39,7 +39,6 @@ ADnote::ADnote(ADnoteParameters *pars, bool besilent) :SynthNote(freq, velocity, portamento_, midinote, besilent) { - ready = false; tmpwavel = new REALTYPE [SOUND_BUFFER_SIZE]; tmpwaver = new REALTYPE [SOUND_BUFFER_SIZE]; @@ -394,7 +393,6 @@ ADnote::ADnote(ADnoteParameters *pars, } initparameters(); - ready = true; } // ADlegatonote: This function is (mostly) a copy of ADnote(...) and @@ -614,22 +612,12 @@ void ADnote::legatonote(REALTYPE freq, REALTYPE velocity, int portamento_, if(partparams->VoicePar[nvoice].PextFMoscil != -1) vc = partparams->VoicePar[nvoice].PextFMoscil; - REALTYPE tmp = 1.0; - if((partparams->VoicePar[vc].FMSmp->Padaptiveharmonics != 0) - || (NoteVoicePar[nvoice].FMEnabled == MORPH) - || (NoteVoicePar[nvoice].FMEnabled == RING_MOD)) - tmp = getFMvoicebasefreq(nvoice); - if(!partparams->GlobalPar.Hrandgrouping) partparams->VoicePar[vc].FMSmp->newrandseed(rand()); - ///oscposhiFM[nvoice]=(oscposhi[nvoice]+partparams->VoicePar[vc].FMSmp->get(NoteVoicePar[nvoice].FMSmp,tmp)) % OSCIL_SIZE; - // / oscposhi[nvoice]+partparams->VoicePar[vc].FMSmp->get(NoteVoicePar[nvoice].FMSmp,tmp); //(gf) Modif of the above line. for(int i = 0; i < OSCIL_SMP_EXTRA_SAMPLES; i++) - NoteVoicePar[nvoice].FMSmp[OSCIL_SIZE - + i] = NoteVoicePar[nvoice].FMSmp[i]; - ///oscposhiFM[nvoice]+=(int)((partparams->VoicePar[nvoice].PFMoscilphase-64.0)/128.0*OSCIL_SIZE+OSCIL_SIZE*4); - ///oscposhiFM[nvoice]%=OSCIL_SIZE; + NoteVoicePar[nvoice].FMSmp[OSCIL_SIZE + i] = + NoteVoicePar[nvoice].FMSmp[i]; } FMnewamplitude[nvoice] = NoteVoicePar[nvoice].FMVolume diff --git a/src/Synth/Envelope.cpp b/src/Synth/Envelope.cpp @@ -20,8 +20,9 @@ */ -#include <stdio.h> +#include <cmath> #include "Envelope.h" +#include "../Params/EnvelopeParams.h" Envelope::Envelope(EnvelopeParams *envpars, REALTYPE basefreq) { diff --git a/src/Synth/Envelope.h b/src/Synth/Envelope.h @@ -23,7 +23,6 @@ #ifndef ENVELOPE_H #define ENVELOPE_H -#include <math.h> #include "../globals.h" #include "../Params/EnvelopeParams.h" @@ -33,7 +32,7 @@ class Envelope public: /**Constructor*/ - Envelope(EnvelopeParams *envpars, REALTYPE basefreq); + Envelope(class EnvelopeParams *envpars, REALTYPE basefreq); /**Destructor*/ ~Envelope(); void relasekey(); diff --git a/src/Synth/OscilGen.cpp b/src/Synth/OscilGen.cpp @@ -654,7 +654,7 @@ void OscilGen::prepare() void OscilGen::adaptiveharmonic(FFTFREQS f, REALTYPE freq) { - if((Padaptiveharmonics == 0) /*||(freq<1.0)*/) + if(Padaptiveharmonics == 0 /*||(freq<1.0)*/) return; if(freq < 1.0) freq = 440.0; diff --git a/src/Synth/PADnote.cpp b/src/Synth/PADnote.cpp @@ -31,7 +31,6 @@ PADnote::PADnote(PADnoteParameters *parameters, bool besilent) :SynthNote(freq, velocity, portamento_, midinote, besilent) { - ready = false; pars = parameters; ctl = ctl_; @@ -156,8 +155,6 @@ void PADnote::setup(REALTYPE freq, REALTYPE velocity,int portamento_, int midino NoteGlobalPar.FilterFreqTracking = pars->GlobalFilter->getfreqtracking( basefreq); - ready = true; ///sa il pun pe asta doar cand e chiar gata - if(pars->sample[nsample].smp == NULL) { finished_ = true; return; diff --git a/src/Synth/SUBnote.cpp b/src/Synth/SUBnote.cpp @@ -36,7 +36,6 @@ SUBnote::SUBnote(SUBnoteParameters *parameters, bool besilent) :SynthNote(freq, velocity, portamento_, midinote, besilent) { - ready = false; pars = parameters; ctl = ctl_; NoteEnabled= ON; @@ -205,7 +204,6 @@ void SUBnote::setup(REALTYPE freq, REALTYPE velocity, int portamento_, int midin } oldamplitude = newamplitude; - ready = true; } void SUBnote::legatonote(REALTYPE freq, REALTYPE velocity, int portamento_, diff --git a/src/Synth/SUBnote.h b/src/Synth/SUBnote.h @@ -95,9 +95,6 @@ class SUBnote :public SynthNote bpfilter *lfilter, *rfilter; - REALTYPE *tmpsmp; - REALTYPE *tmprnd; //this is filled with random numbers - Controller *ctl; int oldpitchwheel, oldbandwidth; REALTYPE globalfiltercenterq; diff --git a/src/Synth/SynthNote.cpp b/src/Synth/SynthNote.cpp @@ -20,7 +20,8 @@ SynthNote::Legato::Legato(REALTYPE freq, REALTYPE vel, int port, param.vel = vel; param.portamento = port; param.midinote = note; - silent = quiet; + lastfreq = 0.0; + silent = quiet; } int SynthNote::Legato::update(REALTYPE freq, REALTYPE velocity, int portamento_, diff --git a/src/Synth/SynthNote.h b/src/Synth/SynthNote.h @@ -43,9 +43,6 @@ class SynthNote virtual void legatonote(REALTYPE freq, REALTYPE velocity, int portamento_, int midinote_, bool externcall) = 0; - /**true when ready for output(the parameters has been computed) - * false when parameters need to be computed.*/ - bool ready; protected: // Legato transitions class Legato{ diff --git a/src/Tests/AdNoteTest.h b/src/Tests/AdNoteTest.h @@ -45,6 +45,10 @@ class AdNoteTest:public CxxTest::TestSuite //prepare the default settings ADnoteParameters *defaultPreset = new ADnoteParameters( new FFTwrapper(OSCIL_SIZE)); + + //Assert defaults + TS_ASSERT(!defaultPreset->VoicePar[1].Enabled); + XMLwrapper *wrap = new XMLwrapper(); cout << string(SOURCE_DIR) + string("/Tests/guitar-adnote.xmz") << endl; @@ -59,6 +63,9 @@ class AdNoteTest:public CxxTest::TestSuite defaultPreset->getfromXML(wrap); //defaultPreset->defaults(); + //verify xml was loaded + TS_ASSERT(defaultPreset->VoicePar[1].Enabled); + controller = new Controller(); @@ -86,7 +93,6 @@ class AdNoteTest:public CxxTest::TestSuite } void testDefaults() { - TS_ASSERT(note->ready); int sampleCount = 0; //#define WRITE_OUTPUT diff --git a/src/Tests/SubNoteTest.h b/src/Tests/SubNoteTest.h @@ -83,7 +83,6 @@ class SubNoteTest:public CxxTest::TestSuite //Note: if these tests fail it is due to the relationship between //global.h::RND and SUBnote.cpp - TS_ASSERT(note->ready); int sampleCount = 0; //#define WRITE_OUTPUT diff --git a/src/UI/PartUI.fl b/src/UI/PartUI.fl @@ -1045,7 +1045,7 @@ char tmp[10]; while (klimits[k]!=0){ sprintf(tmp,"%d",klimits[k]); keylimitlist->add(tmp); - if ((val==-1)){ + if (val==-1){ if (klimits[k]>part->Pkeylimit) val=k; }; k++; diff --git a/src/main.cpp b/src/main.cpp @@ -312,6 +312,7 @@ int main(int argc, char *argv[]) opt = getopt(argc, argv, "l:L:r:b:o:I:O:hSDUY", &option_index); char *optarguments = &winoptarguments[0]; #else + char *optarguments = NULL; #error Undefined OS #endif