Skip to content

Commit

Permalink
Add configuration option to select preset
Browse files Browse the repository at this point in the history
  • Loading branch information
terual committed Jan 28, 2025
1 parent 5e24487 commit e40856d
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 31 deletions.
18 changes: 17 additions & 1 deletion HTML/EN/plugins/BS2B/settings/player.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@

[% WRAPPER settingSection %]

[% WRAPPER setting title="Enable BS2B" desc="" %]
[% WRAPPER setting title="PLUGIN_BS2B" desc="PLUGIN_BS2B_DESC" %]
<input name="pref_bs2b" id="pref_bs2b" type="checkbox" [% IF prefs.pref_bs2b %] checked [% END %]>
<label for="pref_bs2b">[% "PLUGIN_BS2B_ENABLE" | string %]</label>
[% END %]

[% WRAPPER setting title="PLUGIN_BS2B_CROSSFEED_LEVEL" desc="PLUGIN_BS2B_CROSSFEED_LEVEL_DESC" %]
<p>
<input name="pref_bs2b_crossfeed_level" id="pref_bs2b_crossfeed_level" type="radio" value='d' [% IF prefs.pref_bs2b_crossfeed_level == 'd' %]checked[% END %]>
<label for="pref_bs2b_crossfeed_level_default">[% "PLUGIN_BS2B_CROSSFEED_LEVEL_DEFAULT" | string %]</label>
</p>
<p>
<input name="pref_bs2b_crossfeed_level" id="pref_bs2b_crossfeed_level" type="radio" value='c' [% IF prefs.pref_bs2b_crossfeed_level == 'c' %]checked[% END %]>
<label for="pref_bs2b_crossfeed_level_chumoy">[% "PLUGIN_BS2B_CROSSFEED_LEVEL_CHUMOY" | string %]</label>
</p>
<p>

<input name="pref_bs2b_crossfeed_level" id="pref_bs2b_crossfeed_level" type="radio" value='m' [% IF prefs.pref_bs2b_crossfeed_level == 'm' %]checked[% END %]>
<label for="pref_bs2b_crossfeed_level_janmeier">[% "PLUGIN_BS2B_CROSSFEED_LEVEL_JANMEIER" | string %]</label>
</p>
[% END %]

[% END %]

[% PROCESS settings/footer.html %]
23 changes: 15 additions & 8 deletions PlayerSettings.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,24 @@ sub page {
}

