[yoshimi-user] Patch to fix pitch problem in 0.062

  • From: jimmy <wg2002a@xxxxxxxxx>
  • To: yoshimi-user@xxxxxxxxxxxxxxxxxxxxx
  • Date: Thu, 23 Feb 2012 10:49:48 -0800 (PST)

Attached is my patch, I think it should fix the "wrong-pitch" problem. Not
pretty, but let's get it to work first. I only tried with the "default"
instrument. Will try some other instruments later when I have time. Perhaps
other folks here can help checking it out with their ears, too.

The patch should apply to the current trunk 0.062 . If anyone want to try it
out, feel free to give feed back if you found any problems. If it works for
you, let us know, too.

Some notes:

1) The change in Config.cpp is a "must" have, try stripping that out and the
pitch problem would rear its ugly face.

2) The changes to the .fl files are needed to build with FLTK 1.3 on 32-bit
system.

3) I changed CMakeFiles.txt variable BuildForAMD_X86_64 to OFF. I think
folks on 32-bit system may not be aware of the "default". I myself ran to this
weird build wild-goose chase on some header files not found. While I think on
64-bit system, if you build 32-bit binaries, it should still run fine.

Of course, who ever putting the code in can decide selectively what they want
to do with the changes.

Jimmydiff -burp yoshimi.062/src/CMakeLists.txt yoshimi.062.jn005/src/CMakeLists.txt
--- yoshimi.062/src/CMakeLists.txt 2012-02-22 16:36:26.000000000 -0500
+++ yoshimi.062.jn005/src/CMakeLists.txt 2012-02-23 13:33:41.000000000
-0500
@@ -55,7 +55,7 @@ endif (HAS_JACK_SESSION)
set (DefaultAudio jack CACHE STRING "Default audio driver - alsa or jack")
set (DefaultMidi jack CACHE STRING "Default midi driver - alsa or jack")

-option (BuildForAMD_X86_64 "Build for AMD x86_64 system" ON)
+option (BuildForAMD_X86_64 "Build for AMD x86_64 system" OFF)
option (BuildForCore2_X86_64 "Build for Intel Core2 x86_64 system" OFF)
option (BuildForDebug "Include gdb debugging support" OFF)

@@ -260,7 +260,7 @@ add_definitions (
-DYOSHI_FIFO_DIR="${FifoDirectory}"
)

-add_definitions (-DBANK_LIMIT=128)
+add_definitions (-DMAX_BANK_SIZE=128)
add_definitions (-DMAX_AD_HARMONICS=128)
add_definitions (-DMAX_SUB_HARMONICS=64)
add_definitions (-DPAD_MAX_SAMPLES=64)
diff -burp yoshimi.062/src/Misc/Config.cpp yoshimi.062.jn005/src/Misc/Config.cpp
--- yoshimi.062/src/Misc/Config.cpp 2012-02-22 16:36:26.000000000 -0500
+++ yoshimi.062.jn005/src/Misc/Config.cpp 2012-02-23 13:01:38.000000000
-0500
@@ -22,6 +22,7 @@
*/

#include <iostream>
+#include <fenv.h>

#include <cmath>
#include <string>
@@ -120,6 +121,9 @@ Config::Config() :
{
setlocale( LC_TIME, "" ); // use compiler's native locale
std::ios::sync_with_stdio(false);
+ // We need lrintf() to round toward zero. Special thanks go to
+ // Lars Luthman for this one!!
+ fesetround(FE_TOWARDZERO);
cerr.precision(4);
std::ios::sync_with_stdio(false);
}
diff -burp yoshimi.062/src/Misc/Part.cpp yoshimi.062.jn005/src/Misc/Part.cpp
--- yoshimi.062/src/Misc/Part.cpp 2012-02-22 16:36:26.000000000 -0500
+++ yoshimi.062.jn005/src/Misc/Part.cpp 2012-02-23 13:06:53.000000000 -0500
@@ -350,13 +350,14 @@ void Part::NoteOn(unsigned char note, un
if (Pdrummode == 0)
{
notebasefreq = microtonal->getnotefreq(note, keyshift);
- if (notebasefreq < 0.0f)
+ if (notebasefreq < 0.0)
return; // the key is no mapped
- } else
- notebasefreq = 440.0f * powf(2.0f, (note - 69.0f) / 12.0f);
+ } else {
+ notebasefreq = 440.0 * powf(2.0, (note - 69.0) / 12.0);
+ }

