Skip to content

Commit

Permalink
fix tp fmb3 to initialise w_rates
Browse files Browse the repository at this point in the history
  • Loading branch information
jpffitch committed Dec 20, 2018
1 parent 4499dae commit c2bd7e4
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Opcodes/fluidOpcodes/fluidOpcodes.cpp
Expand Up @@ -225,7 +225,7 @@ class FluidLoad : public OpcodeBase<FluidLoad> {
OPARMS oparms;
csound->GetOParms(csound, &oparms);
if (oparms.msglevel & 0x7)
while ((fluidPreset = fluid_sfont_iteration_next(fluidSoundfont))) {
while ((fluidPreset = fluid_sfont_iteration_next(fluidSoundfont))) {
log(csound, "SoundFont: %3d Bank: %3d Preset: %3d %s\n",
soundFontId, fluid_preset_get_banknum(fluidPreset),
fluid_preset_get_num(fluidPreset),
Expand Down Expand Up @@ -310,7 +310,7 @@ class FluidInfo : public OpcodeBase<FluidInfo> {
OPARMS oparms;
csound->GetOParms(csound, &oparms);
if (oparms.msglevel & 0x7)
while ((fluidPreset = fluid_sfont_iteration_next(fluidSoundfont))) {
while ((fluidPreset = fluid_sfont_iteration_next(fluidSoundfont))) {
{
std::stringstream ss;
ss << "Bank: " << fluid_preset_get_banknum(fluidPreset) <<
Expand Down
12 changes: 10 additions & 2 deletions Opcodes/fm4op.c
Expand Up @@ -160,6 +160,7 @@ int32_t make_FM4Op(CSOUND *csound, FM4OP *p)
p->gains[3] = FL(1.0);
TwoZero_setZeroCoeffs(&p->twozero, tempCoeffs);
p->twozero.gain = FL(0.0);
p->w_phase[3] = 0; /* *** FIDDLE???? *** */
return OK;
err1:
/* Expect sine wave */
Expand Down Expand Up @@ -641,6 +642,10 @@ int32_t b3set(CSOUND *csound, FM4OP *p)
ADSR_keyOn(&p->adsr[1]);
ADSR_keyOn(&p->adsr[2]);
ADSR_keyOn(&p->adsr[3]);
p->w_rate[0] = p->ratios[0] * p->baseFreq * csound->onedsr * p->waves[0]->flen;
p->w_rate[1] = p->ratios[1] * p->baseFreq * csound->onedsr * p->waves[1]->flen;
p->w_rate[2] = p->ratios[2] * p->baseFreq * csound->onedsr * p->waves[2]->flen;
p->w_rate[3] = p->ratios[3] * p->baseFreq * csound->onedsr * p->waves[3]->flen;
return OK;
}

Expand All @@ -654,6 +659,7 @@ int32_t hammondB3(CSOUND *csound, FM4OP *p)
MYFLT c1 = *p->control1;
MYFLT c2 = *p->control2;
MYFLT temp;
MYFLT moddep = *p->modDepth;

p->baseFreq = *p->frequency;
p->gains[0] = amp * FM4Op_gains[95];
Expand All @@ -667,9 +673,9 @@ int32_t hammondB3(CSOUND *csound, FM4OP *p)
}
for (n=offset;n<nsmps;n++) {
MYFLT lastOutput;
if (*p->modDepth > FL(0.0)) {
if (moddep > FL(0.0)) {
p->v_rate = *p->vibFreq * p->vibWave->flen * csound->onedsr;
temp = FL(1.0) + (*p->modDepth * FL(0.1) *
temp = FL(1.0) + (moddep * FL(0.1) *
Wave_tick(&p->v_time, (int32_t)p->vibWave->flen,
p->vibWave->ftable, p->v_rate, FL(0.0)));
temp *= p->baseFreq * csound->onedsr;
Expand All @@ -678,6 +684,8 @@ int32_t hammondB3(CSOUND *csound, FM4OP *p)
p->w_rate[2] = p->ratios[2] * temp * p->waves[2]->flen;
p->w_rate[3] = p->ratios[3] * temp * p->waves[3]->flen;
}
// *** if modDepth is zero it looks as if w_rate should be initialised
// *** but it make no difference ***
lastOutput = FM4Alg8_tick(p, c1, c2);
ar[n]= lastOutput*AMP_SCALE;
}
Expand Down
4 changes: 2 additions & 2 deletions Opcodes/fm4op.h
Expand Up @@ -59,7 +59,7 @@ typedef struct TwoZero {
/* ********************************************************************** */

typedef struct FM4OP {
OPDS h;
OPDS h;
MYFLT *ar; /* Output */
MYFLT *amp, *frequency;
MYFLT *control1, *control2, *modDepth; /* Control1 doubles as vowel */
Expand All @@ -82,7 +82,7 @@ typedef struct FM4OP {
} FM4OP;

typedef struct FM4OPV {
OPDS h;
OPDS h;
MYFLT *ar; /* Output */
MYFLT *amp, *frequency;
MYFLT *control1, *control2, *modDepth; /* Control1 doubles as vowel */
Expand Down
10 changes: 5 additions & 5 deletions Opcodes/ftsamplebank.cpp
Expand Up @@ -145,12 +145,12 @@ int loadSamplesToTables(CSOUND *csound, int index, char *directory,
while ((ent = readdir(dir)) != NULL) {
std::ostringstream fullFileName;
// only use supported file types
for (int i = 0; (size_t)i < fileExtensions.size(); i++)
for (int i = 0; (size_t)i < fileExtensions.size(); i++)
{
std::string fname = ent->d_name;
std::string extension;
if(fname.find_last_of(".") != std::string::npos)
extension = fname.substr(fname.find_last_of(".")+1);
extension = fname.substr(fname.find_last_of(".")+1);

if(extension == fileExtensions[i])
{
Expand All @@ -160,7 +160,7 @@ int loadSamplesToTables(CSOUND *csound, int index, char *directory,
#else
fullFileName << directory << "/" << ent->d_name;
#endif
}
}
else
fullFileName << ent->d_name;

Expand Down Expand Up @@ -294,8 +294,8 @@ std::vector<std::string> searchDir(CSOUND *csound, char *directory,

std::string fname = ent->d_name;
size_t lastPos = fname.find_last_of(".");
if (fname.length() > 2 && (fileExtension.empty() ||
(lastPos != std::string::npos &&
if (fname.length() > 2 && (fileExtension.empty() ||
(lastPos != std::string::npos &&
fname.substr(lastPos) == fileExtension))) {
if (strlen(directory) > 2) {
#if defined(WIN32)
Expand Down
12 changes: 6 additions & 6 deletions Opcodes/grain.c
Expand Up @@ -105,15 +105,15 @@ static int32_t ags(CSOUND *csound, PGRA *p) /* Granular U.G. a-rate main routin
gcvt = glen/csound->GetSr(csound);

pow2tab = ISPOW2(glen);

etp = p->eftp;
etbl = etp->ftable;
elen = etp->flen;
ecvt = elen/csound->GetSr(csound);

lb = gtp->lobits;
lb2 = etp->lobits;

buf = p->x;
rem = p->y;

Expand Down Expand Up @@ -141,7 +141,7 @@ static int32_t ags(CSOUND *csound, PGRA *p) /* Granular U.G. a-rate main routin
amp = *xamp + Unirand(csound, *p->kabnd);

temp = buf + i;
n = ekglen;
n = ekglen;
isc = (int32) Unirand(csound, p->pr);
isc2 = 0;
if(pow2tab) {
Expand All @@ -158,13 +158,14 @@ static int32_t ags(CSOUND *csound, PGRA *p) /* Granular U.G. a-rate main routin
/* VL 21/11/18 new code, floating-point indexing */
MYFLT gph = (MYFLT) isc;
MYFLT eph = FL(0.0);
MYFLT ginc = (*xlfr + Unirand(csound, *p->kbnd)) * gcvt;
MYFLT ginc = (*xlfr + Unirand(csound, *p->kbnd)) * gcvt;
do {
*temp++ += amp * gtbl[(int)gph] * etbl[(int)eph];
gph += ginc;
eph += einc;
while(gph < 0) gph += glen;
while(gph >= glen) gph -= glen;
/* *** Can eph ever be negative? only if einc negative *** * */
while(eph < 0) eph += elen;
while(eph >= elen) eph -= elen;
} while (--n);
Expand Down Expand Up @@ -204,4 +205,3 @@ int32_t grain_init_(CSOUND *csound)
(int32_t
) (sizeof(localops) / sizeof(OENTRY)));
}

2 changes: 1 addition & 1 deletion include/plugin.h
Expand Up @@ -962,7 +962,7 @@ template <std::size_t N, std::size_t M> struct Plugin : OPDS {

};


/** Fsig plugin template base class:
N outputs and M inputs
*/
Expand Down
22 changes: 11 additions & 11 deletions util/hetro.c
Expand Up @@ -100,7 +100,7 @@ typedef struct {
static int32_t writesdif(CSOUND*, HET*);
#endif
static double GETVAL(HET *, double *, int32);
static double sq(double);
//static double sq(double);
static void PUTVAL(HET *,double *, int32, double);
static int32_t hetdyn(CSOUND *csound, HET *, int32_t);
static void lpinit(HET*);
Expand Down Expand Up @@ -516,7 +516,7 @@ static void output_ph(HET *thishet,int32 smpl)
{ /* is taken to represent the freq. change. */
double delt_temp; /* the pairs are then comb filtered. */
double temp_a;

if ((temp_a=GETVAL(thishet,thishet->a_term,smpl)) == 0)
thishet->new_ph=
(-PI/FL(2.0))*sgn(GETVAL(thishet,thishet->b_term,smpl));
Expand All @@ -533,8 +533,8 @@ static void output_ph(HET *thishet,int32 smpl)
(TWOPI*thishet->delta_t));
if ((thishet->freq_c <= 1) || (smpl < 3)) {
PUTVAL(thishet,thishet->amp_av1,smpl,
(MYFLT)sqrt(sq(GETVAL(thishet,thishet->a_term,smpl))
+ sq(GETVAL(thishet,thishet->b_term,smpl))));
(MYFLT)hypot(GETVAL(thishet,thishet->a_term,smpl),
GETVAL(thishet,thishet->b_term,smpl)));
average(thishet, thishet->windsiz,thishet->amp_av1,thishet->amp_av2,smpl);
average(thishet, thishet->windsiz,thishet->amp_av2,thishet->amp_av3,smpl);
average(thishet, thishet->windsiz,thishet->amp_av3,thishet->r_ampl,smpl);
Expand All @@ -545,8 +545,8 @@ static void output_ph(HET *thishet,int32 smpl)
}
else {
PUTVAL(thishet,thishet->r_ampl,smpl,
(MYFLT)sqrt(sq(GETVAL(thishet,thishet->a_term,smpl))
+ sq(GETVAL(thishet,thishet->b_term,smpl))));
(MYFLT)hypot(GETVAL(thishet,thishet->a_term,smpl),
GETVAL(thishet,thishet->b_term,smpl)));
PUTVAL(thishet,thishet->a_avg,smpl,delt_temp);
}
}
Expand All @@ -573,10 +573,10 @@ static void output(HET *thishet, int32 smpl, int32_t hno, int32_t pnt)
}

/* If this function worthwhile? Need to coinsider recalculation */
inline static double sq(double num) /* RETURNS SQUARE OF ARGUMENT */
{
return (num * num);
}
/* inline static double sq(double num) /\* RETURNS SQUARE OF ARGUMENT *\/ */
/* { */
/* return (num * num); */
/* } */

static int32_t quit(CSOUND *csound, char *msg)
{
Expand Down Expand Up @@ -752,7 +752,7 @@ static int32_t filedump(HET *thishet, CSOUND *csound)
"\tpeakamp %d\n"),
h, mpoints, fpoints, pkamp);
}
csound->Message(csound, "%s%" PRId64 " %s%s\n", Str("wrote %"),
csound->Message(csound, "%s%" PRId64 " %s%s\n", Str("wrote "),
(int64_t)lenfil, Str("bytes to "), thishet->outfilnam);
csound->Free(csound, magout);
csound->Free(csound, frqout);
Expand Down

0 comments on commit c2bd7e4

Please sign in to comment.