[yoshimi-user] Some optimization patches for Yoshimi

  • From: Kristian Amlie <kristian@xxxxxxxxxx>
  • To: yoshimi-user@xxxxxxxxxxxxxxxxxxxxx
  • Date: Sat, 06 Oct 2012 12:10:48 +0200

I made some optimizations to Yoshimi to improve its CPU usage, which resulted in two patches. Especially the second patch gives a large improvement on CPU usage when Yoshimi is idle; on my system it drops from 13% to 3%. Both patches are pretty straightforward, and I have been using them for several hours without running into any issues.

If someone on the list wants to test them, maybe we could apply them to the next version of Yoshimi. The patches are based on the 1.0 branch.

--
Kristian

From e9a056f475b612f6b92bb9401bee57de2f6a8bdc Mon Sep 17 00:00:00 2001
From: Kristian Amlie <kristian@xxxxxxxxxx>
Date: Sun, 30 Sep 2012 16:54:05 +0200
Subject: [PATCH 1/2] Removed memory reset.

It is a waste of cycles, since it is reset later in MasterAudio()
anyway.
---
src/MusicIO/JackEngine.cpp | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/src/MusicIO/JackEngine.cpp b/src/MusicIO/JackEngine.cpp
index 845b182..5eba968 100644
--- a/src/MusicIO/JackEngine.cpp
+++ b/src/MusicIO/JackEngine.cpp
@@ -307,8 +307,6 @@ bool JackEngine::processAudio(jack_nframes_t nframes)
return false;
}
}
- memset(audio.portBuffs[0], 0, sizeof(float) * nframes);
- memset(audio.portBuffs[1], 0, sizeof(float) * nframes);
getAudio();
memcpy(audio.portBuffs[0], zynLeft, sizeof(float) * nframes);
memcpy(audio.portBuffs[1], zynRight, sizeof(float) * nframes);
--
1.7.3.4

From a19f9680c3f6ee66fe9e5bd867ebe8e550fae4b6 Mon Sep 17 00:00:00 2001
From: Kristian Amlie <kristian@xxxxxxxxxx>
Date: Sun, 30 Sep 2012 16:55:15 +0200
Subject: [PATCH 2/2] Removed numerous locks and replaced them with one.

Instead of locking the same lock over and over, lock it once for the
entire code section. This greatly reduces Yoshimi's CPU usage when it
is idle, and even under load it will reduce CPU usage significantly.
---
src/Misc/SynthEngine.cpp | 18 ++++--------------
1 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/src/Misc/SynthEngine.cpp b/src/Misc/SynthEngine.cpp
index d665207..5bfb064 100644
--- a/src/Misc/SynthEngine.cpp
+++ b/src/Misc/SynthEngine.cpp
@@ -364,14 +364,14 @@ void SynthEngine::MasterAudio(float *outl, float *outr)
if (isMuted())
return;

+ actionLock(lock);
+
// Compute part samples and store them npart]->partoutl,partoutr
int npart;
for (npart = 0; npart < NUM_MIDI_PARTS; ++npart)
if (part[npart]->Penabled)
{
- actionLock(lock);
part[npart]->ComputePartSmps();
- actionLock(unlock);
}
// Insertion effects
int nefx;
@@ -382,9 +382,7 @@ void SynthEngine::MasterAudio(float *outl, float *outr)
int efxpart = Pinsparts[nefx];
if (part[efxpart]->Penabled)
{
- actionLock(lock);
insefx[nefx]->out(part[efxpart]->partoutl,
part[efxpart]->partoutr);
- actionLock(unlock);
}
}
}
@@ -443,10 +441,8 @@ void SynthEngine::MasterAudio(float *outl, float *outr)
float vol = sysefxvol[nefx][npart];
for (int i = 0; i < buffersize; ++i)
{
- actionLock(lock);
tmpmixl[i] += part[npart]->partoutl[i] * vol;
tmpmixr[i] += part[npart]->partoutr[i] * vol;
- actionLock(unlock);
}
}
}
@@ -459,10 +455,8 @@ void SynthEngine::MasterAudio(float *outl, float *outr)
float v = sysefxsend[nefxfrom][nefx];
for (int i = 0; i < buffersize; ++i)
{
- actionLock(lock);
tmpmixl[i] += sysefx[nefxfrom]->efxoutl[i] * v;
tmpmixr[i] += sysefx[nefxfrom]->efxoutr[i] * v;
- actionLock(unlock);
}
}
}
@@ -472,10 +466,8 @@ void SynthEngine::MasterAudio(float *outl, float *outr)
float outvol = sysefx[nefx]->sysefxgetvolume();
for (int i = 0; i < buffersize; ++i)
{
- actionLock(lock);
outl[i] += tmpmixl[i] * outvol;
outr[i] += tmpmixr[i] * outvol;
- actionLock(unlock);
}
}

@@ -484,10 +476,8 @@ void SynthEngine::MasterAudio(float *outl, float *outr)
{
for (int i = 0; i < buffersize; ++i)
{ // the volume did not change
- actionLock(lock);
outl[i] += part[npart]->partoutl[i];
outr[i] += part[npart]->partoutr[i];
- actionLock(unlock);
}
}

@@ -496,12 +486,12 @@ void SynthEngine::MasterAudio(float *outl, float *outr)
{
if (Pinsparts[nefx] == -2)
{
- actionLock(lock);
insefx[nefx]->out(outl, outr);
- actionLock(unlock);
}
}

+ actionLock(unlock);
+
LFOParams::time++; // update the LFO's time

vupeakLock(lock);
--
1.7.3.4

Other related posts:

  • » [yoshimi-user] Some optimization patches for Yoshimi - Kristian Amlie