mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	audioconvert: add function to get phase to resampler API
Support getting any fractional phase part of the resampler delay in its API.
This commit is contained in:
		
							parent
							
								
									d36a867788
								
							
						
					
					
						commit
						07f6dde3dd
					
				
					 3 changed files with 30 additions and 0 deletions
				
			
		| 
						 | 
					@ -315,6 +315,27 @@ static uint32_t impl_native_delay (struct resample *r)
 | 
				
			||||||
	return d->n_taps / 2 - 1;
 | 
						return d->n_taps / 2 - 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int32_t impl_native_phase_ns(struct resample *r)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct native_data *d = r->data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (d->func == d->info->process_full) {
 | 
				
			||||||
 | 
							float pho = -(float)((int32_t)d->phase) / d->out_rate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (pho != 0.0f)
 | 
				
			||||||
 | 
								pho += 1.0f;
 | 
				
			||||||
 | 
							return (int32_t)(pho * SPA_NSEC_PER_SEC / r->i_rate);
 | 
				
			||||||
 | 
						} else if (d->func == d->info->process_inter) {
 | 
				
			||||||
 | 
							float pho = -d->phase / d->out_rate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (pho != 0.0f)
 | 
				
			||||||
 | 
								pho += 1.0f;
 | 
				
			||||||
 | 
							return (int32_t)(pho * SPA_NSEC_PER_SEC / r->i_rate);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int resample_native_init(struct resample *r)
 | 
					int resample_native_init(struct resample *r)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct native_data *d;
 | 
						struct native_data *d;
 | 
				
			||||||
| 
						 | 
					@ -331,6 +352,7 @@ int resample_native_init(struct resample *r)
 | 
				
			||||||
	r->process = impl_native_process;
 | 
						r->process = impl_native_process;
 | 
				
			||||||
	r->reset = impl_native_reset;
 | 
						r->reset = impl_native_reset;
 | 
				
			||||||
	r->delay = impl_native_delay;
 | 
						r->delay = impl_native_delay;
 | 
				
			||||||
 | 
						r->phase_ns = impl_native_phase_ns;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	q = &window_qualities[r->quality];
 | 
						q = &window_qualities[r->quality];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -100,6 +100,11 @@ static void impl_peaks_reset (struct resample *r)
 | 
				
			||||||
	d->i_count = d->o_count = 0;
 | 
						d->i_count = d->o_count = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int32_t impl_peaks_phase_ns (struct resample *r)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int resample_peaks_init(struct resample *r)
 | 
					int resample_peaks_init(struct resample *r)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct peaks_data *d;
 | 
						struct peaks_data *d;
 | 
				
			||||||
| 
						 | 
					@ -125,6 +130,7 @@ int resample_peaks_init(struct resample *r)
 | 
				
			||||||
	r->delay = impl_peaks_delay;
 | 
						r->delay = impl_peaks_delay;
 | 
				
			||||||
	r->in_len = impl_peaks_in_len;
 | 
						r->in_len = impl_peaks_in_len;
 | 
				
			||||||
	r->out_len = impl_peaks_out_len;
 | 
						r->out_len = impl_peaks_out_len;
 | 
				
			||||||
 | 
						r->phase_ns = impl_peaks_phase_ns;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_log_debug(r->log, "peaks %p: in:%d out:%d features:%08x:%08x", r,
 | 
						spa_log_debug(r->log, "peaks %p: in:%d out:%d features:%08x:%08x", r,
 | 
				
			||||||
			r->i_rate, r->o_rate, r->cpu_flags, d->peaks.cpu_flags);
 | 
								r->i_rate, r->o_rate, r->cpu_flags, d->peaks.cpu_flags);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,6 +32,7 @@ struct resample {
 | 
				
			||||||
				 void * SPA_RESTRICT dst[], uint32_t *out_len);
 | 
									 void * SPA_RESTRICT dst[], uint32_t *out_len);
 | 
				
			||||||
	void (*reset)		(struct resample *r);
 | 
						void (*reset)		(struct resample *r);
 | 
				
			||||||
	uint32_t (*delay)	(struct resample *r);
 | 
						uint32_t (*delay)	(struct resample *r);
 | 
				
			||||||
 | 
						int32_t (*phase_ns)	(struct resample *r);
 | 
				
			||||||
	void *data;
 | 
						void *data;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,6 +43,7 @@ struct resample {
 | 
				
			||||||
#define resample_process(r,...)		(r)->process(r,__VA_ARGS__)
 | 
					#define resample_process(r,...)		(r)->process(r,__VA_ARGS__)
 | 
				
			||||||
#define resample_reset(r)		(r)->reset(r)
 | 
					#define resample_reset(r)		(r)->reset(r)
 | 
				
			||||||
#define resample_delay(r)		(r)->delay(r)
 | 
					#define resample_delay(r)		(r)->delay(r)
 | 
				
			||||||
 | 
					#define resample_phase_ns(r)		(r)->phase_ns(r)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int resample_native_init(struct resample *r);
 | 
					int resample_native_init(struct resample *r);
 | 
				
			||||||
int resample_peaks_init(struct resample *r);
 | 
					int resample_peaks_init(struct resample *r);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue