Bauer stereophonic-to-binaural DSP: library description.
· Description · License · Download The bs2b library is simple to use. See tables 1 and 2 for example. It is a reductive code of 'bs2bstream.c'. The 'bs2b.h' and 'bs2bclass.h' files of the source code package can help also. There is a more complex example available on-line. Table 1. Example of using of bs2b library (C). #include <stdio.h> #include "bs2b.h" int main() { t_bs2bdp bs2bdp; short sample[ 2 ]; bs2bdp = bs2b_open(); /* Default init value bs2b_set_srate( bs2bdp, 44100 ); bs2b_set_level( bs2bdp, BS2B_DEFAULT_CLEVEL ); // 700 Hz, 4.5 dB // or another way bs2b_set_srate( bs2bdp, 44100 ); bs2b_set_level_fcut( bs2bdp, 700 ); // 700 Hz bs2b_set_level_feed( bs2bdp, 45 ); // 4.5 dB */ /* raw LPCM, signed 16 bit, native to CPU byte order, stereo interleaved */ while( 2 == fread( sample, sizeof( short ), 2, stdin ) ) { bs2b_cross_feed_s16( bs2bdp, sample, 1 ); fwrite( sample, sizeof( short ), 2, stdout ); } bs2b_close( bs2bdp ); bs2bdp = 0; return 0 ; } Sample rate default value is 44100 Hz. Crossfeed level default value is 700 Hz, 4.5 dB. If a sample rate of audio data is different or if you want to change crossfeed level then you must call 'bs2b_set_srate' and 'bs2b_set_level' functions (or 'bs2b_set_srate', 'bs2b_set_level_fcut', 'bs2b_set_level_feed') accordingly. Table 2. Example of using of bs2b library (C++). #include <stdio.h> #include "bs2bclass.h" int main() { bs2b_base bs2b; // Default init value //bs2b.set_srate( 44100 ); //bs2b.set_level( BS2B_DEFAULT_CLEVEL ); // 700 Hz, 4.5 dB // or another way //bs2b.set_srate( 44100 ); //bs2b.set_level_fcut( 700 ); // 700 Hz //bs2b.set_level_feed( 45 ); // 4.5 dB // raw LPCM, signed 16 bit, native to CPU byte order, stereo interleaved short sample[ 2 ]; while( 2 == fread( sample, sizeof( short ), 2, stdin ) ) { bs2b.cross_feed( sample ); fwrite( sample, sizeof( short ), 2, stdout ); } return 0 ; } You can use a 'bs2bstream' with 'lame' by a command line like this: lame -t --decode test.wav - | bs2bstream | lame -r -x -m j -s 44.1 --bitwidth 16 --preset extreme - test.mp3 or without of '-x' swap bytes of input file, like this: lame -t --decode test.wav - | bs2bstream | lame -r -m j -s 44.1 --bitwidth 16 --preset extreme - test.mp3 There is a bash script below for example of using of bs2bstream. Table 3. Example of using of bs2bstream (bash). #!/bin/bash # FLAC player using the bs2b DSP # # (c) 2011 Bart Lauret # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # Do not loop though files when no flac exists: shopt -s nullglob # Change this to your soundcard's address # If your soundcard supports S16_LE and S24_3LE, use hw:X,X to circumvent software resampling DEVICE="plughw:0,0" function checkplay { if [ `soxi -V0 -c "$FILE"` -eq "2" ]; then RATE=`soxi -V0 -r "$FILE"` RATEKHZ=`echo "scale=1 ; $RATE / 1000" | bc` case `soxi -V0 -b "$FILE"` in 16) play16;; 24) play24;; *) echo "File format not supported: use FLACs with 16 or 24 bit resolution.";; esac else echo "File is mono, crossfeed not possible..." fi } function play16 { echo "*** Playing $FILE... (16 bit/$RATEKHZ kHz)" if [ "$CROSSFEED" ]; then flac --endian=little --sign=signed --force-raw-format --totally-silent -dc "$FILE" | \ bs2bstream -e l -b 16 -r "$RATEKHZ" -l "$CROSSFEED" | \ aplay -c 2 -r "$RATE" -f S16_LE -D "$DEVICE" -t raw --quiet else echo "*** No crossfeed selected, playing without..." flac --totally-silent -dc "$FILE" | \ aplay -c 2 -r "$RATE" -f S16_LE -D "$DEVICE" -t wav --quiet fi } function play24 { echo "*** Playing $FILE... (24 bit/$RATEKHZ kHz)" if [ "$CROSSFEED" ]; then flac --endian=little --sign=signed --force-raw-format --totally-silent -dc "$FILE" | \ bs2bstream -e l -b 24 -r "$RATEKHZ" -l "$CROSSFEED" | \ aplay -c 2 -r "$RATE" -f S24_3LE -D "$DEVICE" -t raw --quiet else echo "*** No crossfeed selected, playing without..." flac --totally-silent -dc "$FILE" | \ aplay -c 2 -r "$RATE" -f S24_3LE -D "$DEVICE" -t wav --quiet fi } function usage { echo "Usage:" echo "Play a single file: bs2b [-dcm] -f <filename>" echo "Play all FLACs in a directory: bs2b [-dcm] -D" echo echo " -d - default preset - 700Hz/260us, 4.5 dB;" echo " -c - Chu Moy's preset - 700Hz/260us, 6.0 dB;" echo " -m - Jan Meier's preset - 650Hz/280us, 9.5 dB." echo } # Script starts here echo "bs2b - FLAC player with Bauer stereophonic-to-binaural DSP" echo "bs2b comes with ABSOLUTELY NO WARRANTY. This is free software, and you are" echo "welcome to redistribute it under certain conditions." echo if [ ! `which soxi` ]; then echo "Please install sox. For more information see http://sox.sourceforge.net/" if [ ! `which flac` ]; then echo "Please install flac. For more information see http://flac.sourceforge.net/" fi exit 1 fi while getopts "dcmDf:" flag do case "$flag" in d) CROSSFEED="$flag"; echo "*** Crossfeed set to default preset.";; c) CROSSFEED="$flag"; echo "*** Crossfeed set to Chu Moy's preset.";; m) CROSSFEED="$flag"; echo "*** Crossfeed set to Jan Meier's preset.";; D) DIR="$OPTIND";; f) FILE="$OPTARG" esac done if [ -f "$FILE" ]; then checkplay elif [ $DIR ]; then for FILE in *.flac do checkplay done else usage exit 1 fi Hosted at © Boris Mikhaylov |