summaryrefslogtreecommitdiff
path: root/src/libffmpeg/libavcodec/adpcm.c
diff options
context:
space:
mode:
authorMiguel Freitas <miguelfreitas@users.sourceforge.net>2006-02-05 14:11:16 +0000
committerMiguel Freitas <miguelfreitas@users.sourceforge.net>2006-02-05 14:11:16 +0000
commit40c9e400fdaf1e9bb49eb0d0f0e437025b0ab6e8 (patch)
tree0a0d683a843d5d50b12233116b777e8e2780cad9 /src/libffmpeg/libavcodec/adpcm.c
parent9a299a12ea17a363354f451d2efd15bfbf3c7dc6 (diff)
downloadxine-lib-40c9e400fdaf1e9bb49eb0d0f0e437025b0ab6e8.tar.gz
xine-lib-40c9e400fdaf1e9bb49eb0d0f0e437025b0ab6e8.tar.bz2
ffmpeg sync
CVS patchset: 7872 CVS date: 2006/02/05 14:11:16
Diffstat (limited to 'src/libffmpeg/libavcodec/adpcm.c')
-rw-r--r--src/libffmpeg/libavcodec/adpcm.c240
1 files changed, 120 insertions, 120 deletions
diff --git a/src/libffmpeg/libavcodec/adpcm.c b/src/libffmpeg/libavcodec/adpcm.c
index 3c67242f4..ed3106aa0 100644
--- a/src/libffmpeg/libavcodec/adpcm.c
+++ b/src/libffmpeg/libavcodec/adpcm.c
@@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "bitstream.h"
@@ -59,7 +59,7 @@ static const int index_table[16] = {
-1, -1, -1, -1, 2, 4, 6, 8,
};
-/**
+/**
* This is the step table. Note that many programs use slight deviations from
* this table, but such deviations are negligible:
*/
@@ -205,7 +205,7 @@ static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, sho
{
int step_index;
unsigned char nibble;
-
+
int sign = 0; /* sign bit of the nibble (MSB) */
int delta, predicted_delta;
@@ -241,7 +241,7 @@ static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, sho
CLAMP_TO_SHORT(c->prev_sample);
- nibble += sign << 3; /* sign * 8 */
+ nibble += sign << 3; /* sign * 8 */
/* save back */
c->step_index = step_index;
@@ -254,14 +254,14 @@ static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, shor
int predictor, nibble, bias;
predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
-
+
nibble= sample - predictor;
if(nibble>=0) bias= c->idelta/2;
else bias=-c->idelta/2;
-
+
nibble= (nibble + bias) / c->idelta;
nibble= clip(nibble, -8, 7)&0x0F;
-
+
predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
CLAMP_TO_SHORT(predictor);
@@ -300,7 +300,7 @@ static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c,
}
static int adpcm_encode_frame(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
+ unsigned char *frame, int buf_size, void *data)
{
int n, i, st;
short *samples;
@@ -333,7 +333,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx,
*dst++ = 0;
samples++;
}
-
+
/* stereo: 4 bytes (8 samples) for left, 4 bytes for right, 4 bytes left, ... */
for (; n>0; n--) {
*dst = adpcm_ima_compress_sample(&c->status[0], samples[0]) & 0x0F;
@@ -375,9 +375,9 @@ static int adpcm_encode_frame(AVCodecContext *avctx,
c->status[i].coeff2 = AdaptCoeff2[predictor];
}
for(i=0; i<avctx->channels; i++){
- if (c->status[i].idelta < 16)
+ if (c->status[i].idelta < 16)
c->status[i].idelta = 16;
-
+
*dst++ = c->status[i].idelta & 0xFF;
*dst++ = c->status[i].idelta >> 8;
}
@@ -431,8 +431,8 @@ static int adpcm_decode_init(AVCodecContext * avctx)
switch(avctx->codec->id) {
case CODEC_ID_ADPCM_CT:
- c->status[0].step = c->status[1].step = 511;
- break;
+ c->status[0].step = c->status[1].step = 511;
+ break;
default:
break;
}
@@ -498,16 +498,16 @@ static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
predictor = c->predictor;
/* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
if(sign)
- predictor = ((predictor * 254) >> 8) - diff;
+ predictor = ((predictor * 254) >> 8) - diff;
else
- predictor = ((predictor * 254) >> 8) + diff;
+ predictor = ((predictor * 254) >> 8) + diff;
/* calculate new step and clamp it to range 511..32767 */
new_step = (ct_adpcm_table[nibble & 7] * c->step) >> 8;
c->step = new_step;
if(c->step < 511)
- c->step = 511;
+ c->step = 511;
if(c->step > 32767)
- c->step = 32767;
+ c->step = 32767;
CLAMP_TO_SHORT(predictor);
c->predictor = predictor;
@@ -528,7 +528,7 @@ static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned c
return c->predictor;
}
-static void xa_decode(short *out, const unsigned char *in,
+static void xa_decode(short *out, const unsigned char *in,
ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc)
{
int i, j;
@@ -612,8 +612,8 @@ static void xa_decode(short *out, const unsigned char *in,
}
static int adpcm_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
{
ADPCMContext *c = avctx->priv_data;
ADPCMChannelStatus *cs;
@@ -701,7 +701,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
cs->predictor -= 0x10000;
CLAMP_TO_SHORT(cs->predictor);
- // XXX: is this correct ??: *samples++ = cs->predictor;
+ // XXX: is this correct ??: *samples++ = cs->predictor;
cs->step_index = *src++;
if (cs->step_index < 0) cs->step_index = 0;
@@ -710,19 +710,19 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
}
for(m=4; src < (buf + buf_size);) {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] & 0x0F, 3);
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] & 0x0F, 3);
if (st)
*samples++ = adpcm_ima_expand_nibble(&c->status[1], src[4] & 0x0F, 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F, 3);
- if (st) {
+ if (st) {
*samples++ = adpcm_ima_expand_nibble(&c->status[1], (src[4] >> 4) & 0x0F, 3);
- if (!--m) {
- m=4;
- src+=4;
- }
- }
- src++;
- }
+ if (!--m) {
+ m=4;
+ src+=4;
+ }
+ }
+ src++;
+ }
break;
case CODEC_ID_ADPCM_4XM:
cs = &(c->status[0]);
@@ -739,13 +739,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
m= (buf_size - (src - buf))>>st;
for(i=0; i<m; i++) {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] & 0x0F, 4);
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] & 0x0F, 4);
if (st)
*samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] & 0x0F, 4);
*samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] >> 4, 4);
- if (st)
+ if (st)
*samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] >> 4, 4);
- }
+ }
src += m<<st;
@@ -770,7 +770,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]];
c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]];
c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]];
-
+
c->status[0].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
src+=2;
if (st) c->status[1].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
@@ -807,16 +807,16 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
while (src < buf + buf_size) {
/* take care of the top nibble (always left or mono channel) */
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
(src[0] >> 4) & 0x0F, 3);
/* take care of the bottom nibble, which is right sample for
* stereo, or another mono sample */
if (st)
- *samples++ = adpcm_ima_expand_nibble(&c->status[1],
+ *samples++ = adpcm_ima_expand_nibble(&c->status[1],
src[0] & 0x0F, 3);
else
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
src[0] & 0x0F, 3);
src++;
@@ -869,14 +869,14 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
while (src < buf + buf_size) {
if (st) {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
(src[0] >> 4) & 0x0F, 3);
- *samples++ = adpcm_ima_expand_nibble(&c->status[1],
+ *samples++ = adpcm_ima_expand_nibble(&c->status[1],
src[0] & 0x0F, 3);
} else {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
(src[0] >> 4) & 0x0F, 3);
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0],
src[0] & 0x0F, 3);
}
@@ -884,10 +884,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
}
break;
case CODEC_ID_ADPCM_XA:
- c->status[0].sample1 = c->status[0].sample2 =
+ c->status[0].sample1 = c->status[0].sample2 =
c->status[1].sample1 = c->status[1].sample2 = 0;
while (buf_size >= 128) {
- xa_decode(samples, src, &c->status[0], &c->status[1],
+ xa_decode(samples, src, &c->status[0], &c->status[1],
avctx->channels);
src += 128;
samples += 28 * 8;
@@ -926,11 +926,11 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
next_right_sample = (((*src & 0x0F) << 28) >> shift_right);
src++;
- next_left_sample = (next_left_sample +
- (current_left_sample * coeff1l) +
+ next_left_sample = (next_left_sample +
+ (current_left_sample * coeff1l) +
(previous_left_sample * coeff2l) + 0x80) >> 8;
- next_right_sample = (next_right_sample +
- (current_right_sample * coeff1r) +
+ next_right_sample = (next_right_sample +
+ (current_right_sample * coeff1r) +
(previous_right_sample * coeff2r) + 0x80) >> 8;
CLAMP_TO_SHORT(next_left_sample);
CLAMP_TO_SHORT(next_right_sample);
@@ -958,90 +958,90 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
}
break;
case CODEC_ID_ADPCM_CT:
- while (src < buf + buf_size) {
+ while (src < buf + buf_size) {
if (st) {
- *samples++ = adpcm_ct_expand_nibble(&c->status[0],
+ *samples++ = adpcm_ct_expand_nibble(&c->status[0],
(src[0] >> 4) & 0x0F);
- *samples++ = adpcm_ct_expand_nibble(&c->status[1],
+ *samples++ = adpcm_ct_expand_nibble(&c->status[1],
src[0] & 0x0F);
} else {
- *samples++ = adpcm_ct_expand_nibble(&c->status[0],
+ *samples++ = adpcm_ct_expand_nibble(&c->status[0],
(src[0] >> 4) & 0x0F);
- *samples++ = adpcm_ct_expand_nibble(&c->status[0],
+ *samples++ = adpcm_ct_expand_nibble(&c->status[0],
src[0] & 0x0F);
}
- src++;
+ src++;
}
break;
case CODEC_ID_ADPCM_SWF:
{
- GetBitContext gb;
- const int *table;
- int k0, signmask;
- int size = buf_size*8;
-
- init_get_bits(&gb, buf, size);
-
- // first frame, read bits & inital values
- if (!c->nb_bits)
- {
- c->nb_bits = get_bits(&gb, 2)+2;
-// av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", c->nb_bits);
- }
-
- table = swf_index_tables[c->nb_bits-2];
- k0 = 1 << (c->nb_bits-2);
- signmask = 1 << (c->nb_bits-1);
-
- while (get_bits_count(&gb) <= size)
- {
- int i;
-
- c->nb_samples++;
- // wrap around at every 4096 samples...
- if ((c->nb_samples & 0xfff) == 1)
- {
- for (i = 0; i <= st; i++)
- {
- *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
- c->status[i].step_index = get_bits(&gb, 6);
- }
- }
-
- // similar to IMA adpcm
- for (i = 0; i <= st; i++)
- {
- int delta = get_bits(&gb, c->nb_bits);
- int step = step_table[c->status[i].step_index];
- long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
- int k = k0;
-
- do {
- if (delta & k)
- vpdiff += step;
- step >>= 1;
- k >>= 1;
- } while(k);
- vpdiff += step;
-
- if (delta & signmask)
- c->status[i].predictor -= vpdiff;
- else
- c->status[i].predictor += vpdiff;
-
- c->status[i].step_index += table[delta & (~signmask)];
-
- c->status[i].step_index = clip(c->status[i].step_index, 0, 88);
- c->status[i].predictor = clip(c->status[i].predictor, -32768, 32767);
-
- *samples++ = c->status[i].predictor;
- }
- }
-
-// src += get_bits_count(&gb)*8;
- src += size;
-
- break;
+ GetBitContext gb;
+ const int *table;
+ int k0, signmask;
+ int size = buf_size*8;
+
+ init_get_bits(&gb, buf, size);
+
+ // first frame, read bits & inital values
+ if (!c->nb_bits)
+ {
+ c->nb_bits = get_bits(&gb, 2)+2;
+// av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", c->nb_bits);
+ }
+
+ table = swf_index_tables[c->nb_bits-2];
+ k0 = 1 << (c->nb_bits-2);
+ signmask = 1 << (c->nb_bits-1);
+
+ while (get_bits_count(&gb) <= size)
+ {
+ int i;
+
+ c->nb_samples++;
+ // wrap around at every 4096 samples...
+ if ((c->nb_samples & 0xfff) == 1)
+ {
+ for (i = 0; i <= st; i++)
+ {
+ *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
+ c->status[i].step_index = get_bits(&gb, 6);
+ }
+ }
+
+ // similar to IMA adpcm
+ for (i = 0; i <= st; i++)
+ {
+ int delta = get_bits(&gb, c->nb_bits);
+ int step = step_table[c->status[i].step_index];
+ long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
+ int k = k0;
+
+ do {
+ if (delta & k)
+ vpdiff += step;
+ step >>= 1;
+ k >>= 1;
+ } while(k);
+ vpdiff += step;
+
+ if (delta & signmask)
+ c->status[i].predictor -= vpdiff;
+ else
+ c->status[i].predictor += vpdiff;
+
+ c->status[i].step_index += table[delta & (~signmask)];
+
+ c->status[i].step_index = clip(c->status[i].step_index, 0, 88);
+ c->status[i].predictor = clip(c->status[i].predictor, -32768, 32767);
+
+ *samples++ = c->status[i].predictor;
+ }
+ }
+
+// src += get_bits_count(&gb)*8;
+ src += size;
+
+ break;
}
case CODEC_ID_ADPCM_YAMAHA:
while (src < buf + buf_size) {