mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	audioconvert: track and compensate for rate changes
Follow the rate of the _io_position area and adjust the resampler to match. This ensures that we always process at the DSP samplerate to the target negotiated fixed rate of the device/stream.
This commit is contained in:
		
							parent
							
								
									519bd342be
								
							
						
					
					
						commit
						2ad202b8e8
					
				
					 1 changed files with 27 additions and 5 deletions
				
			
		| 
						 | 
					@ -124,6 +124,8 @@ struct impl {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct resample resample;
 | 
						struct resample resample;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						double rate_scale;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	float empty[MAX_SAMPLES + MAX_ALIGN];
 | 
						float empty[MAX_SAMPLES + MAX_ALIGN];
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -252,9 +254,9 @@ static void update_rate_match(struct impl *this, bool passthrough, uint32_t out_
 | 
				
			||||||
			match_size = out_size;
 | 
								match_size = out_size;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if (SPA_FLAG_IS_SET(this->io_rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE))
 | 
								if (SPA_FLAG_IS_SET(this->io_rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE))
 | 
				
			||||||
				resample_update_rate(&this->resample, this->io_rate_match->rate);
 | 
									resample_update_rate(&this->resample, this->rate_scale * this->io_rate_match->rate);
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
				resample_update_rate(&this->resample, 1.0);
 | 
									resample_update_rate(&this->resample, this->rate_scale);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			this->io_rate_match->delay = resample_delay(&this->resample);
 | 
								this->io_rate_match->delay = resample_delay(&this->resample);
 | 
				
			||||||
			match_size = resample_in_len(&this->resample, out_size);
 | 
								match_size = resample_in_len(&this->resample, out_size);
 | 
				
			||||||
| 
						 | 
					@ -263,7 +265,7 @@ static void update_rate_match(struct impl *this, bool passthrough, uint32_t out_
 | 
				
			||||||
		this->io_rate_match->size = match_size;
 | 
							this->io_rate_match->size = match_size;
 | 
				
			||||||
		spa_log_trace_fp(this->log, NAME " %p: next match %u", this, match_size);
 | 
							spa_log_trace_fp(this->log, NAME " %p: next match %u", this, match_size);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		resample_update_rate(&this->resample, this->props.rate);
 | 
							resample_update_rate(&this->resample, this->rate_scale * this->props.rate);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -824,8 +826,26 @@ static int impl_node_process(void *object)
 | 
				
			||||||
	size = sb->datas[0].chunk->size;
 | 
						size = sb->datas[0].chunk->size;
 | 
				
			||||||
	maxsize = db->datas[0].maxsize;
 | 
						maxsize = db->datas[0].maxsize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (SPA_LIKELY(this->io_position))
 | 
						if (SPA_LIKELY(this->io_position)) {
 | 
				
			||||||
 | 
							double r =  this->rate_scale;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		max = this->io_position->clock.duration;
 | 
							max = this->io_position->clock.duration;
 | 
				
			||||||
 | 
							if (this->mode == MODE_SPLIT) {
 | 
				
			||||||
 | 
								if (this->io_position->clock.rate.denom != this->resample.o_rate)
 | 
				
			||||||
 | 
									r = (double) this->io_position->clock.rate.denom / this->resample.o_rate;
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									r = 1.0;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								if (this->io_position->clock.rate.denom != this->resample.i_rate)
 | 
				
			||||||
 | 
									r = (double) this->resample.i_rate / this->io_position->clock.rate.denom;
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									r = 1.0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (this->rate_scale != r) {
 | 
				
			||||||
 | 
								spa_log_info(this->log, "scale %f->%f", this->rate_scale, r);
 | 
				
			||||||
 | 
								this->rate_scale = r;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		max = maxsize / sizeof(float);
 | 
							max = maxsize / sizeof(float);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -867,7 +887,7 @@ static int impl_node_process(void *object)
 | 
				
			||||||
	pin_len = in_len;
 | 
						pin_len = in_len;
 | 
				
			||||||
	pout_len = out_len;
 | 
						pout_len = out_len;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	passthrough = this->resample.i_rate == this->resample.o_rate &&
 | 
						passthrough = this->resample.i_rate == this->resample.o_rate && this->rate_scale == 1.0 &&
 | 
				
			||||||
		(this->io_rate_match == NULL ||
 | 
							(this->io_rate_match == NULL ||
 | 
				
			||||||
		 !SPA_FLAG_IS_SET(this->io_rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE));
 | 
							 !SPA_FLAG_IS_SET(this->io_rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1030,6 +1050,8 @@ impl_init(const struct spa_handle_factory *factory,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_hook_list_init(&this->hooks);
 | 
						spa_hook_list_init(&this->hooks);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						this->rate_scale = 1.0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this->info = SPA_NODE_INFO_INIT();
 | 
						this->info = SPA_NODE_INFO_INIT();
 | 
				
			||||||
	this->info_all = SPA_NODE_CHANGE_MASK_FLAGS;
 | 
						this->info_all = SPA_NODE_CHANGE_MASK_FLAGS;
 | 
				
			||||||
	this->info.max_input_ports = 1;
 | 
						this->info.max_input_ports = 1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue