Skip to content

Commit

Permalink
Merge remote-tracking branch 'zhaoxiu-zeng/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Jul 28, 2014
2 parents 2cab9fc + 9af50c3 commit 70bff18
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 41 deletions.
11 changes: 5 additions & 6 deletions src/lib/bitstream.c
Expand Up @@ -41,8 +41,6 @@ void shine_close_bit_stream(bitstream_t *bs)
*/
void shine_putbits(bitstream_t *bs, unsigned int val, unsigned int N)
{
const unsigned int endian = 1;

#ifdef DEBUG
if (N > 32)
printf("Cannot read or write more than %d bits at a time.\n", 32);
Expand All @@ -61,10 +59,11 @@ void shine_putbits(bitstream_t *bs, unsigned int val, unsigned int N)

N -= bs->cache_bits;
bs->cache |= val >> N;
if (*((unsigned char*)&endian))
*(unsigned int*)(bs->data + bs->data_position) = SWAB32(bs->cache);
else
*(unsigned int*)(bs->data + bs->data_position) = bs->cache;
#ifdef SHINE_BIG_ENDIAN
*(unsigned int*)(bs->data + bs->data_position) = bs->cache;
#else
*(unsigned int*)(bs->data + bs->data_position) = SWAB32(bs->cache);
#endif
bs->data_position += sizeof(unsigned int);
bs->cache_bits = 32 - N;
bs->cache = val << bs->cache_bits;
Expand Down
59 changes: 25 additions & 34 deletions src/lib/l3loop.c
Expand Up @@ -514,8 +514,6 @@ int count1_bitcount(int ix[GRANULE_SIZE], gr_info *cod_info)
*/
void subdivide(gr_info *cod_info, shine_global_config *config)
{
const int *scalefac_band_long = &shine_scale_fact_band_index[config->mpeg.samplerate_index][0];

static const struct
{
unsigned region0_count;
Expand Down Expand Up @@ -547,47 +545,40 @@ void subdivide(gr_info *cod_info, shine_global_config *config)
{6, 7}, /* 22 bands */
};

int scfb_anz = 0;
int bigvalues_region;

if ( !cod_info->big_values)
if (!cod_info->big_values)
{ /* no big_values region */
cod_info->region0_count = 0;
cod_info->region1_count = 0;
}
else
{
const int *scalefac_band_long = &shine_scale_fact_band_index[config->mpeg.samplerate_index][0];
int bigvalues_region, scfb_anz, thiscount;

bigvalues_region = 2 * cod_info->big_values;
{
int thiscount, index;
/* Calculate scfb_anz */
while ( scalefac_band_long[scfb_anz] < bigvalues_region )
scfb_anz++;

cod_info->region0_count = subdv_table[scfb_anz].region0_count;
thiscount = cod_info->region0_count;
index = thiscount + 1;
while ( thiscount && (scalefac_band_long[index] > bigvalues_region) )
{
thiscount--;
index--;
}
cod_info->region0_count = thiscount;

cod_info->region1_count = subdv_table[scfb_anz].region1_count;
index = cod_info->region0_count + cod_info->region1_count + 2;
thiscount = cod_info->region1_count;
while ( thiscount && (scalefac_band_long[index] > bigvalues_region) )
{
thiscount--;
index--;
}
cod_info->region1_count = thiscount;
cod_info->address1 = scalefac_band_long[cod_info->region0_count+1];
cod_info->address2 = scalefac_band_long[cod_info->region0_count
+ cod_info->region1_count + 2 ];
cod_info->address3 = bigvalues_region;
/* Calculate scfb_anz */
scfb_anz = 0;
while ( scalefac_band_long[scfb_anz] < bigvalues_region )
scfb_anz++;

for (thiscount = subdv_table[scfb_anz].region0_count; thiscount; thiscount--) {
if (scalefac_band_long[thiscount + 1] <= bigvalues_region)
break;
}
cod_info->region0_count = thiscount;
cod_info->address1 = scalefac_band_long[thiscount + 1];

scalefac_band_long += cod_info->region0_count + 1;

for (thiscount = subdv_table[scfb_anz].region1_count; thiscount; thiscount--) {
if (scalefac_band_long[thiscount + 1] <= bigvalues_region)
break;
}
cod_info->region1_count = thiscount;
cod_info->address2 = scalefac_band_long[thiscount + 1];

cod_info->address3 = bigvalues_region;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/layer3.h
Expand Up @@ -96,7 +96,7 @@ void shine_set_config_mpeg_defaults(shine_mpeg_t *mpeg);
* of acceptable values. */
int shine_find_bitrate_index(int bitr, int mpeg_version);

/* Check if a given bitrate is supported by the encoder (see `samplerates` above for a list
/* Check if a given samplerate is supported by the encoder (see `samplerates` above for a list
* of acceptable values. */
int shine_find_samplerate_index(int freq);

Expand Down
12 changes: 12 additions & 0 deletions src/lib/mult_mips_gcc.h
Expand Up @@ -37,3 +37,15 @@ do { \
__asm__ __volatile__("mfhi %0; mflo %1" : "=r" (t1), "=r" (t2)); \
dim = (t1 << 1) | ((uint32_t)t2 >> 31); \
} while (0)

#if __mips_isa_rev >= 2
static inline uint32_t SWAB32(uint32_t x)
{
__asm__(
" wsbh %0, %1 \n"
" rotr %0, %0, 16 \n"
: "=r" (x) : "r" (x));
return x;
}
#define SWAB32 SWAB32
#endif
9 changes: 9 additions & 0 deletions src/lib/mult_sarm_gcc.h
Expand Up @@ -98,3 +98,12 @@ do { \
dre = tre; \
dim = tim; \
} while (0)

#if __ARM_ARCH >= 6
static inline uint32_t SWAB32(uint32_t x)
{
asm ("rev %0, %1" : "=r" (x) : "r" (x));
return x;
}
#define SWAB32 SWAB32
#endif
4 changes: 4 additions & 0 deletions src/lib/types.h 100644 → 100755
Expand Up @@ -24,8 +24,12 @@
#include "mult_noarch_gcc.h"

#ifndef SWAB32
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
#define SWAB32(x) __builtin_bswap32(x)
#else
#define SWAB32(x) (((unsigned int)(x) >> 24) | (((unsigned int)(x) >> 8) & 0xff00) | (((unsigned int)(x) & 0xff00) << 8) | ((unsigned int)(x) << 24))
#endif
#endif

/* #define DEBUG if you want the library to dump info to stdout */

Expand Down

0 comments on commit 70bff18

Please sign in to comment.