Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/alexmarsev/libbs2b.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorboris_mikhaylov <boris_mikhaylov@bc0edfbe-c936-4687-b64d-f70bc3985e72>2009-03-11 13:46:25 +0300
committerboris_mikhaylov <boris_mikhaylov@bc0edfbe-c936-4687-b64d-f70bc3985e72>2009-03-11 13:46:25 +0300
commitdfa20057eb877c23fdd9f541cecf5e4e0c62d3df (patch)
tree1b75ce6364d93c25c2ea9419e6a3fbedccd8221c
parent054988cd8ff029e5105a4973d628c35bb3eae15a (diff)
Changed processing from one stereo sample to more
git-svn-id: svn://svn.code.sf.net/p/bs2b/code/trunk/libbs2b@62 bc0edfbe-c936-4687-b64d-f70bc3985e72
-rw-r--r--ChangeLog3
-rw-r--r--src/bs2b.c217
-rw-r--r--src/bs2b.h36
-rw-r--r--src/bs2bclass.cpp33
-rw-r--r--src/bs2bclass.h27
-rw-r--r--src/bs2bconvert.c23
-rw-r--r--src/bs2bstream.c15
7 files changed, 207 insertions, 147 deletions
diff --git a/ChangeLog b/ChangeLog
index 00c0224..28968d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2009-03-11 Boris Mikhaylov <http://www.tmn.ru/~bor>
+ * Changed processing from one stereo sample to more.
+
2009-03-06 Boris Mikhaylov <http://www.tmn.ru/~bor>
* libsndfile v1.0.17 -> v1.0.19.
* Added more systems compatability (Integer types changed).
diff --git a/src/bs2b.c b/src/bs2b.c
index 6ea135c..1861101 100644
--- a/src/bs2b.c
+++ b/src/bs2b.c
@@ -143,6 +143,47 @@ static void init( t_bs2bdp bs2bdp )
bs2bdp->gain = 1.0 / ( 1.0 - G_hi + G_lo );
} /* init() */
+/* Single pole IIR filter.
+ * O[n] = a0*I[n] + a1*I[n-1] + b1*O[n-1]
+ */
+
+/* Lowpass filter */
+#define lo_filter( in, out_1 ) \
+ ( bs2bdp->a0_lo * in + bs2bdp->b1_lo * out_1 )
+
+/* Highboost filter */
+#define hi_filter( in, in_1, out_1 ) \
+ ( bs2bdp->a0_hi * in + bs2bdp->a1_hi * in_1 + bs2bdp->b1_hi * out_1 )
+
+static void cross_feed_dne( t_bs2bdp bs2bdp, double *sample )
+{
+ /* Lowpass filter */
+ bs2bdp->lfs.lo[ 0 ] = lo_filter( sample[ 0 ], bs2bdp->lfs.lo[ 0 ] );
+ bs2bdp->lfs.lo[ 1 ] = lo_filter( sample[ 1 ], bs2bdp->lfs.lo[ 1 ] );
+
+ /* Highboost filter */
+ bs2bdp->lfs.hi[ 0 ] =
+ hi_filter( sample[ 0 ], bs2bdp->lfs.asis[ 0 ], bs2bdp->lfs.hi[ 0 ] );
+ bs2bdp->lfs.hi[ 1 ] =
+ hi_filter( sample[ 1 ], bs2bdp->lfs.asis[ 1 ], bs2bdp->lfs.hi[ 1 ] );
+ bs2bdp->lfs.asis[ 0 ] = sample[ 0 ];
+ bs2bdp->lfs.asis[ 1 ] = sample[ 1 ];
+
+ /* Crossfeed */
+ sample[ 0 ] = bs2bdp->lfs.hi[ 0 ] + bs2bdp->lfs.lo[ 1 ];
+ sample[ 1 ] = bs2bdp->lfs.hi[ 1 ] + bs2bdp->lfs.lo[ 0 ];
+
+ /* Bass boost cause allpass attenuation */
+ sample[ 0 ] *= bs2bdp->gain;
+ sample[ 1 ] *= bs2bdp->gain;
+
+ /* Clipping of overloaded samples */
+ if( sample[ 0 ] > 1.0 ) sample[ 0 ] = 1.0;
+ if( sample[ 0 ] < -1.0 ) sample[ 0 ] = -1.0;
+ if( sample[ 1 ] > 1.0 ) sample[ 1 ] = 1.0;
+ if( sample[ 1 ] < -1.0 ) sample[ 1 ] = -1.0;
+} /* cross_feed_dne() */
+
/* Exported functions.
* See descriptions in "bs2b.h"
*/
@@ -222,58 +263,40 @@ int bs2b_is_clear( t_bs2bdp bs2bdp )
return 1;
} /* bs2b_is_clear() */
-/* Lowpass filter */
-#define lo_filter( in, out_1 ) \
- ( bs2bdp->a0_lo * in + bs2bdp->b1_lo * out_1 )
-
-/* Highboost filter */
-#define hi_filter( in, in_1, out_1 ) \
- ( bs2bdp->a0_hi * in + bs2bdp->a1_hi * in_1 + bs2bdp->b1_hi * out_1 )
-
-void bs2b_cross_feed_dne( t_bs2bdp bs2bdp, double *sample )
+char const *bs2b_runtime_version( void )
{
- /* Single pole IIR filter.
- * O[n] = a0*I[n] + a1*I[n-1] + b1*O[n-1]
- */
-
- /* Lowpass filter */
- bs2bdp->lfs.lo[ 0 ] = lo_filter( sample[ 0 ], bs2bdp->lfs.lo[ 0 ] );
- bs2bdp->lfs.lo[ 1 ] = lo_filter( sample[ 1 ], bs2bdp->lfs.lo[ 1 ] );
-
- /* Highboost filter */
- bs2bdp->lfs.hi[ 0 ] =
- hi_filter( sample[ 0 ], bs2bdp->lfs.asis[ 0 ], bs2bdp->lfs.hi[ 0 ] );
- bs2bdp->lfs.hi[ 1 ] =
- hi_filter( sample[ 1 ], bs2bdp->lfs.asis[ 1 ], bs2bdp->lfs.hi[ 1 ] );
- bs2bdp->lfs.asis[ 0 ] = sample[ 0 ];
- bs2bdp->lfs.asis[ 1 ] = sample[ 1 ];
-
- /* Crossfeed */
- sample[ 0 ] = bs2bdp->lfs.hi[ 0 ] + bs2bdp->lfs.lo[ 1 ];
- sample[ 1 ] = bs2bdp->lfs.hi[ 1 ] + bs2bdp->lfs.lo[ 0 ];
+ return BS2B_VERSION_STR;
+} /* bs2b_runtime_version() */
- /* Bass boost cause allpass attenuation */
- sample[ 0 ] *= bs2bdp->gain;
- sample[ 1 ] *= bs2bdp->gain;
+void bs2b_cross_feed_dne( t_bs2bdp bs2bdp, double *sample, int n )
+{
+ if( n <= 0 ) return;
- /* Clipping of overloaded samples */
- if( sample[ 0 ] > 1.0 ) sample[ 0 ] = 1.0;
- if( sample[ 0 ] < -1.0 ) sample[ 0 ] = -1.0;
- if( sample[ 1 ] > 1.0 ) sample[ 1 ] = 1.0;
- if( sample[ 1 ] < -1.0 ) sample[ 1 ] = -1.0;
+ while( n-- )
+ {
+ cross_feed_dne( bs2bdp, sample );
+ sample += 2;
+ } /* while */
} /* bs2b_cross_feed_dne() */
-void bs2b_cross_feed_fne( t_bs2bdp bs2bdp, float *sample )
+void bs2b_cross_feed_fne( t_bs2bdp bs2bdp, float *sample, int n )
{
- double sample_d[ 2 ];
+ if( n <= 0 ) return;
+
+ while( n-- )
+ {
+ double sample_d[ 2 ];
- sample_d[ 0 ] = ( double )sample[ 0 ];
- sample_d[ 1 ] = ( double )sample[ 1 ];
+ sample_d[ 0 ] = ( double )sample[ 0 ];
+ sample_d[ 1 ] = ( double )sample[ 1 ];
- bs2b_cross_feed_dne( bs2bdp, sample_d );
+ cross_feed_dne( bs2bdp, sample_d );
- sample[ 0 ] = ( float )sample_d[ 0 ];
- sample[ 1 ] = ( float )sample_d[ 1 ];
+ sample[ 0 ] = ( float )sample_d[ 0 ];
+ sample[ 1 ] = ( float )sample_d[ 1 ];
+
+ sample += 2;
+ } /* while */
} /* bs2b_cross_feed_fne() */
#define MAX_INT32_VALUE 2147483647.0
@@ -281,72 +304,102 @@ void bs2b_cross_feed_fne( t_bs2bdp bs2bdp, float *sample )
#define MAX_INT8_VALUE 127.0
#define MAX_INT24_VALUE 8388607.0
-void bs2b_cross_feed_s32ne( t_bs2bdp bs2bdp, int32_t *sample )
+void bs2b_cross_feed_s32ne( t_bs2bdp bs2bdp, int32_t *sample, int n )
{
- double sample_d[ 2 ];
+ if( n <= 0 ) return;
+
+ while( n-- )
+ {
+ double sample_d[ 2 ];
- sample_d[ 0 ] = ( double )sample[ 0 ] / MAX_INT32_VALUE;
- sample_d[ 1 ] = ( double )sample[ 1 ] / MAX_INT32_VALUE;
+ sample_d[ 0 ] = ( double )sample[ 0 ] / MAX_INT32_VALUE;
+ sample_d[ 1 ] = ( double )sample[ 1 ] / MAX_INT32_VALUE;
- bs2b_cross_feed_dne( bs2bdp, sample_d );
+ cross_feed_dne( bs2bdp, sample_d );
- sample[ 0 ] = ( int32_t )( sample_d[ 0 ] * MAX_INT32_VALUE );
- sample[ 1 ] = ( int32_t )( sample_d[ 1 ] * MAX_INT32_VALUE );
+ sample[ 0 ] = ( int32_t )( sample_d[ 0 ] * MAX_INT32_VALUE );
+ sample[ 1 ] = ( int32_t )( sample_d[ 1 ] * MAX_INT32_VALUE );
+
+ sample += 2;
+ } /* while */
} /* bs2b_cross_feed_s32ne() */
-void bs2b_cross_feed_s16ne( t_bs2bdp bs2bdp, int16_t *sample )
+void bs2b_cross_feed_s16ne( t_bs2bdp bs2bdp, int16_t *sample, int n )
{
- double sample_d[ 2 ];
+ if( n <= 0 ) return;
- sample_d[ 0 ] = ( double )sample[ 0 ] / MAX_INT16_VALUE;
- sample_d[ 1 ] = ( double )sample[ 1 ] / MAX_INT16_VALUE;
+ while( n-- )
+ {
+ double sample_d[ 2 ];
- bs2b_cross_feed_dne( bs2bdp, sample_d );
+ sample_d[ 0 ] = ( double )sample[ 0 ] / MAX_INT16_VALUE;
+ sample_d[ 1 ] = ( double )sample[ 1 ] / MAX_INT16_VALUE;
- sample[ 0 ] = ( int16_t )( sample_d[ 0 ] * MAX_INT16_VALUE );
- sample[ 1 ] = ( int16_t )( sample_d[ 1 ] * MAX_INT16_VALUE );
+ cross_feed_dne( bs2bdp, sample_d );
+
+ sample[ 0 ] = ( int16_t )( sample_d[ 0 ] * MAX_INT16_VALUE );
+ sample[ 1 ] = ( int16_t )( sample_d[ 1 ] * MAX_INT16_VALUE );
+
+ sample += 2;
+ } /* while */
} /* bs2b_cross_feed_s16ne() */
-void bs2b_cross_feed_s8( t_bs2bdp bs2bdp, int8_t *sample )
+void bs2b_cross_feed_s8( t_bs2bdp bs2bdp, int8_t *sample, int n )
{
- double sample_d[ 2 ];
+ if( n <= 0 ) return;
+
+ while( n-- )
+ {
+ double sample_d[ 2 ];
+
+ sample_d[ 0 ] = ( double )sample[ 0 ] / MAX_INT8_VALUE;
+ sample_d[ 1 ] = ( double )sample[ 1 ] / MAX_INT8_VALUE;
- sample_d[ 0 ] = ( double )sample[ 0 ] / MAX_INT8_VALUE;
- sample_d[ 1 ] = ( double )sample[ 1 ] / MAX_INT8_VALUE;
+ cross_feed_dne( bs2bdp, sample_d );
- bs2b_cross_feed_dne( bs2bdp, sample_d );
+ sample[ 0 ] = ( int8_t )( sample_d[ 0 ] * MAX_INT8_VALUE );
+ sample[ 1 ] = ( int8_t )( sample_d[ 1 ] * MAX_INT8_VALUE );
- sample[ 0 ] = ( int8_t )( sample_d[ 0 ] * MAX_INT8_VALUE );
- sample[ 1 ] = ( int8_t )( sample_d[ 1 ] * MAX_INT8_VALUE );
+ sample += 2;
+ } /* while */
} /* bs2b_cross_feed_s8() */
-void bs2b_cross_feed_u8( t_bs2bdp bs2bdp, uint8_t *sample )
+void bs2b_cross_feed_u8( t_bs2bdp bs2bdp, uint8_t *sample, int n )
{
- double sample_d[ 2 ];
+ if( n <= 0 ) return;
+
+ while( n-- )
+ {
+ double sample_d[ 2 ];
- sample_d[ 0 ] = ( ( double )( ( int8_t )( sample[ 0 ] ^ 0x80 ) ) ) / MAX_INT8_VALUE;
- sample_d[ 1 ] = ( ( double )( ( int8_t )( sample[ 1 ] ^ 0x80 ) ) ) / MAX_INT8_VALUE;
+ sample_d[ 0 ] = ( ( double )( ( int8_t )( sample[ 0 ] ^ 0x80 ) ) ) / MAX_INT8_VALUE;
+ sample_d[ 1 ] = ( ( double )( ( int8_t )( sample[ 1 ] ^ 0x80 ) ) ) / MAX_INT8_VALUE;
- bs2b_cross_feed_dne( bs2bdp, sample_d );
+ cross_feed_dne( bs2bdp, sample_d );
- sample[ 0 ] = ( ( uint8_t )( sample_d[ 0 ] * MAX_INT8_VALUE ) ) ^ 0x80;
- sample[ 1 ] = ( ( uint8_t )( sample_d[ 1 ] * MAX_INT8_VALUE ) ) ^ 0x80;
+ sample[ 0 ] = ( ( uint8_t )( sample_d[ 0 ] * MAX_INT8_VALUE ) ) ^ 0x80;
+ sample[ 1 ] = ( ( uint8_t )( sample_d[ 1 ] * MAX_INT8_VALUE ) ) ^ 0x80;
+
+ sample += 2;
+ } /* while */
} /* bs2b_cross_feed_u8() */
-void bs2b_cross_feed_s24ne( t_bs2bdp bs2bdp, int24_t *sample )
+void bs2b_cross_feed_s24ne( t_bs2bdp bs2bdp, int24_t *sample, int n )
{
+ if( n <= 0 ) return;
+
+ while( n-- )
+ {
double sample_d[ 2 ];
- sample_d[ 0 ] = int242double( sample ) / MAX_INT24_VALUE;
- sample_d[ 1 ] = int242double( sample + 1 ) / MAX_INT24_VALUE;
+ sample_d[ 0 ] = int242double( sample ) / MAX_INT24_VALUE;
+ sample_d[ 1 ] = int242double( sample + 1 ) / MAX_INT24_VALUE;
- bs2b_cross_feed_dne( bs2bdp, sample_d );
+ cross_feed_dne( bs2bdp, sample_d );
- double2int24( sample_d[ 0 ] * MAX_INT24_VALUE, sample );
- double2int24( sample_d[ 1 ] * MAX_INT24_VALUE, sample + 1 );
-} /* bs2b_cross_feed_s24ne() */
+ double2int24( sample_d[ 0 ] * MAX_INT24_VALUE, sample );
+ double2int24( sample_d[ 1 ] * MAX_INT24_VALUE, sample + 1 );
-char const *bs2b_runtime_version( void )
-{
- return BS2B_VERSION_STR;
-} /* bs2b_runtime_version() */
+ sample += 2;
+ } /* while */
+} /* bs2b_cross_feed_s24ne() */
diff --git a/src/bs2b.h b/src/bs2b.h
index b1ef755..4daaafd 100644
--- a/src/bs2b.h
+++ b/src/bs2b.h
@@ -29,19 +29,19 @@
#include "bs2bversion.h"
#if HAVE_STDINT_H
-# include <stdint.h>
+#include <stdint.h>
#else
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
-# if UINT_MAX == 0xffff /* 16 bit compiler */
+#if UINT_MAX == 0xffff /* 16 bit compiler */
typedef signed long int32_t;
typedef unsigned long uint32_t;
-# else /* UINT_MAX != 0xffff */ /* 32/64 bit compiler */
+#else /* UINT_MAX != 0xffff */ /* 32/64 bit compiler */
typedef signed int int32_t;
typedef unsigned int uint32_t;
-# endif
+#endif
#endif /* HAVE_STDINT_H */
typedef struct
@@ -136,34 +136,36 @@ void bs2b_clear( t_bs2bdp bs2bdp );
/* Return 1 if buffer is clear */
int bs2b_is_clear( t_bs2bdp bs2bdp );
-/* Crossfeeds one stereo sample that are pointed by sample.
- * [0] - first channel, [1] - second channel.
- * Returns crossfided samle by sample pointer.
+/* Return bs2b version string */
+char const *bs2b_runtime_version( void );
+
+/* 'bs2b_cross_feed_*' crossfeeds buffer of 'n' stereo samples
+ * pointed by 'sample'.
+ * sample[i] - first channel,
+ * sample[i+1] - second channel.
+ * Where 'i' is ( i = 0; i < n * 2; i += 2 )
*/
/* sample poits to double floats native endians */
-void bs2b_cross_feed_dne( t_bs2bdp bs2bdp, double *sample );
+void bs2b_cross_feed_dne( t_bs2bdp bs2bdp, double *sample, int n );
/* sample poits to floats native endians */
-void bs2b_cross_feed_fne( t_bs2bdp bs2bdp, float *sample );
+void bs2b_cross_feed_fne( t_bs2bdp bs2bdp, float *sample, int n );
/* sample poits to 32bit signed integers native endians */
-void bs2b_cross_feed_s32ne( t_bs2bdp bs2bdp, int32_t *sample );
+void bs2b_cross_feed_s32ne( t_bs2bdp bs2bdp, int32_t *sample, int n );
/* sample poits to 16bit signed integers native endians */
-void bs2b_cross_feed_s16ne( t_bs2bdp bs2bdp, int16_t *sample );
+void bs2b_cross_feed_s16ne( t_bs2bdp bs2bdp, int16_t *sample, int n );
/* sample poits to 8bit signed integers */
-void bs2b_cross_feed_s8( t_bs2bdp bs2bdp, int8_t *sample );
+void bs2b_cross_feed_s8( t_bs2bdp bs2bdp, int8_t *sample, int n );
/* sample poits to 8bit unsigned integers */
-void bs2b_cross_feed_u8( t_bs2bdp bs2bdp, uint8_t *sample );
+void bs2b_cross_feed_u8( t_bs2bdp bs2bdp, uint8_t *sample, int n );
/* sample poits to 24bit signed integers native endians */
-void bs2b_cross_feed_s24ne( t_bs2bdp bs2bdp, int24_t *sample );
-
-/* Return bs2b version string */
-char const *bs2b_runtime_version( void );
+void bs2b_cross_feed_s24ne( t_bs2bdp bs2bdp, int24_t *sample, int n );
#ifdef __cplusplus
} /* extern "C" */
diff --git a/src/bs2bclass.cpp b/src/bs2bclass.cpp
index bedeb40..aa63b4a 100644
--- a/src/bs2bclass.cpp
+++ b/src/bs2bclass.cpp
@@ -63,37 +63,42 @@ bool bs2b_base::is_clear()
return( bs2b_is_clear( bs2bdp ) ? true : false );
}
-void bs2b_base::cross_feed( double *sample )
+char const *bs2b_base::runtime_version( void )
{
- bs2b_cross_feed_dne( bs2bdp, sample );
+ return bs2b_runtime_version();
}
-void bs2b_base::cross_feed( float *sample )
+void bs2b_base::cross_feed( double *sample, int n )
{
- bs2b_cross_feed_fne( bs2bdp, sample );
+ bs2b_cross_feed_dne( bs2bdp, sample, n );
}
-void bs2b_base::cross_feed( int32_t *sample )
+void bs2b_base::cross_feed( float *sample, int n )
{
- bs2b_cross_feed_s32ne( bs2bdp, sample );
+ bs2b_cross_feed_fne( bs2bdp, sample, n );
}
-void bs2b_base::cross_feed( int16_t *sample )
+void bs2b_base::cross_feed( int32_t *sample, int n )
{
- bs2b_cross_feed_s16ne( bs2bdp, sample );
+ bs2b_cross_feed_s32ne( bs2bdp, sample, n );
}
-void bs2b_base::cross_feed( int8_t *sample )
+void bs2b_base::cross_feed( int16_t *sample, int n )
{
- bs2b_cross_feed_s8( bs2bdp, sample );
+ bs2b_cross_feed_s16ne( bs2bdp, sample, n );
}
-void bs2b_base::cross_feed( uint8_t *sample )
+void bs2b_base::cross_feed( int8_t *sample, int n )
{
- bs2b_cross_feed_u8( bs2bdp, sample );
+ bs2b_cross_feed_s8( bs2bdp, sample, n );
}
-void bs2b_base::cross_feed( int24_t *sample )
+void bs2b_base::cross_feed( uint8_t *sample, int n )
{
- bs2b_cross_feed_s24ne( bs2bdp, sample );
+ bs2b_cross_feed_u8( bs2bdp, sample, n );
+}
+
+void bs2b_base::cross_feed( int24_t *sample, int n )
+{
+ bs2b_cross_feed_s24ne( bs2bdp, sample, n );
}
diff --git a/src/bs2bclass.h b/src/bs2bclass.h
index d3766dc..d2e5071 100644
--- a/src/bs2bclass.h
+++ b/src/bs2bclass.h
@@ -35,20 +35,21 @@ public:
bs2b_base();
~bs2b_base();
- void set_level( uint32_t level );
- uint32_t get_level();
- void set_srate( uint32_t srate );
- uint32_t get_srate();
- void clear();
- bool is_clear();
+ void set_level( uint32_t level );
+ uint32_t get_level();
+ void set_srate( uint32_t srate );
+ uint32_t get_srate();
+ void clear();
+ bool is_clear();
+ char const *runtime_version( void );
- void cross_feed( double *sample );
- void cross_feed( float *sample );
- void cross_feed( int32_t *sample );
- void cross_feed( int16_t *sample );
- void cross_feed( int8_t *sample );
- void cross_feed( uint8_t *sample );
- void cross_feed( int24_t *sample );
+ void cross_feed( double *sample, int n = 1 );
+ void cross_feed( float *sample, int n = 1 );
+ void cross_feed( int32_t *sample, int n = 1 );
+ void cross_feed( int16_t *sample, int n = 1 );
+ void cross_feed( int8_t *sample, int n = 1 );
+ void cross_feed( uint8_t *sample, int n = 1 );
+ void cross_feed( int24_t *sample, int n = 1 );
}; // class bs2b_base
#endif // BS2BCLASS_H
diff --git a/src/bs2bconvert.c b/src/bs2bconvert.c
index 2c1c4dd..90a6308 100644
--- a/src/bs2bconvert.c
+++ b/src/bs2bconvert.c
@@ -55,8 +55,8 @@ int main( int argc, char *argv[] )
SNDFILE *infile = NULL, *outfile = NULL;
SF_INFO sfinfo;
t_bs2bdp bs2bdp;
- long srate;
- int level;
+ uint32_t srate;
+ uint32_t level;
tmpstr = strrchr( argv[ 0 ], '/' );
tmpstr = tmpstr ? tmpstr + 1 : argv[ 0 ];
@@ -140,7 +140,7 @@ int main( int argc, char *argv[] )
{
char *levels[] = { "low", "middle", "high", "low easy", "middle easy", "high easy" };
- printf( "Converting file %s to file %s\nsample rate=%li, crossfeed level=%s...",
+ printf( "Converting file %s to file %s\nsample rate=%u, crossfeed level=%s...",
infilename, outfilename, srate, levels[ level - 1 ] );
}
@@ -188,20 +188,13 @@ static void copy_metadata( SNDFILE *outfile, SNDFILE *infile )
static void copy_data( SNDFILE *outfile, SNDFILE *infile, t_bs2bdp bs2bdp )
{
static double data[ BUFFER_LEN ];
- int items, readcount, k;
+ int readcount;
- items = BUFFER_LEN;
- readcount = items;
-
- while( readcount > 0 )
+ for( ;; )
{
- readcount = (int)sf_read_double( infile, data, items );
-
- for( k = 0; k < readcount; k += 2 )
- bs2b_cross_feed_dne( bs2bdp, data + k );
-
+ readcount = ( int )sf_read_double( infile, data, BUFFER_LEN );
+ if( readcount < 2 ) break;
+ bs2b_cross_feed_dne( bs2bdp, data, readcount / 2 );
sf_write_double( outfile, data, readcount );
}
-
- return;
} /* copy_data() */
diff --git a/src/bs2bstream.c b/src/bs2bstream.c
index 2817d68..1a57983 100644
--- a/src/bs2bstream.c
+++ b/src/bs2bstream.c
@@ -25,7 +25,7 @@
#include <string.h>
#include <fcntl.h>
-#if defined(_O_BINARY) || defined(_O_RAW)
+#if defined( _O_BINARY ) || defined( _O_RAW )
#include <io.h>
#endif
@@ -50,8 +50,8 @@ int main( int argc, char *argv[] )
{
t_bs2bdp bs2bdp;
char *progname, *tmpstr;
- long srate;
- int level;
+ uint32_t srate;
+ uint32_t level;
short sample[ 2 ];
tmpstr = strrchr( argv[0], '/' );
@@ -99,21 +99,24 @@ int main( int argc, char *argv[] )
} /* switch */
}
- srate = 44100L;
+ srate = 44100;
bs2bdp = bs2b_open();
bs2b_set_srate( bs2bdp, srate );
bs2b_set_level( bs2bdp, level );
-#if defined(_O_BINARY) || defined(_O_RAW)
+#if defined( _O_BINARY )
_setmode( _fileno( stdin ), _O_BINARY );
_setmode( _fileno( stdout ), _O_BINARY );
+#elif defined( _O_RAW )
+ _setmode( _fileno( stdin ), _O_RAW );
+ _setmode( _fileno( stdout ), _O_RAW );
#endif
while( 2 == fread( sample, sizeof( short ), 2, stdin ) )
{
- bs2b_cross_feed_s16ne( bs2bdp, sample );
+ bs2b_cross_feed_s16ne( bs2bdp, sample, 1 );
fwrite( sample, sizeof( short ), 2, stdout );
}