* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
+/**
+ * @file pcm.c
+ * PCM codecs
+ */
+
#include "avcodec.h"
/* from g711.c by SUN microsystems (unrestricted use) */
a_val ^= 0x55;
- t = (a_val & QUANT_MASK) << 4;
+ t = a_val & QUANT_MASK;
seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
- switch (seg) {
- case 0:
- t += 8;
- break;
- case 1:
- t += 0x108;
- break;
- default:
- t += 0x108;
- t <<= seg - 1;
- }
+ if(seg) t= (t + t + 1 + 32) << (seg + 2);
+ else t= (t + t + 1 ) << 3;
+
return ((a_val & SIGN_BIT) ? t : -t);
}
}
/* 16384 entries per table */
-static UINT8 *linear_to_alaw = NULL;
+static uint8_t *linear_to_alaw = NULL;
static int linear_to_alaw_ref = 0;
-static UINT8 *linear_to_ulaw = NULL;
+static uint8_t *linear_to_ulaw = NULL;
static int linear_to_ulaw_ref = 0;
-static void build_xlaw_table(UINT8 *linear_to_xlaw,
+static void build_xlaw_table(uint8_t *linear_to_xlaw,
int (*xlaw2linear)(unsigned char),
int mask)
{
linear_to_xlaw[0] = linear_to_xlaw[1];
}
-static int encode_init(AVCodecContext *avctx)
+static int pcm_encode_init(AVCodecContext *avctx)
{
avctx->frame_size = 1;
switch(avctx->codec->id) {
default:
break;
}
+
+ avctx->coded_frame= avcodec_alloc_frame();
+ avctx->coded_frame->key_frame= 1;
+
return 0;
}
-static int encode_close(AVCodecContext *avctx)
+static int pcm_encode_close(AVCodecContext *avctx)
{
+ av_freep(&avctx->coded_frame);
+
switch(avctx->codec->id) {
case CODEC_ID_PCM_ALAW:
if (--linear_to_alaw_ref == 0)
return 0;
}
-static int encode_frame(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
+static int pcm_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data)
{
int n, sample_size, v;
short *samples;
case CODEC_ID_PCM_S8:
for(;n>0;n--) {
v = *samples++;
- dst[0] = (v + 128) >> 8;
+ dst[0] = v >> 8;
dst++;
}
break;
case CODEC_ID_PCM_U8:
for(;n>0;n--) {
v = *samples++;
- dst[0] = ((v + 128) >> 8) + 128;
+ dst[0] = (v >> 8) + 128;
dst++;
}
break;
default:
return -1;
}
- avctx->key_frame = 1;
//avctx->frame_size = (dst - frame) / (sample_size * avctx->channels);
return dst - frame;
short table[256];
} PCMDecode;
-static int decode_init(AVCodecContext * avctx)
+static int pcm_decode_init(AVCodecContext * avctx)
{
PCMDecode *s = avctx->priv_data;
int i;
return 0;
}
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- UINT8 *buf, int buf_size)
+static int pcm_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ uint8_t *buf, int buf_size)
{
PCMDecode *s = avctx->priv_data;
int n;
short *samples;
- UINT8 *src;
+ uint8_t *src;
samples = data;
src = buf;
*data_size = 0;
return -1;
}
- *data_size = (UINT8 *)samples - (UINT8 *)data;
+ *data_size = (uint8_t *)samples - (uint8_t *)data;
return src - buf;
}
CODEC_TYPE_AUDIO, \
id, \
0, \
- encode_init, \
- encode_frame, \
- encode_close, \
+ pcm_encode_init, \
+ pcm_encode_frame, \
+ pcm_encode_close, \
NULL, \
}; \
AVCodec name ## _decoder = { \
CODEC_TYPE_AUDIO, \
id, \
sizeof(PCMDecode), \
- decode_init, \
+ pcm_decode_init, \
NULL, \
NULL, \
- decode_frame, \
-};
+ pcm_decode_frame, \
+}
PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
+
+#undef PCM_CODEC