// Portamento
- if (oldfreq < 1.0f)
+ if (oldfreq < 1.0)
oldfreq = notebasefreq; // this is only the first note is played

// For Mono/Legato: Force Portamento Off on first
@@ -500,11 +501,11 @@ void Part::NoteOn(unsigned char note, un
partnote[pos].kititem[0].sendtoparteffect = 0;
if (kit[0].Padenabled)
partnote[pos].kititem[0].adnote =
- new ADnote(kit[0].adpars, ctl,notebasefreq, vel,
+ new ADnote(kit[0].adpars, ctl, notebasefreq, vel,
portamento, note, false /*not silent*/);
if (kit[0].Psubenabled)
partnote[pos].kititem[0].subnote =
- new SUBnote(kit[0].subpars, ctl,notebasefreq, vel,
+ new SUBnote(kit[0].subpars, ctl, notebasefreq, vel,
portamento, note, false);
if (kit[0].Ppadenabled)
{
diff -burp yoshimi.062/src/Misc/Part.h yoshimi.062.jn005/src/Misc/Part.h
--- yoshimi.062/src/Misc/Part.h 2012-02-22 16:36:26.000000000 -0500
+++ yoshimi.062.jn005/src/Misc/Part.h 2012-02-23 11:06:07.000000000 -0500
@@ -199,7 +199,7 @@ class Part : private MiscFuncs, SynthHel
float oldfreq; // for portamento
Microtonal *microtonal;
FFTwrapper *fft;
- int partMuted;
+ unsigned char partMuted;
};

#endif
diff -burp yoshimi.062/src/Sql/ProgramBanks.cpp
yoshimi.062.jn005/src/Sql/ProgramBanks.cpp
--- yoshimi.062/src/Sql/ProgramBanks.cpp 2012-02-22 16:36:26.000000000
-0500
+++ yoshimi.062.jn005/src/Sql/ProgramBanks.cpp 2012-02-23 05:38:49.000000000
-0500
@@ -149,7 +149,7 @@ bool ProgramBanks::newDatabase(bool load
list<string>::iterator progitx;
string qry;
Runtime.Log("Loading program bank database from base .xiz files");
- for (unsigned char bank = 0; bank < BANK_LIMIT && (dent =
readdir(rootDIR)) != NULL;)
+ for (unsigned char bank = 0; bank < MAX_BANK_SIZE && (dent =
readdir(rootDIR)) != NULL;)
{
string chkbank = string(dent->d_name);
if (chkbank[0] == '.')
@@ -173,7 +173,7 @@ bool ProgramBanks::newDatabase(bool load
progfiles.push_back(string(subdent->d_name));
progfiles.sort();
int prognum = 0;
- for (progitx = progfiles.begin(); progitx != progfiles.end() &&
prognum < BANK_LIMIT; ++progitx)
+ for (progitx = progfiles.begin(); progitx != progfiles.end() &&
prognum < MAX_BANK_SIZE; ++progitx)
{
string chkfile = *progitx;
if (chkfile[0] == '.' )
@@ -228,7 +228,7 @@ not_good:
void ProgramBanks::loadBankList(void)
{
bankList.clear();
- for (int i = 0; i < BANK_LIMIT; ++i)
+ for (int i = 0; i < MAX_BANK_SIZE; ++i)
bankList[i] = string();
string qry = string("select banknum, name from banks order by banknum");
sqlite3_stmt *stmt = NULL;
@@ -246,7 +246,7 @@ void ProgramBanks::loadBankList(void)
void ProgramBanks::loadProgramList(unsigned char bk)
{
programList.clear();
- for (int i = 0; i < BANK_LIMIT; ++i)
+ for (int i = 0; i < MAX_BANK_SIZE; ++i)
programList[i] = string();
string qry = string("select prognum, name from programs where banknum=")
+ asString(bk) + string(" order by prognum");
diff -burp yoshimi.062/src/Sql/ProgramBanks.h
yoshimi.062.jn005/src/Sql/ProgramBanks.h
--- yoshimi.062/src/Sql/ProgramBanks.h 2012-02-22 16:36:26.000000000 -0500
+++ yoshimi.062.jn005/src/Sql/ProgramBanks.h 2012-02-23 03:55:32.000000000
-0500
@@ -17,8 +17,8 @@
along with yoshimi. If not, see <http://www.gnu.org/licenses/>.
*/

-#ifndef BANK_H
-#define BANK_H
+#ifndef PROGRAMBANKS_H
+#define PROGRAMBANKS_H

#include <map>
#include <sqlite3.h>
diff -burp yoshimi.062/src/Synth/ADnote.cpp
yoshimi.062.jn005/src/Synth/ADnote.cpp
--- yoshimi.062/src/Synth/ADnote.cpp 2012-02-22 16:36:26.000000000 -0500
+++ yoshimi.062.jn005/src/Synth/ADnote.cpp 2012-02-23 13:31:00.000000000
-0500
@@ -898,7 +898,7 @@ void ADnote::initParameters()


// Get Voice's Modullator base frequency
-float ADnote::getFMVoiceBaseFreq(int nvoice) const
+float ADnote::getFMVoiceBaseFreq(int nvoice)
{
//float detune = NoteVoicePar[nvoice].FMDetune / 100.0f;
return getVoiceBaseFreq(nvoice) * powf(2.0f,
(NoteVoicePar[nvoice].FMDetune / 100.0f) / 12.0f);
@@ -925,7 +925,7 @@ void ADnote::computeUnisonFreqRap(int nv
pos = -1.0f;
step = -step;
}
- if (pos >= 1.0f)
+ else if (pos >= 1.0f)
{
pos = 1.0f;
step = -step;
@@ -950,7 +950,7 @@ void ADnote::setfreq(int nvoice, float i
speed = synth->oscilsize_f;

//F2I(speed, oscfreqhi[nvoice][k]);
- oscfreqhi[nvoice][k] = (speed > 0.0f) ? lrintf(speed) : lrintf(speed -
1.0f);
+ oscfreqhi[nvoice][k] = (speed >= 0.0) ? lrintf(speed) : lrintf(speed -
1.0);
oscfreqlo[nvoice][k] = speed - floorf(speed);
}
}
@@ -966,14 +966,14 @@ void ADnote::setfreqFM(int nvoice, float
speed = synth->oscilsize_f;

//F2I(speed, oscfreqhiFM[nvoice][k]);
- oscfreqhiFM[nvoice][k] = (speed > 0.0f) ? lrintf(speed) : lrintf(speed
- 1.0f);
+ oscfreqloFM[nvoice][k] = (speed >= 0.0) ? lrintf(speed) : lrintf(speed
- 1.0);
oscfreqloFM[nvoice][k] = speed - floorf(speed);
}
}


// Get Voice base frequency
-float ADnote::getVoiceBaseFreq(int nvoice) const
+float ADnote::getVoiceBaseFreq(int nvoice)
{
float detune =
NoteVoicePar[nvoice].Detune / 100.0f + NoteVoicePar[nvoice].FineDetune
/ 100.0f * ctl->bandwidth.relbw * bandwidthDetuneMultiplier +
NoteGlobalPar.Detune / 100.0f;
@@ -1058,8 +1058,7 @@ void ADnote::computeCurrentParameters(vo
if (NoteVoicePar[nvoice].FilterLfo != NULL)
filterpitch += NoteVoicePar[nvoice].FilterLfo->lfoout();
filterfreq = filterpitch + NoteVoicePar[nvoice].FilterFreqTracking;
- filterfreq = NoteVoicePar[nvoice].VoiceFilterL->getrealfreq(
- filterfreq);
+ filterfreq =
NoteVoicePar[nvoice].VoiceFilterL->getrealfreq(filterfreq);
NoteVoicePar[nvoice].VoiceFilterL->setfreq(filterfreq);
if (stereo && NoteVoicePar[nvoice].VoiceFilterR)
NoteVoicePar[nvoice].VoiceFilterR->setfreq(filterfreq);
@@ -1072,8 +1071,7 @@ void ADnote::computeCurrentParameters(vo
voicepitch += NoteVoicePar[nvoice].FreqLfo->lfoout() / 100.0f
* ctl->bandwidth.relbw;

if (NoteVoicePar[nvoice].FreqEnvelope != NULL)
- voicepitch += NoteVoicePar[nvoice].FreqEnvelope->envout()
- / 100.0f;
+ voicepitch += NoteVoicePar[nvoice].FreqEnvelope->envout() /
100.0f;
voicefreq = getVoiceBaseFreq(nvoice)
* powf(2.0f, (voicepitch + globalpitch) / 12.0f); //
Hz frequency
voicefreq *= ctl->pitchwheel.relfreq; //change the frequency by
the controller
@@ -1100,7 +1098,7 @@ void ADnote::computeCurrentParameters(vo
}

// Fadein in a way that removes clicks but keep sound "punchy"
-void ADnote::fadein(float *smps) const
+void ADnote::fadein(float *smps)
{
int zerocrossings = 0;
for (int i = 1; i < synth->buffersize; ++i)
@@ -1112,12 +1110,12 @@ void ADnote::fadein(float *smps) const
tmp = 8.0f;

//F2I(tmp, n); // how many samples is the fade-in
- int n = (tmp > 0.0f) ? lrintf(tmp) : lrintf(tmp - 1.0f);
+ int n = (tmp > 0.0) ? lrintf(tmp) : lrintf(tmp - 1.0);
if (n > synth->buffersize)
n = synth->buffersize;
for (int i = 0; i < n; ++i) // fade-in
{
- float tmp = 0.5f - cosf((float)i / (float) n * PI) * 0.5f;
+ float tmp = 0.5f - cosf((float)i / (float)n * PI) * 0.5f;
smps[i] *= tmp;
}
}
@@ -1230,7 +1228,8 @@ void ADnote::computeVoiceOscillatorRingM
FMnewamplitude[nvoice],
i, synth->buffersize);
int FMVoice = NoteVoicePar[nvoice].FMVoice;
- for (i = 0; i < synth->buffersize; ++i)
+ // !!! another case of i being incorrectly clobbered??
+ // for (i = 0; i < synth->buffersize; ++i)
tw[i] *= (1.0f - amp) + amp *
NoteVoicePar[FMVoice].VoiceOut[i];
}
}
@@ -1269,8 +1268,8 @@ void ADnote::computeVoiceOscillatorFrequ
{
int carposhi = 0;
int i, FMmodfreqhi = 0;
- float FMmodfreqlo = 0;
- float carposlo = 0;
+ float FMmodfreqlo = 0.0;
+ float carposlo = 0.0;

if (NoteVoicePar[nvoice].FMVoice >= 0)
{
@@ -1367,7 +1366,7 @@ void ADnote::computeVoiceOscillatorFrequ
for (i = 0; i < synth->buffersize; ++i)
{
// F2I(tw[i], FMmodfreqhi);
- FMmodfreqhi = (tw[i] > 0.0f) ? lrintf(tw[i]) : lrintf(tw[i] -
1.0f);
+ FMmodfreqhi = (tw[i] > 0.0) ? lrintf(tw[i]) : lrintf(tw[i] - 1.0);
FMmodfreqlo = fmodf(tw[i] + 0.0000000001f, 1.0f);
if (FMmodfreqhi < 0)
FMmodfreqlo++;
@@ -1470,7 +1469,7 @@ int ADnote::noteout(float *outl, float *
float *tw = tmpwave_unison[k];
if (stereo)
{
- float stereo_pos = 0;
+ float stereo_pos = 0.0f;
if (unison_size[nvoice] > 1)
stereo_pos = k / (float)(unison_size[nvoice] - 1) * 2.0f -
1.0f;
float stereo_spread = unison_stereo_spread[nvoice] * 2.0f;
//between 0 and 2.0
@@ -1741,8 +1740,8 @@ int ADnote::noteout(float *outl, float *
{
//for (int j = i; j < synth->buffersize; j++)
//{
- // outl[j] = 0.0;
- // outr[j] = 0.0;
+ // outl[j] = 0.0f;
+ // outr[j] = 0.0f;
//}
memset(outl, 0, synth->buffersize * sizeof(float));
memset(outr, 0, synth->buffersize * sizeof(float));
diff -burp yoshimi.062/src/Synth/ADnote.h yoshimi.062.jn005/src/Synth/ADnote.h
--- yoshimi.062/src/Synth/ADnote.h 2012-02-22 16:36:26.000000000 -0500
+++ yoshimi.062.jn005/src/Synth/ADnote.h 2012-02-23 11:52:57.000000000
-0500
@@ -63,8 +63,8 @@ class ADnote : public Carcass, private S
void initParameters();
void killVoice(int nvoice);
void killNote();
- float getVoiceBaseFreq(int nvoice) const;
- float getFMVoiceBaseFreq(int nvoice) const;
+ float getVoiceBaseFreq(int nvoice);
+ float getFMVoiceBaseFreq(int nvoice);
void computeVoiceOscillator_LinearInterpolation(int nvoice);
void computeVoiceOscillator_CubicInterpolation(int nvoice);
void computeVoiceOscillatorMorph(int nvoice);
@@ -76,7 +76,7 @@ class ADnote : public Carcass, private S

void computeVoiceNoise(int nvoice);

- void fadein(float *smps) const;
+ void fadein(float *smps);


// Globals
diff -burp yoshimi.062/src/Synth/OscilGen.cpp
yoshimi.062.jn005/src/Synth/OscilGen.cpp
--- yoshimi.062/src/Synth/OscilGen.cpp 2012-02-22 16:36:26.000000000 -0500
+++ yoshimi.062.jn005/src/Synth/OscilGen.cpp 2012-02-23 13:17:21.000000000
-0500
@@ -658,18 +658,18 @@ void OscilGen::modulation(void)
break;
case 2:
modulationpar1 = (powf(2.0f, modulationpar1 * 7.0f) - 1.0f) /
100.0f;
- modulationpar3 = 1.0f + floorf((powf(2, modulationpar3 * 5.0f) -
1.0f));
+ modulationpar3 = 1.0f + floorf((powf(2.0f, modulationpar3 * 5.0f)
- 1.0f));
break;
case 3:
modulationpar1 = (powf(2.0f, modulationpar1 * 9.0f) - 1.0f) /
100.0f;
- modulationpar3 = 0.01f + (powf(2, modulationpar3 * 16.0f) - 1.0f)
/ 10.0f;
+ modulationpar3 = 0.01f + (powf(2.0f, modulationpar3 * 16.0f) -
1.0f) / 10.0f;
break;
}

int eighth_i = synth->oscilsize / 8;
float eighth_f = synth->oscilsize_f / 8.0f;

- oscilFFTfreqs.c[0] = 0.0; // remove the DC
+ oscilFFTfreqs.c[0] = 0.0f; // remove the DC
// reduce the amplitude of the freqs near the nyquist
for (int i = 1; i < eighth_i; ++i)
{
diff -burp yoshimi.062/src/UI/OscilGenUI.fl
yoshimi.062.jn005/src/UI/OscilGenUI.fl
--- yoshimi.062/src/UI/OscilGenUI.fl 2012-02-22 16:36:26.000000000 -0500
+++ yoshimi.062.jn005/src/UI/OscilGenUI.fl 2012-02-23 06:43:00.000000000
-0500
@@ -174,7 +174,7 @@ class OscilSpectrum {open : {public Fl_B

class PSlider {open : {public Fl_Slider}
} {
- Function {PSlider(int x,int y, int w, int h, const char
*label=0):Fl_Slider(x,y,w,h,label)} {} {}
+ Function {PSlider(int x,int y, int w, int h, const char
*label=0):Fl_Slider(x,y,w,h,label)} {} {code{;}}
Function {handle(int event)} {open return_type int
} {
code {//
diff -burp yoshimi.062/src/UI/PresetsUI.fl yoshimi.062.jn005/src/UI/PresetsUI.fl
--- yoshimi.062/src/UI/PresetsUI.fl 2012-02-22 16:36:26.000000000 -0500
+++ yoshimi.062.jn005/src/UI/PresetsUI.fl 2012-02-23 06:41:23.000000000
-0500
@@ -40,9 +40,9 @@ decl {\#include <string>
class PresetsUI_ {open
} {
Function {refresh(void)} {return_type {virtual void}
- } {}
+ } {code{;}}
Function {~PresetsUI_()} {return_type virtual
- } {}
+ } {code{;}}
}

class PresetsUI {open

Other related posts:

  • » [yoshimi-user] Patch to fix pitch problem in 0.062 - jimmy