ref: 8f98f6ba0fb009ffe70c7c6d9be4e3fd9e80d72a
parent: 753d2b72a1c2e76fc6f189e50bdc9632904d915d
author: Christopher Snowhill <kode54@gmail.com>
date: Wed Sep 13 23:36:46 EDT 2017
Reworked mixing chain to be mostly float now.
--- a/include/internal/resampler.h
+++ b/include/internal/resampler.h
@@ -16,6 +16,7 @@
#define resampler_get_free_count EVALUATE(RESAMPLER_DECORATE,_resampler_get_free_count)
#define resampler_write_sample EVALUATE(RESAMPLER_DECORATE,_resampler_write_sample)
#define resampler_write_sample_fixed EVALUATE(RESAMPLER_DECORATE,_resampler_write_sample_fixed)
+#define resampler_write_sample_float EVALUATE(RESAMPLER_DECORATE,_resampler_write_sample_float)
#define resampler_set_rate EVALUATE(RESAMPLER_DECORATE,_resampler_set_rate)
#define resampler_ready EVALUATE(RESAMPLER_DECORATE,_resampler_ready)
#define resampler_clear EVALUATE(RESAMPLER_DECORATE,_resampler_clear)
@@ -49,6 +50,7 @@
int resampler_get_free_count(void *);
void resampler_write_sample(void *, short sample);
void resampler_write_sample_fixed(void *, int sample, unsigned char depth);
+void resampler_write_sample_float(void *, float sample);
void resampler_set_rate( void *, double new_factor );
int resampler_ready(void *);
void resampler_clear(void *);
--- a/src/helpers/resamp2.inc
+++ b/src/helpers/resamp2.inc
@@ -105,11 +105,11 @@
#define VOLUME_VARIABLES lvol, lvolr, lvold, lvolt, lvolm, rvol, rvolr, rvold, rvolt, rvolm
#define SET_VOLUME_VARIABLES { \
if ( volume_left ) { \
- lvolr = (int)(volume_left->volume * 16777216.0); \
- lvold = (int)(volume_left->delta * 16777216.0); \
- lvolt = (int)(volume_left->target * 16777216.0); \
- lvolm = (int)(volume_left->mix * 16777216.0); \
- lvol = MULSCV( lvolr, lvolm ); \
+ lvolr = volume_left->volume; \
+ lvold = volume_left->delta; \
+ lvolt = volume_left->target; \
+ lvolm = volume_left->mix; \
+ lvol = lvolr * lvolm; \
if ( lvolr == lvolt ) volume_left = NULL; \
} else { \
lvol = 0; \
@@ -118,11 +118,11 @@
lvolm = 0; \
} \
if ( volume_right ) { \
- rvolr = (int)(volume_right->volume * 16777216.0); \
- rvold = (int)(volume_right->delta * 16777216.0); \
- rvolt = (int)(volume_right->target * 16777216.0); \
- rvolm = (int)(volume_right->mix * 16777216.0); \
- rvol = MULSCV( rvolr, rvolm ); \
+ rvolr = volume_right->volume; \
+ rvold = volume_right->delta; \
+ rvolt = volume_right->target; \
+ rvolm = volume_right->mix; \
+ rvol = rvolr * rvolm; \
if ( rvolr == rvolt ) volume_right = NULL; \
} else { \
rvol = 0; \
@@ -132,8 +132,8 @@
} \
}
#define RETURN_VOLUME_VARIABLES { \
- if ( volume_left ) volume_left->volume = (float)lvolr / 16777216.0f; \
- if ( volume_right ) volume_right->volume = (float)rvolr / 16777216.0f; \
+ if ( volume_left ) volume_left->volume = lvolr; \
+ if ( volume_right ) volume_right->volume = rvolr; \
}
#define VOLUMES_ARE_ZERO (lvol == 0 && lvolt == 0 && rvol == 0 && rvolt == 0)
#define PEEK_FIR STEREO_DEST_PEEK_FIR
--- a/src/helpers/resamp3.inc
+++ b/src/helpers/resamp3.inc
@@ -47,7 +47,7 @@
long dumb_resample(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, VOLUME_PARAMETERS, float delta)
{
int dt, inv_dt;
- int VOLUME_VARIABLES;
+ float VOLUME_VARIABLES;
long done;
long todo;
LONG_LONG todo64;
@@ -209,7 +209,7 @@
void dumb_resample_get_current_sample(DUMB_RESAMPLER *resampler, VOLUME_PARAMETERS, sample_t *dst)
{
- int VOLUME_VARIABLES;
+ float VOLUME_VARIABLES;
SRCTYPE *src;
long pos;
int subpos;
--- a/src/helpers/resample.c
+++ b/src/helpers/resample.c
@@ -179,7 +179,7 @@
#define SUFFIX _16
#define SRCTYPE short
#define SRCBITS 16
-#define FIR(x) (x)
+#define FIR(x) (x * (1.0f / 32768.0f))
#include "resample.inc"
/* Create resamplers for 8-bit source samples. */
@@ -186,7 +186,7 @@
#define SUFFIX _8
#define SRCTYPE signed char
#define SRCBITS 8
-#define FIR(x) (x << 8)
+#define FIR(x) (x * (1.0f / 256.0f))
#include "resample.inc"
--- a/src/helpers/resample.inc
+++ b/src/helpers/resample.inc
@@ -98,9 +98,9 @@
pvol->declick_stage >= 3) \
pvol->declick_stage++; \
pvol = NULL; \
- vol = MULSCV( vol##t, vol##m ); \
+ vol = vol##t * vol##m; \
} else { \
- vol = MULSCV( vol##r, vol##m ); \
+ vol = vol##r * vol##m; \
} \
} \
}
@@ -118,11 +118,11 @@
#define MONO_DEST_VOLUME_ZEROS 0
#define SET_MONO_DEST_VOLUME_VARIABLES { \
if ( volume ) { \
- volr = (int)(volume->volume * 16777216.0); \
- vold = (int)(volume->delta * 16777216.0); \
- volt = (int)(volume->target * 16777216.0); \
- volm = (int)(volume->mix * 16777216.0); \
- vol = MULSCV( volr, volm ); \
+ volr = volume->volume; \
+ vold = volume->delta; \
+ volt = volume->target; \
+ volm = volume->mix; \
+ vol = volr * volm; \
if ( volr == volt ) volume = NULL; \
} else { \
vol = 0; \
@@ -131,26 +131,26 @@
volm = 0; \
} \
}
-#define RETURN_MONO_DEST_VOLUME_VARIABLES if ( volume ) volume->volume = (float)volr / 16777216.0f
+#define RETURN_MONO_DEST_VOLUME_VARIABLES if ( volume ) volume->volume = volr
#define MONO_DEST_VOLUMES_ARE_ZERO (vol == 0 && volt == 0)
#define POKE_FIR(offset) { \
- resampler_write_sample( resampler->fir_resampler[0], FIR(x[offset]) ); \
+ resampler_write_sample_float( resampler->fir_resampler[0], FIR(x[offset]) ); \
}
-#define MONO_DEST_PEEK_FIR *dst = MULSC( resampler_get_sample( resampler->fir_resampler[0] ), vol )
+#define MONO_DEST_PEEK_FIR *dst = resampler_get_sample_float( resampler->fir_resampler[0] ) * vol * 16777216.0f
#define MONO_DEST_MIX_FIR { \
- *dst++ += MULSC( resampler_get_sample( resampler->fir_resampler[0] ), vol ); \
+ *dst++ += resampler_get_sample_float( resampler->fir_resampler[0] ) * vol * 16777216.0f; \
UPDATE_VOLUME( volume, vol ); \
}
#define ADVANCE_FIR resampler_remove_sample( resampler->fir_resampler[0], 1 )
#define STEREO_DEST_PEEK_FIR { \
- int sample = resampler_get_sample( resampler->fir_resampler[0] ); \
- *dst++ = MULSC( sample, lvol ); \
- *dst++ = MULSC( sample, rvol ); \
+ float sample = resampler_get_sample_float( resampler->fir_resampler[0] ); \
+ *dst++ = sample * lvol * 16777216.0f; \
+ *dst++ = sample * rvol * 16777216.0f; \
}
#define STEREO_DEST_MIX_FIR { \
- int sample = resampler_get_sample( resampler->fir_resampler[0] ); \
- *dst++ += MULSC( sample, lvol ); \
- *dst++ += MULSC( sample, rvol ); \
+ float sample = resampler_get_sample_float( resampler->fir_resampler[0] ); \
+ *dst++ += sample * lvol * 16777216.0f; \
+ *dst++ += sample * rvol * 16777216.0f; \
UPDATE_VOLUME( volume_left, lvol ); \
UPDATE_VOLUME( volume_right, rvol ); \
}
@@ -179,11 +179,11 @@
#define MONO_DEST_VOLUME_ZEROS 0, 0
#define SET_MONO_DEST_VOLUME_VARIABLES { \
if ( volume_left ) { \
- lvolr = (int)(volume_left->volume * 16777216.0); \
- lvold = (int)(volume_left->delta * 16777216.0); \
- lvolt = (int)(volume_left->target * 16777216.0); \
- lvolm = (int)(volume_left->mix * 16777216.0); \
- lvol = MULSCV( lvolr, lvolm ); \
+ lvolr = volume_left->volume; \
+ lvold = volume_left->delta; \
+ lvolt = volume_left->target; \
+ lvolm = volume_left->mix; \
+ lvol = lvolr * lvolm; \
if ( lvolr == lvolt ) volume_left = NULL; \
} else { \
lvol = 0; \
@@ -192,11 +192,11 @@
lvolm = 0; \
} \
if ( volume_right ) { \
- rvolr = (int)(volume_right->volume * 16777216.0); \
- rvold = (int)(volume_right->delta * 16777216.0); \
- rvolt = (int)(volume_right->target * 16777216.0); \
- rvolm = (int)(volume_right->mix * 16777216.0); \
- rvol = MULSCV( rvolr, rvolm ); \
+ rvolr = volume_right->volume; \
+ rvold = volume_right->delta; \
+ rvolt = volume_right->target; \
+ rvolm = volume_right->mix; \
+ rvol = rvolr * rvolm; \
if ( rvolr == rvolt ) volume_right = NULL; \
} else { \
rvol = 0; \
@@ -206,21 +206,21 @@
} \
}
#define RETURN_MONO_DEST_VOLUME_VARIABLES { \
- if ( volume_left ) volume_left->volume = (float)lvolr / 16777216.0f; \
- if ( volume_right ) volume_right->volume = (float)rvolr / 16777216.0f; \
+ if ( volume_left ) volume_left->volume = lvolr; \
+ if ( volume_right ) volume_right->volume = rvolr; \
}
#define MONO_DEST_VOLUMES_ARE_ZERO (lvol == 0 && lvolt == 0 && rvol == 0 && rvolt == 0)
#define POKE_FIR(offset) { \
- resampler_write_sample( resampler->fir_resampler[0], FIR(x[(offset)*2+0]) ); \
- resampler_write_sample( resampler->fir_resampler[1], FIR(x[(offset)*2+1]) ); \
+ resampler_write_sample_float( resampler->fir_resampler[0], FIR(x[(offset)*2+0]) ); \
+ resampler_write_sample_float( resampler->fir_resampler[1], FIR(x[(offset)*2+1]) ); \
}
#define MONO_DEST_PEEK_FIR { \
- *dst = MULSC( resampler_get_sample( resampler->fir_resampler[0] ), lvol ) + \
- MULSC( resampler_get_sample( resampler->fir_resampler[1] ), rvol ); \
+ *dst = (resampler_get_sample_float( resampler->fir_resampler[0] ) * lvol + \
+ resampler_get_sample_float( resampler->fir_resampler[1] ) * rvol) * 16777216.0f; \
}
#define MONO_DEST_MIX_FIR { \
- *dst++ += MULSC( resampler_get_sample( resampler->fir_resampler[0] ), lvol ) + \
- MULSC( resampler_get_sample( resampler->fir_resampler[1] ), rvol ); \
+ *dst++ += (resampler_get_sample_float( resampler->fir_resampler[0] ) * lvol + \
+ resampler_get_sample_float( resampler->fir_resampler[1] ) * rvol) * 16777216.0f; \
UPDATE_VOLUME( volume_left, lvol ); \
UPDATE_VOLUME( volume_right, rvol ); \
}
@@ -229,12 +229,12 @@
resampler_remove_sample( resampler->fir_resampler[1], 1 ); \
}
#define STEREO_DEST_PEEK_FIR { \
- *dst++ = MULSC( resampler_get_sample( resampler->fir_resampler[0] ), lvol ); \
- *dst++ = MULSC( resampler_get_sample( resampler->fir_resampler[1] ), rvol ); \
+ *dst++ = resampler_get_sample_float( resampler->fir_resampler[0] ) * lvol * 16777216.0f; \
+ *dst++ = resampler_get_sample_float( resampler->fir_resampler[1] ) * rvol * 16777216.0f; \
}
#define STEREO_DEST_MIX_FIR { \
- *dst++ += MULSC( resampler_get_sample( resampler->fir_resampler[0] ), lvol ); \
- *dst++ += MULSC( resampler_get_sample( resampler->fir_resampler[1] ), rvol ); \
+ *dst++ += resampler_get_sample_float( resampler->fir_resampler[0] ) * lvol * 16777216.0f; \
+ *dst++ += resampler_get_sample_float( resampler->fir_resampler[1] ) * rvol * 16777216.0f; \
UPDATE_VOLUME( volume_left, lvol ); \
UPDATE_VOLUME( volume_right, rvol ); \
}
--- a/src/helpers/resampler.c
+++ b/src/helpers/resampler.c
@@ -388,6 +388,27 @@
}
}
+void resampler_write_sample_float(void *_r, float s)
+{
+ resampler * r = ( resampler * ) _r;
+
+ if ( r->delay_added < 0 )
+ {
+ r->delay_added = 0;
+ r->write_filled = resampler_input_delay( r );
+ }
+
+ if ( r->write_filled < resampler_buffer_size )
+ {
+ r->buffer_in[ r->write_pos ] = s;
+ r->buffer_in[ r->write_pos + resampler_buffer_size ] = s;
+
+ ++r->write_filled;
+
+ r->write_pos = ( r->write_pos + 1 ) % resampler_buffer_size;
+ }
+}
+
static int resampler_run_zoh(resampler * r, float ** out_, float * out_end)
{
int in_size = r->write_filled;