mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-27 07:46:24 -04:00
PBE+Surround: Localize some variables and fixup some flush ops
Change-Id: I9fba5b8cbf69d261a7ca1c66e080c08d2fc6d9db
This commit is contained in:
parent
5eee28e37d
commit
a8e4b3a190
2 changed files with 55 additions and 73 deletions
|
|
@ -40,7 +40,6 @@
|
||||||
static int pbe_strength = 0;
|
static int pbe_strength = 0;
|
||||||
static int pbe_precut = 0;
|
static int pbe_precut = 0;
|
||||||
static int32_t tcoef1, tcoef2, tcoef3;
|
static int32_t tcoef1, tcoef2, tcoef3;
|
||||||
static int32_t *b0[2], *b2[2], *b3[2];
|
|
||||||
static int b0_r[2],b2_r[2],b3_r[2],b0_w[2],b2_w[2],b3_w[2];
|
static int b0_r[2],b2_r[2],b3_r[2],b0_w[2],b2_w[2],b3_w[2];
|
||||||
int32_t temp_buffer;
|
int32_t temp_buffer;
|
||||||
static struct dsp_filter pbe_filter[5];
|
static struct dsp_filter pbe_filter[5];
|
||||||
|
|
@ -63,18 +62,6 @@ static void pbe_buffer_free(void)
|
||||||
handle = -1;
|
handle = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pbe_buffer_get_data(void)
|
|
||||||
{
|
|
||||||
if (handle < 0)
|
|
||||||
return;
|
|
||||||
b0[0] = core_get_data(handle);
|
|
||||||
b0[1] = b0[0] + B0_SIZE;
|
|
||||||
b2[0] = b0[1] + B0_SIZE;
|
|
||||||
b2[1] = b2[0] + B2_SIZE;
|
|
||||||
b3[0] = b2[1] + B2_SIZE;
|
|
||||||
b3[1] = b3[0] + B3_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dsp_pbe_flush(void)
|
static void dsp_pbe_flush(void)
|
||||||
{
|
{
|
||||||
memset(core_get_data(handle), 0, PBE_BUFSIZE);
|
memset(core_get_data(handle), 0, PBE_BUFSIZE);
|
||||||
|
|
@ -153,7 +140,14 @@ static void pbe_process(struct dsp_proc_entry *this,
|
||||||
int b0_level = (B0_DLY * pbe_strength) / 100;
|
int b0_level = (B0_DLY * pbe_strength) / 100;
|
||||||
int32_t x;
|
int32_t x;
|
||||||
|
|
||||||
pbe_buffer_get_data();
|
int32_t *b0[2], *b2[2], *b3[2];
|
||||||
|
|
||||||
|
b0[0] = core_get_data(handle);
|
||||||
|
b0[1] = b0[0] + B0_SIZE;
|
||||||
|
b2[0] = b0[1] + B0_SIZE;
|
||||||
|
b2[1] = b2[0] + B2_SIZE;
|
||||||
|
b3[0] = b2[1] + B2_SIZE;
|
||||||
|
b3[1] = b3[0] + B3_SIZE;
|
||||||
|
|
||||||
for(int ch = 0; ch < num_channels; ch++)
|
for(int ch = 0; ch < num_channels; ch++)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,6 @@ static int surround_strength = 0;
|
||||||
#define BB_DLY (MAX_DLY/4 + 1)
|
#define BB_DLY (MAX_DLY/4 + 1)
|
||||||
#define HH_DLY (MAX_DLY/2 + 1)
|
#define HH_DLY (MAX_DLY/2 + 1)
|
||||||
#define CL_DLY B2_DLY
|
#define CL_DLY B2_DLY
|
||||||
/*only need to buffer right channel */
|
|
||||||
static int32_t *b0, *b2, *bb, *hh, *cl;
|
|
||||||
static int32_t temp_buffer[2];
|
|
||||||
static int32_t mid, side;
|
|
||||||
|
|
||||||
/*voice from 300hz - 3400hz ?*/
|
/*voice from 300hz - 3400hz ?*/
|
||||||
static int32_t tcoef1,tcoef2,bcoef,hcoef;
|
static int32_t tcoef1,tcoef2,bcoef,hcoef;
|
||||||
|
|
@ -80,15 +76,6 @@ static void surround_buffer_free(void)
|
||||||
handle = -1;
|
handle = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void surround_buffer_get_data(void)
|
|
||||||
{
|
|
||||||
b0 = core_get_data(handle);
|
|
||||||
b2 = b0 + B0_DLY;
|
|
||||||
bb = b2 + B2_DLY;
|
|
||||||
hh = bb + BB_DLY;
|
|
||||||
cl = hh + HH_DLY;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dsp_surround_flush(void)
|
static void dsp_surround_flush(void)
|
||||||
{
|
{
|
||||||
memset(core_get_data(handle), 0, SURROUND_BUFSIZE);
|
memset(core_get_data(handle), 0, SURROUND_BUFSIZE);
|
||||||
|
|
@ -109,16 +96,7 @@ void dsp_surround_set_balance(int var)
|
||||||
|
|
||||||
void dsp_surround_side_only(bool var)
|
void dsp_surround_side_only(bool var)
|
||||||
{
|
{
|
||||||
if (var == surround_side_only)
|
|
||||||
return; /* No setting change */
|
|
||||||
|
|
||||||
surround_side_only = var;
|
surround_side_only = var;
|
||||||
|
|
||||||
struct dsp_config *dsp = dsp_get_config(CODEC_IDX_AUDIO);
|
|
||||||
if (!dsp_proc_enabled(dsp, DSP_PROC_SURROUND))
|
|
||||||
return;
|
|
||||||
|
|
||||||
dsp_surround_flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dsp_surround_mix(int var)
|
void dsp_surround_mix(int var)
|
||||||
|
|
@ -143,7 +121,9 @@ void dsp_surround_set_cutoff(int frq_l, int frq_h)
|
||||||
|
|
||||||
static void surround_set_stepsize(int surround_strength)
|
static void surround_set_stepsize(int surround_strength)
|
||||||
{
|
{
|
||||||
dsp_surround_flush();
|
if (handle > 0)
|
||||||
|
dsp_surround_flush();
|
||||||
|
|
||||||
switch(surround_strength)
|
switch(surround_strength)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
|
@ -175,7 +155,7 @@ void dsp_surround_enable(int var)
|
||||||
bool was_enabled = dsp_proc_enabled(dsp, DSP_PROC_SURROUND);
|
bool was_enabled = dsp_proc_enabled(dsp, DSP_PROC_SURROUND);
|
||||||
bool now_enabled = var > 0;
|
bool now_enabled = var > 0;
|
||||||
|
|
||||||
if (was_enabled == now_enabled && !now_enabled)
|
if (was_enabled == now_enabled)
|
||||||
return; /* No change in enabled status */
|
return; /* No change in enabled status */
|
||||||
|
|
||||||
if (now_enabled)
|
if (now_enabled)
|
||||||
|
|
@ -201,88 +181,96 @@ static void surround_process(struct dsp_proc_entry *this,
|
||||||
int i;
|
int i;
|
||||||
int32_t x;
|
int32_t x;
|
||||||
|
|
||||||
surround_buffer_get_data();
|
/*only need to buffer right channel */
|
||||||
|
static int32_t *b0, *b2, *bb, *hh, *cl;
|
||||||
|
|
||||||
|
b0 = core_get_data(handle);
|
||||||
|
b2 = b0 + B0_DLY;
|
||||||
|
bb = b2 + B2_DLY;
|
||||||
|
hh = bb + BB_DLY;
|
||||||
|
cl = hh + HH_DLY;
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
mid = buf->p32[0][i] /2 + buf->p32[1][i] /2;
|
int32_t mid = buf->p32[0][i] / 2 + buf->p32[1][i] / 2;
|
||||||
side = buf->p32[0][i] - buf->p32[1][i];
|
int32_t side = buf->p32[0][i] - buf->p32[1][i];
|
||||||
|
int32_t temp0, temp1;
|
||||||
|
|
||||||
if (!surround_side_only)
|
if (!surround_side_only)
|
||||||
{
|
{
|
||||||
/*clone the left channal*/
|
/*clone the left channal*/
|
||||||
temp_buffer[0]= buf->p32[0][i];
|
temp0 = buf->p32[0][i];
|
||||||
/*keep the middle band of right channel*/
|
/*keep the middle band of right channel*/
|
||||||
temp_buffer[1]= FRACMUL(buf->p32[1][i], tcoef1) -
|
temp1 = FRACMUL(buf->p32[1][i], tcoef1) -
|
||||||
FRACMUL(buf->p32[1][i], tcoef2);
|
FRACMUL(buf->p32[1][i], tcoef2);
|
||||||
}
|
}
|
||||||
else /* apply haas to side only*/
|
else /* apply haas to side only*/
|
||||||
{
|
{
|
||||||
temp_buffer[0] = side / 2;
|
temp0 = side / 2;
|
||||||
temp_buffer[1] = FRACMUL(-side,tcoef1)/2 -
|
temp1 = FRACMUL(-side, tcoef1) / 2 -
|
||||||
FRACMUL(-side, tcoef2)/2;
|
FRACMUL(-side, tcoef2) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* inverted crossfeed delay (left channel) to make sound wider*/
|
/* inverted crossfeed delay (left channel) to make sound wider*/
|
||||||
x = temp_buffer[1]/100 * 35;
|
x = temp1/100 * 35;
|
||||||
temp_buffer[0] += dequeue(cl, &cl_r, dly);
|
temp0 += dequeue(cl, &cl_r, dly);
|
||||||
enqueue(-x, cl, &cl_w, dly);
|
enqueue(-x, cl, &cl_w, dly);
|
||||||
|
|
||||||
/* apply 1/8 delay to frequency below fx2 */
|
/* apply 1/8 delay to frequency below fx2 */
|
||||||
x = buf->p32[1][i] - FRACMUL(buf->p32[1][i], tcoef1);
|
x = buf->p32[1][i] - FRACMUL(buf->p32[1][i], tcoef1);
|
||||||
temp_buffer[1] += dequeue(b0, &b0_r, dly_shift3);
|
temp1 += dequeue(b0, &b0_r, dly_shift3);
|
||||||
enqueue(x, b0, &b0_w, dly_shift3 );
|
enqueue(x, b0, &b0_w, dly_shift3 );
|
||||||
|
|
||||||
/* cut frequency below half fx2*/
|
/* cut frequency below half fx2*/
|
||||||
temp_buffer[1] = FRACMUL(temp_buffer[1], bcoef);
|
temp1 = FRACMUL(temp1, bcoef);
|
||||||
|
|
||||||
/* apply 1/4 delay to frequency below half fx2 */
|
/* apply 1/4 delay to frequency below half fx2 */
|
||||||
/* use different delay to fake the sound direction*/
|
/* use different delay to fake the sound direction*/
|
||||||
x = buf->p32[1][i] - FRACMUL(buf->p32[1][i], bcoef);
|
x = buf->p32[1][i] - FRACMUL(buf->p32[1][i], bcoef);
|
||||||
temp_buffer[1] += dequeue(bb, &bb_r, dly_shift2);
|
temp1 += dequeue(bb, &bb_r, dly_shift2);
|
||||||
enqueue(x, bb, &bb_w, dly_shift2 );
|
enqueue(x, bb, &bb_w, dly_shift2 );
|
||||||
|
|
||||||
/* apply full delay to higher band */
|
/* apply full delay to higher band */
|
||||||
x = FRACMUL(buf->p32[1][i], tcoef2);
|
x = FRACMUL(buf->p32[1][i], tcoef2);
|
||||||
temp_buffer[1] += dequeue(b2, &b2_r, dly);
|
temp1 += dequeue(b2, &b2_r, dly);
|
||||||
enqueue(x, b2, &b2_w, dly );
|
enqueue(x, b2, &b2_w, dly );
|
||||||
|
|
||||||
/* do the same direction trick again */
|
/* do the same direction trick again */
|
||||||
temp_buffer[1] -= FRACMUL(temp_buffer[1], hcoef);
|
temp1 -= FRACMUL(temp1, hcoef);
|
||||||
|
|
||||||
x = FRACMUL(buf->p32[1][i], hcoef);
|
x = FRACMUL(buf->p32[1][i], hcoef);
|
||||||
temp_buffer[1] += dequeue(hh, &hh_r, dly_shift1);
|
temp1 += dequeue(hh, &hh_r, dly_shift1);
|
||||||
enqueue(x, hh, &hh_w, dly_shift1 );
|
enqueue(x, hh, &hh_w, dly_shift1 );
|
||||||
/*balance*/
|
/*balance*/
|
||||||
if (surround_balance > 0 && !surround_side_only)
|
if (surround_balance > 0 && !surround_side_only)
|
||||||
{
|
{
|
||||||
temp_buffer[0] -= temp_buffer[0]/200 * surround_balance;
|
temp0 -= temp0/200 * surround_balance;
|
||||||
temp_buffer[1] += temp_buffer[1]/200 * surround_balance;
|
temp1 += temp1/200 * surround_balance;
|
||||||
}
|
}
|
||||||
else if (surround_balance > 0)
|
else if (surround_balance > 0)
|
||||||
{
|
{
|
||||||
temp_buffer[0] += temp_buffer[0]/200 * surround_balance;
|
temp0 += temp0/200 * surround_balance;
|
||||||
temp_buffer[1] -= temp_buffer[1]/200 * surround_balance;
|
temp1 -= temp1/200 * surround_balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (surround_side_only)
|
if (surround_side_only)
|
||||||
{
|
{
|
||||||
temp_buffer[0] += mid;
|
temp0 += mid;
|
||||||
temp_buffer[1] += mid;
|
temp1 += mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (surround_mix == 100)
|
if (surround_mix == 100)
|
||||||
{
|
{
|
||||||
buf->p32[0][i] = temp_buffer[0];
|
buf->p32[0][i] = temp0;
|
||||||
buf->p32[1][i] = temp_buffer[1];
|
buf->p32[1][i] = temp1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*dry wet mix*/
|
/*dry wet mix*/
|
||||||
buf->p32[0][i] = buf->p32[0][i]/100 * (100-surround_mix) +
|
buf->p32[0][i] = buf->p32[0][i]/100 * (100-surround_mix) +
|
||||||
temp_buffer[0]/100 * surround_mix;
|
temp0/100 * surround_mix;
|
||||||
buf->p32[1][i] = buf->p32[1][i]/100 * (100-surround_mix) +
|
buf->p32[1][i] = buf->p32[1][i]/100 * (100-surround_mix) +
|
||||||
temp_buffer[1]/100 * surround_mix;
|
temp1/100 * surround_mix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(void)this;
|
(void)this;
|
||||||
|
|
@ -326,16 +314,16 @@ static intptr_t surround_configure(struct dsp_proc_entry *this,
|
||||||
switch (setting)
|
switch (setting)
|
||||||
{
|
{
|
||||||
case DSP_PROC_INIT:
|
case DSP_PROC_INIT:
|
||||||
if (value == 0)
|
/* Coming online; was disabled */
|
||||||
{
|
retval = surround_buffer_alloc();
|
||||||
retval = surround_buffer_alloc();
|
if (retval < 0)
|
||||||
if (retval < 0)
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
this->process = surround_process;
|
this->process = surround_process;
|
||||||
}
|
|
||||||
/* else additional forced messages */
|
|
||||||
|
|
||||||
|
dsp_surround_flush();
|
||||||
|
|
||||||
|
/* Wouldn't have been getting frequency updates */
|
||||||
surround_update_filter(dsp_get_output_frequency(dsp));
|
surround_update_filter(dsp_get_output_frequency(dsp));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue