[Mplayer-cvslog] CVS: main adpcm.c,NONE,1.1 adpcm.h,NONE,1.1 codec-cfg.c,1.53,1.54 codec-cfg.h,1.28,1.29 Makefile,1.127,1.128 dec_audio.c,1.58,1.59
Mike Melanson
melanson at mplayer.dev.hu
Wed Dec 26 07:13:26 CET 2001
Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv32078
Modified Files:
codec-cfg.c codec-cfg.h Makefile dec_audio.c
Added Files:
adpcm.c adpcm.h
Log Message:
Initial support for unified ADPCM decoder
--- NEW FILE ---
/*
Unified ADPCM Decoder for MPlayer
(C) 2001 Mike Melanson
*/
#include "config.h"
#include "bswap.h"
#include "adpcm.h"
#define BE_16(x) (be2me_16(*(unsigned short *)(x)))
#define BE_32(x) (be2me_32(*(unsigned int *)(x)))
#define LE_16(x) (le2me_16(*(unsigned short *)(x)))
#define LE_32(x) (le2me_32(*(unsigned int *)(x)))
// clamp a number between 0 and 88
#define CLAMP_0_TO_88(x) if (x < 0) x = 0; else if (x > 88) x = 88;
// clamp a number within a signed 16-bit range
#define CLAMP_S16(x) if (x < -32768) x = -32768; \
else if (x > 32767) x = 32767;
// sign extend a 16-bit value
#define SE_16BIT(x) if (x & 0x8000) x -= 0x10000;
void ima_dvi_decode_nibbles(unsigned short *output, int channels,
int predictor_l, int index_l,
int predictor_r, int index_r)
{
int step[2];
int predictor[2];
int index[2];
int diff;
int i;
int sign;
int delta;
int channel_number = 0;
step[0] = adpcm_step[index_l];
step[1] = adpcm_step[index_r];
predictor[0] = predictor_l;
predictor[1] = predictor_r;
index[0] = index_l;
index[1] = index_r;
for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK * channels; i++)
{
delta = output[i];
index[channel_number] += adpcm_index[delta];
CLAMP_0_TO_88(index[channel_number]);
sign = delta & 8;
delta = delta & 7;
diff = step[channel_number] >> 3;
if (delta & 4) diff += step[channel_number];
if (delta & 2) diff += step[channel_number] >> 1;
if (delta & 1) diff += step[channel_number] >> 2;
if (sign)
predictor[channel_number] -= diff;
else
predictor[channel_number] += diff;
CLAMP_S16(predictor[channel_number]);
output[i] = predictor[channel_number];
step[channel_number] = adpcm_step[index[channel_number]];
// toggle channel
channel_number ^= channels - 1;
}
}
int ima_adpcm_decode_block(unsigned short *output, unsigned char *input,
int channels)
{
int initial_predictor_l = 0;
int initial_predictor_r = 0;
int initial_index_l = 0;
int initial_index_r = 0;
int stream_ptr = 0;
int i;
initial_predictor_l = BE_16(&input[stream_ptr]);
stream_ptr += 2;
initial_index_l = initial_predictor_l;
// mask, sign-extend, and clamp the predictor portion
initial_predictor_l &= 0xFF80;
SE_16BIT(initial_predictor_l);
CLAMP_S16(initial_predictor_l);
// mask and clamp the index portion
initial_index_l &= 0x7F;
CLAMP_0_TO_88(initial_index_l);
// handle stereo
if (channels > 1)
{
initial_predictor_r = BE_16(&input[stream_ptr]);
stream_ptr += 2;
initial_index_r = initial_predictor_r;
// mask, sign-extend, and clamp the predictor portion
initial_predictor_r &= 0xFF80;
SE_16BIT(initial_predictor_r);
CLAMP_S16(initial_predictor_r);
// mask and clamp the index portion
initial_index_r &= 0x7F;
CLAMP_0_TO_88(initial_index_r);
}
// break apart all of the nibbles in the block
if (channels == 1)
for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2; i++)
{
output[i * 2 + 0] = input[stream_ptr] & 0x0F;
output[i * 2 + 1] = input[stream_ptr] >> 4;
stream_ptr++;
}
else
for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2 * 2; i++)
{
output[i * 4 + 0] = input[stream_ptr] & 0x0F;
output[i * 4 + 1] = input[stream_ptr + 1] & 0x0F;
output[i * 4 + 2] = input[stream_ptr] >> 4;
output[i * 4 + 3] = input[stream_ptr + 1] >> 4;
stream_ptr++;
}
ima_dvi_decode_nibbles(output, channels,
initial_predictor_l, initial_index_l,
initial_predictor_r, initial_index_r);
return IMA_ADPCM_SAMPLES_PER_BLOCK * channels;
}
--- NEW FILE ---
#ifndef ADPCM_H
#define ADPCM_H
#define IMA_ADPCM_BLOCK_SIZE 0x22
#define IMA_ADPCM_SAMPLES_PER_BLOCK 0x40
static int adpcm_step[89] =
{
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
};
static int adpcm_index[16] =
{
-1, -1, -1, -1, 2, 4, 6, 8,
-1, -1, -1, -1, 2, 4, 6, 8
};
static int format_0x62_table[16] =
{
1, 3, 5, 7, 9, 11, 13, 15,
-1, -3, -5, -7, -9, -11, -13, -15
};
#endif
Index: codec-cfg.c
===================================================================
RCS file: /cvsroot/mplayer/main/codec-cfg.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- codec-cfg.c 23 Dec 2001 22:20:45 -0000 1.53
+++ codec-cfg.c 26 Dec 2001 06:13:17 -0000 1.54
@@ -215,6 +215,7 @@
"ima4",
"liba52",
"g72x",
+ "adpcm",
NULL
};
static char *videodrv[] = {
Index: codec-cfg.h
===================================================================
RCS file: /cvsroot/mplayer/main/codec-cfg.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- codec-cfg.h 23 Dec 2001 22:20:45 -0000 1.28
+++ codec-cfg.h 26 Dec 2001 06:13:17 -0000 1.29
@@ -33,6 +33,7 @@
#define AFM_IMA4 13
#define AFM_A52 14
#define AFM_G72X 15
+#define AFM_ADPCM 16
#define VFM_MPEG 1
#define VFM_VFW 2
Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/Makefile,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -r1.127 -r1.128
--- Makefile 25 Dec 2001 22:00:15 -0000 1.127
+++ Makefile 26 Dec 2001 06:13:17 -0000 1.128
@@ -22,7 +22,7 @@
# a BSD compatible 'install' program
INSTALL = install
-SRCS_COMMON = ima4.c xacodec.c cpudetect.c mp_msg.c ac3-iec958.c dec_audio.c dec_video.c msvidc.c cinepak.c fli.c qtrle.c codec-cfg.c cfgparser.c my_profile.c
+SRCS_COMMON = ima4.c adpcm.c xacodec.c cpudetect.c mp_msg.c ac3-iec958.c dec_audio.c dec_video.c msvidc.c cinepak.c fli.c qtrle.c codec-cfg.c cfgparser.c my_profile.c
SRCS_MENCODER = mencoder.c $(SRCS_COMMON) libao2/afmt.c divx4_vbr.c libvo/aclib.c libvo/img_format.c
SRCS_MPLAYER = mplayer.c $(SRCS_COMMON) find_sub.c subreader.c lirc_mp.c mixer.c spudec.c
Index: dec_audio.c
===================================================================
RCS file: /cvsroot/mplayer/main/dec_audio.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- dec_audio.c 10 Dec 2001 20:11:31 -0000 1.58
+++ dec_audio.c 26 Dec 2001 06:13:17 -0000 1.59
@@ -39,7 +39,7 @@
#include "ac3-iec958.h"
-#include "ima4.h"
+#include "adpcm.h"
#include "cpudetect.h"
@@ -279,10 +279,11 @@
sh_audio->audio_out_minsize=4*320;
break;
case AFM_IMA4:
+case AFM_ADPCM:
// IMA-ADPCM 4:1 audio codec:
- sh_audio->audio_out_minsize=4096; //4*IMA4_SAMPLES_PER_BLOCK;
- sh_audio->ds->ss_div=IMA4_SAMPLES_PER_BLOCK;
- sh_audio->ds->ss_mul=IMA4_BLOCK_SIZE;
+ sh_audio->audio_out_minsize=4096;
+ sh_audio->ds->ss_div=IMA_ADPCM_SAMPLES_PER_BLOCK;
+ sh_audio->ds->ss_mul=IMA_ADPCM_BLOCK_SIZE;
break;
case AFM_MPEG:
// MPEG Audio:
@@ -502,12 +503,13 @@
sh_audio->i_bps=65*(sh_audio->channels*sh_audio->samplerate)/320; // 1:10
break;
}
+case AFM_ADPCM:
case AFM_IMA4: {
// IMA-ADPCM 4:1 audio codec:
sh_audio->channels=sh_audio->wf->nChannels;
sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
// decodes 34 byte -> 64 short
- sh_audio->i_bps=IMA4_BLOCK_SIZE*(sh_audio->channels*sh_audio->samplerate)/IMA4_SAMPLES_PER_BLOCK; // 1:4
+ sh_audio->i_bps=IMA_ADPCM_BLOCK_SIZE*(sh_audio->channels*sh_audio->samplerate)/IMA_ADPCM_SAMPLES_PER_BLOCK; // 1:4
break;
}
case AFM_MPEG: {
@@ -904,10 +906,15 @@
memcpy(buf,g72x_data.samples,len);
break;
}
+ case AFM_ADPCM:
case AFM_IMA4: // IMA-ADPCM 4:1 audio codec:
- { unsigned char ibuf[IMA4_BLOCK_SIZE]; // bytes / frame
- if(demux_read_data(sh_audio->ds,ibuf,IMA4_BLOCK_SIZE)!=IMA4_BLOCK_SIZE) break; // EOF
- len=2*ima4_decode_block((unsigned short*)buf,ibuf,2*IMA4_SAMPLES_PER_BLOCK);
+ { unsigned char ibuf[IMA_ADPCM_BLOCK_SIZE * 2]; // bytes / stereo frame
+ if (demux_read_data(sh_audio->ds, ibuf,
+ IMA_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) !=
+ IMA_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels)
+ break; // EOF
+ len=2*ima_adpcm_decode_block((unsigned short*)buf,ibuf, sh_audio->wf->nChannels);
+// len=2*ima4_decode_block((unsigned short*)buf,ibuf,2*IMA_ADPCM_SAMPLES_PER_BLOCK);
break;
}
case AFM_AC3: // AC3 decoder
More information about the MPlayer-cvslog
mailing list