@ -14,7 +14,9 @@
* limitations under the License .
* limitations under the License .
*/
*/
# ifdef VERBOSE
# include <iostream>
# include <iostream>
# endif
# include <math.h>
# include <math.h>
# include "synth.h"
# include "synth.h"
# include "freqlut.h"
# include "freqlut.h"
@ -66,14 +68,14 @@ const uint8_t velocity_data[64] = {
// See "velocity" section of notes. Returns velocity delta in microsteps.
// See "velocity" section of notes. Returns velocity delta in microsteps.
int ScaleVelocity ( int velocity , int sensitivity ) {
int ScaleVelocity ( int velocity , int sensitivity ) {
int clamped_vel = std : : max ( 0 , std : : min ( 127 , velocity ) ) ;
int clamped_vel = max ( 0 , min ( 127 , velocity ) ) ;
int vel_value = velocity_data [ clamped_vel > > 1 ] - 239 ;
int vel_value = velocity_data [ clamped_vel > > 1 ] - 239 ;
int scaled_vel = ( ( sensitivity * vel_value + 7 ) > > 3 ) < < 4 ;
int scaled_vel = ( ( sensitivity * vel_value + 7 ) > > 3 ) < < 4 ;
return scaled_vel ;
return scaled_vel ;
}
}
int ScaleRate ( int midinote , int sensitivity ) {
int ScaleRate ( int midinote , int sensitivity ) {
int x = std : : min ( 31 , std : : max ( 0 , midinote / 3 - 7 ) ) ;
int x = min ( 31 , max ( 0 , midinote / 3 - 7 ) ) ;
int qratedelta = ( sensitivity * x ) > > 3 ;
int qratedelta = ( sensitivity * x ) > > 3 ;
# ifdef SUPER_PRECISE
# ifdef SUPER_PRECISE
int rem = x & 7 ;
int rem = x & 7 ;
@ -99,7 +101,7 @@ int ScaleCurve(int group, int depth, int curve) {
} else {
} else {
// exponential
// exponential
int n_scale_data = sizeof ( exp_scale_data ) ;
int n_scale_data = sizeof ( exp_scale_data ) ;
int raw_exp = exp_scale_data [ std : : min ( group , n_scale_data - 1 ) ] ;
int raw_exp = exp_scale_data [ min ( group , n_scale_data - 1 ) ] ;
scale = ( raw_exp * depth * 329 ) > > 15 ;
scale = ( raw_exp * depth * 329 ) > > 15 ;
}
}
if ( curve < 2 ) {
if ( curve < 2 ) {
@ -129,17 +131,21 @@ Dx7Note::Dx7Note(const char patch[128], int midinote, int velocity) {
levels [ i ] = patch [ off + 4 + i ] ;
levels [ i ] = patch [ off + 4 + i ] ;
}
}
int outlevel = patch [ off + 14 ] ;
int outlevel = patch [ off + 14 ] ;
# ifdef VERBOSE
for ( int j = 8 ; j < 12 ; j + + ) {
for ( int j = 8 ; j < 12 ; j + + ) {
cout < < ( int ) patch [ off + j ] < < " " ;
cout < < ( int ) patch [ off + j ] < < " " ;
}
}
# endif
int level_scaling = ScaleLevel ( midinote , patch [ off + 8 ] , patch [ off + 9 ] ,
int level_scaling = ScaleLevel ( midinote , patch [ off + 8 ] , patch [ off + 9 ] ,
patch [ off + 10 ] , patch [ off + 11 ] & 3 , patch [ off + 11 ] > > 2 ) ;
patch [ off + 10 ] , patch [ off + 11 ] & 3 , patch [ off + 11 ] > > 2 ) ;
outlevel + = level_scaling ;
outlevel + = level_scaling ;
outlevel = std : : min ( 99 , outlevel ) ;
outlevel = min ( 99 , outlevel ) ;
# ifdef VERBOSE
cout < < op < < " : " < < level_scaling < < " " < < outlevel < < endl ;
cout < < op < < " : " < < level_scaling < < " " < < outlevel < < endl ;
# endif
outlevel = outlevel < < 5 ;
outlevel = outlevel < < 5 ;
outlevel + = ScaleVelocity ( velocity , patch [ off + 13 ] > > 2 ) ;
outlevel + = ScaleVelocity ( velocity , patch [ off + 13 ] > > 2 ) ;
outlevel = std : : max ( 0 , outlevel ) ;
outlevel = max ( 0 , outlevel ) ;
int rate_scaling = ScaleRate ( midinote , patch [ off + 12 ] & 7 ) ;
int rate_scaling = ScaleRate ( midinote , patch [ off + 12 ] & 7 ) ;
env_ [ op ] . init ( rates , levels , outlevel , rate_scaling ) ;
env_ [ op ] . init ( rates , levels , outlevel , rate_scaling ) ;