node: add active flag for rate match

Add flags to the rate match io area
Add flag to activate/deactivate rate match
Set active flag in rate match when slaved
Update rate before starting resample
This commit is contained in:
Wim Taymans 2019-10-21 10:13:56 +02:00
parent f5b9862a89
commit 116676e149
3 changed files with 14 additions and 3 deletions

View file

@ -265,6 +265,8 @@ struct spa_io_rate_match {
uint32_t delay; /**< extra delay in samples for resampler */
uint32_t size; /**< requested input size for resampler */
double rate; /**< rate for resampler */
#define SPA_IO_RATE_MATCH_FLAG_ACTIVE (1 << 0)
uint32_t flags; /**< extra flags */
};
#ifdef __cplusplus

View file

@ -608,7 +608,7 @@ static int get_status(struct state *state, snd_pcm_uframes_t *delay, snd_pcm_ufr
*target = state->last_threshold;
if (state->rate_match) {
if (state->slaved && state->rate_match) {
state->delay = state->rate_match->delay;
state->read_size = state->rate_match->size;
/* We try to compensate for the latency introduced by rate matching
@ -672,11 +672,13 @@ static int update_time(struct state *state, uint64_t nsec, snd_pcm_sframes_t del
err, state->z1, state->z2, state->z3);
}
if (slave && state->rate_match) {
if (state->rate_match) {
if (state->stream == SND_PCM_STREAM_PLAYBACK)
state->rate_match->rate = SPA_CLAMP(corr, 0.95, 1.05);
else
state->rate_match->rate = SPA_CLAMP(1.0/corr, 0.95, 1.05);
SPA_FLAG_UPDATE(state->rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE, slave);
}
state->next_time += state->threshold / corr * 1e9 / state->rate;

View file

@ -767,6 +767,14 @@ static int impl_node_process(void *object)
break;
}
if (this->io_rate_match) {
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);
} else {
resample_update_rate(&this->resample, 1.0);
}
}
in_len = (size - inport->offset) / sizeof(float);
out_len = (maxsize - outport->offset) / sizeof(float);
@ -812,7 +820,6 @@ static int impl_node_process(void *object)
}
if (this->io_rate_match) {
resample_update_rate(&this->resample, this->io_rate_match->rate);
this->io_rate_match->delay = resample_delay(&this->resample);
this->io_rate_match->size = resample_in_len(&this->resample, max);
}