mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	resample: add some more qualities
Clamp quality to available qualities. 0 is a valid quality
This commit is contained in:
		
							parent
							
								
									484d211119
								
							
						
					
					
						commit
						0023aac9b9
					
				
					 2 changed files with 15 additions and 7 deletions
				
			
		| 
						 | 
					@ -40,7 +40,11 @@ static const struct quality blackman_qualities[] = {
 | 
				
			||||||
	{ 96, 0.933, },
 | 
						{ 96, 0.933, },
 | 
				
			||||||
	{ 128, 0.950, },
 | 
						{ 128, 0.950, },
 | 
				
			||||||
	{ 144, 0.955, },
 | 
						{ 144, 0.955, },
 | 
				
			||||||
	{ 160, 0.960, }
 | 
						{ 160, 0.960, },
 | 
				
			||||||
 | 
						{ 180, 0.965, },
 | 
				
			||||||
 | 
						{ 256, 0.975, },
 | 
				
			||||||
 | 
						{ 896, 0.997, },
 | 
				
			||||||
 | 
						{ 1024, 0.998, },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline double sinc(double x)
 | 
					static inline double sinc(double x)
 | 
				
			||||||
| 
						 | 
					@ -255,11 +259,12 @@ static uint32_t impl_native_delay (struct resample *r)
 | 
				
			||||||
static int impl_native_init(struct resample *r)
 | 
					static int impl_native_init(struct resample *r)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct native_data *d;
 | 
						struct native_data *d;
 | 
				
			||||||
	const struct quality *q = &blackman_qualities[r->quality];
 | 
						const struct quality *q;
 | 
				
			||||||
	double scale;
 | 
						double scale;
 | 
				
			||||||
	uint32_t c, n_taps, n_phases, filter_size, in_rate, out_rate, gcd, filter_stride;
 | 
						uint32_t c, n_taps, n_phases, filter_size, in_rate, out_rate, gcd, filter_stride;
 | 
				
			||||||
	uint32_t history_stride, history_size, oversample;
 | 
						uint32_t history_stride, history_size, oversample;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						r->quality = SPA_CLAMP(r->quality, 0, (int) SPA_N_ELEMENTS(blackman_qualities) - 1);
 | 
				
			||||||
	r->free = impl_native_free;
 | 
						r->free = impl_native_free;
 | 
				
			||||||
	r->update_rate = impl_native_update_rate;
 | 
						r->update_rate = impl_native_update_rate;
 | 
				
			||||||
	r->in_len = impl_native_in_len;
 | 
						r->in_len = impl_native_in_len;
 | 
				
			||||||
| 
						 | 
					@ -267,6 +272,8 @@ static int impl_native_init(struct resample *r)
 | 
				
			||||||
	r->reset = impl_native_reset;
 | 
						r->reset = impl_native_reset;
 | 
				
			||||||
	r->delay = impl_native_delay;
 | 
						r->delay = impl_native_delay;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						q = &blackman_qualities[r->quality];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gcd = calc_gcd(r->i_rate, r->o_rate);
 | 
						gcd = calc_gcd(r->i_rate, r->o_rate);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	in_rate = r->i_rate / gcd;
 | 
						in_rate = r->i_rate / gcd;
 | 
				
			||||||
| 
						 | 
					@ -311,8 +318,8 @@ static int impl_native_init(struct resample *r)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	build_filter(d->filter, d->filter_stride, n_taps, n_phases, scale);
 | 
						build_filter(d->filter, d->filter_stride, n_taps, n_phases, scale);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_log_debug(r->log, "native %p: in:%d out:%d n_taps:%d n_phases:%d",
 | 
						spa_log_debug(r->log, "native %p: q:%d in:%d out:%d n_taps:%d n_phases:%d",
 | 
				
			||||||
			r, in_rate, out_rate, n_taps, n_phases);
 | 
								r, r->quality, in_rate, out_rate, n_taps, n_phases);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	impl_native_reset(r);
 | 
						impl_native_reset(r);
 | 
				
			||||||
	impl_native_update_rate(r, 1.0);
 | 
						impl_native_update_rate(r, 1.0);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,7 +42,7 @@ SPA_LOG_IMPL(logger);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define DEFAULT_QUALITY	RESAMPLE_DEFAULT_QUALITY
 | 
					#define DEFAULT_QUALITY	RESAMPLE_DEFAULT_QUALITY
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MAX_SAMPLES	1024
 | 
					#define MAX_SAMPLES	4096u
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct data {
 | 
					struct data {
 | 
				
			||||||
	bool verbose;
 | 
						bool verbose;
 | 
				
			||||||
| 
						 | 
					@ -165,7 +165,7 @@ static int do_conversion(struct data *d)
 | 
				
			||||||
	r.channels = channels;
 | 
						r.channels = channels;
 | 
				
			||||||
	r.i_rate = d->iinfo.samplerate;
 | 
						r.i_rate = d->iinfo.samplerate;
 | 
				
			||||||
	r.o_rate = d->oinfo.samplerate;
 | 
						r.o_rate = d->oinfo.samplerate;
 | 
				
			||||||
	r.quality = d->quality > 0 ? d->quality : DEFAULT_QUALITY;
 | 
						r.quality = d->quality < 0 ? DEFAULT_QUALITY : d->quality;
 | 
				
			||||||
	impl_native_init(&r);
 | 
						impl_native_init(&r);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (j = 0; j < channels; j++)
 | 
						for (j = 0; j < channels; j++)
 | 
				
			||||||
| 
						 | 
					@ -176,7 +176,7 @@ static int do_conversion(struct data *d)
 | 
				
			||||||
	queued = 0;
 | 
						queued = 0;
 | 
				
			||||||
	while (true) {
 | 
						while (true) {
 | 
				
			||||||
		pout_len = out_len = MAX_SAMPLES;
 | 
							pout_len = out_len = MAX_SAMPLES;
 | 
				
			||||||
                in_len = SPA_MIN(MAX_SAMPLES, (int)resample_in_len(&r, out_len)) - queued;
 | 
					                in_len = SPA_MIN(MAX_SAMPLES, resample_in_len(&r, out_len)) - queued;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	        pin_len = in_len = sf_readf_float(d->ifile, &ibuf[queued * channels], in_len);
 | 
						        pin_len = in_len = sf_readf_float(d->ifile, &ibuf[queued * channels], in_len);
 | 
				
			||||||
		if (pin_len == 0) {
 | 
							if (pin_len == 0) {
 | 
				
			||||||
| 
						 | 
					@ -226,6 +226,7 @@ int main(int argc, char *argv[])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	logger.log.level = SPA_LOG_LEVEL_DEBUG;
 | 
						logger.log.level = SPA_LOG_LEVEL_DEBUG;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						data.quality = -1;
 | 
				
			||||||
	while ((c = getopt_long(argc, argv, OPTIONS, long_options, &longopt_index)) != -1) {
 | 
						while ((c = getopt_long(argc, argv, OPTIONS, long_options, &longopt_index)) != -1) {
 | 
				
			||||||
		switch (c) {
 | 
							switch (c) {
 | 
				
			||||||
		case 'h':
 | 
							case 'h':
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue