1 /*****************************************************************************
2 * format.c : PCM format converter
3 *****************************************************************************
4 * Copyright (C) 2002-2005 the VideoLAN team
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Gildas Bazin <gbazin@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 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 General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
36 #include <vlc_block.h>
37 #include <vlc_filter.h>
39 /*****************************************************************************
41 *****************************************************************************/
42 static int Open ( vlc_object_t * );
44 static block_t *Float32toS24( filter_t *, block_t * );
45 static block_t *Float32toS16( filter_t *, block_t * );
46 static block_t *Float32toU16( filter_t *, block_t * );
47 static block_t *Float32toS8 ( filter_t *, block_t * );
48 static block_t *Float32toU8 ( filter_t *, block_t * );
50 static block_t *S24toFloat32 ( filter_t *, block_t * );
51 static block_t *S24toS16 ( filter_t *, block_t * );
52 static block_t *S24toS16Invert( filter_t *, block_t * );
54 static block_t *S16toFloat32 ( filter_t *, block_t * );
55 static block_t *S16toS24 ( filter_t *, block_t * );
56 static block_t *S16toS24Invert( filter_t *, block_t * );
57 static block_t *S16toS8 ( filter_t *, block_t * );
58 static block_t *S16toU8 ( filter_t *, block_t * );
59 static block_t *S16toU16 ( filter_t *, block_t * );
61 static block_t *U16toFloat32( filter_t *, block_t * );
62 static block_t *U16toS8 ( filter_t *, block_t * );
63 static block_t *U16toU8 ( filter_t *, block_t * );
64 static block_t *U16toS16 ( filter_t *, block_t * );
66 static block_t *Float32toS24Invert( filter_t *, block_t * );
67 static block_t *Float32toS16Invert( filter_t *, block_t * );
68 static block_t *Float32toU16Invert( filter_t *, block_t * );
70 static block_t *S24InverttoFloat32 ( filter_t *, block_t * );
71 static block_t *S24InverttoS16 ( filter_t *, block_t * );
72 static block_t *S24InverttoS16Invert( filter_t *, block_t * );
74 static block_t *S16InverttoFloat32 ( filter_t *, block_t * );
75 static block_t *S16InverttoS24 ( filter_t *, block_t * );
76 static block_t *S16InverttoS24Invert( filter_t *, block_t * );
77 static block_t *S16InverttoS8 ( filter_t *, block_t * );
78 static block_t *S16InverttoU8 ( filter_t *, block_t * );
79 static block_t *S16InverttoU16 ( filter_t *, block_t * );
81 static block_t *U16InverttoFloat32( filter_t *, block_t * );
82 static block_t *U16InverttoS8 ( filter_t *, block_t * );
83 static block_t *U16InverttoU8 ( filter_t *, block_t * );
84 static block_t *U16InverttoS16 ( filter_t *, block_t * );
86 static block_t *S8toFloat32 ( filter_t *, block_t * );
87 static block_t *S8toS16 ( filter_t *, block_t * );
88 static block_t *S8toU16 ( filter_t *, block_t * );
89 static block_t *S8toU8 ( filter_t *, block_t * );
90 static block_t *S8toS16Invert( filter_t *, block_t * );
91 static block_t *S8toU16Invert( filter_t *, block_t * );
93 static block_t *U8toFloat32 ( filter_t *, block_t * );
94 static block_t *U8toFloat32 ( filter_t *, block_t * );
95 static block_t *U8toS16 ( filter_t *, block_t * );
96 static block_t *U8toU16 ( filter_t *, block_t * );
97 static block_t *U8toS8 ( filter_t *, block_t * );
98 static block_t *U8toS16Invert( filter_t *, block_t * );
99 static block_t *U8toU16Invert( filter_t *, block_t * );
102 static block_t *U8toS8( filter_t *, block_t * );
103 static block_t *S8toU8( filter_t *, block_t * );
106 static block_t *Swap16( filter_t *, block_t * );
107 static block_t *Swap24( filter_t *, block_t * );
113 block_t *(*pf_convert)( filter_t *, block_t *);
117 { VLC_CODEC_FL32, VLC_CODEC_S24N, Float32toS24 },
118 { VLC_CODEC_FL32, VLC_CODEC_S16N, Float32toS16 },
119 { VLC_CODEC_FL32, VLC_CODEC_U16N, Float32toU16 },
120 { VLC_CODEC_FL32, VLC_CODEC_S24I, Float32toS24Invert },
121 { VLC_CODEC_FL32, VLC_CODEC_S16I, Float32toS16Invert },
122 { VLC_CODEC_FL32, VLC_CODEC_U16I, Float32toU16Invert },
123 { VLC_CODEC_FL32, VLC_CODEC_S8, Float32toS8 },
124 { VLC_CODEC_FL32, VLC_CODEC_U8, Float32toU8 },
126 /* From s24 invert */
127 { VLC_CODEC_S24N, VLC_CODEC_FL32, S24toFloat32 },
128 { VLC_CODEC_S24N, VLC_CODEC_S24I, Swap24 },
129 { VLC_CODEC_S24N, VLC_CODEC_S16N, S24toS16 },
130 { VLC_CODEC_S24N, VLC_CODEC_S16I, S24toS16Invert },
133 { VLC_CODEC_S16N, VLC_CODEC_FL32, S16toFloat32 },
134 { VLC_CODEC_S16N, VLC_CODEC_S24N, S16toS24 },
135 { VLC_CODEC_S16N, VLC_CODEC_S24I, S16toS24Invert },
136 { VLC_CODEC_S16N, VLC_CODEC_S16I, Swap16 },
137 { VLC_CODEC_S16N, VLC_CODEC_U16I, S16toU16 },
138 { VLC_CODEC_S16N, VLC_CODEC_S8, S16toS8 },
139 { VLC_CODEC_S16N, VLC_CODEC_U8, S16toU8 },
142 { VLC_CODEC_U16N, VLC_CODEC_FL32, U16toFloat32 },
143 { VLC_CODEC_U16N, VLC_CODEC_U16I, Swap16 },
144 { VLC_CODEC_U16N, VLC_CODEC_S16I, U16toS16 },
145 { VLC_CODEC_U16N, VLC_CODEC_S8, U16toS8 },
146 { VLC_CODEC_U16N, VLC_CODEC_U8, U16toU8 },
149 { VLC_CODEC_S8, VLC_CODEC_FL32, S8toFloat32 },
150 { VLC_CODEC_S8, VLC_CODEC_S16N, S8toS16 },
151 { VLC_CODEC_S8, VLC_CODEC_S16I, S8toS16Invert },
152 { VLC_CODEC_S8, VLC_CODEC_U16N, S8toU16 },
153 { VLC_CODEC_S8, VLC_CODEC_U16I, S8toU16Invert },
154 { VLC_CODEC_S8, VLC_CODEC_U8, S8toU8 },
157 { VLC_CODEC_U8, VLC_CODEC_FL32, U8toFloat32 },
158 { VLC_CODEC_U8, VLC_CODEC_S16N, U8toS16 },
159 { VLC_CODEC_U8, VLC_CODEC_S16I, U8toS16Invert },
160 { VLC_CODEC_U8, VLC_CODEC_U16N, U8toU16 },
161 { VLC_CODEC_U8, VLC_CODEC_U16I, U8toU16Invert },
162 { VLC_CODEC_U8, VLC_CODEC_S8, U8toS8 },
164 /* From s24 invert */
165 { VLC_CODEC_S24I, VLC_CODEC_FL32, S24InverttoFloat32 },
166 { VLC_CODEC_S24I, VLC_CODEC_S24N, Swap24 },
167 { VLC_CODEC_S24I, VLC_CODEC_S16N, S24InverttoS16 },
168 { VLC_CODEC_S24I, VLC_CODEC_S16I, S24InverttoS16Invert },
170 /* From s16 invert */
171 { VLC_CODEC_S16I, VLC_CODEC_FL32, S16InverttoFloat32 },
172 { VLC_CODEC_S16I, VLC_CODEC_S24N, S16InverttoS24 },
173 { VLC_CODEC_S16I, VLC_CODEC_S24I, S16InverttoS24Invert },
174 { VLC_CODEC_S16I, VLC_CODEC_S16N, Swap16 },
175 { VLC_CODEC_S16I, VLC_CODEC_U16N, S16InverttoU16 },
176 { VLC_CODEC_S16I, VLC_CODEC_S8, S16InverttoS8 },
177 { VLC_CODEC_S16I, VLC_CODEC_U8, S16InverttoU8 },
179 /* From u16 invert */
180 { VLC_CODEC_U16I, VLC_CODEC_FL32, U16InverttoFloat32 },
181 { VLC_CODEC_U16I, VLC_CODEC_U16N, Swap16 },
182 { VLC_CODEC_U16I, VLC_CODEC_S16N, U16InverttoS16 },
183 { VLC_CODEC_U16I, VLC_CODEC_S8, U16InverttoS8 },
184 { VLC_CODEC_U16I, VLC_CODEC_U8, U16InverttoU8 },
190 /*****************************************************************************
192 *****************************************************************************/
194 set_description( N_("Audio filter for PCM format conversion") )
195 set_category( CAT_AUDIO )
196 set_subcategory( SUBCAT_AUDIO_MISC )
197 set_capability( "audio filter", 1 )
198 set_callbacks( Open, NULL )
201 /*****************************************************************************
203 *****************************************************************************/
204 static int Open( vlc_object_t *p_this )
206 filter_t *p_filter = (filter_t *)p_this;
209 if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) )
212 for( i = 0; ConvertTable[i].pf_convert != NULL; i++ )
214 if( ConvertTable[i].i_src == p_filter->fmt_in.i_codec &&
215 ConvertTable[i].i_dst == p_filter->fmt_out.i_codec )
218 if( ConvertTable[i].pf_convert == NULL )
221 p_filter->pf_audio_filter = ConvertTable[i].pf_convert;
222 p_filter->fmt_out.audio = p_filter->fmt_in.audio;
223 p_filter->fmt_out.audio.i_format = p_filter->fmt_out.i_codec;
224 p_filter->fmt_out.audio.i_bitspersample =
225 aout_BitsPerSample( p_filter->fmt_out.i_codec );
227 msg_Dbg( p_this, "%4.4s->%4.4s, bits per sample: %i->%i",
228 (char *)&p_filter->fmt_in.i_codec,
229 (char *)&p_filter->fmt_out.i_codec,
230 p_filter->fmt_in.audio.i_bitspersample,
231 p_filter->fmt_out.audio.i_bitspersample );
236 /*****************************************************************************
238 *****************************************************************************/
239 static block_t *Float32toS24( filter_t *p_filter, block_t *p_block )
241 VLC_UNUSED(p_filter);
243 float *p_in = (float *)p_block->p_buffer;
244 uint8_t *p_out = (uint8_t *)p_in;
247 for( i = p_block->i_buffer / 4; i--; )
249 if ( *p_in >= 1.0 ) out = 8388607;
250 else if ( *p_in < -1.0 ) out = -8388608;
251 else out = *p_in * 8388608.0;
253 #ifdef WORDS_BIGENDIAN
254 *((int16_t *)p_out) = out >> 8;
255 p_out[2] = out & 0xFF;
257 *((int16_t *)(p_out+1)) = out >> 8;
258 p_out[0] = out & 0xFF;
264 p_block->i_buffer = p_block->i_buffer * 3 / 4;
268 static block_t *Float32toS16( filter_t *p_filter, block_t *p_block )
270 VLC_UNUSED(p_filter);
272 float *p_in = (float *)p_block->p_buffer;
273 int16_t *p_out = (int16_t *)p_in;
275 for( i = p_block->i_buffer / 4; i--; )
279 if ( *p_in >= 1.0 ) *p_out = 32767;
280 else if ( *p_in < -1.0 ) *p_out = -32768;
281 else *p_out = *p_in * 32768.0;
283 /* This is walken's trick based on IEEE float format. */
284 union { float f; int32_t i; } u;
286 if ( u.i > 0x43c07fff ) *p_out = 32767;
287 else if ( u.i < 0x43bf8000 ) *p_out = -32768;
288 else *p_out = u.i - 0x43c00000;
293 p_block->i_buffer /= 2;
297 static block_t *Float32toU16( filter_t *p_filter, block_t *p_block )
299 VLC_UNUSED(p_filter);
301 float *p_in = (float *)p_block->p_buffer;
302 uint16_t *p_out = (uint16_t *)p_in;
304 for( i = p_block->i_buffer / 4; i--; )
306 if ( *p_in >= 1.0 ) *p_out = 65535;
307 else if ( *p_in < -1.0 ) *p_out = 0;
308 else *p_out = (uint16_t)(32768 + *p_in * 32768);
312 p_block->i_buffer /= 2;
316 static block_t *S24toFloat32( filter_t *p_filter, block_t *p_block )
318 block_t *p_block_out;
324 p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer * 4 / 3 );
327 msg_Warn( p_filter, "can't get output buffer" );
331 p_in = p_block->p_buffer;
332 p_out = (float *)p_block_out->p_buffer;
334 for( i = p_block->i_buffer / 3; i--; )
336 /* FIXME: unaligned reads */
337 #ifdef WORDS_BIGENDIAN
338 *p_out = ((float)( (((int32_t)*(int16_t *)(p_in)) << 8) + p_in[2]))
340 *p_out = ((float)( (((int32_t)*(int16_t *)(p_in+1)) << 8) + p_in[0]))
347 p_block_out->i_nb_samples = p_block->i_nb_samples;
348 p_block_out->i_dts = p_block->i_dts;
349 p_block_out->i_pts = p_block->i_pts;
350 p_block_out->i_length = p_block->i_length;
351 p_block_out->i_rate = p_block->i_rate;
353 block_Release( p_block );
357 static block_t *S24toS16( filter_t *p_filter, block_t *p_block )
359 VLC_UNUSED(p_filter);
361 uint8_t *p_in = (uint8_t *)p_block->p_buffer;
362 uint8_t *p_out = (uint8_t *)p_in;
364 for( i = p_block->i_buffer / 3; i--; )
366 #ifdef WORDS_BIGENDIAN
377 p_block->i_buffer = p_block->i_buffer * 2 / 3;
381 static block_t *S16toFloat32( filter_t *p_filter, block_t *p_block )
383 block_t *p_block_out;
389 p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer*2 );
392 msg_Warn( p_filter, "can't get output buffer" );
396 p_in = (int16_t *)p_block->p_buffer;
397 p_out = (float *)p_block_out->p_buffer;
399 for( i = p_block->i_buffer / 2; i--; )
403 *p_out = (float)*p_in / 32768.0;
405 /* This is walken's trick based on IEEE float format. On my PIII
406 * this takes 16 seconds to perform one billion conversions, instead
407 * of 19 seconds for the above division. */
408 union { float f; int32_t i; } u;
409 u.i = *p_in + 0x43c00000;
410 *p_out = u.f - 384.0;
416 p_block_out->i_nb_samples = p_block->i_nb_samples;
417 p_block_out->i_dts = p_block->i_dts;
418 p_block_out->i_pts = p_block->i_pts;
419 p_block_out->i_length = p_block->i_length;
420 p_block_out->i_rate = p_block->i_rate;
422 block_Release( p_block );
426 static block_t *U16toFloat32( filter_t *p_filter, block_t *p_block )
428 block_t *p_block_out;
434 p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer*2 );
437 msg_Warn( p_filter, "can't get output buffer" );
441 p_in = (uint16_t *)p_block->p_buffer;
442 p_out = (float *)p_block_out->p_buffer;
444 for( i = p_block->i_buffer / 2; i--; )
446 *p_out++ = (float)(*p_in++ - 32768) / 32768.0;
449 p_block_out->i_nb_samples = p_block->i_nb_samples;
450 p_block_out->i_dts = p_block->i_dts;
451 p_block_out->i_pts = p_block->i_pts;
452 p_block_out->i_length = p_block->i_length;
453 p_block_out->i_rate = p_block->i_rate;
455 block_Release( p_block );
459 static block_t *S16toS24( filter_t *p_filter, block_t *p_block )
461 block_t *p_block_out;
462 uint8_t *p_in, *p_out;
466 p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer*3/2 );
469 msg_Warn( p_filter, "can't get output buffer" );
473 p_in = (uint8_t *)p_block->p_buffer;
474 p_out = (uint8_t *)p_block_out->p_buffer;
476 for( i = p_block->i_buffer / 2; i--; )
478 #ifdef WORDS_BIGENDIAN
489 p_block_out->i_nb_samples = p_block->i_nb_samples;
490 p_block_out->i_dts = p_block->i_dts;
491 p_block_out->i_pts = p_block->i_pts;
492 p_block_out->i_length = p_block->i_length;
493 p_block_out->i_rate = p_block->i_rate;
495 block_Release( p_block );
499 static block_t *S16toS8( filter_t *p_filter, block_t *p_block )
501 VLC_UNUSED(p_filter);
503 int16_t *p_in = (int16_t *)p_block->p_buffer;
504 int8_t *p_out = (int8_t *)p_in;
506 for( i = p_block->i_buffer / 2; i--; )
507 *p_out++ = (*p_in++) >> 8;
509 p_block->i_buffer /= 2;
512 static block_t *S16toU8( filter_t *p_filter, block_t *p_block )
514 VLC_UNUSED(p_filter);
516 int16_t *p_in = (int16_t *)p_block->p_buffer;
517 uint8_t *p_out = (uint8_t *)p_in;
519 for( i = p_block->i_buffer / 2; i--; )
520 *p_out++ = ((*p_in++) + 32768) >> 8;
522 p_block->i_buffer /= 2;
525 static block_t *S16toU16( filter_t *p_filter, block_t *p_block )
527 VLC_UNUSED(p_filter);
529 int16_t *p_in = (int16_t *)p_block->p_buffer;
530 uint16_t *p_out = (uint16_t *)p_in;
532 for( i = p_block->i_buffer / 2; i--; )
533 *p_out++ = (*p_in++) + 32768;
538 static block_t *U16toS8( filter_t *p_filter, block_t *p_block )
540 VLC_UNUSED(p_filter);
542 uint16_t *p_in = (uint16_t *)p_block->p_buffer;
543 int8_t *p_out = (int8_t *)p_in;
545 for( i = p_block->i_buffer / 2; i--; )
546 *p_out++ = ((int)(*p_in++) - 32768) >> 8;
548 p_block->i_buffer /= 2;
551 static block_t *U16toU8( filter_t *p_filter, block_t *p_block )
553 VLC_UNUSED(p_filter);
555 uint16_t *p_in = (uint16_t *)p_block->p_buffer;
556 uint8_t *p_out = (uint8_t *)p_in;
558 for( i = p_block->i_buffer / 2; i--; )
559 *p_out++ = (*p_in++) >> 8;
561 p_block->i_buffer /= 2;
564 static block_t *U16toS16( filter_t *p_filter, block_t *p_block )
566 VLC_UNUSED(p_filter);
568 uint16_t *p_in = (uint16_t *)p_block->p_buffer;
569 int16_t *p_out = (int16_t *)p_in;
571 for( i = p_block->i_buffer / 2; i--; )
572 *p_out++ = (int)(*p_in++) - 32768;
577 static block_t *S8toU8( filter_t *p_filter, block_t *p_block )
579 VLC_UNUSED(p_filter);
581 int8_t *p_in = (int8_t *)p_block->p_buffer;
582 uint8_t *p_out = (uint8_t *)p_in;
584 for( i = p_block->i_buffer; i--; )
585 *p_out++ = ((*p_in++) + 128);
589 static block_t *U8toS8( filter_t *p_filter, block_t *p_block )
591 VLC_UNUSED(p_filter);
593 uint8_t *p_in = (uint8_t *)p_block->p_buffer;
594 int8_t *p_out = (int8_t *)p_in;
596 for( i = p_block->i_buffer; i--; )
597 *p_out++ = ((*p_in++) - 128);
603 static block_t *S8toU16( filter_t *p_filter, block_t *p_block )
605 block_t *p_block_out;
611 p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer*2 );
614 msg_Warn( p_filter, "can't get output buffer" );
618 p_in = (int8_t *)p_block->p_buffer;
619 p_out = (uint16_t *)p_block_out->p_buffer;
621 for( i = p_block->i_buffer; i--; )
622 *p_out++ = ((*p_in++) + 128) << 8;
624 p_block_out->i_nb_samples = p_block->i_nb_samples;
625 p_block_out->i_dts = p_block->i_dts;
626 p_block_out->i_pts = p_block->i_pts;
627 p_block_out->i_length = p_block->i_length;
628 p_block_out->i_rate = p_block->i_rate;
630 block_Release( p_block );
634 static block_t *U8toS16( filter_t *p_filter, block_t *p_block )
636 block_t *p_block_out;
642 p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer*2 );
645 msg_Warn( p_filter, "can't get output buffer" );
649 p_in = (uint8_t *)p_block->p_buffer;
650 p_out = (int16_t *)p_block_out->p_buffer;
652 for( i = p_block->i_buffer; i--; )
653 *p_out++ = ((*p_in++) - 128) << 8;
655 p_block_out->i_nb_samples = p_block->i_nb_samples;
656 p_block_out->i_dts = p_block->i_dts;
657 p_block_out->i_pts = p_block->i_pts;
658 p_block_out->i_length = p_block->i_length;
659 p_block_out->i_rate = p_block->i_rate;
661 block_Release( p_block );
666 static block_t *S8toS16( filter_t *p_filter, block_t *p_block )
668 block_t *p_block_out;
674 p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer*2 );
677 msg_Warn( p_filter, "can't get output buffer" );
681 p_in = (int8_t *)p_block->p_buffer;
682 p_out = (int16_t *)p_block_out->p_buffer;
684 for( i = p_block->i_buffer; i--; )
685 *p_out++ = (*p_in++) << 8;
687 p_block_out->i_nb_samples = p_block->i_nb_samples;
688 p_block_out->i_dts = p_block->i_dts;
689 p_block_out->i_pts = p_block->i_pts;
690 p_block_out->i_length = p_block->i_length;
691 p_block_out->i_rate = p_block->i_rate;
693 block_Release( p_block );
697 static block_t *U8toU16( filter_t *p_filter, block_t *p_block )
699 block_t *p_block_out;
705 p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer*2 );
708 msg_Warn( p_filter, "can't get output buffer" );
712 p_in = (uint8_t *)p_block->p_buffer;
713 p_out = (uint16_t *)p_block_out->p_buffer;
715 for( i = p_block->i_buffer; i--; )
716 *p_out++ = (*p_in++) << 8;
718 p_block_out->i_nb_samples = p_block->i_nb_samples;
719 p_block_out->i_dts = p_block->i_dts;
720 p_block_out->i_pts = p_block->i_pts;
721 p_block_out->i_length = p_block->i_length;
722 p_block_out->i_rate = p_block->i_rate;
724 block_Release( p_block );
728 /*****************************************************************************
729 * Swap a buffer of words
730 *****************************************************************************/
731 static block_t *Swap16( filter_t *p_filter, block_t *p_block )
733 VLC_UNUSED(p_filter);
735 uint8_t *p_in = (uint8_t *)p_block->p_buffer;
738 for( i = 0; i < p_block->i_buffer / 2; i++ )
749 static block_t *Swap24( filter_t *p_filter, block_t *p_block )
751 VLC_UNUSED(p_filter);
753 uint8_t *p_in = (uint8_t *)p_block->p_buffer;
756 for( i = 0; i < p_block->i_buffer / 3; i++ )
767 #define CONVERT_NN( func, f_in, f_out, b_pre_invert, b_post_invert, swapa, swapb ) \
768 static block_t *func( filter_t *p_filter, block_t *p_block ) \
771 swapa( p_filter, p_block ); \
773 p_block = f_in##to##f_out( p_filter, p_block ); \
775 if( b_post_invert ) \
776 swapb( p_filter, p_block ); \
781 CONVERT_NN( Float32toS24Invert, Float32, S24, 0, 1, Swap24, Swap24 )
782 CONVERT_NN( Float32toS16Invert, Float32, S16, 0, 1, Swap16, Swap16 )
783 CONVERT_NN( Float32toU16Invert, Float32, U16, 0, 1, Swap16, Swap16 )
785 CONVERT_NN( S24InverttoFloat32, S24, Float32, 1, 0, Swap24, Swap24 )
786 CONVERT_NN( S24InverttoS16, S24, S16, 1, 0, Swap24, Swap16 )
787 CONVERT_NN( S24InverttoS16Invert, S24, S16, 1, 1, Swap24, Swap16 )
788 CONVERT_NN( S24toS16Invert, S24, S16, 0, 1, Swap24, Swap16 )
790 CONVERT_NN( S16InverttoFloat32, S16, Float32, 1, 0, Swap16, Swap16 )
791 CONVERT_NN( S16InverttoS24, S16, S24, 1, 0, Swap16, Swap24 )
792 CONVERT_NN( S16toS24Invert, S16, S24, 0, 1, Swap16, Swap24 )
793 CONVERT_NN( S16InverttoS24Invert, S16, S24, 1, 1, Swap16, Swap24 )
794 CONVERT_NN( S16InverttoS8, S16, S8, 1, 0, Swap16, Swap16 )
795 CONVERT_NN( S16InverttoU8, S16, U8, 1, 0, Swap16, Swap16 )
796 CONVERT_NN( S16InverttoU16, S16, U16, 1, 0, Swap16, Swap16 )
798 CONVERT_NN( U16InverttoFloat32, U16, Float32, 1, 0, Swap16, Swap16 )
799 CONVERT_NN( U16InverttoS8, U16, S8, 1, 0, Swap16, Swap16 )
800 CONVERT_NN( U16InverttoU8, U16, U8, 1, 0, Swap16, Swap16 )
801 CONVERT_NN( U16InverttoS16, U16, S16, 1, 0, Swap16, Swap16 )
805 #define CONVERT_INDIRECT( func, f_in, f_mid, f_out ) \
806 static block_t *func( filter_t *p_filter, block_t *p_block ) \
808 return f_mid##to##f_out( p_filter, \
809 f_in##to##f_mid( p_filter, p_block ) ); \
812 CONVERT_INDIRECT( Float32toS8, Float32, S16, U8 )
813 CONVERT_INDIRECT( Float32toU8, Float32, U16, U8 )
814 CONVERT_INDIRECT( S8toFloat32, S8, S16, Float32 )
815 CONVERT_INDIRECT( U8toFloat32, U8, U16, Float32 )
817 #define S16toS16Invert Swap16
818 #define U16toU16Invert Swap16
820 CONVERT_INDIRECT( U8toS16Invert, U8, S16, S16Invert )
821 CONVERT_INDIRECT( S8toU16Invert, S8, U16, U16Invert )
823 CONVERT_INDIRECT( U8toU16Invert, U8, U16, U16Invert )
824 CONVERT_INDIRECT( S8toS16Invert, S8, S16, S16Invert )
826 #undef CONVERT_INDIRECT