mirror of
https://github.com/google/liblc3.git
synced 2026-05-30 00:17:01 +00:00
mdct: work on 2 input buffers, and remove 1 encoding buffer
This commit is contained in:
@@ -83,6 +83,7 @@
|
||||
#define LC3_ND(dt, sr) \
|
||||
( (dt) == LC3_DT_7M5 ? 23 * LC3_NS(dt, sr) / 30 \
|
||||
: 5 * LC3_NS(dt, sr) / 8 )
|
||||
|
||||
#define LC3_NE(dt, sr) \
|
||||
( 20 * (3 + (dt)) * (1 + (sr)) )
|
||||
|
||||
|
||||
@@ -205,12 +205,12 @@ static void analyze(struct lc3_encoder *encoder,
|
||||
enum lc3_srate sr = encoder->sr;
|
||||
enum lc3_srate sr_pcm = encoder->sr_pcm;
|
||||
int ns = LC3_NS(dt, sr_pcm);
|
||||
int nd = LC3_ND(dt, sr_pcm);
|
||||
int nt = LC3_NT(sr_pcm);
|
||||
|
||||
int16_t *xt = encoder->xt;
|
||||
float *xs = encoder->xs;
|
||||
float *xf = encoder->xf;
|
||||
float *xd = encoder->xd;
|
||||
float *xf = xs;
|
||||
|
||||
/* --- Temporal --- */
|
||||
|
||||
@@ -225,8 +225,7 @@ static void analyze(struct lc3_encoder *encoder,
|
||||
|
||||
float e[LC3_NUM_BANDS];
|
||||
|
||||
lc3_mdct_forward(dt, sr_pcm, sr, xs, xf);
|
||||
memmove(xs - nd, xs + (ns-nd), nd * sizeof(*xs));
|
||||
lc3_mdct_forward(dt, sr_pcm, sr, xs, xd, xf);
|
||||
|
||||
bool nn_flag = lc3_energy_compute(dt, sr, xf, e);
|
||||
if (nn_flag)
|
||||
@@ -256,7 +255,7 @@ static void encode(struct lc3_encoder *encoder,
|
||||
enum lc3_dt dt = encoder->dt;
|
||||
enum lc3_srate sr = encoder->sr;
|
||||
enum lc3_bandwidth bw = side->bw;
|
||||
float *xf = encoder->xf;
|
||||
float *xf = encoder->xs;
|
||||
|
||||
lc3_bits_t bits;
|
||||
|
||||
@@ -312,7 +311,6 @@ struct lc3_encoder *lc3_setup_encoder(
|
||||
|
||||
struct lc3_encoder *encoder = mem;
|
||||
int ns = LC3_NS(dt, sr_pcm);
|
||||
int nd = LC3_ND(dt, sr_pcm);
|
||||
int nt = LC3_NT(sr_pcm);
|
||||
|
||||
*encoder = (struct lc3_encoder){
|
||||
@@ -320,8 +318,8 @@ struct lc3_encoder *lc3_setup_encoder(
|
||||
.sr_pcm = sr_pcm,
|
||||
|
||||
.xt = (int16_t *)encoder->s + nt,
|
||||
.xs = encoder->s + (nt+ns)/2 + nd,
|
||||
.xf = encoder->s + (nt+ns)/2 + nd+ns,
|
||||
.xs = encoder->s + (nt+ns)/2,
|
||||
.xd = encoder->s + (nt+ns)/2 + ns,
|
||||
};
|
||||
|
||||
memset(encoder->s, 0,
|
||||
|
||||
+22
-25
@@ -193,39 +193,35 @@ static struct lc3_complex *fft(const struct lc3_complex *x, int n,
|
||||
/**
|
||||
* Windowing of samples before MDCT
|
||||
* dt, sr Duration and samplerate (size of the transform)
|
||||
* x [-nd..-1] Previous, [0..ns-1] Current samples
|
||||
* y Output `ns` windowed samples
|
||||
*
|
||||
* The number of previous samples `nd` accessed on `x` is :
|
||||
* nd: `ns` * 23/30 for 7.5ms frame duration
|
||||
* nd: `ns` * 5/ 8 for 10ms frame duration
|
||||
* x, y Input current and delayed samples
|
||||
* y, d Output windowed samples, and delayed ones
|
||||
*/
|
||||
static void mdct_window(
|
||||
enum lc3_dt dt, enum lc3_srate sr, const float *x, float *y)
|
||||
static void mdct_window(enum lc3_dt dt, enum lc3_srate sr,
|
||||
const float *x, float *d, float *y)
|
||||
{
|
||||
int ns = LC3_NS(dt, sr), nd = LC3_ND(dt, sr);
|
||||
|
||||
const float *w0 = lc3_mdct_win[dt][sr], *w1 = w0 + ns;
|
||||
const float *w2 = w1, *w3 = w2 + nd;
|
||||
|
||||
const float *x0 = x - nd, *x1 = x0 + ns;
|
||||
const float *x2 = x1, *x3 = x2 + nd;
|
||||
|
||||
const float *x0 = x + ns-nd, *x1 = x0;
|
||||
float *y0 = y + ns/2, *y1 = y0;
|
||||
float *d0 = d, *d1 = d + nd;
|
||||
|
||||
while (x0 < x1) {
|
||||
*(--y0) = *(x0++) * *(w0++) - *(--x1) * *(--w1);
|
||||
*(--y0) = *(x0++) * *(w0++) - *(--x1) * *(--w1);
|
||||
while (x1 > x) {
|
||||
*(--y0) = *d0 * *(w0++) - *(--x1) * *(--w1);
|
||||
*(y1++) = (*(d0++) = *(x0++)) * *(w2++);
|
||||
|
||||
*(--y0) = *d0 * *(w0++) - *(--x1) * *(--w1);
|
||||
*(y1++) = (*(d0++) = *(x0++)) * *(w2++);
|
||||
}
|
||||
|
||||
for (const float *xe = x2 + ns-nd; x2 < xe; ) {
|
||||
*(y1++) = *(x2++) * *(w2++);
|
||||
*(y1++) = *(x2++) * *(w2++);
|
||||
}
|
||||
for (x1 += ns; x0 < x1; ) {
|
||||
*(--y0) = *d0 * *(w0++) - *(--d1) * *(--w1);
|
||||
*(y1++) = (*(d0++) = *(x0++)) * *(w2++) + (*d1 = *(--x1)) * *(--w3);
|
||||
|
||||
while (x2 < x3) {
|
||||
*(y1++) = *(x2++) * *(w2++) + *(--x3) * *(--w3);
|
||||
*(y1++) = *(x2++) * *(w2++) + *(--x3) * *(--w3);
|
||||
*(--y0) = *d0 * *(w0++) - *(--d1) * *(--w1);
|
||||
*(y1++) = (*(d0++) = *(x0++)) * *(w2++) + (*d1 = *(--x1)) * *(--w3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,16 +405,17 @@ static void imdct_window(enum lc3_dt dt, enum lc3_srate sr,
|
||||
* Forward MDCT transformation
|
||||
*/
|
||||
void lc3_mdct_forward(enum lc3_dt dt, enum lc3_srate sr,
|
||||
enum lc3_srate sr_dst, const float *x, float *y)
|
||||
enum lc3_srate sr_dst, const float *x, float *d, float *y)
|
||||
{
|
||||
const struct lc3_mdct_rot_def *rot = lc3_mdct_rot[dt][sr];
|
||||
int nf = LC3_NS(dt, sr_dst);
|
||||
int ns = LC3_NS(dt, sr);
|
||||
|
||||
union { float *f; struct lc3_complex *z; } u = { .f = y };
|
||||
struct lc3_complex z[ns/2];
|
||||
struct lc3_complex buffer[ns/2];
|
||||
struct lc3_complex *z = (struct lc3_complex *)y;
|
||||
union { float *f; struct lc3_complex *z; } u = { .z = buffer };
|
||||
|
||||
mdct_window(dt, sr, x, u.f);
|
||||
mdct_window(dt, sr, x, d, u.f);
|
||||
|
||||
mdct_pre_fft(rot, u.f, u.z);
|
||||
u.z = fft(u.z, ns/2, u.z, z);
|
||||
|
||||
+4
-6
@@ -33,15 +33,13 @@
|
||||
* Forward MDCT transformation
|
||||
* dt, sr Duration and samplerate (size of the transform)
|
||||
* sr_dst Samplerate destination, scale transforam accordingly
|
||||
* x [-nd..-1] Previous, [0..ns-1] Current samples
|
||||
* y Output `ns` frequency coefficients
|
||||
* x, d Temporal samples and delayed buffer
|
||||
* y, d Output `ns` coefficients and `nd` delayed samples
|
||||
*
|
||||
* The number of previous samples `nd` accessed on `x` is :
|
||||
* nd: `ns` * 23/30 for 7.5ms frame duration
|
||||
* nd: `ns` * 5/ 8 for 10ms frame duration
|
||||
* `x` and `y` can be the same buffer
|
||||
*/
|
||||
void lc3_mdct_forward(enum lc3_dt dt, enum lc3_srate sr,
|
||||
enum lc3_srate sr_dst, const float *x, float *y);
|
||||
enum lc3_srate sr_dst, const float *x, float *d, float *y);
|
||||
|
||||
/**
|
||||
* Inverse MDCT transformation
|
||||
|
||||
Reference in New Issue
Block a user