Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/DSP/AnalogFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,11 @@ void AnalogFilter::filterout(float *smp)

if(needsinterpolation) {
//Merge Filter at old coeff with new coeff
#ifdef _MSC_VER
const auto ismp = static_cast<float*>(_alloca(buffersize * sizeof(float)));
#else
float ismp[buffersize];
#endif
memcpy(ismp, smp, bufferbytes);

for(int i = 0; i < stages + 1; ++i)
Expand Down
7 changes: 6 additions & 1 deletion src/DSP/FormantFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,18 @@ void FormantFilter::setfreq_and_q(float frequency, float q_)

void FormantFilter::filterout(float *smp)
{
#ifdef _MSC_VER
const auto inbuffer = static_cast<float*>(_alloca(buffersize * sizeof(float)));
const auto tmpbuf = static_cast<float*>(_alloca(buffersize * sizeof(float)));
#else
float inbuffer[buffersize];
float tmpbuf[buffersize];
#endif

memcpy(inbuffer, smp, bufferbytes);
memset(smp, 0, bufferbytes);

for(int j = 0; j < numformants; ++j) {
float tmpbuf[buffersize];
for(int i = 0; i < buffersize; ++i)
tmpbuf[i] = inbuffer[i] * outgain;
formant[j]->filterout(tmpbuf);
Expand Down
4 changes: 4 additions & 0 deletions src/DSP/SVFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ void SVFilter::filterout(float *smp)
singlefilterout(smp, st[i], par);

if(needsinterpolation) {
#ifdef _MSC_VER
const auto ismp = static_cast<float*>(_alloca(buffersize * sizeof(float)));
#else
float ismp[buffersize];
#endif
memcpy(ismp, smp, bufferbytes);

for(int i = 0; i < stages + 1; ++i)
Expand Down
10 changes: 5 additions & 5 deletions src/Effects/EffectMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <iostream>
using namespace std;

EffectMgr::EffectMgr(const bool insertion_, pthread_mutex_t *mutex_)
EffectMgr::EffectMgr(const bool insertion_, std::mutex *mutex_)
:insertion(insertion_),
efxoutl(new float[synth->buffersize]),
efxoutr(new float[synth->buffersize]),
Expand Down Expand Up @@ -142,9 +142,9 @@ void EffectMgr::changepreset_nolock(unsigned char npreset)
//Change the preset of the current effect(with thread locking)
void EffectMgr::changepreset(unsigned char npreset)
{
pthread_mutex_lock(mutex);
mutex->lock();
changepreset_nolock(npreset);
pthread_mutex_unlock(mutex);
mutex->unlock();
}


Expand All @@ -159,9 +159,9 @@ void EffectMgr::seteffectpar_nolock(int npar, unsigned char value)
// Change a parameter of the current effect (with thread locking)
void EffectMgr::seteffectpar(int npar, unsigned char value)
{
pthread_mutex_lock(mutex);
mutex->lock();
seteffectpar_nolock(npar, value);
pthread_mutex_unlock(mutex);
mutex->unlock();
}

//Get a parameter of the current effect
Expand Down
6 changes: 3 additions & 3 deletions src/Effects/EffectMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifndef EFFECTMGR_H
#define EFFECTMGR_H

#include <pthread.h>
#include "ThreadShims.h"

#include "Alienwah.h"
#include "Phaser.h"
Expand All @@ -43,7 +43,7 @@ class XMLwrapper;
class EffectMgr:public Presets
{
public:
EffectMgr(const bool insertion_, pthread_mutex_t *mutex_);
EffectMgr(const bool insertion_, std::mutex *mutex_);
~EffectMgr();

void add2XML(XMLwrapper *xml);
Expand Down Expand Up @@ -79,7 +79,7 @@ class EffectMgr:public Presets
private:
int nefx;
Effect *efx;
pthread_mutex_t *mutex;
std::mutex *mutex;
bool dryonly;
};

Expand Down
4 changes: 4 additions & 0 deletions src/Effects/Reverb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ void Reverb::out(const Stereo<float *> &smp)
if(!Pvolume && insertion)
return;

#ifdef _MSC_VER
const auto inputbuf = static_cast<float*>(_alloca(buffersize * sizeof(float)));
#else
float inputbuf[buffersize];
#endif
for(int i = 0; i < buffersize; ++i)
inputbuf[i] = (smp.l[i] + smp.r[i]) / 2.0f;

Expand Down
9 changes: 7 additions & 2 deletions src/Misc/Bank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@
#include <algorithm>
#include <iostream>

#ifdef WIN32
#include <wchar.h>
#include "IoHelper.h"
#else
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#endif

#include "Config.h"
#include "Util.h"
Expand Down Expand Up @@ -260,14 +265,14 @@ int Bank::newbank(string newbankdirname)

// FIXME: Zyn should automatically handle creation of parent directory
#ifdef WIN32
if(mkdir(bankdir.c_str()) < 0) return -1;
if(_wmkdir(lmms::toWString(bankdir).c_str()) < 0) return -1;
#else
if(mkdir(bankdir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) return -1;
#endif

bankdir += newbankdirname;
#ifdef WIN32
if(mkdir(bankdir.c_str()) < 0)
if(_wmkdir(lmms::toWString(bankdir).c_str()) < 0)
#else
if(mkdir(bankdir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0)
#endif
Expand Down
46 changes: 22 additions & 24 deletions src/Misc/Master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <algorithm>
#include <cmath>

#include <unistd.h>

using namespace std;

vuData::vuData(void)
Expand All @@ -55,8 +53,6 @@ Master::Master()
bufl = new float[synth->buffersize];
bufr = new float[synth->buffersize];

pthread_mutex_init(&mutex, NULL);
pthread_mutex_init(&vumutex, NULL);
fft = new FFTwrapper(synth->oscilsize);

shutup = 0;
Expand Down Expand Up @@ -116,11 +112,11 @@ bool Master::mutexLock(lockset request)
{
switch(request) {
case MUTEX_TRYLOCK:
return !pthread_mutex_trylock(&mutex);
return mutex.try_lock();
case MUTEX_LOCK:
return !pthread_mutex_lock(&mutex);
mutex.lock(); return true;
case MUTEX_UNLOCK:
return !pthread_mutex_unlock(&mutex);
mutex.unlock(); return true;
}
return false;
}
Expand Down Expand Up @@ -245,9 +241,9 @@ void Master::setProgram(char chan, unsigned int pgm)
//Hack to get pad note parameters to update
//this is not real time safe and makes assumptions about the calling
//convention of this function...
pthread_mutex_unlock(&mutex);
mutex.unlock();
part[npart]->applyparameters();
pthread_mutex_lock(&mutex);
mutex.lock();
}
}

Expand Down Expand Up @@ -336,9 +332,9 @@ void Master::AudioOut(float *outl, float *outr)

//Compute part samples and store them part[npart]->partoutl,partoutr
for(int npart = 0; npart < NUM_MIDI_PARTS; ++npart) {
if(part[npart]->Penabled != 0 && !pthread_mutex_trylock(&part[npart]->load_mutex)) {
if(part[npart]->Penabled != 0 && part[npart]->load_mutex.try_lock()) {
part[npart]->ComputePartSmps();
pthread_mutex_unlock(&part[npart]->load_mutex);
part[npart]->load_mutex.unlock();
}
}

Expand Down Expand Up @@ -394,8 +390,13 @@ void Master::AudioOut(float *outl, float *outr)
if(sysefx[nefx]->geteffect() == 0)
continue; //the effect is disabled

#ifdef _MSC_VER
const auto tmpmixl = static_cast<float*>(_alloca(synth->buffersize * sizeof(float)));
const auto tmpmixr = static_cast<float*>(_alloca(synth->buffersize * sizeof(float)));
#else
float tmpmixl[synth->buffersize];
float tmpmixr[synth->buffersize];
#endif
//Clean up the samples used by the system effects
memset(tmpmixl, 0, synth->bufferbytes);
memset(tmpmixr, 0, synth->bufferbytes);
Expand Down Expand Up @@ -458,9 +459,9 @@ void Master::AudioOut(float *outl, float *outr)
outr[i] *= volume;
}

if(!pthread_mutex_trylock(&vumutex)) {
if(vumutex.try_lock()) {
vuUpdate(outl, outr);
pthread_mutex_unlock(&vumutex);
vumutex.unlock();
}

//Shutup if it is asked (with fade-out)
Expand Down Expand Up @@ -530,9 +531,6 @@ Master::~Master()
delete sysefx[nefx];

delete fft;

pthread_mutex_destroy(&mutex);
pthread_mutex_destroy(&vumutex);
}


Expand Down Expand Up @@ -588,21 +586,21 @@ void Master::ShutUp()
*/
void Master::vuresetpeaks()
{
pthread_mutex_lock(&vumutex);
vumutex.lock();
vu.outpeakl = 1e-9;
vu.outpeakr = 1e-9;
vu.maxoutpeakl = 1e-9;
vu.maxoutpeakr = 1e-9;
vu.clipped = 0;
pthread_mutex_unlock(&vumutex);
vumutex.unlock();
}

vuData Master::getVuData()
{
vuData tmp;
pthread_mutex_lock(&vumutex);
vumutex.lock();
tmp = vu;
pthread_mutex_unlock(&vumutex);
vumutex.unlock();
return tmp;
}

Expand Down Expand Up @@ -673,9 +671,9 @@ int Master::getalldata(char **data)

xml->beginbranch("MASTER");

pthread_mutex_lock(&mutex);
mutex.lock();
add2XML(xml);
pthread_mutex_unlock(&mutex);
mutex.unlock();

xml->endbranch();

Expand All @@ -695,9 +693,9 @@ void Master::putalldata(char *data, int /*size*/)
if(xml->enterbranch("MASTER") == 0)
return;

pthread_mutex_lock(&mutex);
mutex.lock();
getfromXML(xml);
pthread_mutex_unlock(&mutex);
mutex.unlock();

xml->exitbranch();

Expand Down
6 changes: 3 additions & 3 deletions src/Misc/Master.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#ifndef MASTER_H
#define MASTER_H
#include <pthread.h>
#include "ThreadShims.h"

#include "../globals.h"
#include "Microtonal.h"
Expand Down Expand Up @@ -162,8 +162,8 @@ class Master
Bank bank;

class FFTwrapper * fft;
pthread_mutex_t mutex;
pthread_mutex_t vumutex;
std::mutex mutex;
std::mutex vumutex;


private:
Expand Down
20 changes: 12 additions & 8 deletions src/Misc/Part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@
#include <stdio.h>
#include <string.h>

Part::Part(Microtonal *microtonal_, FFTwrapper *fft_, pthread_mutex_t *mutex_)
Part::Part(Microtonal *microtonal_, FFTwrapper *fft_, std::mutex *mutex_)
{
microtonal = microtonal_;
fft = fft_;
mutex = mutex_;
pthread_mutex_init(&load_mutex, NULL);
partoutl = new float [synth->buffersize];
partoutr = new float [synth->buffersize];

Expand Down Expand Up @@ -232,7 +231,7 @@ void Part::NoteOn(unsigned char note,
}
else
// Poly mode is On so just make sure the list is empty.
if(not monomemnotes.empty())
if(!monomemnotes.empty())
monomemnotes.clear();

lastnote = note;
Expand All @@ -254,7 +253,7 @@ void Part::NoteOn(unsigned char note,
else {
// Legato mode is on and applicable.
legatomodevalid = true;
if((not ismonofirstnote) && (lastlegatomodevalid)) {
if((!ismonofirstnote) && (lastlegatomodevalid)) {
// At least one other key is held or sustained, and the
// previous note was played while in valid legato mode.
doinglegato = true; // So we'll do a legato note.
Expand Down Expand Up @@ -337,7 +336,7 @@ void Part::NoteOn(unsigned char note,
// still held down or sustained for the Portamento to activate
// (that's like Legato).
int portamento = 0;
if((Ppolymode != 0) || (not ismonofirstnote))
if((Ppolymode != 0) || (!ismonofirstnote))
// I added a third argument to the
// ctl.initportamento(...) function to be able
// to tell it if we're doing a legato note.
Expand Down Expand Up @@ -629,13 +628,13 @@ void Part::NoteOff(unsigned char note) //release the key
int i;

// This note is released, so we remove it from the list.
if(not monomemnotes.empty())
if(!monomemnotes.empty())
monomemnotes.remove(note);

for(i = POLIPHONY - 1; i >= 0; i--) //first note in, is first out if there are same note multiple times
if((partnote[i].status == KEY_PLAYING) && (partnote[i].note == note)) {
if(ctl.sustain.sustain == 0) { //the sustain pedal is not pushed
if((Ppolymode == 0) && (not monomemnotes.empty()))
if((Ppolymode == 0) && (!monomemnotes.empty()))
MonoMemRenote(); // To play most recent still held note.
else
RelaseNotePos(i);
Expand Down Expand Up @@ -796,7 +795,7 @@ void Part::SetController(unsigned int type, int par)
void Part::RelaseSustainedKeys()
{
// Let's call MonoMemRenote() on some conditions:
if((Ppolymode == 0) && (not monomemnotes.empty()))
if((Ppolymode == 0) && (!monomemnotes.empty()))
if(monomemnotes.back() != lastnote) // Sustain controller manipulation would cause repeated same note respawn without this check.
MonoMemRenote(); // To play most recent still held note.

Expand Down Expand Up @@ -947,8 +946,13 @@ void Part::RunNote(unsigned int k)
continue;
noteplay++;

#ifdef _MSC_VER
const auto tmpoutr = static_cast<float*>(_alloca(synth->buffersize * sizeof(float)));
const auto tmpoutl = static_cast<float*>(_alloca(synth->buffersize * sizeof(float)));
#else
float tmpoutr[synth->buffersize];
float tmpoutl[synth->buffersize];
#endif
(*note)->noteout(&tmpoutl[0], &tmpoutr[0]);

if((*note)->finished()) {
Expand Down
Loading