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;
323 p_block_out = filter_NewAudioBuffer( p_filter, p_block->i_buffer * 4 / 3 );
326 msg_Warn( p_filter, "can't get output buffer" );
330 p_in = p_block->p_buffer;
331 p_out = (float *)p_block_out->p_buffer;
333 for( i = p_block->i_buffer / 3; i--; )
335 /* FIXME: unaligned reads */
336 #ifdef WORDS_BIGENDIAN
337 *p_out = ((float)( (((int32_t)*(int16_t *)(p_in)) << 8) + p_in[2]))
339 *p_out = ((float)( (((int32_t)*(int16_t *)(p_in+1)) << 8) + p_in[0]))
346 p_block_out->i_nb_samples = p_block->i_nb_samples;
347 p_block_out->i_dts = p_block->i_dts;
348 p_block_out->i_pts = p_block->i_pts;
349 p_block_out->i_length = p_block->i_length;
350 p_block_out->i_rate = p_block->i_rate;
352 block_Release( p_block );
356 static block_t *S24toS16( filter_t *p_filter, block_t *p_block )
358 VLC_UNUSED(p_filter);
360 uint8_t *p_in = (uint8_t *)p_block->p_buffer;
361 uint8_t *p_out = (uint8_t *)p_in;
363 for( i = p_block->i_buffer / 3; i--; )
365 #ifdef WORDS_BIGENDIAN
376 p_block->i_buffer = p_block->i_buffer * 2 / 3;
380 static block_t *S16toFloat32( filter_t *p_filter, block_t *p_block )
382 block_t *p_block_out;
387 p_block_out = filter_NewAudioBuffer( p_filter, p_block->i_buffer*2 );
390 msg_Warn( p_filter, "can't get output buffer" );
394 p_in = (int16_t *)p_block->p_buffer;
395 p_out = (float *)p_block_out->p_buffer;
397 for( i = p_block->i_buffer / 2; i--; )
401 *p_out = (float)*p_in / 32768.0;
403 /* This is walken's trick based on IEEE float format. On my PIII
404 * this takes 16 seconds to perform one billion conversions, instead
405 * of 19 seconds for the above division. */
406 union { float f; int32_t i; } u;
407 u.i = *p_in + 0x43c00000;
408 *p_out = u.f - 384.0;
414 p_block_out->i_nb_samples = p_block->i_nb_samples;
415 p_block_out->i_dts = p_block->i_dts;
416 p_block_out->i_pts = p_block->i_pts;
417 p_block_out->i_length = p_block->i_length;
418 p_block_out->i_rate = p_block->i_rate;
420 block_Release( p_block );
424 static block_t *U16toFloat32( filter_t *p_filter, block_t *p_block )
426 block_t *p_block_out;
431 p_block_out = filter_NewAudioBuffer( p_filter, p_block->i_buffer*2 );
434 msg_Warn( p_filter, "can't get output buffer" );
438 p_in = (uint16_t *)p_block->p_buffer;
439 p_out = (float *)p_block_out->p_buffer;
441 for( i = p_block->i_buffer / 2; i--; )
443 *p_out++ = (float)(*p_in++ - 32768) / 32768.0;
446 p_block_out->i_nb_samples = p_block->i_nb_samples;
447 p_block_out->i_dts = p_block->i_dts;
448 p_block_out->i_pts = p_block->i_pts;
449 p_block_out->i_length = p_block->i_length;
450 p_block_out->i_rate = p_block->i_rate;
452 block_Release( p_block );
456 static block_t *S16toS24( filter_t *p_filter, block_t *p_block )
458 block_t *p_block_out;
459 uint8_t *p_in, *p_out;
462 p_block_out = filter_NewAudioBuffer( p_filter, p_block->i_buffer*3/2 );
465 msg_Warn( p_filter, "can't get output buffer" );
469 p_in = (uint8_t *)p_block->p_buffer;
470 p_out = (uint8_t *)p_block_out->p_buffer;
472 for( i = p_block->i_buffer / 2; i--; )
474 #ifdef WORDS_BIGENDIAN
485 p_block_out->i_nb_samples = p_block->i_nb_samples;
486 p_block_out->i_dts = p_block->i_dts;
487 p_block_out->i_pts = p_block->i_pts;
488 p_block_out->i_length = p_block->i_length;
489 p_block_out->i_rate = p_block->i_rate;
491 block_Release( p_block );
495 static block_t *S16toS8( filter_t *p_filter, block_t *p_block )
497 VLC_UNUSED(p_filter);
499 int16_t *p_in = (int16_t *)p_block->p_buffer;
500 int8_t *p_out = (int8_t *)p_in;
502 for( i = p_block->i_buffer / 2; i--; )
503 *p_out++ = (*p_in++) >> 8;
505 p_block->i_buffer /= 2;
508 static block_t *S16toU8( filter_t *p_filter, block_t *p_block )
510 VLC_UNUSED(p_filter);
512 int16_t *p_in = (int16_t *)p_block->p_buffer;
513 uint8_t *p_out = (uint8_t *)p_in;
515 for( i = p_block->i_buffer / 2; i--; )
516 *p_out++ = ((*p_in++) + 32768) >> 8;
518 p_block->i_buffer /= 2;
521 static block_t *S16toU16( filter_t *p_filter, block_t *p_block )
523 VLC_UNUSED(p_filter);
525 int16_t *p_in = (int16_t *)p_block->p_buffer;
526 uint16_t *p_out = (uint16_t *)p_in;
528 for( i = p_block->i_buffer / 2; i--; )
529 *p_out++ = (*p_in++) + 32768;
534 static block_t *U16toS8( filter_t *p_filter, block_t *p_block )
536 VLC_UNUSED(p_filter);
538 uint16_t *p_in = (uint16_t *)p_block->p_buffer;
539 int8_t *p_out = (int8_t *)p_in;
541 for( i = p_block->i_buffer / 2; i--; )
542 *p_out++ = ((int)(*p_in++) - 32768) >> 8;
544 p_block->i_buffer /= 2;
547 static block_t *U16toU8( filter_t *p_filter, block_t *p_block )
549 VLC_UNUSED(p_filter);
551 uint16_t *p_in = (uint16_t *)p_block->p_buffer;
552 uint8_t *p_out = (uint8_t *)p_in;
554 for( i = p_block->i_buffer / 2; i--; )
555 *p_out++ = (*p_in++) >> 8;
557 p_block->i_buffer /= 2;
560 static block_t *U16toS16( filter_t *p_filter, block_t *p_block )
562 VLC_UNUSED(p_filter);
564 uint16_t *p_in = (uint16_t *)p_block->p_buffer;
565 int16_t *p_out = (int16_t *)p_in;
567 for( i = p_block->i_buffer / 2; i--; )
568 *p_out++ = (int)(*p_in++) - 32768;
573 static block_t *S8toU8( filter_t *p_filter, block_t *p_block )
575 VLC_UNUSED(p_filter);
577 int8_t *p_in = (int8_t *)p_block->p_buffer;
578 uint8_t *p_out = (uint8_t *)p_in;
580 for( i = p_block->i_buffer; i--; )
581 *p_out++ = ((*p_in++) + 128);
585 static block_t *U8toS8( filter_t *p_filter, block_t *p_block )
587 VLC_UNUSED(p_filter);
589 uint8_t *p_in = (uint8_t *)p_block->p_buffer;
590 int8_t *p_out = (int8_t *)p_in;
592 for( i = p_block->i_buffer; i--; )
593 *p_out++ = ((*p_in++) - 128);
599 static block_t *S8toU16( filter_t *p_filter, block_t *p_block )
601 block_t *p_block_out;
607 filter_NewAudioBuffer( p_filter, p_block->i_buffer*2 );
610 msg_Warn( p_filter, "can't get output buffer" );
614 p_in = (int8_t *)p_block->p_buffer;
615 p_out = (uint16_t *)p_block_out->p_buffer;
617 for( i = p_block->i_buffer; i--; )
618 *p_out++ = ((*p_in++) + 128) << 8;
620 p_block_out->i_nb_samples = p_block->i_nb_samples;
621 p_block_out->i_dts = p_block->i_dts;
622 p_block_out->i_pts = p_block->i_pts;
623 p_block_out->i_length = p_block->i_length;
624 p_block_out->i_rate = p_block->i_rate;
626 block_Release( p_block );
630 static block_t *U8toS16( filter_t *p_filter, block_t *p_block )
632 block_t *p_block_out;
637 p_block_out = filter_NewAudioBuffer( p_filter, p_block->i_buffer*2 );
640 msg_Warn( p_filter, "can't get output buffer" );
644 p_in = (uint8_t *)p_block->p_buffer;
645 p_out = (int16_t *)p_block_out->p_buffer;
647 for( i = p_block->i_buffer; i--; )
648 *p_out++ = ((*p_in++) - 128) << 8;
650 p_block_out->i_nb_samples = p_block->i_nb_samples;
651 p_block_out->i_dts = p_block->i_dts;
652 p_block_out->i_pts = p_block->i_pts;
653 p_block_out->i_length = p_block->i_length;
654 p_block_out->i_rate = p_block->i_rate;
656 block_Release( p_block );
661 static block_t *S8toS16( filter_t *p_filter, block_t *p_block )
663 block_t *p_block_out;
668 p_block_out = filter_NewAudioBuffer( p_filter, p_block->i_buffer*2 );
671 msg_Warn( p_filter, "can't get output buffer" );
675 p_in = (int8_t *)p_block->p_buffer;
676 p_out = (int16_t *)p_block_out->p_buffer;
678 for( i = p_block->i_buffer; i--; )
679 *p_out++ = (*p_in++) << 8;
681 p_block_out->i_nb_samples = p_block->i_nb_samples;
682 p_block_out->i_dts = p_block->i_dts;
683 p_block_out->i_pts = p_block->i_pts;
684 p_block_out->i_length = p_block->i_length;
685 p_block_out->i_rate = p_block->i_rate;
687 block_Release( p_block );
691 static block_t *U8toU16( filter_t *p_filter, block_t *p_block )
693 block_t *p_block_out;
698 p_block_out = filter_NewAudioBuffer( p_filter, p_block->i_buffer*2 );
701 msg_Warn( p_filter, "can't get output buffer" );
705 p_in = (uint8_t *)p_block->p_buffer;
706 p_out = (uint16_t *)p_block_out->p_buffer;
708 for( i = p_block->i_buffer; i--; )
709 *p_out++ = (*p_in++) << 8;
711 p_block_out->i_nb_samples = p_block->i_nb_samples;
712 p_block_out->i_dts = p_block->i_dts;
713 p_block_out->i_pts = p_block->i_pts;
714 p_block_out->i_length = p_block->i_length;
715 p_block_out->i_rate = p_block->i_rate;
717 block_Release( p_block );
721 /*****************************************************************************
722 * Swap a buffer of words
723 *****************************************************************************/
724 static block_t *Swap16( filter_t *p_filter, block_t *p_block )
726 VLC_UNUSED(p_filter);
728 uint8_t *p_in = (uint8_t *)p_block->p_buffer;
731 for( i = 0; i < p_block->i_buffer / 2; i++ )
742 static block_t *Swap24( filter_t *p_filter, block_t *p_block )
744 VLC_UNUSED(p_filter);
746 uint8_t *p_in = (uint8_t *)p_block->p_buffer;
749 for( i = 0; i < p_block->i_buffer / 3; i++ )
760 #define CONVERT_NN( func, f_in, f_out, b_pre_invert, b_post_invert, swapa, swapb ) \
761 static block_t *func( filter_t *p_filter, block_t *p_block ) \
764 swapa( p_filter, p_block ); \
766 p_block = f_in##to##f_out( p_filter, p_block ); \
768 if( b_post_invert ) \
769 swapb( p_filter, p_block ); \
774 CONVERT_NN( Float32toS24Invert, Float32, S24, 0, 1, Swap24, Swap24 )
775 CONVERT_NN( Float32toS16Invert, Float32, S16, 0, 1, Swap16, Swap16 )
776 CONVERT_NN( Float32toU16Invert, Float32, U16, 0, 1, Swap16, Swap16 )
778 CONVERT_NN( S24InverttoFloat32, S24, Float32, 1, 0, Swap24, Swap24 )
779 CONVERT_NN( S24InverttoS16, S24, S16, 1, 0, Swap24, Swap16 )
780 CONVERT_NN( S24InverttoS16Invert, S24, S16, 1, 1, Swap24, Swap16 )
781 CONVERT_NN( S24toS16Invert, S24, S16, 0, 1, Swap24, Swap16 )
783 CONVERT_NN( S16InverttoFloat32, S16, Float32, 1, 0, Swap16, Swap16 )
784 CONVERT_NN( S16InverttoS24, S16, S24, 1, 0, Swap16, Swap24 )
785 CONVERT_NN( S16toS24Invert, S16, S24, 0, 1, Swap16, Swap24 )
786 CONVERT_NN( S16InverttoS24Invert, S16, S24, 1, 1, Swap16, Swap24 )
787 CONVERT_NN( S16InverttoS8, S16, S8, 1, 0, Swap16, Swap16 )
788 CONVERT_NN( S16InverttoU8, S16, U8, 1, 0, Swap16, Swap16 )
789 CONVERT_NN( S16InverttoU16, S16, U16, 1, 0, Swap16, Swap16 )
791 CONVERT_NN( U16InverttoFloat32, U16, Float32, 1, 0, Swap16, Swap16 )
792 CONVERT_NN( U16InverttoS8, U16, S8, 1, 0, Swap16, Swap16 )
793 CONVERT_NN( U16InverttoU8, U16, U8, 1, 0, Swap16, Swap16 )
794 CONVERT_NN( U16InverttoS16, U16, S16, 1, 0, Swap16, Swap16 )
798 #define CONVERT_INDIRECT( func, f_in, f_mid, f_out ) \
799 static block_t *func( filter_t *p_filter, block_t *p_block ) \
801 return f_mid##to##f_out( p_filter, \
802 f_in##to##f_mid( p_filter, p_block ) ); \
805 CONVERT_INDIRECT( Float32toS8, Float32, S16, U8 )
806 CONVERT_INDIRECT( Float32toU8, Float32, U16, U8 )
807 CONVERT_INDIRECT( S8toFloat32, S8, S16, Float32 )
808 CONVERT_INDIRECT( U8toFloat32, U8, U16, Float32 )
810 #define S16toS16Invert Swap16
811 #define U16toU16Invert Swap16
813 CONVERT_INDIRECT( U8toS16Invert, U8, S16, S16Invert )
814 CONVERT_INDIRECT( S8toU16Invert, S8, U16, U16Invert )
816 CONVERT_INDIRECT( U8toU16Invert, U8, U16, U16Invert )
817 CONVERT_INDIRECT( S8toS16Invert, S8, S16, S16Invert )
819 #undef CONVERT_INDIRECT