4444#include "mathops.h"
4545
4646typedef struct DPCMContext {
47- int16_t roq_square_array [256 ];
47+ int16_t square_array [256 ];
4848 int sample [2 ]; ///< previous sample (for SOL_DPCM)
4949 const int8_t * sol_table ; ///< delta table for SOL_DPCM
5050} DPCMContext ;
@@ -130,8 +130,8 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx)
130130 /* initialize square table */
131131 for (i = 0 ; i < 128 ; i ++ ) {
132132 int16_t square = i * i ;
133- s -> roq_square_array [i ] = square ;
134- s -> roq_square_array [i + 128 ] = - square ;
133+ s -> square_array [i ] = square ;
134+ s -> square_array [i + 128 ] = - square ;
135135 }
136136 break ;
137137
@@ -153,6 +153,13 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx)
153153 }
154154 break ;
155155
156+ case AV_CODEC_ID_SDX2_DPCM :
157+ for (i = -128 ; i < 128 ; i ++ ) {
158+ int16_t square = i * i * 2 ;
159+ s -> square_array [i + 128 ] = i < 0 ? - square : square ;
160+ }
161+ break ;
162+
156163 default :
157164 break ;
158165 }
@@ -200,6 +207,9 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
200207 else
201208 out = buf_size ;
202209 break ;
210+ case AV_CODEC_ID_SDX2_DPCM :
211+ out = buf_size ;
212+ break ;
203213 }
204214 if (out <= 0 ) {
205215 av_log (avctx , AV_LOG_ERROR , "packet is too small\n" );
@@ -230,7 +240,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
230240
231241 /* decode the samples */
232242 while (output_samples < samples_end ) {
233- predictor [ch ] += s -> roq_square_array [bytestream2_get_byteu (& gb )];
243+ predictor [ch ] += s -> square_array [bytestream2_get_byteu (& gb )];
234244 predictor [ch ] = av_clip_int16 (predictor [ch ]);
235245 * output_samples ++ = predictor [ch ];
236246
@@ -318,6 +328,19 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
318328 }
319329 }
320330 break ;
331+
332+ case AV_CODEC_ID_SDX2_DPCM :
333+ while (output_samples < samples_end ) {
334+ int8_t n = bytestream2_get_byteu (& gb );
335+
336+ if (!(n & 1 ))
337+ s -> sample [ch ] = 0 ;
338+ s -> sample [ch ] += s -> square_array [n + 128 ];
339+ s -> sample [ch ] = av_clip_int16 (s -> sample [ch ]);
340+ * output_samples ++ = s -> sample [ch ];
341+ ch ^= stereo ;
342+ }
343+ break ;
321344 }
322345
323346 * got_frame_ptr = 1 ;
@@ -339,5 +362,6 @@ AVCodec ff_ ## name_ ## _decoder = { \
339362
340363DPCM_DECODER (AV_CODEC_ID_INTERPLAY_DPCM , interplay_dpcm , "DPCM Interplay" );
341364DPCM_DECODER (AV_CODEC_ID_ROQ_DPCM , roq_dpcm , "DPCM id RoQ" );
365+ DPCM_DECODER (AV_CODEC_ID_SDX2_DPCM , sdx2_dpcm , "DPCM Squareroot-Delta-Exact" );
342366DPCM_DECODER (AV_CODEC_ID_SOL_DPCM , sol_dpcm , "DPCM Sol" );
343367DPCM_DECODER (AV_CODEC_ID_XAN_DPCM , xan_dpcm , "DPCM Xan" );
0 commit comments