aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/liba52/resample_c.c
diff options
context:
space:
mode:
authorArpi <arpi@thot.banki.hu>2003-04-16 20:03:07 +0000
committerArpi <arpi@thot.banki.hu>2003-04-16 20:03:07 +0000
commit1a7c3c85622fa0ff48127cfe38ece15e27bfb17c (patch)
treed2129e00537036d9851375e045518d4e2b1d4597 /libavcodec/liba52/resample_c.c
parent6814a25c676ae3f0eb73a2d7180b7fe9e62a62ec (diff)
downloadffmpeg-1a7c3c85622fa0ff48127cfe38ece15e27bfb17c.tar.gz
Utility functions (CRC calc & float->int converters)
[imported from MPlayer, based on a52dec's libao] Originally committed as revision 1780 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/liba52/resample_c.c')
-rw-r--r--libavcodec/liba52/resample_c.c183
1 files changed, 183 insertions, 0 deletions
diff --git a/libavcodec/liba52/resample_c.c b/libavcodec/liba52/resample_c.c
new file mode 100644
index 0000000000..a618ec6e9e
--- /dev/null
+++ b/libavcodec/liba52/resample_c.c
@@ -0,0 +1,183 @@
+// this code is based on a52dec/libao/audio_out_oss.c
+
+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 a52_resample_MONO_to_5_C(float * _f, int16_t * s16){
+ int i;
+ int32_t * f = (int32_t *) _f;
+ 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]);
+ }
+ return 5*256;
+}
+
+static int a52_resample_MONO_to_1_C(float * _f, int16_t * s16){
+ int i;
+ int32_t * f = (int32_t *) _f;
+ for (i = 0; i < 256; i++) {
+ s16[i] = convert (f[i]);
+ }
+ return 1*256;
+}
+
+static int a52_resample_STEREO_to_2_C(float * _f, int16_t * s16){
+ int i;
+ int32_t * f = (int32_t *) _f;
+ for (i = 0; i < 256; i++) {
+ s16[2*i] = convert (f[i]);
+ s16[2*i+1] = convert (f[i+256]);
+ }
+ return 2*256;
+}
+
+static int a52_resample_3F_to_5_C(float * _f, int16_t * s16){
+ int i;
+ int32_t * f = (int32_t *) _f;
+ 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]);
+ }
+ return 5*256;
+}
+
+static int a52_resample_2F_2R_to_4_C(float * _f, int16_t * s16){
+ int i;
+ int32_t * f = (int32_t *) _f;
+ 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]);
+ }
+ return 4*256;
+}
+
+static int a52_resample_3F_2R_to_5_C(float * _f, int16_t * s16){
+ int i;
+ int32_t * f = (int32_t *) _f;
+ 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]);
+ }
+ return 5*256;
+}
+
+static int a52_resample_MONO_LFE_to_6_C(float * _f, int16_t * s16){
+ int i;
+ int32_t * f = (int32_t *) _f;
+ 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]);
+ }
+ return 6*256;
+}
+
+static int a52_resample_STEREO_LFE_to_6_C(float * _f, int16_t * s16){
+ int i;
+ int32_t * f = (int32_t *) _f;
+ 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]);
+ }
+ return 6*256;
+}
+
+static int a52_resample_3F_LFE_to_6_C(float * _f, int16_t * s16){
+ int i;
+ int32_t * f = (int32_t *) _f;
+ 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]);
+ }
+ return 6*256;
+}
+
+static int a52_resample_2F_2R_LFE_to_6_C(float * _f, int16_t * s16){
+ int i;
+ int32_t * f = (int32_t *) _f;
+ 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]);
+ }
+ return 6*256;
+}
+
+static int a52_resample_3F_2R_LFE_to_6_C(float * _f, int16_t * s16){
+ int i;
+ int32_t * f = (int32_t *) _f;
+ 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]);
+ }
+ return 6*256;
+}
+
+
+static void* a52_resample_C(int flags, int ch){
+ switch (flags) {
+ case A52_MONO:
+ if(ch==5) return a52_resample_MONO_to_5_C;
+ if(ch==1) return a52_resample_MONO_to_1_C;
+ break;
+ case A52_CHANNEL:
+ case A52_STEREO:
+ case A52_DOLBY:
+ if(ch==2) return a52_resample_STEREO_to_2_C;
+ break;
+ case A52_3F:
+ if(ch==5) return a52_resample_3F_to_5_C;
+ break;
+ case A52_2F2R:
+ if(ch==4) return a52_resample_2F_2R_to_4_C;
+ break;
+ case A52_3F2R:
+ if(ch==5) return a52_resample_3F_2R_to_5_C;
+ break;
+ case A52_MONO | A52_LFE:
+ if(ch==6) return a52_resample_MONO_LFE_to_6_C;
+ break;
+ case A52_CHANNEL | A52_LFE:
+ case A52_STEREO | A52_LFE:
+ case A52_DOLBY | A52_LFE:
+ if(ch==6) return a52_resample_STEREO_LFE_to_6_C;
+ break;
+ case A52_3F | A52_LFE:
+ if(ch==6) return a52_resample_3F_LFE_to_6_C;
+ break;
+ case A52_2F2R | A52_LFE:
+ if(ch==6) return a52_resample_2F_2R_LFE_to_6_C;
+ break;
+ case A52_3F2R | A52_LFE:
+ if(ch==6) return a52_resample_3F_2R_LFE_to_6_C;
+ break;
+ }
+ return NULL;
+}