@ -50,11 +50,13 @@ int32_t osc_freq(int midinote, int mode, int coarse, int fine, int detune) {
// (1 << 24) / log(2)
// (1 << 24) / log(2)
logfreq + = ( int32_t ) floor ( 24204406.323123 * log ( 1 + 0.01 * fine ) + 0.5 ) ;
logfreq + = ( int32_t ) floor ( 24204406.323123 * log ( 1 + 0.01 * fine ) + 0.5 ) ;
}
}
// TODO: detune
// This was measured at 7.213Hz per count at 9600Hz, but the exact
// value is somewhat dependent on midinote. Close enough for now.
logfreq + = 12606 * ( detune - 7 ) ;
} else {
} else {
// ((1 << 24) * log(10) / log(2) * .01) << 3
// ((1 << 24) * log(10) / log(2) * .01) << 3
logfreq = ( 4458616 * ( ( coarse & 3 ) * 100 + fine ) ) > > 3 ;
logfreq = ( 4458616 * ( ( coarse & 3 ) * 100 + fine ) ) > > 3 ;
// TODO: detune
logfreq + = detune > 7 ? 13457 * ( detune - 7 ) : 0 ;
}
}
int32_t base_freq = Freqlut : : lookup ( logfreq ) ;
int32_t base_freq = Freqlut : : lookup ( logfreq ) ;
return base_freq ;
return base_freq ;
@ -122,8 +124,7 @@ int ScaleLevel(int midinote, int break_pt, int left_depth, int right_depth,
}
}
}
}
// Considering making this an init method...
void Dx7Note : : init ( const char bulk [ 128 ] , int midinote , int velocity ) {
Dx7Note : : Dx7Note ( const char bulk [ 128 ] , int midinote , int velocity ) {
char patch [ 156 ] ;
char patch [ 156 ] ;
UnpackPatch ( bulk , patch ) ; // TODO: move this out, take unpacked patch
UnpackPatch ( bulk , patch ) ; // TODO: move this out, take unpacked patch
for ( int op = 0 ; op < 6 ; op + + ) {
for ( int op = 0 ; op < 6 ; op + + ) {
@ -135,6 +136,7 @@ Dx7Note::Dx7Note(const char bulk[128], int midinote, int velocity) {
levels [ i ] = patch [ off + 4 + i ] ;
levels [ i ] = patch [ off + 4 + i ] ;
}
}
int outlevel = patch [ off + 16 ] ;
int outlevel = patch [ off + 16 ] ;
outlevel = Env : : scaleoutlevel ( outlevel ) ;
# ifdef VERBOSE
# 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 ] < < " " ;
@ -143,7 +145,7 @@ Dx7Note::Dx7Note(const char bulk[128], int midinote, int velocity) {
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 ] , patch [ off + 12 ] ) ;
patch [ off + 10 ] , patch [ off + 11 ] , patch [ off + 12 ] ) ;
outlevel + = level_scaling ;
outlevel + = level_scaling ;
outlevel = min ( 99 , outlevel ) ;
outlevel = min ( 127 , outlevel ) ;
# ifdef VERBOSE
# ifdef VERBOSE
cout < < op < < " : " < < level_scaling < < " " < < outlevel < < endl ;
cout < < op < < " : " < < level_scaling < < " " < < outlevel < < endl ;
# endif
# endif