Mercurial > libavcodec.hg
comparison roqaudioenc.c @ 10427:1a3908177e87 libavcodec
Replace big square-root table by a call to ff_sqrt(). Based on a patch
by Reimar Dffinger.
author | vitor |
---|---|
date | Sun, 18 Oct 2009 16:29:10 +0000 |
parents | 7955db355703 |
children | 421c9441c11e |
comparison
equal
deleted
inserted
replaced
10426:8d15af816144 | 10427:1a3908177e87 |
---|---|
27 #define ROQ_FIRST_FRAME_SIZE (735*8) | 27 #define ROQ_FIRST_FRAME_SIZE (735*8) |
28 #define ROQ_FRAME_SIZE 735 | 28 #define ROQ_FRAME_SIZE 735 |
29 | 29 |
30 | 30 |
31 #define MAX_DPCM (127*127) | 31 #define MAX_DPCM (127*127) |
32 static unsigned char dpcmValues[MAX_DPCM]; | |
33 | 32 |
34 | 33 |
35 typedef struct | 34 typedef struct |
36 { | 35 { |
37 short lastSample[2]; | 36 short lastSample[2]; |
38 } ROQDPCMContext; | 37 } ROQDPCMContext; |
39 | |
40 static av_cold void roq_dpcm_table_init(void) | |
41 { | |
42 int i; | |
43 | |
44 /* Create a table of quick DPCM values */ | |
45 for (i=0; i<MAX_DPCM; i++) { | |
46 int s= ff_sqrt(i); | |
47 int mid= s*s + s; | |
48 dpcmValues[i]= s + (i>mid); | |
49 } | |
50 } | |
51 | 38 |
52 static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx) | 39 static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx) |
53 { | 40 { |
54 ROQDPCMContext *context = avctx->priv_data; | 41 ROQDPCMContext *context = avctx->priv_data; |
55 | 42 |
63 } | 50 } |
64 if (avctx->sample_fmt != SAMPLE_FMT_S16) { | 51 if (avctx->sample_fmt != SAMPLE_FMT_S16) { |
65 av_log(avctx, AV_LOG_ERROR, "Audio must be signed 16-bit\n"); | 52 av_log(avctx, AV_LOG_ERROR, "Audio must be signed 16-bit\n"); |
66 return -1; | 53 return -1; |
67 } | 54 } |
68 | |
69 roq_dpcm_table_init(); | |
70 | 55 |
71 avctx->frame_size = ROQ_FIRST_FRAME_SIZE; | 56 avctx->frame_size = ROQ_FIRST_FRAME_SIZE; |
72 | 57 |
73 context->lastSample[0] = context->lastSample[1] = 0; | 58 context->lastSample[0] = context->lastSample[1] = 0; |
74 | 59 |
90 negative = diff<0; | 75 negative = diff<0; |
91 diff = FFABS(diff); | 76 diff = FFABS(diff); |
92 | 77 |
93 if (diff >= MAX_DPCM) | 78 if (diff >= MAX_DPCM) |
94 result = 127; | 79 result = 127; |
95 else | 80 else { |
96 result = dpcmValues[diff]; | 81 result = ff_sqrt(diff); |
82 result += diff > result*result+result; | |
83 } | |
97 | 84 |
98 /* See if this overflows */ | 85 /* See if this overflows */ |
99 retry: | 86 retry: |
100 diff = result*result; | 87 diff = result*result; |
101 if (negative) | 88 if (negative) |