* 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)
{
break;
}
+ switch(avctx->codec->id) {
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_U16LE:
+ case CODEC_ID_PCM_U16BE:
+ avctx->block_align = 2 * avctx->channels;
+ break;
+ case CODEC_ID_PCM_S8:
+ case CODEC_ID_PCM_U8:
+ case CODEC_ID_PCM_MULAW:
+ case CODEC_ID_PCM_ALAW:
+ avctx->block_align = avctx->channels;
+ break;
+ default:
+ break;
+ }
+
avctx->coded_frame= avcodec_alloc_frame();
avctx->coded_frame->key_frame= 1;
static int pcm_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
- UINT8 *buf, int buf_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;
+ if(buf_size > AVCODEC_MAX_AUDIO_FRAME_SIZE/2)
+ buf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE/2;
+
switch(avctx->codec->id) {
case CODEC_ID_PCM_S16LE:
n = buf_size >> 1;
}
break;
default:
- *data_size = 0;
return -1;
}
- *data_size = (UINT8 *)samples - (UINT8 *)data;
+ *data_size = (uint8_t *)samples - (uint8_t *)data;
return src - buf;
}