OpenCores
URL https://opencores.org/ocsvn/sqmusic/sqmusic/trunk

Subversion Repositories sqmusic

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 14 to Rev 15
    Reverse comparison

Rev 14 → Rev 15

/sqmusic/trunk/memos/opn.ods Cannot display: file marked as a binary type. svn:mime-type = application/vnd.oasis.opendocument.spreadsheet
/sqmusic/trunk/sqm/sintable.cc
16,6 → 16,95
 
using namespace std;
 
#define ENV_BITS 10
#define ENV_LEN (1<<ENV_BITS)
#define ENV_STEP (128.0/ENV_LEN)
#define TL_RES_LEN (256) /* 8 bits addressing (real chip) */
#define SIN_BITS 10
#define SIN_LEN (1<<SIN_BITS)
#define SIN_MASK (SIN_LEN-1)
#define TL_TAB_LEN (13*2*TL_RES_LEN)
 
signed int tl_tab[TL_TAB_LEN];
unsigned int sin_tab[SIN_LEN];
 
void init_tables(void) // copied from fm.c
{
signed int i,x;
signed int n;
double o,m;
 
for (x=0; x<TL_RES_LEN; x++)
{
m = (1<<16) / pow(2, (x+1) * (ENV_STEP/4.0) / 8.0);
m = floor(m);
 
/* we never reach (1<<16) here due to the (x+1) */
/* result fits within 16 bits at maximum */
 
n = (int)m; /* 16 bits here */
n >>= 4; /* 12 bits here */
if (n&1) /* round to nearest */
n = (n>>1)+1;
else
n = n>>1;
/* 11 bits here (rounded) */
n <<= 2; /* 13 bits here (as in real chip) */
tl_tab[ x*2 + 0 ] = n;
tl_tab[ x*2 + 1 ] = -tl_tab[ x*2 + 0 ];
 
for (i=1; i<13; i++)
{
tl_tab[ x*2+0 + i*2*TL_RES_LEN ] = tl_tab[ x*2+0 ]>>i;
tl_tab[ x*2+1 + i*2*TL_RES_LEN ] = -tl_tab[ x*2+0 + i*2*TL_RES_LEN ];
}
}
 
for (i=0; i<SIN_LEN; i++)
{
/* non-standard sinus */
m = sin( ((i*2)+1) * M_PI / SIN_LEN ); /* checked against the real chip */
 
/* we never reach zero here due to ((i*2)+1) */
if (m>0.0)
o = 8*log(1.0/m)/log(2.0); /* convert to 'decibels' */
else
o = 8*log(-1.0/m)/log(2.0); /* convert to 'decibels' */
 
o = o / (ENV_STEP/4);
 
n = (int)(2.0*o);
if (n&1) /* round to nearest */
n = (n>>1)+1;
else
n = n>>1;
 
sin_tab[ i ] = n*2 + (m>=0.0? 0: 1 );
/*logerror("FM.C: sin [%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[i],tl_tab[sin_tab[i]]);*/
}
}
 
void dump_tl_tab() {
// cout.setf( ios::hex, ios::basefield );
for( int i=0; i<TL_TAB_LEN; i++ ) {
cout << i << " => " << tl_tab[i] << "\n";
}
}
 
void dump_sin_tab() {
// cout.setf( ios::hex, ios::basefield );
for( int i=0; i<SIN_LEN; i++ ) {
cout /*<< i << " => " */<< sin_tab[i] << "\n";
}
}
 
void dump_composite() {
// cout.setf( ios::hex, ios::basefield );
for( int i=0; i<SIN_LEN; i++ ) {
cout << sin_tab[i] << "," << tl_tab[ sin_tab[i] ] << "\n";
}
}
 
unsigned conv( double x ) {
double xmax = 0xFFFFF; // 20 bits, all ones
return (unsigned)(xmax* 20*log(x+0.5));
22,17 → 111,7
}
 
int main(void) {
const double pi = 3.141592654;
const double factor = pi / 1024;
cout.setf( ios::hex, ios::basefield );
for(double i=0; i<1024; i++ ) {
double sin_val = sin( (2*i+1)*factor );
double log_val = 8*log( 1/abs(sin_val) )/log(2);
int rounded_val = log_val*2;
rounded_val = rounded_val&1 ? (rounded_val>>1)+1 : rounded_val>>1;
unsigned int sin_tab = (rounded_val<<1) + (sin_val>=0.0? 0: 1);
cout << sin_val << " -> " << log_val << " dB2 " << " -> "
<< rounded_val << " -> " << sin_tab << "\n";
}
init_tables();
dump_composite();
return 0;
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.