Mercurial > mplayer.hg
changeset 3412:21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
author | arpi |
---|---|
date | Sun, 09 Dec 2001 19:23:15 +0000 |
parents | 1c571bccd19a |
children | 6236baa23bde |
files | liba52/Makefile liba52/resample.c liba52/resample_c.c liba52/resample_mmx.c |
diffstat | 4 files changed, 376 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/liba52/Makefile Sun Dec 09 19:11:42 2001 +0000 +++ b/liba52/Makefile Sun Dec 09 19:23:15 2001 +0000 @@ -3,7 +3,7 @@ include ../config.mak -SRCS = bit_allocate.c bitstream.c downmix.c imdct.c imdct_mlib.c parse.c +SRCS = resample.c bit_allocate.c bitstream.c downmix.c imdct.c imdct_mlib.c parse.c OBJS = $(SRCS:.c=.o) CFLAGS = $(OPTFLAGS)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liba52/resample.c Sun Dec 09 19:23:15 2001 +0000 @@ -0,0 +1,125 @@ +// this code come from a52dec/libao/audio_out_oss.c + +// FIXME FIXME FIXME + +// a52_resample_init should find the requested converter (from type flags -> +// given number of channels) and set up some function pointers... + +// a52_resample() should do the conversion. + +#include <inttypes.h> +#include "a52.h" + +static inline int16_t convert (int32_t i) +{ + if (i > 0x43c07fff) + return 32767; + else if (i < 0x43bf8000) + return -32768; + else + return i - 0x43c00000; +} + +static int chans=2; +static int flags=0; + +void a52_resample_init(int _flags,int _chans){ + chans=_chans; + flags=_flags; +} + +int a52_resample(float * _f, int16_t * s16) +{ + int i; + int32_t * f = (int32_t *) _f; + + switch (flags) { + case A52_MONO: + for (i = 0; i < 256; i++) { + s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0; + s16[5*i+4] = convert (f[i]); + } + break; + case A52_CHANNEL: + case A52_STEREO: + case A52_DOLBY: + for (i = 0; i < 256; i++) { + s16[2*i] = convert (f[i]); + s16[2*i+1] = convert (f[i+256]); + } + break; + case A52_3F: + for (i = 0; i < 256; i++) { + s16[5*i] = convert (f[i]); + s16[5*i+1] = convert (f[i+512]); + s16[5*i+2] = s16[5*i+3] = 0; + s16[5*i+4] = convert (f[i+256]); + } + break; + case A52_2F2R: + for (i = 0; i < 256; i++) { + s16[4*i] = convert (f[i]); + s16[4*i+1] = convert (f[i+256]); + s16[4*i+2] = convert (f[i+512]); + s16[4*i+3] = convert (f[i+768]); + } + break; + case A52_3F2R: + for (i = 0; i < 256; i++) { + s16[5*i] = convert (f[i]); + s16[5*i+1] = convert (f[i+512]); + s16[5*i+2] = convert (f[i+768]); + s16[5*i+3] = convert (f[i+1024]); + s16[5*i+4] = convert (f[i+256]); + } + break; + case A52_MONO | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0; + s16[6*i+4] = convert (f[i+256]); + s16[6*i+5] = convert (f[i]); + } + break; + case A52_CHANNEL | A52_LFE: + case A52_STEREO | A52_LFE: + case A52_DOLBY | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+512]); + s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0; + s16[6*i+5] = convert (f[i]); + } + break; + case A52_3F | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+768]); + s16[6*i+2] = s16[6*i+3] = 0; + s16[6*i+4] = convert (f[i+512]); + s16[6*i+5] = convert (f[i]); + } + break; + case A52_2F2R | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+512]); + s16[6*i+2] = convert (f[i+768]); + s16[6*i+3] = convert (f[i+1024]); + s16[6*i+4] = 0; + s16[6*i+5] = convert (f[i]); + } + break; + case A52_3F2R | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+768]); + s16[6*i+2] = convert (f[i+1024]); + s16[6*i+3] = convert (f[i+1280]); + s16[6*i+4] = convert (f[i+512]); + s16[6*i+5] = convert (f[i]); + } + break; + } + return chans*256; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liba52/resample_c.c Sun Dec 09 19:23:15 2001 +0000 @@ -0,0 +1,125 @@ +// this code come from a52dec/libao/audio_out_oss.c + +// FIXME FIXME FIXME + +// a52_resample_init should find the requested converter (from type flags -> +// given number of channels) and set up some function pointers... + +// a52_resample() should do the conversion. + +#include <inttypes.h> +#include "a52.h" + +static inline int16_t convert (int32_t i) +{ + if (i > 0x43c07fff) + return 32767; + else if (i < 0x43bf8000) + return -32768; + else + return i - 0x43c00000; +} + +static int chans=2; +static int flags=0; + +void a52_resample_init(int _flags,int _chans){ + chans=_chans; + flags=_flags; +} + +int a52_resample(float * _f, int16_t * s16) +{ + int i; + int32_t * f = (int32_t *) _f; + + switch (flags) { + case A52_MONO: + for (i = 0; i < 256; i++) { + s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0; + s16[5*i+4] = convert (f[i]); + } + break; + case A52_CHANNEL: + case A52_STEREO: + case A52_DOLBY: + for (i = 0; i < 256; i++) { + s16[2*i] = convert (f[i]); + s16[2*i+1] = convert (f[i+256]); + } + break; + case A52_3F: + for (i = 0; i < 256; i++) { + s16[5*i] = convert (f[i]); + s16[5*i+1] = convert (f[i+512]); + s16[5*i+2] = s16[5*i+3] = 0; + s16[5*i+4] = convert (f[i+256]); + } + break; + case A52_2F2R: + for (i = 0; i < 256; i++) { + s16[4*i] = convert (f[i]); + s16[4*i+1] = convert (f[i+256]); + s16[4*i+2] = convert (f[i+512]); + s16[4*i+3] = convert (f[i+768]); + } + break; + case A52_3F2R: + for (i = 0; i < 256; i++) { + s16[5*i] = convert (f[i]); + s16[5*i+1] = convert (f[i+512]); + s16[5*i+2] = convert (f[i+768]); + s16[5*i+3] = convert (f[i+1024]); + s16[5*i+4] = convert (f[i+256]); + } + break; + case A52_MONO | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0; + s16[6*i+4] = convert (f[i+256]); + s16[6*i+5] = convert (f[i]); + } + break; + case A52_CHANNEL | A52_LFE: + case A52_STEREO | A52_LFE: + case A52_DOLBY | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+512]); + s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0; + s16[6*i+5] = convert (f[i]); + } + break; + case A52_3F | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+768]); + s16[6*i+2] = s16[6*i+3] = 0; + s16[6*i+4] = convert (f[i+512]); + s16[6*i+5] = convert (f[i]); + } + break; + case A52_2F2R | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+512]); + s16[6*i+2] = convert (f[i+768]); + s16[6*i+3] = convert (f[i+1024]); + s16[6*i+4] = 0; + s16[6*i+5] = convert (f[i]); + } + break; + case A52_3F2R | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+768]); + s16[6*i+2] = convert (f[i+1024]); + s16[6*i+3] = convert (f[i+1280]); + s16[6*i+4] = convert (f[i+512]); + s16[6*i+5] = convert (f[i]); + } + break; + } + return chans*256; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liba52/resample_mmx.c Sun Dec 09 19:23:15 2001 +0000 @@ -0,0 +1,125 @@ +// this code come from a52dec/libao/audio_out_oss.c + +// FIXME FIXME FIXME + +// a52_resample_init should find the requested converter (from type flags -> +// given number of channels) and set up some function pointers... + +// a52_resample() should do the conversion. + +#include <inttypes.h> +#include "a52.h" + +static inline int16_t convert (int32_t i) +{ + if (i > 0x43c07fff) + return 32767; + else if (i < 0x43bf8000) + return -32768; + else + return i - 0x43c00000; +} + +static int chans=2; +static int flags=0; + +void a52_resample_init(int _flags,int _chans){ + chans=_chans; + flags=_flags; +} + +int a52_resample(float * _f, int16_t * s16) +{ + int i; + int32_t * f = (int32_t *) _f; + + switch (flags) { + case A52_MONO: + for (i = 0; i < 256; i++) { + s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0; + s16[5*i+4] = convert (f[i]); + } + break; + case A52_CHANNEL: + case A52_STEREO: + case A52_DOLBY: + for (i = 0; i < 256; i++) { + s16[2*i] = convert (f[i]); + s16[2*i+1] = convert (f[i+256]); + } + break; + case A52_3F: + for (i = 0; i < 256; i++) { + s16[5*i] = convert (f[i]); + s16[5*i+1] = convert (f[i+512]); + s16[5*i+2] = s16[5*i+3] = 0; + s16[5*i+4] = convert (f[i+256]); + } + break; + case A52_2F2R: + for (i = 0; i < 256; i++) { + s16[4*i] = convert (f[i]); + s16[4*i+1] = convert (f[i+256]); + s16[4*i+2] = convert (f[i+512]); + s16[4*i+3] = convert (f[i+768]); + } + break; + case A52_3F2R: + for (i = 0; i < 256; i++) { + s16[5*i] = convert (f[i]); + s16[5*i+1] = convert (f[i+512]); + s16[5*i+2] = convert (f[i+768]); + s16[5*i+3] = convert (f[i+1024]); + s16[5*i+4] = convert (f[i+256]); + } + break; + case A52_MONO | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0; + s16[6*i+4] = convert (f[i+256]); + s16[6*i+5] = convert (f[i]); + } + break; + case A52_CHANNEL | A52_LFE: + case A52_STEREO | A52_LFE: + case A52_DOLBY | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+512]); + s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0; + s16[6*i+5] = convert (f[i]); + } + break; + case A52_3F | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+768]); + s16[6*i+2] = s16[6*i+3] = 0; + s16[6*i+4] = convert (f[i+512]); + s16[6*i+5] = convert (f[i]); + } + break; + case A52_2F2R | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+512]); + s16[6*i+2] = convert (f[i+768]); + s16[6*i+3] = convert (f[i+1024]); + s16[6*i+4] = 0; + s16[6*i+5] = convert (f[i]); + } + break; + case A52_3F2R | A52_LFE: + for (i = 0; i < 256; i++) { + s16[6*i] = convert (f[i+256]); + s16[6*i+1] = convert (f[i+768]); + s16[6*i+2] = convert (f[i+1024]); + s16[6*i+3] = convert (f[i+1280]); + s16[6*i+4] = convert (f[i+512]); + s16[6*i+5] = convert (f[i]); + } + break; + } + return chans*256; +} +