feature: Add lc3_encoder_disable_ltpf

LTPF requires a lot of processing power, so disabling it might be
required for embedded low-performance devices.
This commit is contained in:
anonymix007
2025-02-28 19:44:17 +03:00
committed by Antoine SOULIER
parent 1de85e2d9b
commit 9f1e206b34
4 changed files with 26 additions and 2 deletions

View File

@@ -355,6 +355,17 @@ LC3_EXPORT lc3_encoder_t lc3_hr_setup_encoder(
LC3_EXPORT lc3_encoder_t lc3_setup_encoder( LC3_EXPORT lc3_encoder_t lc3_setup_encoder(
int dt_us, int sr_hz, int sr_pcm_hz, void *mem); int dt_us, int sr_hz, int sr_pcm_hz, void *mem);
/**
* Disable LTPF analysis
* encoder Handle of the encoder
*
* LTPF analysis is known to take a lot of CPU time and work quite bad on
* synthetic signals such as sine waves, so it might be beneficial to
* disable it in such cases.
*/
LC3_EXPORT void lc3_encoder_disable_ltpf(
lc3_encoder_t encoder);
/** /**
* Encode a frame * Encode a frame
* encoder Handle of the encoder * encoder Handle of the encoder

View File

@@ -137,6 +137,11 @@ class Encoder : public Base<struct lc3_encoder> {
} }
} }
void DisableLTPF() {
for (auto &s : states)
lc3_encoder_disable_ltpf(s.get());
}
~Encoder() override = default; ~Encoder() override = default;
// Reset encoder state // Reset encoder state

View File

@@ -113,6 +113,8 @@ typedef struct lc3_spec_analysis {
} lc3_spec_analysis_t; } lc3_spec_analysis_t;
struct lc3_encoder { struct lc3_encoder {
bool ltpf_bypass;
enum lc3_dt dt; enum lc3_dt dt;
enum lc3_srate sr, sr_pcm; enum lc3_srate sr, sr_pcm;

View File

@@ -301,7 +301,7 @@ static void analyze(struct lc3_encoder *encoder,
bool att = lc3_attdet_run(dt, sr_pcm, nbytes, &encoder->attdet, xt); bool att = lc3_attdet_run(dt, sr_pcm, nbytes, &encoder->attdet, xt);
side->pitch_present = side->pitch_present = !encoder->ltpf_bypass &&
lc3_ltpf_analyse(dt, sr_pcm, &encoder->ltpf, xt, &side->ltpf); lc3_ltpf_analyse(dt, sr_pcm, &encoder->ltpf, xt, &side->ltpf);
memmove(xt - nt, xt + (ns-nt), nt * sizeof(*xt)); memmove(xt - nt, xt + (ns-nt), nt * sizeof(*xt));
@@ -313,7 +313,7 @@ static void analyze(struct lc3_encoder *encoder,
lc3_mdct_forward(dt, sr_pcm, sr, xs, xd, xf); lc3_mdct_forward(dt, sr_pcm, sr, xs, xd, xf);
bool nn_flag = lc3_energy_compute(dt, sr, xf, e); bool nn_flag = lc3_energy_compute(dt, sr, xf, e);
if (nn_flag) if (nn_flag || encoder->ltpf_bypass)
lc3_ltpf_disable(&side->ltpf); lc3_ltpf_disable(&side->ltpf);
side->bw = lc3_bwdet_run(dt, sr, e); side->bw = lc3_bwdet_run(dt, sr, e);
@@ -424,6 +424,12 @@ LC3_EXPORT struct lc3_encoder *lc3_setup_encoder(
return lc3_hr_setup_encoder(false, dt_us, sr_hz, sr_pcm_hz, mem); return lc3_hr_setup_encoder(false, dt_us, sr_hz, sr_pcm_hz, mem);
} }
LC3_EXPORT void lc3_encoder_disable_ltpf(
struct lc3_encoder *encoder)
{
encoder->ltpf_bypass = true;
}
/** /**
* Encode a frame * Encode a frame
*/ */