Skip to content

Commit

Permalink
Add callback to specttuner to track frequency changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BatchDrake committed May 12, 2023
1 parent b5be9b4 commit 927b921
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/include/sigutils/pll.h
Expand Up @@ -86,6 +86,12 @@ SU_DESTRUCTOR(su_pll);
SU_METHOD(su_pll, SUCOMPLEX, track, SUCOMPLEX x);
SU_METHOD(su_pll, void, feed, SUFLOAT x);

SUINLINE
SU_METHOD(su_pll, SUFLOAT, locksig)
{
return self->lock;
}

/* QPSK costas loops are way more complex than that */
SU_CONSTRUCTOR(
su_costas,
Expand Down
20 changes: 14 additions & 6 deletions src/include/sigutils/specttuner.h
Expand Up @@ -63,12 +63,19 @@ struct sigutils_specttuner_channel_params {
SUBOOL precise; /* Precision mode */
enum sigutils_specttuner_channel_domain domain; /* Domain */
void *privdata; /* Private data */
SUBOOL(*on_data)
(const struct sigutils_specttuner_channel *channel,
void *privdata,
const SUCOMPLEX
*data, /* This pointer remains valid until the next call to feed */
SUSCOUNT size);

SUBOOL (*on_data) (
const struct sigutils_specttuner_channel *channel,
void *privdata,
const SUCOMPLEX *data, /* This pointer remains valid until the next call to feed */
SUSCOUNT size);

void (*on_freq_changed) (
const struct sigutils_specttuner_channel *channel,
void *privdata,
SUFLOAT f0_bin,
const su_ncqo_t *old_lo,
const su_ncqo_t *new_lo);
};

#define sigutils_specttuner_channel_params_INITIALIZER \
Expand All @@ -81,6 +88,7 @@ struct sigutils_specttuner_channel_params {
SU_SPECTTUNER_CHANNEL_TIME_DOMAIN, /* domain */ \
NULL, /* private */ \
NULL, /* on_data */ \
NULL /* on_freq_changed */ \
}

struct sigutils_specttuner_channel {
Expand Down
1 change: 1 addition & 0 deletions src/sigutils/pll.c
Expand Up @@ -59,6 +59,7 @@ SU_METHOD(su_pll, SUCOMPLEX, track, SUCOMPLEX x)

su_ncqo_inc_angfreq(&self->ncqo, self->alpha * error);
su_ncqo_inc_phase(&self->ncqo, self->beta * error);
SU_SPLPF_FEED(self->lock, SU_C_REAL(mix), self->alpha);

return mix;
}
Expand Down
17 changes: 16 additions & 1 deletion src/sigutils/specttuner.c
Expand Up @@ -172,7 +172,8 @@ SU_METHOD_CONST(
{
unsigned int window_size = self->params.window_size;
SUFLOAT rbw = 2 * PI / window_size;
SUFLOAT off, ef;
SUFLOAT off = 0, ef;
const su_ncqo_t *old = NULL, *new = NULL;

ef = su_specttuner_channel_get_effective_freq(channel);
channel->center = 2 * SU_FLOOR(.5 * (ef + 1 * rbw) / (2 * PI) * window_size);
Expand All @@ -188,6 +189,20 @@ SU_METHOD_CONST(
off *= channel->decimation;
su_ncqo_set_angfreq(&channel->lo, off);
}

if (channel->params.on_freq_changed != NULL) {
if (channel->params.precise) {
old = &channel->old_lo;
new = &channel->lo;
}

channel->params.on_freq_changed(
channel,
channel->params.privdata,
channel->center * rbw,
old,
new);
}
}

SU_METHOD_CONST(
Expand Down

0 comments on commit 927b921

Please sign in to comment.