Skip to content

Commit

Permalink
Version 0.01
Browse files Browse the repository at this point in the history
  • Loading branch information
terual committed Oct 5, 2020
0 parents commit 2ecaa10
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 0 deletions.
Binary file added Bin/x86_64-linux/bs2bconvert
Binary file not shown.
12 changes: 12 additions & 0 deletions HTML/EN/plugins/BS2B/settings/player.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[% PROCESS settings/header.html %]

[% WRAPPER settingSection %]

[% WRAPPER setting title="Enable 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 %]

[% END %]

[% PROCESS settings/footer.html %]
47 changes: 47 additions & 0 deletions PlayerSettings.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package Plugins::BS2B::PlayerSettings;

use strict;

use base qw(Slim::Web::Settings);

use Slim::Utils::Prefs;
use Slim::Utils::Log;
use Slim::Player::CapabilitiesHelper;

use Plugins::BS2B::Plugin;

my $prefs = preferences('plugin.bs2b');
my $log = logger('plugin.bs2b');

sub getDisplayName {
return 'PLUGIN_BS2B';
}

sub needsClient {
return 1;
}

sub name {
return Slim::Web::HTTP::CSRF->protectName('PLUGIN_BS2B');
}

sub page {
return Slim::Web::HTTP::CSRF->protectURI('plugins/BS2B/settings/player.html');
}

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

if ($params->{'saveSettings'}) {

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

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

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

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

1;
59 changes: 59 additions & 0 deletions Plugin.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package Plugins::BS2B::Plugin;

use strict;

use base qw(Slim::Plugin::OPMLBased);

use Slim::Utils::Log;
use Slim::Utils::Prefs;
use Slim::Player::TranscodingHelper;

use Plugins::BS2B::PlayerSettings;

my $prefs = preferences('plugin.bs2b');

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

sub initPlugin {
my $class = shift;

Plugins::BS2B::PlayerSettings->new;

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

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

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

my $flc = 'flc-flc-*-' . 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' };

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

} else {

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

}
}

sub initClient {
my $request = shift;

setupTranscoder($request->client());
}

1;
17 changes: 17 additions & 0 deletions install.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<extension>
<name>PLUGIN_BS2B</name>
<module>Plugins::BS2B::Plugin</module>
<version>0.01</version>
<description>PLUGIN_BS2B_DESC</description>
<creator>Terual</creator>
<homepageURL>https://github.com/terual/BS2B</homepageURL>
<defaultState>enabled</defaultState>
<type>2</type>
<!-- type=extension -->
<targetApplication>
<id>SlimServer</id>
<minVersion>7.9</minVersion>
<maxVersion>8.*</maxVersion>
</targetApplication>
</extension>
6 changes: 6 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM ubuntu:14.04
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get -y update && apt-get -y upgrade && \
apt-get install -y gcc g++ make libsndfile-dev build-essential

14 changes: 14 additions & 0 deletions src/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

docker build . -t bs2b

rm -rf "libbs2b-3.1.0"
tar -xvf "libbs2b-3.1.0.tar.bz2"
patch -p0 < fix-stderr.patch

cd "libbs2b-3.1.0"
docker run -t --rm -u "${UID}" -v "${PWD}:${PWD}" -w "${PWD}" \
bs2b \
sh -c "./configure --help && LIBS=-lm ./configure --enable-static --disable-shared && make"


76 changes: 76 additions & 0 deletions src/fix-stderr.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
--- libbs2b-3.1.0/src/bs2bconvert.c.orig 2009-06-04 20:01:15.000000000 +0200
+++ libbs2b-3.1.0/src/bs2bconvert.c 2020-10-05 15:00:34.332595456 +0200
@@ -146,20 +146,20 @@

if( strcmp( infilename, outfilename ) == 0 )
{
- printf( "Error : Input and output filenames are the same.\n\n" );
+ fprintf( stderr, "Error : Input and output filenames are the same.\n\n" );
return 1;
}

if( ( infile = sf_open( infilename, SFM_READ, &sfinfo ) ) == NULL )
{
- printf( "Not able to open input file %s.\n", infilename );
- printf( sf_strerror( NULL ) );
+ fprintf( stderr, "Not able to open input file %s.\n", infilename );
+ fprintf( stderr, sf_strerror( NULL ) );
return 1;
}

if( sfinfo.channels != 2 )
{
- printf( "Input file is not a stereo.\n" );
+ fprintf( stderr, "Input file is not a stereo.\n" );
sf_close( infile );
return 1;
}
@@ -168,7 +168,7 @@

if( srate < BS2B_MINSRATE || srate > BS2B_MAXSRATE )
{
- printf( "Not supported sample rate '%d'.\n", srate );
+ fprintf( stderr, "Not supported sample rate '%d'.\n", srate );
sf_close( infile );
return 1;
}
@@ -176,7 +176,7 @@
/* Open the output file. */
if( ( outfile = sf_open( outfilename, SFM_WRITE, &sfinfo ) ) == NULL )
{
- printf( "Not able to open output file %s : %s\n",
+ fprintf( stderr, "Not able to open output file %s : %s\n",
outfilename, sf_strerror( NULL ) );
sf_close( infile );
return 1;
@@ -184,7 +184,7 @@

if( NULL == ( bs2bdp = bs2b_open() ) )
{
- printf( "Not able to allocate data\n" );
+ fprintf( stderr, "Not able to allocate data\n" );
sf_close( infile );
sf_close( outfile );
return 1;
@@ -193,10 +193,10 @@
bs2b_set_srate( bs2bdp, srate );
bs2b_set_level( bs2bdp, level );

- printf( "Crossfeed level: %.1f dB, %d Hz, %d us.\n",
+ fprintf( stderr, "Crossfeed level: %.1f dB, %d Hz, %d us.\n",
( double )bs2b_get_level_feed( bs2bdp ) / 10.0,
bs2b_get_level_fcut( bs2bdp ), bs2b_get_level_delay( bs2bdp ) );
- printf( "Converting file '%s' to file '%s'\nsample rate = %u...",
+ fprintf( stderr, "Converting file '%s' to file '%s'\nsample rate = %u...",
infilename, outfilename, bs2b_get_srate( bs2bdp ) );

copy_metadata( outfile, infile );
@@ -209,7 +209,7 @@
sf_close( infile );
sf_close( outfile );

- printf( " Done.\n" );
+ fprintf( stderr, " Done.\n" );

return 0;
} /* main() */
Binary file added src/libbs2b-3.1.0.tar.bz2
Binary file not shown.
10 changes: 10 additions & 0 deletions strings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# String file for BS2B plugin

PLUGIN_BS2B
EN Bauer stereophonic-to-binaural DSP

PLUGIN_BS2B_DESC
EN Bauer stereophonic-to-binaural DSP: headphone filter

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

0 comments on commit 2ecaa10

Please sign in to comment.