2023-02-08 18:12:00 +01:00
|
|
|
/* Spa */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2018-12-05 15:58:55 +01:00
|
|
|
|
2019-03-27 17:58:48 +01:00
|
|
|
#ifndef RESAMPLE_H
|
|
|
|
|
#define RESAMPLE_H
|
|
|
|
|
|
2018-12-19 16:47:20 +01:00
|
|
|
#include <spa/support/cpu.h>
|
2019-04-02 23:06:46 +02:00
|
|
|
#include <spa/support/log.h>
|
2018-12-19 16:47:20 +01:00
|
|
|
|
2020-02-12 13:31:03 +01:00
|
|
|
#define RESAMPLE_DEFAULT_QUALITY 4
|
2025-11-20 12:33:14 +01:00
|
|
|
#define RESAMPLE_MAX_PARAMS 16
|
2020-02-12 13:31:03 +01:00
|
|
|
|
2025-11-14 18:15:38 +01:00
|
|
|
struct resample_config {
|
2025-11-20 12:33:14 +01:00
|
|
|
#define RESAMPLE_WINDOW_EXP 0
|
|
|
|
|
#define RESAMPLE_WINDOW_BLACKMAN 1
|
|
|
|
|
#define RESAMPLE_WINDOW_KAISER 2
|
2025-11-14 18:15:38 +01:00
|
|
|
uint32_t window;
|
|
|
|
|
|
|
|
|
|
double cutoff;
|
2025-11-20 12:33:14 +01:00
|
|
|
uint32_t n_taps;
|
2025-11-14 18:15:38 +01:00
|
|
|
|
2025-11-20 12:33:14 +01:00
|
|
|
#define RESAMPLE_PARAM_EXP_A 0
|
|
|
|
|
#define RESAMPLE_PARAM_BLACKMAN_ALPHA 0
|
|
|
|
|
#define RESAMPLE_PARAM_KAISER_ALPHA 0
|
|
|
|
|
#define RESAMPLE_PARAM_KAISER_SB_ATT 1 /* stopband attenuation */
|
|
|
|
|
#define RESAMPLE_PARAM_KAISER_TR_BW 2 /* transition bandwidth */
|
|
|
|
|
#define RESAMPLE_PARAM_INVALID (RESAMPLE_MAX_PARAMS-1)
|
|
|
|
|
double params[RESAMPLE_MAX_PARAMS];
|
2025-11-14 18:15:38 +01:00
|
|
|
};
|
|
|
|
|
|
2018-12-05 15:58:55 +01:00
|
|
|
struct resample {
|
2022-06-28 16:45:07 +02:00
|
|
|
struct spa_log *log;
|
2022-09-19 12:35:49 +02:00
|
|
|
#define RESAMPLE_OPTION_PREFILL (1<<0)
|
|
|
|
|
uint32_t options;
|
2018-12-19 16:47:20 +01:00
|
|
|
uint32_t cpu_flags;
|
2022-06-28 16:45:07 +02:00
|
|
|
const char *func_name;
|
|
|
|
|
|
2018-12-05 15:58:55 +01:00
|
|
|
uint32_t channels;
|
|
|
|
|
uint32_t i_rate;
|
|
|
|
|
uint32_t o_rate;
|
2019-04-23 17:34:27 +02:00
|
|
|
double rate;
|
2020-02-12 13:31:03 +01:00
|
|
|
int quality;
|
2018-12-05 15:58:55 +01:00
|
|
|
|
2025-11-20 12:33:14 +01:00
|
|
|
struct resample_config config; /* set to all 0 for defaults */
|
2025-11-14 18:15:38 +01:00
|
|
|
|
2019-03-26 12:58:26 +01:00
|
|
|
void (*free) (struct resample *r);
|
|
|
|
|
void (*update_rate) (struct resample *r, double rate);
|
2019-07-08 18:26:08 +02:00
|
|
|
uint32_t (*in_len) (struct resample *r, uint32_t out_len);
|
|
|
|
|
uint32_t (*out_len) (struct resample *r, uint32_t in_len);
|
2019-03-26 12:58:26 +01:00
|
|
|
void (*process) (struct resample *r,
|
|
|
|
|
const void * SPA_RESTRICT src[], uint32_t *in_len,
|
|
|
|
|
void * SPA_RESTRICT dst[], uint32_t *out_len);
|
|
|
|
|
void (*reset) (struct resample *r);
|
|
|
|
|
uint32_t (*delay) (struct resample *r);
|
2025-01-18 12:39:21 +02:00
|
|
|
|
|
|
|
|
/** Fractional part of delay (in input samples) */
|
|
|
|
|
float (*phase) (struct resample *r);
|
|
|
|
|
|
2018-12-05 15:58:55 +01:00
|
|
|
void *data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define resample_free(r) (r)->free(r)
|
|
|
|
|
#define resample_update_rate(r,...) (r)->update_rate(r,__VA_ARGS__)
|
2019-07-08 18:26:08 +02:00
|
|
|
#define resample_in_len(r,...) (r)->in_len(r,__VA_ARGS__)
|
|
|
|
|
#define resample_out_len(r,...) (r)->out_len(r,__VA_ARGS__)
|
2018-12-05 15:58:55 +01:00
|
|
|
#define resample_process(r,...) (r)->process(r,__VA_ARGS__)
|
|
|
|
|
#define resample_reset(r) (r)->reset(r)
|
2019-03-26 12:58:26 +01:00
|
|
|
#define resample_delay(r) (r)->delay(r)
|
2025-01-18 12:39:21 +02:00
|
|
|
#define resample_phase(r) (r)->phase(r)
|
2019-03-27 17:58:48 +01:00
|
|
|
|
2020-04-03 17:46:04 +02:00
|
|
|
int resample_native_init(struct resample *r);
|
2025-11-14 18:15:38 +01:00
|
|
|
int resample_native_init_config(struct resample *r, struct resample_config *conf);
|
2020-04-03 17:46:04 +02:00
|
|
|
int resample_peaks_init(struct resample *r);
|
|
|
|
|
|
2025-11-14 18:15:38 +01:00
|
|
|
static const struct resample_window_info {
|
|
|
|
|
uint32_t window;
|
|
|
|
|
const char *label;
|
|
|
|
|
const char *description;
|
|
|
|
|
} resample_window_info[] = {
|
|
|
|
|
[RESAMPLE_WINDOW_EXP] = { RESAMPLE_WINDOW_EXP,
|
|
|
|
|
"exponential", "Exponential window", },
|
|
|
|
|
[RESAMPLE_WINDOW_BLACKMAN] = { RESAMPLE_WINDOW_BLACKMAN,
|
|
|
|
|
"blackman", "Blackman window", },
|
|
|
|
|
[RESAMPLE_WINDOW_KAISER] = { RESAMPLE_WINDOW_KAISER,
|
|
|
|
|
"kaiser", "Kaiser window", },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static inline uint32_t resample_window_from_label(const char *label)
|
|
|
|
|
{
|
|
|
|
|
SPA_FOR_EACH_ELEMENT_VAR(resample_window_info, i) {
|
|
|
|
|
if (spa_streq(i->label, label))
|
|
|
|
|
return i->window;
|
|
|
|
|
}
|
|
|
|
|
return RESAMPLE_WINDOW_EXP;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-20 12:33:14 +01:00
|
|
|
static const struct resample_param_info {
|
|
|
|
|
uint32_t idx;
|
|
|
|
|
const char *label;
|
|
|
|
|
} resample_param_info[] = {
|
|
|
|
|
{ RESAMPLE_PARAM_EXP_A, "exp.A" },
|
|
|
|
|
{ RESAMPLE_PARAM_BLACKMAN_ALPHA, "blackman.alpha" },
|
|
|
|
|
{ RESAMPLE_PARAM_KAISER_ALPHA, "kaiser.alpha" },
|
|
|
|
|
{ RESAMPLE_PARAM_KAISER_SB_ATT, "kaiser.stopband-attenuation" },
|
|
|
|
|
{ RESAMPLE_PARAM_KAISER_TR_BW, "kaiser.transition-bandwidth" },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static inline uint32_t resample_param_from_label(const char *label)
|
|
|
|
|
{
|
|
|
|
|
SPA_FOR_EACH_ELEMENT_VAR(resample_param_info, i) {
|
|
|
|
|
if (spa_streq(i->label, label))
|
|
|
|
|
return i->idx;
|
|
|
|
|
}
|
|
|
|
|
return RESAMPLE_PARAM_INVALID;
|
|
|
|
|
}
|
2025-11-14 18:15:38 +01:00
|
|
|
|
2019-03-27 17:58:48 +01:00
|
|
|
#endif /* RESAMPLE_H */
|