sub handler {
my ($class, $client, $params, $callback, @args) = @_;

if ($params->{'saveSettings'}) {
my ($class, $client, $params) = @_;

$prefs->client($client)->set('bs2b', $params->{'pref_bs2b'} || 0);
if ( $client ) {

if ($params->{saveSettings}) {

$prefs->client($client)->set('bs2b', $params->{'pref_bs2b'} || 0);
$prefs->client($client)->set('bs2b_crossfeed_level', $params->{'pref_bs2b_crossfeed_level'} || 'd');

}

$params->{prefs}->{pref_bs2b} = $prefs->client($client)->get('bs2b') || 0;
$params->{prefs}->{pref_bs2b_crossfeed_level} = $prefs->client($client)->get('bs2b_crossfeed_level') || 'd';

Plugins::BS2B::Plugin::setupTranscoder($client);

Plugins::BS2B::Plugin::setupTranscoder($client);
}

$params->{'prefs'}->{'pref_bs2b'}= $prefs->client($client)->get('bs2b') || 0;


return $class->SUPER::handler($client, $params);
}

Expand Down
56 changes: 35 additions & 21 deletions Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,58 @@ use Plugins::BS2B::PlayerSettings;
my $prefs = preferences('plugin.bs2b');

my $log = Slim::Utils::Log->addLogCategory({
'category' => 'plugin.bs2b',
'defaultLevel' => 'WARN',
'description' => 'PLUGIN_BS2B',
'category' => 'plugin.bs2b',
'defaultLevel' => 'WARN',
'description' => 'PLUGIN_BS2B',
});

sub initPlugin {
my $class = shift;
my $class = shift;

Plugins::BS2B::PlayerSettings->new;
Plugins::BS2B::PlayerSettings->new;

Slim::Control::Request::subscribe(\&initClient, [['client'],['new','reconnect']]);
Slim::Control::Request::subscribe(\&initClient, [['client'],['new','reconnect']]);
}

sub setupTranscoder {
my $client = $_[0] || return;

my $usebs2b = $prefs->client($client)->get('bs2b');
my $usebs2b = $prefs->client($client)->get('bs2b');
my $bs2b_preset = $prefs->client($client)->get('bs2b_crossfeed_level');

my $flc = 'flc-flc-*-' . lc($client->macaddress);
my $flc = 'flc-flc-*-' . lc($client->macaddress);
my $mp3 = 'mp3-mp3-*-' . lc($client->macaddress);

if ($usebs2b) {
# AU is specifically designed to be written to a pipe (http://www.mega-nerd.com/libsndfile/FAQ.html#Q017)
my $cmdTable = '[sox] -q -t flac $FILE$ -t au - $START$ | [bs2bconvert] /dev/stdin /dev/stdout | [sox] -q -t au - -t flac -C 0 - ';
my $capabilities = { F => 'noArgs', T => 'START=trim %s' };
if ($usebs2b) {
# AU is specifically designed to be written to a pipe (http://www.mega-nerd.com/libsndfile/FAQ.html#Q017)
my $flc_cmdTable = '[sox] -q -t flac $FILE$ -t au - $START$ | [bs2bconvert] -l ' . $bs2b_preset . ' /dev/stdin /dev/stdout | [sox] -q -t au - -t flac -C 0 - ';
my $flc_capabilities = { F => 'noArgs', T => 'START=trim %s' };

$Slim::Player::TranscodingHelper::commandTable{ $flc } = $cmdTable;
$Slim::Player::TranscodingHelper::capabilities{ $flc } = $capabilities;

} else {
$Slim::Player::TranscodingHelper::commandTable{ $flc } = $flc_cmdTable;
$Slim::Player::TranscodingHelper::capabilities{ $flc } = $flc_capabilities;

my $mp3_cmdTable = '[sox] -q -t mp3 $FILE$ -t au - $START$ | [bs2bconvert] -l ' . $bs2b_preset . ' /dev/stdin /dev/stdout | [sox] -q -t au - -t wav - | [lame] --silent -q $QUALITY$ $RESAMPLE$ $BITRATE$ - ';
my $mp3_capabilities = { F => 'noArgs', T => 'START=trim %s', IFB => 'BITRATE=--abr %B', 'D' => 'RESAMPLE=--resample %D' };

$Slim::Player::TranscodingHelper::commandTable{ $mp3 } = $mp3_cmdTable;
$Slim::Player::TranscodingHelper::capabilities{ $mp3 } = $mp3_capabilities;

my $cmdTable = '[flac] -dcs $START$ $END$ -- $FILE$ | [sox] -q -t wav - -t flac -C 0 -r 48000 - ';
my $capabilities = { F => 'noArgs', T => 'START=--skip=%t', U => 'END=--until=%v', D => 'RESAMPLE=-r %d' };
} else {

# Revert to standard convert rules
my $cmdTable = '-';
my $capabilities = { };

$Slim::Player::TranscodingHelper::commandTable{ $flc } = $cmdTable;
$Slim::Player::TranscodingHelper::capabilities{ $flc } = $capabilities;

}

$Slim::Player::TranscodingHelper::commandTable{ $mp3 } = $cmdTable;
$Slim::Player::TranscodingHelper::capabilities{ $mp3 } = $capabilities;

}


}

sub initClient {
Expand Down
2 changes: 1 addition & 1 deletion install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<targetApplication>
<id>SlimServer</id>
<minVersion>7.9</minVersion>
<maxVersion>8.*</maxVersion>
<maxVersion>*</maxVersion>
</targetApplication>
</extension>
15 changes: 15 additions & 0 deletions strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,18 @@ PLUGIN_BS2B_DESC

PLUGIN_BS2B_ENABLE
EN Enable Bauer stereophonic-to-binaural DSP for this player

PLUGIN_BS2B_CROSSFEED_LEVEL
EN Crossfeed level

PLUGIN_BS2B_CROSSFEED_LEVEL_DESC
EN Set the crossfeed level and cut-off frequency. The default preset is closest to the virtual speaker placement with azimuth 30 degrees and the removal of about 3 meters, while listening by headphones. Chu Moy's preset is is close to the parameters of a Chu Moy's crossfeeder. Jan Meier's preset is close to the parameters of a crossfeeder implemented in Jan Meier's CORDA amplifiers.

PLUGIN_BS2B_CROSSFEED_LEVEL_DEFAULT
EN Default (700Hz/260us, 4.5 dB)

PLUGIN_BS2B_CROSSFEED_LEVEL_CHUMOY
EN Chu Moy's preset (700Hz/260us, 6.0 dB)

PLUGIN_BS2B_CROSSFEED_LEVEL_JANMEIER
EN Jan Meier's preset (650Hz/280us, 9.5 dB)

0 comments on commit e40856d

Please sign in to comment.