From: Francois B <mrs...@us...> - 2006-10-10 23:46:50
|
Update of /cvsroot/openneo/openneo/firmware In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv10274 Modified Files: audio.c Log Message: More precise log function Index: audio.c =================================================================== RCS file: /cvsroot/openneo/openneo/firmware/audio.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** audio.c 22 Oct 2004 23:47:08 -0000 1.12 --- audio.c 10 Oct 2006 23:46:48 -0000 1.13 *************** *** 43,55 **** struct audio_settings { ! char volume; // [0,100] ! char balance; // [-18,18] ! char bass; // [-15dB, 15dB] ! char treble; // [-15dB, 15dB] ! char channels; // [0,8] ! char dac_mode; // [0,2] ! bool reversed; // 1 or 0 ! char pitch; // [-10,30] ! bool muted; }; --- 43,57 ---- struct audio_settings { ! char volume; // [0,100] ! char balance; // [-18,18] ! char bass; // [-15dB, 15dB] ! char treble; // [-15dB, 15dB] ! char channels; // [0,8] ! char dac_mode; // [0,2] ! bool reversed; // 1 or 0 ! char pitch; // [-10,30] ! bool muted; ! ! int added_gain; // dB x 100 }; *************** *** 178,181 **** --- 180,184 ---- current_audio.balance = balance; current_audio.muted = false; + current_audio.added_gain = 0; audio_set( AUDIO_PITCH, pitch ); //Sets the 44kHz PLL Offset *************** *** 191,206 **** /* I * 100 = (0x80000*100 - H*100 ) / 0x80000 */ // intensity range is [0,100] ! // boost is in dB ! static unsigned long mas_intensity2reg( int intensity, int boost ) { ! int r1 = 524288 * 100; ! int result = intensity * 524288; ! if( intensity == 0 ) ! return 0; ! result -= r1; ! result /= -100; ! return ((result & 0xfffff ) | 0x00080000); //Value is always negative } --- 194,240 ---- /* I * 100 = (0x80000*100 - H*100 ) / 0x80000 */ // intensity range is [0,100] ! ! static unsigned long mas_intensity2reg( int intensity ) { ! int r1 = 0x80000 * 100; ! int result; ! if( intensity == 0 ) ! return 0; ! ! result = intensity * 0x80000; ! ! result -= r1; ! result /= -100; ! return ((result & 0xfffff ) | 0x00080000); //Value is always negative ! } ! static unsigned long mas_db2reg( int db ) ! { ! return 0; ! } ! ! /* Converts a precentage to the corresponding dB value ! Ex: 95% -> -0.445 dB -> returns 44 ! ! Returns (db x 100) ! */ ! static int mas_intensity2db( int intensity ) ! { ! int tdb; ! ! tdb = logbase10( intensity ); ! tdb = tdb / 5; ! ! return tdb; ! } ! ! /* input is dB x 10 */ ! static int mas_tendb2reg( int dbx10 ) ! { ! int reg = 0x80000; ! ! ! return 0; } *************** *** 210,213 **** --- 244,254 ---- } + /* gain = dB x 100 */ + void audio_set_extra_gain( int gain ) + { + current_audio.added_gain = gain; + gain2device(); + } + void audio_set( int setting, int value ) { *************** *** 262,266 **** //Dac is used as an amp ! // Anything over 0x32 produces distortion in the sound dac_volume( 0x32 , 0x32, false ); } --- 303,307 ---- //Dac is used as an amp ! //Anything over 0x32 produces distortion in the sound dac_volume( 0x32 , 0x32, false ); } *************** *** 321,325 **** } ! //Apply changes gain2device(); } --- 362,366 ---- } ! //Apply volume change gain2device(); } *************** *** 388,431 **** } ! unsigned char tenthdb2reg(int db) { ! int val; ! ! /* For more details see page 7 of DAC manual */ ! if(db < -540) ! val = (db + 780) / 30; ! else ! val = (db + 660) / 15; ! ! return (unsigned char)val; } ! ! // intensity range is [0,100] ! // We convert the intensity to a value in tenths of dB ! // Then this value is converted to a DAC acceptable value ! // The boost value is in dB ! static unsigned char dac_intensity2reg( int intensity, int boost ) { ! int ratio, tenthdb; ! ! if( intensity == 0 ) ! return 0; ! ! //The dac can output 8 times the input [0 -> 800%] ! //We limit this to 6x ! ratio = intensity * 60; ! tenthdb = log10( ratio ); ! tenthdb = tenthdb / 50; ! ! //Add the boost value ! tenthdb += boost*10; ! ! //clip value to what the DAC can handle ! if( tenthdb < -750 ) ! tenthdb = -750; ! if( tenthdb > 180 ) ! tenthdb = 180; ! ! return tenthdb2reg( tenthdb ); } --- 429,473 ---- } ! // intensity range is [0,100] ! // We convert the intensity to a value in dB x 100 ! // The boost value is in dB x 1 ! static int dac_intensity2db( int intensity, int boost ) { ! int ratio; ! int tdb; // dB x 100; ! ! if( intensity == 0 ) ! return -7500; //-75 dB ! ! //The dac can output 8 times the input [0 -> 800%] ! //We limit this to 6x ! ratio = intensity * 6; ! tdb = logbase10( ratio ); ! tdb = tdb / 5; ! ! //Add the boost value ! tdb += boost*100; ! ! //clip value to what the DAC can handle ! if( tdb < -7500 ) ! tdb = -7500; ! else if( tdb > 1800 ) ! tdb = 1800; ! ! return tdb; } ! ! /* db is scaled by 100*/ ! static unsigned char dac_db2reg( int db ) { ! int val; ! ! /* For more details see page 7 of DAC manual */ ! if(db < -5400) ! val = (db + 7800) / 300; ! else ! val = (db + 6600) / 150; ! ! return (unsigned char)val; } *************** *** 437,441 **** int sub; int boost; ! //Prefactor for Bass and/or Treble boost = MAX((int)current_audio.bass, (int)current_audio.treble); --- 479,484 ---- int sub; int boost; ! int db; //db x 100 ! //Prefactor for Bass and/or Treble boost = MAX((int)current_audio.bass, (int)current_audio.treble); *************** *** 469,544 **** if( current_audio.dac_mode == AUDIO_MODE_ANALOG ){ ! // Calculate DAC 6 bit values ! if( left != right ){ ! dac_l = dac_intensity2reg( left, boost ); ! dac_r = dac_intensity2reg( right, boost ); ! } ! else ! dac_l = dac_r = dac_intensity2reg( left, boost ); ! //Because the DAC Line out -> RCA plugs are wired wrong, we need to switch the volume channels ! dac_volume( dac_r, dac_l, false); } else { // MAS Values ! ! switch( current_audio.channels ) { ! ! case AUDIO_STEREO_NARROW: ! mas_ll = mas_intensity2reg( (left*3)/4,0 ); //75% ! mas_lr = mas_intensity2reg( left/4,0 ); //25% ! mas_rl = mas_intensity2reg( right/4,0 ); ! mas_rr = mas_intensity2reg( (right*3)/4,0 ); ! break; ! ! case AUDIO_STEREO_WIDE: ! mas_ll = mas_intensity2reg( left,0 ); ! mas_lr = mas_intensity2reg( left/2,0 ); ! mas_rl = mas_intensity2reg( right/2,0 ); ! mas_rr = mas_intensity2reg( right,0 ); ! break; ! /* ! case AUDIO_KARAOKE: ! mas_ll = mas_intensity2reg( left ) + 1; ! mas_lr = 0x100000 - mas_intensity2reg( left ); ! mas_rl = 0x100000 - mas_intensity2reg( right ); ! mas_rr = mas_intensity2reg( right ) + 1; ! break; ! */ ! case AUDIO_MONO: ! mas_ll = mas_intensity2reg( left/2,0 ); ! mas_lr = mas_ll; ! mas_rl = mas_intensity2reg( right/2,0 ); ! mas_rr = mas_rl; ! break; ! case AUDIO_MONO_LEFT: ! mas_ll = mas_intensity2reg( left,0 ); ! mas_lr = mas_ll; ! mas_rl = 0; ! mas_rr = 0; ! break; ! ! case AUDIO_MONO_RIGHT: ! mas_ll = 0; ! mas_lr = 0; ! mas_rl = mas_intensity2reg( right,0 ); ! mas_rr = mas_rl; ! break; ! case AUDIO_STEREO: ! default: ! mas_ll = mas_intensity2reg( left,0 ); // L ! mas_lr = 0; ! mas_rl = 0; ! mas_rr = mas_intensity2reg( right,0 ); // R ! break; ! } ! ! mas_writemem( MAS_BANK_D1, 0x7f8, &mas_ll, 1 ); /* LL */ ! mas_writemem( MAS_BANK_D1, 0x7f9, &mas_lr, 1 ); /* LR */ ! mas_writemem( MAS_BANK_D1, 0x7fa, &mas_rl, 1 ); /* RL */ ! mas_writemem( MAS_BANK_D1, 0x7fb, &mas_rr, 1 ); /* RR */ } } --- 512,598 ---- if( current_audio.dac_mode == AUDIO_MODE_ANALOG ){ + + // Calculate DAC 6 bit values + if( left != right ){ ! db = dac_intensity2db( left, boost ) + current_audio.added_gain; ! dac_l = dac_db2reg( db ); ! db = dac_intensity2db( right, boost ) + current_audio.added_gain; ! dac_r = dac_db2reg( db ); ! } ! else { ! db = dac_intensity2db( current_audio.volume, boost ) + current_audio.added_gain; ! dac_l = dac_r = dac_db2reg( db ); ! } ! //Because the DAC Line out -> RCA plugs are wired wrong, we need to switch the volume channels ! dac_volume( dac_r, dac_l, false); } else { // MAS Values ! ! db = logbase10( left ) / 5; ! db += current_audio.added_gain; ! //Convert dB back to a percentage or ratio value ! int i = rlogbase10( db * 5 ) / 100; ! switch( current_audio.channels ) { ! ! case AUDIO_STEREO_NARROW: ! mas_ll = mas_intensity2reg( (left*3)/4 ); //75% ! mas_lr = mas_intensity2reg( left/4 ); //25% ! mas_rl = mas_intensity2reg( right/4 ); ! mas_rr = mas_intensity2reg( (right*3)/4 ); ! break; ! ! case AUDIO_STEREO_WIDE: ! mas_ll = mas_intensity2reg( left ); ! mas_lr = mas_intensity2reg( left/2 ); ! mas_rl = mas_intensity2reg( right/2 ); ! mas_rr = mas_intensity2reg( right ); ! break; ! /* ! case AUDIO_KARAOKE: ! mas_ll = mas_intensity2reg( left ) + 1; ! mas_lr = 0x100000 - mas_intensity2reg( left ); ! mas_rl = 0x100000 - mas_intensity2reg( right ); ! mas_rr = mas_intensity2reg( right ) + 1; ! break; ! */ ! case AUDIO_MONO: ! mas_ll = mas_intensity2reg( left/2 ); ! mas_lr = mas_ll; ! mas_rl = mas_intensity2reg( right/2 ); ! mas_rr = mas_rl; ! break; ! ! case AUDIO_MONO_LEFT: ! mas_ll = mas_intensity2reg( left ); ! mas_lr = mas_ll; ! mas_rl = 0; ! mas_rr = 0; ! break; ! ! case AUDIO_MONO_RIGHT: ! mas_ll = 0; ! mas_lr = 0; ! mas_rl = mas_intensity2reg( right ); ! mas_rr = mas_rl; ! break; ! ! case AUDIO_STEREO: ! default: ! mas_ll = mas_intensity2reg( left ); // L ! mas_lr = 0; ! mas_rl = 0; ! mas_rr = mas_intensity2reg( right ); // R ! break; ! } ! ! mas_writemem( MAS_BANK_D1, 0x7f8, &mas_ll, 1 ); /* LL */ ! mas_writemem( MAS_BANK_D1, 0x7f9, &mas_lr, 1 ); /* LR */ ! mas_writemem( MAS_BANK_D1, 0x7fa, &mas_rl, 1 ); /* RL */ ! mas_writemem( MAS_BANK_D1, 0x7fb, &mas_rr, 1 ); /* RR */ } } |