Skip to content

Commit

Permalink
That's it! No more globals in encoding loops!
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Jul 23, 2012
1 parent 6034e07 commit 4dc53fc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
30 changes: 12 additions & 18 deletions src/lib/l3subband.c
Expand Up @@ -5,29 +5,23 @@
#include "tables.h"
#include "l3subband.h"

static int off[2] = {0,0};
static long fl[SBLIMIT][64];
static long x[2][HAN_SIZE];
static long z[2][HAN_SIZE];
static long ew[HAN_SIZE];

/*extern long mul(long x, long y); */ /* inlined in header file */

/*
* L3_subband_initialise:
* ----------------------
* Calculates the analysis filterbank coefficients and rounds to the
* 9th decimal place accuracy of the filterbank tables in the ISO
* document. The coefficients are stored in #filter#
*/
void L3_subband_initialise()
void L3_subband_initialise(shine_global_config *config)
{
int i,j;
double filter;

config->subband.off[0] = config->subband.off[1] = 0;

for(i=2; i-- ; )
for(j=HAN_SIZE; j--; )
x[i][j] = 0;
config->subband.x[i][j] = 0;

for (i=SBLIMIT; i--; )
for (j=64; j--; )
Expand All @@ -37,13 +31,13 @@ void L3_subband_initialise()
else
modf(filter-0.5, &filter);
/* scale and convert to fixed point before storing */
fl[i][j] = (long)(filter * (0x7fffffff * 1e-9));
config->subband.fl[i][j] = (long)(filter * (0x7fffffff * 1e-9));
}

/* note. 0.035781 is enwindow maximum value */
/* scale and convert to fixed point before storing */
for (i=HAN_SIZE; i--;)
ew[i] = (long)(enwindow[i] * 0x7fffffff);
config->subband.ew[i] = (long)(enwindow[i] * 0x7fffffff);
}

/*
Expand All @@ -60,27 +54,27 @@ void L3_subband_initialise()
* picking out values from the windowed samples, and then multiplying
* them by the filter matrix, producing 32 subband samples.
*/
void L3_window_filter_subband(int16_t **buffer, long s[SBLIMIT] , int k)
void L3_window_filter_subband(int16_t **buffer, long s[SBLIMIT] , int k, shine_global_config *config)
{
long y[64];
int i,j;

/* replace 32 oldest samples with 32 new samples */
for (i=31;i>=0;i--)
x[k][i+off[k]] = ((long)*(*buffer)++) << 16;
config->subband.x[k][i+config->subband.off[k]] = ((long)*(*buffer)++) << 16;

/* shift samples into proper window positions */
for (i=HAN_SIZE; i--; )
z[k][i] = mul(x[k][(i+off[k])&(HAN_SIZE-1)],ew[i]);
config->subband.z[k][i] = mul(config->subband.x[k][(i+config->subband.off[k])&(HAN_SIZE-1)],config->subband.ew[i]);

off[k] = (off[k] + 480) & (HAN_SIZE-1); /* offset is modulo (HAN_SIZE)*/
config->subband.off[k] = (config->subband.off[k] + 480) & (HAN_SIZE-1); /* offset is modulo (HAN_SIZE)*/

for (i=64; i--; )
for (j=8, y[i] = 0; j--; )
y[i] += z[k][i+(j<<6)];
y[i] += config->subband.z[k][i+(j<<6)];

for (i=SBLIMIT; i--; )
for (j=64, s[i]= 0; j--; )
s[i] += mul(fl[i][j],y[j]);
s[i] += mul(config->subband.fl[i][j],y[j]);
}

4 changes: 2 additions & 2 deletions src/lib/l3subband.h
Expand Up @@ -3,7 +3,7 @@

#include <stdint.h>

void L3_subband_initialise();
void L3_window_filter_subband(int16_t **buffer, long s[SBLIMIT], int k);
void L3_subband_initialise( shine_global_config *config );
void L3_window_filter_subband(int16_t **buffer, long s[SBLIMIT], int k, shine_global_config *config);

#endif
4 changes: 2 additions & 2 deletions src/lib/layer3.c
Expand Up @@ -27,7 +27,7 @@ shine_global_config *L3_initialise(config_t *pub_config)
if (config == NULL)
return config;

L3_subband_initialise();
L3_subband_initialise(config);
L3_mdct_initialise(config);
L3_loop_initialise(config);
L3_formatbits_initialise(config);
Expand Down Expand Up @@ -125,7 +125,7 @@ unsigned char *L3_encode_frame(shine_global_config *config, int16_t data[2][samp
for(gr=0;gr<2;gr++)
for(channel=config->wave.channels; channel--; )
for(i=0;i<18;i++)
L3_window_filter_subband(&config->buffer[channel], &config->l3_sb_sample[channel][gr+1][i][0] ,channel);
L3_window_filter_subband(&config->buffer[channel], &config->l3_sb_sample[channel][gr+1][i][0] ,channel,config);

/* apply mdct to the polyphase output */
L3_mdct_sub(config);
Expand Down
9 changes: 9 additions & 0 deletions src/lib/types.h
Expand Up @@ -195,6 +195,14 @@ typedef struct {
long cos_l[18][36];
} mdct_t;

typedef struct {
int off[2];
long fl[SBLIMIT][64];
long x[2][HAN_SIZE];
long z[2][HAN_SIZE];
long ew[HAN_SIZE];
} subband_t;

typedef struct shine_global_flags {
wave_t wave;
priv_mpeg_t mpeg;
Expand All @@ -215,6 +223,7 @@ typedef struct shine_global_flags {
l3stream_t l3stream;
l3loop_t l3loop;
mdct_t mdct;
subband_t subband;
} shine_global_config;

#endif

0 comments on commit 4dc53fc

Please sign in to comment.