From 083585e25f881f99b4f4d3a3b9a2f109daa7ec57 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 26 Apr 2009 11:28:26 +0300 Subject: [PATCH] detune type enum constants --- addnote.cpp | 63 +++++++++++++++++++++++++----------------------------------- addsynth.cpp | 6 +++--- common.h | 6 ++++++ util.c | 17 +++++++++------- util.h | 7 +++++-- 5 files changed, 50 insertions(+), 49 deletions(-) diff --git a/addnote.cpp b/addnote.cpp index 4bb6ca0..1ef62d3 100644 --- a/addnote.cpp +++ b/addnote.cpp @@ -279,7 +279,7 @@ zyn_addnote_create( note_ptr->stereo = synth_ptr->stereo; - note_ptr->detune = getdetune( + note_ptr->detune = zyn_get_detune( synth_ptr->detune.type, synth_ptr->detune.coarse, synth_ptr->detune.fine); @@ -835,6 +835,7 @@ zyn_addnote_note_on( float filter_velocity_adjust; int voice_oscillator_index; REALTYPE tmp; + unsigned char detune_type; note_ptr->portamento = portamento; note_ptr->midinote = midinote; @@ -911,53 +912,41 @@ zyn_addnote_note_on( note_ptr->voices_ptr[voice_index].enabled = true; note_ptr->voices_ptr[voice_index].fixed_detune = note_ptr->synth_ptr->voices_params_ptr[voice_index].fixed_detune; - // use the Globalpars.detunetype if the detunetype is 0 - if (note_ptr->synth_ptr->voices_params_ptr[voice_index].detune.type != 0) + // calculate voice detune { - // coarse detune - note_ptr->voices_ptr[voice_index].Detune = - getdetune( - note_ptr->synth_ptr->voices_params_ptr[voice_index].detune.type, - note_ptr->synth_ptr->voices_params_ptr[voice_index].detune.coarse, - 8192); + if (note_ptr->synth_ptr->voices_params_ptr[voice_index].detune.type == ZYN_DETUNE_TYPE_GLOBAL) + { + detune_type = note_ptr->synth_ptr->detune.type; + } + else + { + detune_type = note_ptr->synth_ptr->voices_params_ptr[voice_index].detune.type; + } - // fine detune - note_ptr->voices_ptr[voice_index].FineDetune = - getdetune( - note_ptr->synth_ptr->voices_params_ptr[voice_index].detune.type, - 0, - note_ptr->synth_ptr->voices_params_ptr[voice_index].detune.fine); - } - else - { // coarse detune - note_ptr->voices_ptr[voice_index].Detune = getdetune( - note_ptr->synth_ptr->detune.type, - note_ptr->synth_ptr->voices_params_ptr[voice_index].detune.coarse, - 8192); + note_ptr->voices_ptr[voice_index].Detune = zyn_get_detune(detune_type, note_ptr->synth_ptr->voices_params_ptr[voice_index].detune.coarse, 8192); // fine detune - note_ptr->voices_ptr[voice_index].FineDetune = getdetune( - note_ptr->synth_ptr->detune.type, - 0, - note_ptr->synth_ptr->voices_params_ptr[voice_index].detune.fine); + note_ptr->voices_ptr[voice_index].FineDetune = zyn_get_detune(detune_type, 0, note_ptr->synth_ptr->voices_params_ptr[voice_index].detune.fine); } - if (note_ptr->synth_ptr->voices_params_ptr[voice_index].fm_detune.type != 0) + // calculate voice fm detune { - note_ptr->voices_ptr[voice_index].FMDetune = - getdetune( - note_ptr->synth_ptr->voices_params_ptr[voice_index].fm_detune.type, + if (note_ptr->synth_ptr->voices_params_ptr[voice_index].fm_detune.type == ZYN_DETUNE_TYPE_GLOBAL) + { + detune_type = note_ptr->synth_ptr->detune.type; + } + else + { + detune_type = note_ptr->synth_ptr->voices_params_ptr[voice_index].fm_detune.type; + } + + note_ptr->voices_ptr[voice_index].FMDetune = + zyn_get_detune( + detune_type, note_ptr->synth_ptr->voices_params_ptr[voice_index].fm_detune.coarse, note_ptr->synth_ptr->voices_params_ptr[voice_index].fm_detune.fine); } - else - { - note_ptr->voices_ptr[voice_index].FMDetune = getdetune( - note_ptr->synth_ptr->detune.type, - note_ptr->synth_ptr->voices_params_ptr[voice_index].fm_detune.coarse, - note_ptr->synth_ptr->voices_params_ptr[voice_index].fm_detune.fine); - } note_ptr->osc_pos_hi_ptr[voice_index] = 0; note_ptr->osc_pos_lo_ptr[voice_index] = 0.0; diff --git a/addsynth.cpp b/addsynth.cpp index 6c8c8a8..cedb7b7 100644 --- a/addsynth.cpp +++ b/addsynth.cpp @@ -179,7 +179,7 @@ zyn_addsynth_create( // zyn_addsynth_ptr->GlobalPar.stereo = true; // Stereo zyn_addsynth_ptr->detune.fine = 8192;//zero zyn_addsynth_ptr->detune.coarse = 0; - zyn_addsynth_ptr->detune.type = 1; + zyn_addsynth_ptr->detune.type = ZYN_DETUNE_TYPE_L35CENTS; zyn_addsynth_ptr->detune_bandwidth = 0.0; /* Amplitude Global Parameters */ @@ -213,7 +213,7 @@ zyn_addsynth_create( zyn_addsynth_ptr->voices_params_ptr[voice_index].PPanning=64;//center zyn_addsynth_ptr->voices_params_ptr[voice_index].detune.fine = 8192;//8192=0 zyn_addsynth_ptr->voices_params_ptr[voice_index].detune.coarse = 0; - zyn_addsynth_ptr->voices_params_ptr[voice_index].detune.type = 0; + zyn_addsynth_ptr->voices_params_ptr[voice_index].detune.type = ZYN_DETUNE_TYPE_GLOBAL; zyn_addsynth_ptr->voices_params_ptr[voice_index].PFreqLfoEnabled=0; zyn_addsynth_ptr->voices_params_ptr[voice_index].PFreqEnvelopeEnabled=0; zyn_addsynth_ptr->voices_params_ptr[voice_index].PAmpEnvelopeEnabled=0; @@ -231,7 +231,7 @@ zyn_addsynth_create( zyn_addsynth_ptr->voices_params_ptr[voice_index].PFMVolumeDamp=64; zyn_addsynth_ptr->voices_params_ptr[voice_index].fm_detune.fine = 8192; zyn_addsynth_ptr->voices_params_ptr[voice_index].fm_detune.coarse = 0; - zyn_addsynth_ptr->voices_params_ptr[voice_index].fm_detune.type = 0; + zyn_addsynth_ptr->voices_params_ptr[voice_index].fm_detune.type = ZYN_DETUNE_TYPE_GLOBAL; zyn_addsynth_ptr->voices_params_ptr[voice_index].PFMFreqEnvelopeEnabled=0; zyn_addsynth_ptr->voices_params_ptr[voice_index].PFMAmpEnvelopeEnabled=0; zyn_addsynth_ptr->voices_params_ptr[voice_index].PFMVelocityScaleFunction=64; diff --git a/common.h b/common.h index 2b9b3b9..6d6692c 100644 --- a/common.h +++ b/common.h @@ -112,6 +112,12 @@ #define ZYN_OSCILLATOR_SPECTRUM_ADJUST_TYPE_THERSHOLD_UP 3 #define ZYN_OSCILLATOR_SPECTRUM_ADJUST_TYPES_COUNT 4 +#define ZYN_DETUNE_TYPE_GLOBAL 0 /* use global detune type, valid only for voice parameters */ +#define ZYN_DETUNE_TYPE_L35CENTS 1 +#define ZYN_DETUNE_TYPE_L10CENTS 2 +#define ZYN_DETUNE_TYPE_E100CENTS 3 +#define ZYN_DETUNE_TYPE_E1200CENTS 4 + #ifdef __cplusplus extern "C" { #endif diff --git a/util.c b/util.c index 9252890..d7c7278 100644 --- a/util.c +++ b/util.c @@ -20,6 +20,7 @@ #include #include +#include #include "common.h" #include "util.h" @@ -67,7 +68,7 @@ zyn_velocity_scale(float velocity, float scaling) * Get the detune in cents */ REALTYPE -getdetune( +zyn_get_detune( unsigned char type, unsigned short int coarsedetune, unsigned short int finedetune) @@ -96,22 +97,24 @@ getdetune( switch (type) { -// case 1: is used for the default (see below) - case 2: + case ZYN_DETUNE_TYPE_L35CENTS: + cdet = fabs(cdetune * 50.0); + findet = fabs(fdetune / 8192.0) * 35.0; // almost like "Paul's Sound Designer 2" + case ZYN_DETUNE_TYPE_L10CENTS: cdet = fabs(cdetune * 10.0); findet = fabs(fdetune / 8192.0) * 10.0; break; - case 3: + case ZYN_DETUNE_TYPE_E100CENTS: cdet = fabs(cdetune * 100); findet = pow(10, fabs(fdetune / 8192.0) * 3.0) / 10.0 - 0.1; break; - case 4: + case ZYN_DETUNE_TYPE_E1200CENTS: cdet = fabs(cdetune * 701.95500087); // perfect fifth findet = (pow(2, fabs(fdetune / 8192.0) * 12.0) - 1.0) / 4095 * 1200; break; default: - cdet = fabs(cdetune * 50.0); - findet = fabs(fdetune / 8192.0) * 35.0; // almost like "Paul's Sound Designer 2" + assert(0); + return 0; } if (finedetune < 8192) diff --git a/util.h b/util.h index 0cd1c31..398ed2d 100644 --- a/util.h +++ b/util.h @@ -36,8 +36,11 @@ extern REALTYPE VelF(REALTYPE velocity,unsigned char scaling); float zyn_velocity_scale(float velocity, float scaling); -#define N_DETUNE_TYPES 4 //the number of detune types -extern REALTYPE getdetune(unsigned char type,unsigned short int coarsedetune,unsigned short int finedetune); +REALTYPE +zyn_get_detune( + unsigned char type, + unsigned short int coarsedetune, + unsigned short int finedetune); void silence_buffer( -- 2.11.4.GIT