Skip to content

Commit

Permalink
Fixes/updates for Camilla VC dynamic range option
Browse files Browse the repository at this point in the history
[cdsp/php]
- Change function name from getMappedDbVol() to calcMappedDbVol() to avoid confusion with same named function in mpd.php
- Change 0 factor from 0.0000001 to 0.000001

[mpd.php]
- Fix format width for '-120dB;
- Refactor var name to camelCase
- Reference calcMappedDbVol()
  • Loading branch information
moodeaudio committed Mar 20, 2023
1 parent 86bb50c commit ea76083
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions www/inc/cdsp.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ function backup() {
function restore($values) {
}

static function getMappedDbVol($volume, $dynamic_range) {
static function calcMappedDbVol($volume, $dynamic_range) {
$x = $volume/100.0;
$y = pow(10, $dynamic_range/20);
$a = 1/$y;
Expand All @@ -563,11 +563,10 @@ static function getMappedDbVol($volume, $dynamic_range) {
$y = $x*10*$a*exp(0.1*$b);
}
if( $y == 0) {
$y = 0.0000001;
$y = 0.000001;
}
return 20* log10($y);
}

}

// TODO: Change these to cdsp-> member functions
Expand Down
11 changes: 5 additions & 6 deletions www/inc/mpd.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,16 +737,15 @@ function getMappedDbVol() {
phpSession('open_ro');

if (isMPD2CamillaDSPVolSyncEnabled() && doesCamillaDSPCfgHaveVolFilter()) {
// implement the same curve as with mpd2camilladsp

// Use SQL value instead of session
// For CamillaDSP volume
$result = sqlRead('cfg_system', sqlConnect(), 'volknob');

//TODO: create setting for it
$dynamic_range = 60;
$dynamicRange = 60;

$mappedDbVol = CamillaDsp::getMappedDbVol($result[0]['value'], $dynamic_range) ;
$mappedDbVol = CamillaDsp::calcMappedDbVol($result[0]['value'], $dynamicRange) ;
$mappedDbVol = round($mappedDbVol, 1);
$mappedDbVol = ($mappedDbVol > -10 ? number_format($mappedDbVol, 1) : substr($mappedDbVol, 0, 3)) . 'dB';
$mappedDbVol = ($mappedDbVol > -10 ? number_format($mappedDbVol, 1) : substr($mappedDbVol, 0, 4)) . 'dB';
} else {
// For MPD volume
$result = sysCmd('amixer -c ' . $_SESSION['cardnum'] . ' sget "' . $_SESSION['amixname'] . '" | ' .
Expand Down

0 comments on commit ea76083

Please sign in to comment.