1 /*****************************************************************************
2 * adpcm.c : adpcm variant audio decoder
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VLC authors and VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * RĂ©mi Denis-Courmont <rem # videolan.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
28 * Documentation: http://www.pcisys.net/~melanson/codecs/adpcm.txt
29 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_codec.h>
38 /*****************************************************************************
40 *****************************************************************************/
41 static int OpenDecoder( vlc_object_t
* );
42 static void CloseDecoder( vlc_object_t
* );
44 static int DecodeAudio( decoder_t
*, block_t
* );
45 static void Flush( decoder_t
* );
48 set_description( N_("ADPCM audio decoder") )
49 set_capability( "audio decoder", 50 )
50 set_category( CAT_INPUT
)
51 set_subcategory( SUBCAT_INPUT_ACODEC
)
52 set_callbacks( OpenDecoder
, CloseDecoder
)
55 /*****************************************************************************
57 *****************************************************************************/
70 enum adpcm_codec_e codec
;
73 size_t i_samplesperblock
;
79 static void DecodeAdpcmMs ( decoder_t
*, int16_t *, uint8_t * );
80 static void DecodeAdpcmImaWav( decoder_t
*, int16_t *, uint8_t * );
81 static void DecodeAdpcmImaQT ( decoder_t
*, int16_t *, uint8_t * );
82 static void DecodeAdpcmDk4 ( decoder_t
*, int16_t *, uint8_t * );
83 static void DecodeAdpcmDk3 ( decoder_t
*, int16_t *, uint8_t * );
84 static void DecodeAdpcmEA ( decoder_t
*, int16_t *, uint8_t * );
86 static const int pi_channels_maps
[6] =
90 AOUT_CHAN_LEFT
| AOUT_CHAN_RIGHT
,
91 AOUT_CHAN_LEFT
| AOUT_CHAN_RIGHT
| AOUT_CHAN_CENTER
,
92 AOUT_CHAN_LEFT
| AOUT_CHAN_RIGHT
| AOUT_CHAN_REARLEFT
| AOUT_CHAN_REARLEFT
,
93 AOUT_CHAN_LEFT
| AOUT_CHAN_RIGHT
| AOUT_CHAN_CENTER
94 | AOUT_CHAN_REARLEFT
| AOUT_CHAN_REARLEFT
97 /* Various table from http://www.pcisys.net/~melanson/codecs/adpcm.txt */
98 static const int i_index_table
[16] =
100 -1, -1, -1, -1, 2, 4, 6, 8,
101 -1, -1, -1, -1, 2, 4, 6, 8
104 static const int i_step_table
[89] =
106 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
107 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
108 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
109 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
110 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
111 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
112 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
113 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
114 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
117 static const int i_adaptation_table
[16] =
119 230, 230, 230, 230, 307, 409, 512, 614,
120 768, 614, 512, 409, 307, 230, 230, 230
123 static const int i_adaptation_coeff1
[7] =
125 256, 512, 0, 192, 240, 460, 392
128 static const int i_adaptation_coeff2
[7] =
130 0, -256, 0, 64, 0, -208, -232
133 /*****************************************************************************
134 * OpenDecoder: probe the decoder and return score
135 *****************************************************************************/
136 static int OpenDecoder( vlc_object_t
*p_this
)
138 decoder_t
*p_dec
= (decoder_t
*)p_this
;
139 decoder_sys_t
*p_sys
;
141 switch( p_dec
->fmt_in
.i_codec
)
143 case VLC_CODEC_ADPCM_IMA_QT
:
144 case VLC_CODEC_ADPCM_IMA_WAV
:
145 case VLC_CODEC_ADPCM_MS
:
146 case VLC_CODEC_ADPCM_DK4
:
147 case VLC_CODEC_ADPCM_DK3
:
148 case VLC_CODEC_ADPCM_XA_EA
:
154 if( p_dec
->fmt_in
.audio
.i_rate
<= 0 )
156 msg_Err( p_dec
, "bad samplerate" );
160 /* Allocate the memory needed to store the decoder's structure */
161 p_sys
= malloc(sizeof(*p_sys
));
162 if( unlikely(p_sys
== NULL
) )
166 p_sys
->i_samplesperblock
= 0;
168 unsigned i_channels
= p_dec
->fmt_in
.audio
.i_channels
;
169 uint8_t i_max_channels
= 5;
170 switch( p_dec
->fmt_in
.i_codec
)
172 case VLC_CODEC_ADPCM_IMA_QT
: /* IMA ADPCM */
173 p_sys
->codec
= ADPCM_IMA_QT
;
176 case VLC_CODEC_ADPCM_IMA_WAV
: /* IMA ADPCM */
177 p_sys
->codec
= ADPCM_IMA_WAV
;
180 case VLC_CODEC_ADPCM_MS
: /* MS ADPCM */
181 p_sys
->codec
= ADPCM_MS
;
184 case VLC_CODEC_ADPCM_DK4
: /* Duck DK4 ADPCM */
185 p_sys
->codec
= ADPCM_DK4
;
188 case VLC_CODEC_ADPCM_DK3
: /* Duck DK3 ADPCM */
189 p_sys
->codec
= ADPCM_DK3
;
192 case VLC_CODEC_ADPCM_XA_EA
: /* EA ADPCM */
193 p_sys
->codec
= ADPCM_EA
;
194 p_sys
->prev
= calloc( 2 * p_dec
->fmt_in
.audio
.i_channels
,
196 if( unlikely(p_sys
->prev
== NULL
) )
204 if (i_channels
> i_max_channels
|| i_channels
== 0)
208 msg_Err( p_dec
, "Invalid number of channels %i", p_dec
->fmt_in
.audio
.i_channels
);
212 if( p_dec
->fmt_in
.audio
.i_blockalign
<= 0 )
214 p_sys
->i_block
= (p_sys
->codec
== ADPCM_IMA_QT
) ?
215 34 * p_dec
->fmt_in
.audio
.i_channels
: 1024;
216 msg_Warn( p_dec
, "block size undefined, using %zu", p_sys
->i_block
);
220 p_sys
->i_block
= p_dec
->fmt_in
.audio
.i_blockalign
;
223 /* calculate samples per block */
224 switch( p_sys
->codec
)
227 p_sys
->i_samplesperblock
= 64;
230 if( p_sys
->i_block
>= 4 * i_channels
)
232 p_sys
->i_samplesperblock
= 2 * ( p_sys
->i_block
- 4 * i_channels
)
237 if( p_sys
->i_block
>= 7 * i_channels
)
239 p_sys
->i_samplesperblock
=
240 2 * (p_sys
->i_block
- 7 * i_channels
) / i_channels
+ 2;
244 if( p_sys
->i_block
>= 4 * i_channels
)
246 p_sys
->i_samplesperblock
=
247 2 * (p_sys
->i_block
- 4 * i_channels
) / i_channels
+ 1;
252 if( p_sys
->i_block
>= 16 )
253 p_sys
->i_samplesperblock
= ( 4 * ( p_sys
->i_block
- 16 ) + 2 )/ 3;
256 if( p_sys
->i_block
>= i_channels
)
258 p_sys
->i_samplesperblock
=
259 2 * (p_sys
->i_block
- i_channels
) / i_channels
;
263 msg_Dbg( p_dec
, "format: samplerate:%d Hz channels:%d bits/sample:%d "
264 "blockalign:%zu samplesperblock:%zu",
265 p_dec
->fmt_in
.audio
.i_rate
, i_channels
,
266 p_dec
->fmt_in
.audio
.i_bitspersample
, p_sys
->i_block
,
267 p_sys
->i_samplesperblock
);
269 if (p_sys
->i_samplesperblock
== 0)
273 msg_Err( p_dec
, "Error computing number of samples per block");
277 p_dec
->p_sys
= p_sys
;
278 p_dec
->fmt_out
.i_codec
= VLC_CODEC_S16N
;
279 p_dec
->fmt_out
.audio
.i_rate
= p_dec
->fmt_in
.audio
.i_rate
;
280 p_dec
->fmt_out
.audio
.i_channels
= i_channels
;
281 p_dec
->fmt_out
.audio
.i_physical_channels
= pi_channels_maps
[i_channels
];
283 date_Init( &p_sys
->end_date
, p_dec
->fmt_out
.audio
.i_rate
, 1 );
284 date_Set( &p_sys
->end_date
, 0 );
286 p_dec
->pf_decode
= DecodeAudio
;
287 p_dec
->pf_flush
= Flush
;
292 /*****************************************************************************
294 *****************************************************************************/
295 static void Flush( decoder_t
*p_dec
)
297 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
299 date_Set( &p_sys
->end_date
, 0 );
302 /*****************************************************************************
304 *****************************************************************************/
305 static block_t
*DecodeBlock( decoder_t
*p_dec
, block_t
**pp_block
)
307 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
310 if( !*pp_block
) return NULL
;
314 if( p_block
->i_flags
& (BLOCK_FLAG_DISCONTINUITY
|BLOCK_FLAG_CORRUPTED
) )
317 if( p_block
->i_flags
& BLOCK_FLAG_CORRUPTED
)
321 if( p_block
->i_pts
> VLC_TS_INVALID
&&
322 p_block
->i_pts
!= date_Get( &p_sys
->end_date
) )
324 date_Set( &p_sys
->end_date
, p_block
->i_pts
);
326 else if( !date_Get( &p_sys
->end_date
) )
327 /* We've just started the stream, wait for the first PTS. */
330 /* Don't re-use the same pts twice */
331 p_block
->i_pts
= VLC_TS_INVALID
;
333 if( p_block
->i_buffer
>= p_sys
->i_block
)
337 if( decoder_UpdateAudioFormat( p_dec
) )
339 p_out
= decoder_NewAudioBuffer( p_dec
, p_sys
->i_samplesperblock
);
343 p_out
->i_pts
= date_Get( &p_sys
->end_date
);
344 p_out
->i_length
= date_Increment( &p_sys
->end_date
,
345 p_sys
->i_samplesperblock
) - p_out
->i_pts
;
347 switch( p_sys
->codec
)
350 DecodeAdpcmImaQT( p_dec
, (int16_t*)p_out
->p_buffer
,
354 DecodeAdpcmImaWav( p_dec
, (int16_t*)p_out
->p_buffer
,
358 DecodeAdpcmMs( p_dec
, (int16_t*)p_out
->p_buffer
,
362 DecodeAdpcmDk4( p_dec
, (int16_t*)p_out
->p_buffer
,
366 DecodeAdpcmDk3( p_dec
, (int16_t*)p_out
->p_buffer
,
370 DecodeAdpcmEA( p_dec
, (int16_t*)p_out
->p_buffer
,
376 p_block
->p_buffer
+= p_sys
->i_block
;
377 p_block
->i_buffer
-= p_sys
->i_block
;
382 block_Release( p_block
);
387 static int DecodeAudio( decoder_t
*p_dec
, block_t
*p_block
)
389 if( p_block
== NULL
) /* No Drain */
390 return VLCDEC_SUCCESS
;
392 block_t
**pp_block
= &p_block
, *p_out
;
393 while( ( p_out
= DecodeBlock( p_dec
, pp_block
) ) != NULL
)
394 decoder_QueueAudio( p_dec
, p_out
);
395 return VLCDEC_SUCCESS
;
398 /*****************************************************************************
400 *****************************************************************************/
401 static void CloseDecoder( vlc_object_t
*p_this
)
403 decoder_t
*p_dec
= (decoder_t
*)p_this
;
404 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
410 /*****************************************************************************
412 *****************************************************************************/
413 #define CLAMP( v, min, max ) \
414 if( (v) < (min) ) (v) = (min); \
415 if( (v) > (max) ) (v) = (max)
417 #define GetByte( v ) \
418 (v) = *p_buffer; p_buffer++;
420 #define GetWord( v ) \
421 (v) = *p_buffer; p_buffer++; \
422 (v) |= ( *p_buffer ) << 8; p_buffer++; \
423 if( (v)&0x8000 ) (v) -= 0x010000;
428 typedef struct adpcm_ms_channel_s
431 int i_sample1
, i_sample2
;
432 int i_coeff1
, i_coeff2
;
434 } adpcm_ms_channel_t
;
437 static int AdpcmMsExpandNibble(adpcm_ms_channel_t
*p_channel
,
444 i_snibble
= i_nibble
- ( i_nibble
&0x08 ? 0x10 : 0 );
446 i_predictor
= ( p_channel
->i_sample1
* p_channel
->i_coeff1
+
447 p_channel
->i_sample2
* p_channel
->i_coeff2
) / 256 +
448 i_snibble
* p_channel
->i_idelta
;
450 CLAMP( i_predictor
, -32768, 32767 );
452 p_channel
->i_sample2
= p_channel
->i_sample1
;
453 p_channel
->i_sample1
= i_predictor
;
455 p_channel
->i_idelta
= ( i_adaptation_table
[i_nibble
] *
456 p_channel
->i_idelta
) / 256;
457 if( p_channel
->i_idelta
< 16 )
459 p_channel
->i_idelta
= 16;
461 return( i_predictor
);
464 static void DecodeAdpcmMs( decoder_t
*p_dec
, int16_t *p_sample
,
467 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
468 adpcm_ms_channel_t channel
[2];
470 int i_block_predictor
;
472 size_t i_total_samples
= p_sys
->i_samplesperblock
;
473 if(i_total_samples
< 2)
476 b_stereo
= p_dec
->fmt_out
.audio
.i_channels
== 2 ? 1 : 0;
478 GetByte( i_block_predictor
);
479 CLAMP( i_block_predictor
, 0, 6 );
480 channel
[0].i_coeff1
= i_adaptation_coeff1
[i_block_predictor
];
481 channel
[0].i_coeff2
= i_adaptation_coeff2
[i_block_predictor
];
485 GetByte( i_block_predictor
);
486 CLAMP( i_block_predictor
, 0, 6 );
487 channel
[1].i_coeff1
= i_adaptation_coeff1
[i_block_predictor
];
488 channel
[1].i_coeff2
= i_adaptation_coeff2
[i_block_predictor
];
490 GetWord( channel
[0].i_idelta
);
493 GetWord( channel
[1].i_idelta
);
496 GetWord( channel
[0].i_sample1
);
499 GetWord( channel
[1].i_sample1
);
502 GetWord( channel
[0].i_sample2
);
505 GetWord( channel
[1].i_sample2
);
510 *p_sample
++ = channel
[0].i_sample2
;
511 *p_sample
++ = channel
[1].i_sample2
;
512 *p_sample
++ = channel
[0].i_sample1
;
513 *p_sample
++ = channel
[1].i_sample1
;
517 *p_sample
++ = channel
[0].i_sample2
;
518 *p_sample
++ = channel
[0].i_sample1
;
521 for( i_total_samples
-= 2; i_total_samples
>= 2; i_total_samples
-= 2, p_buffer
++ )
523 *p_sample
++ = AdpcmMsExpandNibble( &channel
[0], (*p_buffer
) >> 4);
524 *p_sample
++ = AdpcmMsExpandNibble( &channel
[b_stereo
? 1 : 0],
532 typedef struct adpcm_ima_wav_channel_s
537 } adpcm_ima_wav_channel_t
;
539 static int AdpcmImaWavExpandNibble(adpcm_ima_wav_channel_t
*p_channel
,
544 i_diff
= i_step_table
[p_channel
->i_step_index
] >> 3;
545 if( i_nibble
&0x04 ) i_diff
+= i_step_table
[p_channel
->i_step_index
];
546 if( i_nibble
&0x02 ) i_diff
+= i_step_table
[p_channel
->i_step_index
]>>1;
547 if( i_nibble
&0x01 ) i_diff
+= i_step_table
[p_channel
->i_step_index
]>>2;
549 p_channel
->i_predictor
-= i_diff
;
551 p_channel
->i_predictor
+= i_diff
;
553 CLAMP( p_channel
->i_predictor
, -32768, 32767 );
555 p_channel
->i_step_index
+= i_index_table
[i_nibble
];
557 CLAMP( p_channel
->i_step_index
, 0, 88 );
559 return( p_channel
->i_predictor
);
562 static void DecodeAdpcmImaWav( decoder_t
*p_dec
, int16_t *p_sample
,
565 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
566 adpcm_ima_wav_channel_t channel
[2];
570 b_stereo
= p_dec
->fmt_out
.audio
.i_channels
== 2 ? 1 : 0;
572 GetWord( channel
[0].i_predictor
);
573 GetByte( channel
[0].i_step_index
);
574 CLAMP( channel
[0].i_step_index
, 0, 88 );
579 GetWord( channel
[1].i_predictor
);
580 GetByte( channel
[1].i_step_index
);
581 CLAMP( channel
[1].i_step_index
, 0, 88 );
587 for( i_nibbles
= 2 * (p_sys
->i_block
- 8);
593 for( i
= 0; i
< 4; i
++ )
596 AdpcmImaWavExpandNibble(&channel
[0],p_buffer
[i
]&0x0f);
597 p_sample
[i
* 4 + 2] =
598 AdpcmImaWavExpandNibble(&channel
[0],p_buffer
[i
] >> 4);
602 for( i
= 0; i
< 4; i
++ )
604 p_sample
[i
* 4 + 1] =
605 AdpcmImaWavExpandNibble(&channel
[1],p_buffer
[i
]&0x0f);
606 p_sample
[i
* 4 + 3] =
607 AdpcmImaWavExpandNibble(&channel
[1],p_buffer
[i
] >> 4);
618 for( i_nibbles
= 2 * (p_sys
->i_block
- 4);
620 i_nibbles
-= 2, p_buffer
++ )
622 *p_sample
++ =AdpcmImaWavExpandNibble( &channel
[0], (*p_buffer
)&0x0f );
623 *p_sample
++ =AdpcmImaWavExpandNibble( &channel
[0], (*p_buffer
) >> 4 );
631 static void DecodeAdpcmImaQT( decoder_t
*p_dec
, int16_t *p_sample
,
634 adpcm_ima_wav_channel_t channel
[2];
639 i_step
= p_dec
->fmt_out
.audio
.i_channels
;
641 for( i_ch
= 0; i_ch
< p_dec
->fmt_out
.audio
.i_channels
; i_ch
++ )
644 channel
[i_ch
].i_predictor
= (int16_t)((( ( p_buffer
[0] << 1 )|( p_buffer
[1] >> 7 ) ))<<7);
645 channel
[i_ch
].i_step_index
= p_buffer
[1]&0x7f;
647 CLAMP( channel
[i_ch
].i_step_index
, 0, 88 );
650 for( i_nibbles
= 0; i_nibbles
< 64; i_nibbles
+=2 )
652 *p_sample
= AdpcmImaWavExpandNibble( &channel
[i_ch
], (*p_buffer
)&0x0f);
655 *p_sample
= AdpcmImaWavExpandNibble( &channel
[i_ch
], (*p_buffer
>> 4)&0x0f);
662 p_sample
+= 1 - 64 * i_step
;
669 static void DecodeAdpcmDk4( decoder_t
*p_dec
, int16_t *p_sample
,
672 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
673 adpcm_ima_wav_channel_t channel
[2];
677 b_stereo
= p_dec
->fmt_out
.audio
.i_channels
== 2 ? 1 : 0;
679 GetWord( channel
[0].i_predictor
);
680 GetByte( channel
[0].i_step_index
);
681 CLAMP( channel
[0].i_step_index
, 0, 88 );
686 GetWord( channel
[1].i_predictor
);
687 GetByte( channel
[1].i_step_index
);
688 CLAMP( channel
[1].i_step_index
, 0, 88 );
692 /* first output predictor */
693 *p_sample
++ = channel
[0].i_predictor
;
696 *p_sample
++ = channel
[1].i_predictor
;
700 i_nibbles
< p_sys
->i_block
- 4 * (b_stereo
? 2:1 );
703 *p_sample
++ = AdpcmImaWavExpandNibble( &channel
[0],
705 *p_sample
++ = AdpcmImaWavExpandNibble( &channel
[b_stereo
? 1 : 0],
715 static void DecodeAdpcmDk3( decoder_t
*p_dec
, int16_t *p_sample
,
718 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
719 uint8_t *p_end
= &p_buffer
[p_sys
->i_block
];
720 adpcm_ima_wav_channel_t sum
;
721 adpcm_ima_wav_channel_t diff
;
726 GetWord( sum
.i_predictor
);
727 GetWord( diff
.i_predictor
);
728 GetByte( sum
.i_step_index
);
729 GetByte( diff
.i_step_index
);
731 i_diff_value
= diff
.i_predictor
;
732 /* we process 6 nibbles at once */
733 while( p_buffer
+ 1 <= p_end
)
735 /* first 3 nibbles */
736 AdpcmImaWavExpandNibble( &sum
,
739 AdpcmImaWavExpandNibble( &diff
,
742 i_diff_value
= ( i_diff_value
+ diff
.i_predictor
) / 2;
744 *p_sample
++ = sum
.i_predictor
+ i_diff_value
;
745 *p_sample
++ = sum
.i_predictor
- i_diff_value
;
749 AdpcmImaWavExpandNibble( &sum
,
752 *p_sample
++ = sum
.i_predictor
+ i_diff_value
;
753 *p_sample
++ = sum
.i_predictor
- i_diff_value
;
755 /* now last 3 nibbles */
756 AdpcmImaWavExpandNibble( &sum
,
759 if( p_buffer
< p_end
)
761 AdpcmImaWavExpandNibble( &diff
,
764 i_diff_value
= ( i_diff_value
+ diff
.i_predictor
) / 2;
766 *p_sample
++ = sum
.i_predictor
+ i_diff_value
;
767 *p_sample
++ = sum
.i_predictor
- i_diff_value
;
769 AdpcmImaWavExpandNibble( &sum
,
773 *p_sample
++ = sum
.i_predictor
+ i_diff_value
;
774 *p_sample
++ = sum
.i_predictor
- i_diff_value
;
784 static void DecodeAdpcmEA( decoder_t
*p_dec
, int16_t *p_sample
,
787 static const int16_t EATable
[]=
789 0x0000, 0x00F0, 0x01CC, 0x0188, 0x0000, 0x0000, 0xFF30, 0xFF24,
790 0x0000, 0x0001, 0x0003, 0x0004, 0x0007, 0x0008, 0x000A, 0x000B,
791 0x0000, 0xFFFF, 0xFFFD, 0xFFFC,
793 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
794 int_fast32_t c1
[MAX_CHAN
], c2
[MAX_CHAN
];
795 int_fast8_t d
[MAX_CHAN
];
797 unsigned chans
= p_dec
->fmt_out
.audio
.i_channels
;
798 const uint8_t *p_end
= &p_buffer
[p_sys
->i_block
];
799 int16_t *prev
= p_sys
->prev
;
800 int16_t *cur
= prev
+ chans
;
802 for (unsigned c
= 0; c
< chans
; c
++)
804 uint8_t input
= p_buffer
[c
];
806 c1
[c
] = EATable
[input
>> 4];
807 c2
[c
] = EATable
[(input
>> 4) + 4];
808 d
[c
] = (input
& 0xf) + 8;
811 for (p_buffer
+= chans
; p_buffer
< p_end
; p_buffer
+= chans
)
813 union { uint32_t u
; int32_t i
; } spl
;
815 for (unsigned c
= 0; c
< chans
; c
++)
817 spl
.u
= (p_buffer
[c
] & 0xf0u
) << 24u;
819 spl
.i
= (spl
.i
+ cur
[c
] * c1
[c
] + prev
[c
] * c2
[c
] + 0x80) >> 8;
820 CLAMP(spl
.i
, -32768, 32767);
824 *(p_sample
++) = spl
.i
;
827 for (unsigned c
= 0; c
< chans
; c
++)
829 spl
.u
= (p_buffer
[c
] & 0x0fu
) << 28u;
831 spl
.i
= (spl
.i
+ cur
[c
] * c1
[c
] + prev
[c
] * c2
[c
] + 0x80) >> 8;
832 CLAMP(spl
.i
, -32768, 32767);
836 *(p_sample
++) = spl
.i
;