Mercurial > libavcodec.hg
comparison pcm.c @ 7519:4b6f7cdce8c5 libavcodec
Add simpler/cleaner/faster F32BE encoding/decoding.
author | pross |
---|---|
date | Thu, 07 Aug 2008 09:32:10 +0000 |
parents | a40c76e98909 |
children | 4801922896e7 |
comparison
equal
deleted
inserted
replaced
7518:a40c76e98909 | 7519:4b6f7cdce8c5 |
---|---|
158 *dst += bps; | 158 *dst += bps; |
159 } | 159 } |
160 if (le) *dst -= bps - 2; | 160 if (le) *dst -= bps - 2; |
161 } | 161 } |
162 | 162 |
163 /** | |
164 * Write PCM samples macro | |
165 * @param type Datatype of native machine format | |
166 * @param endian bytestream_put_xxx() suffix | |
167 * @param src Source pointer (variable name) | |
168 * @param dst Destination pointer (variable name) | |
169 * @param n Total number of samples (variable name) | |
170 * @param offset Sample value offset | |
171 */ | |
172 #define ENCODE(type, endian, src, dst, n, offset) \ | |
173 { \ | |
174 type *samples = src; \ | |
175 for(;n>0;n--) { \ | |
176 register type v = *samples++ + offset; \ | |
177 bytestream_put_##endian(&dst, v); \ | |
178 } \ | |
179 } | |
180 | |
163 static int pcm_encode_frame(AVCodecContext *avctx, | 181 static int pcm_encode_frame(AVCodecContext *avctx, |
164 unsigned char *frame, int buf_size, void *data) | 182 unsigned char *frame, int buf_size, void *data) |
165 { | 183 { |
166 int n, sample_size, v; | 184 int n, sample_size, v; |
167 short *samples; | 185 short *samples; |
172 samples = data; | 190 samples = data; |
173 dst = frame; | 191 dst = frame; |
174 | 192 |
175 switch(avctx->codec->id) { | 193 switch(avctx->codec->id) { |
176 case CODEC_ID_PCM_F32BE: | 194 case CODEC_ID_PCM_F32BE: |
177 { | 195 ENCODE(int32_t, be32, samples, dst, n, 0) |
178 float *fsamples = data; | |
179 for(;n>0;n--) { | |
180 float fv = *fsamples++; | |
181 bytestream_put_be32(&dst, av_flt2int(fv)); | |
182 } | |
183 samples = (void*)fsamples; | |
184 } | |
185 break; | 196 break; |
186 case CODEC_ID_PCM_S32LE: | 197 case CODEC_ID_PCM_S32LE: |
187 encode_from16(4, 1, 0, &samples, &dst, n); | 198 encode_from16(4, 1, 0, &samples, &dst, n); |
188 break; | 199 break; |
189 case CODEC_ID_PCM_S32BE: | 200 case CODEC_ID_PCM_S32BE: |
332 *src += bps; | 343 *src += bps; |
333 } | 344 } |
334 if (le) *src -= bps - 2; | 345 if (le) *src -= bps - 2; |
335 } | 346 } |
336 | 347 |
348 /** | |
349 * Read PCM samples macro | |
350 * @param type Datatype of native machine format | |
351 * @param endian bytestream_get_xxx() endian suffix | |
352 * @param src Source pointer (variable name) | |
353 * @param dst Destination pointer (variable name) | |
354 * @param n Total number of samples (variable name) | |
355 * @param offset Sample value offset | |
356 */ | |
357 #define DECODE(type, endian, src, dst, n, offset) \ | |
358 { \ | |
359 type *dst2 = (type*)dst; \ | |
360 for(;n>0;n--) { \ | |
361 register type v = bytestream_get_##endian(&src); \ | |
362 *dst2++ = v - offset; \ | |
363 } \ | |
364 dst = (short*)dst2; \ | |
365 } | |
366 | |
337 static int pcm_decode_frame(AVCodecContext *avctx, | 367 static int pcm_decode_frame(AVCodecContext *avctx, |
338 void *data, int *data_size, | 368 void *data, int *data_size, |
339 const uint8_t *buf, int buf_size) | 369 const uint8_t *buf, int buf_size) |
340 { | 370 { |
341 PCMDecode *s = avctx->priv_data; | 371 PCMDecode *s = avctx->priv_data; |
369 | 399 |
370 n = buf_size/sample_size; | 400 n = buf_size/sample_size; |
371 | 401 |
372 switch(avctx->codec->id) { | 402 switch(avctx->codec->id) { |
373 case CODEC_ID_PCM_F32BE: | 403 case CODEC_ID_PCM_F32BE: |
374 { | 404 DECODE(int32_t, be32, src, samples, n, 0) |
375 float *fsamples = data; | 405 break; |
376 for(;n>0;n--) | |
377 *fsamples++ = av_int2flt(bytestream_get_be32(&src)); | |
378 samples = (void*)fsamples; | |
379 break; | |
380 } | |
381 case CODEC_ID_PCM_S32LE: | 406 case CODEC_ID_PCM_S32LE: |
382 decode_to16(4, 1, 0, &src, &samples, buf_size); | 407 decode_to16(4, 1, 0, &src, &samples, buf_size); |
383 break; | 408 break; |
384 case CODEC_ID_PCM_S32BE: | 409 case CODEC_ID_PCM_S32BE: |
385 decode_to16(4, 0, 0, &src, &samples, buf_size); | 410 decode_to16(4, 0, 0, &src, &samples, buf_size); |