gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

pa_converters.c (69116B)


      1 /*
      2  * $Id$
      3  * Portable Audio I/O Library sample conversion mechanism
      4  *
      5  * Based on the Open Source API proposed by Ross Bencina
      6  * Copyright (c) 1999-2002 Phil Burk, Ross Bencina
      7  *
      8  * Permission is hereby granted, free of charge, to any person obtaining
      9  * a copy of this software and associated documentation files
     10  * (the "Software"), to deal in the Software without restriction,
     11  * including without limitation the rights to use, copy, modify, merge,
     12  * publish, distribute, sublicense, and/or sell copies of the Software,
     13  * and to permit persons to whom the Software is furnished to do so,
     14  * subject to the following conditions:
     15  *
     16  * The above copyright notice and this permission notice shall be
     17  * included in all copies or substantial portions of the Software.
     18  *
     19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     22  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
     23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
     24  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     26  */
     27 
     28 /*
     29  * The text above constitutes the entire PortAudio license; however, 
     30  * the PortAudio community also makes the following non-binding requests:
     31  *
     32  * Any person wishing to distribute modifications to the Software is
     33  * requested to send the modifications to the original developer so that
     34  * they can be incorporated into the canonical version. It is also 
     35  * requested that these non-binding requests be included along with the 
     36  * license above.
     37  */
     38 
     39 /** @file
     40  @ingroup common_src
     41 
     42  @brief Conversion function implementations.
     43  
     44  If the C9x function lrintf() is available, define PA_USE_C99_LRINTF to use it
     45 
     46  @todo Consider whether functions which dither but don't clip should exist,
     47  V18 automatically enabled clipping whenever dithering was selected. Perhaps
     48  we should do the same. 
     49     see: "require clipping for dithering sample conversion functions?"
     50     http://www.portaudio.com/trac/ticket/112
     51 
     52  @todo implement the converters marked IMPLEMENT ME: Int32_To_Int24_Dither,
     53  Int32_To_UInt8_Dither, Int24_To_Int16_Dither, Int24_To_Int8_Dither, 
     54  Int24_To_UInt8_Dither, Int16_To_Int8_Dither, Int16_To_UInt8_Dither
     55     see: "some conversion functions are not implemented in pa_converters.c"
     56     http://www.portaudio.com/trac/ticket/35
     57 
     58  @todo review the converters marked REVIEW: Float32_To_Int32,
     59  Float32_To_Int32_Dither, Float32_To_Int32_Clip, Float32_To_Int32_DitherClip,
     60  Int32_To_Int16_Dither, Int32_To_Int8_Dither, Int16_To_Int32
     61 */
     62 
     63 
     64 #include "pa_converters.h"
     65 #include "pa_dither.h"
     66 #include "pa_endianness.h"
     67 #include "pa_types.h"
     68 
     69 
     70 PaSampleFormat PaUtil_SelectClosestAvailableFormat(
     71         PaSampleFormat availableFormats, PaSampleFormat format )
     72 {
     73     PaSampleFormat result;
     74 
     75     format &= ~paNonInterleaved;
     76     availableFormats &= ~paNonInterleaved;
     77     
     78     if( (format & availableFormats) == 0 )
     79     {
     80         /* NOTE: this code depends on the sample format constants being in
     81             descending order of quality - ie best quality is 0
     82             FIXME: should write an assert which checks that all of the
     83             known constants conform to that requirement.
     84         */
     85 
     86         if( format != 0x01 )
     87         {
     88             /* scan for better formats */
     89             result = format;
     90             do
     91             {
     92                 result >>= 1;
     93             }
     94             while( (result & availableFormats) == 0 && result != 0 );
     95         }
     96         else
     97         {
     98             result = 0;
     99         }
    100         
    101         if( result == 0 ){
    102             /* scan for worse formats */
    103             result = format;
    104             do
    105             {
    106                 result <<= 1;
    107             }
    108             while( (result & availableFormats) == 0 && result != paCustomFormat );
    109 
    110             if( (result & availableFormats) == 0 )
    111                 result = paSampleFormatNotSupported;
    112         }
    113         
    114     }else{
    115         result = format;
    116     }
    117 
    118     return result;
    119 }
    120 
    121 /* -------------------------------------------------------------------------- */
    122 
    123 #define PA_SELECT_FORMAT_( format, float32, int32, int24, int16, int8, uint8 ) \
    124     switch( format & ~paNonInterleaved ){                                      \
    125     case paFloat32:                                                            \
    126         float32                                                                \
    127     case paInt32:                                                              \
    128         int32                                                                  \
    129     case paInt24:                                                              \
    130         int24                                                                  \
    131     case paInt16:                                                              \
    132         int16                                                                  \
    133     case paInt8:                                                               \
    134         int8                                                                   \
    135     case paUInt8:                                                              \
    136         uint8                                                                  \
    137     default: return 0;                                                         \
    138     }
    139 
    140 /* -------------------------------------------------------------------------- */
    141 
    142 #define PA_SELECT_CONVERTER_DITHER_CLIP_( flags, source, destination )         \
    143     if( flags & paClipOff ){ /* no clip */                                     \
    144         if( flags & paDitherOff ){ /* no dither */                             \
    145             return paConverters. source ## _To_ ## destination;                \
    146         }else{ /* dither */                                                    \
    147             return paConverters. source ## _To_ ## destination ## _Dither;     \
    148         }                                                                      \
    149     }else{ /* clip */                                                          \
    150         if( flags & paDitherOff ){ /* no dither */                             \
    151             return paConverters. source ## _To_ ## destination ## _Clip;       \
    152         }else{ /* dither */                                                    \
    153             return paConverters. source ## _To_ ## destination ## _DitherClip; \
    154         }                                                                      \
    155     }
    156 
    157 /* -------------------------------------------------------------------------- */
    158 
    159 #define PA_SELECT_CONVERTER_DITHER_( flags, source, destination )              \
    160     if( flags & paDitherOff ){ /* no dither */                                 \
    161         return paConverters. source ## _To_ ## destination;                    \
    162     }else{ /* dither */                                                        \
    163         return paConverters. source ## _To_ ## destination ## _Dither;         \
    164     }
    165 
    166 /* -------------------------------------------------------------------------- */
    167 
    168 #define PA_USE_CONVERTER_( source, destination )\
    169     return paConverters. source ## _To_ ## destination;
    170 
    171 /* -------------------------------------------------------------------------- */
    172 
    173 #define PA_UNITY_CONVERSION_( wordlength )\
    174     return paConverters. Copy_ ## wordlength ## _To_ ## wordlength;
    175 
    176 /* -------------------------------------------------------------------------- */
    177 
    178 PaUtilConverter* PaUtil_SelectConverter( PaSampleFormat sourceFormat,
    179         PaSampleFormat destinationFormat, PaStreamFlags flags )
    180 {
    181     PA_SELECT_FORMAT_( sourceFormat,
    182                        /* paFloat32: */
    183                        PA_SELECT_FORMAT_( destinationFormat,
    184                                           /* paFloat32: */        PA_UNITY_CONVERSION_( 32 ),
    185                                           /* paInt32: */          PA_SELECT_CONVERTER_DITHER_CLIP_( flags, Float32, Int32 ),
    186                                           /* paInt24: */          PA_SELECT_CONVERTER_DITHER_CLIP_( flags, Float32, Int24 ),
    187                                           /* paInt16: */          PA_SELECT_CONVERTER_DITHER_CLIP_( flags, Float32, Int16 ),
    188                                           /* paInt8: */           PA_SELECT_CONVERTER_DITHER_CLIP_( flags, Float32, Int8 ),
    189                                           /* paUInt8: */          PA_SELECT_CONVERTER_DITHER_CLIP_( flags, Float32, UInt8 )
    190                                         ),
    191                        /* paInt32: */
    192                        PA_SELECT_FORMAT_( destinationFormat,
    193                                           /* paFloat32: */        PA_USE_CONVERTER_( Int32, Float32 ),
    194                                           /* paInt32: */          PA_UNITY_CONVERSION_( 32 ),
    195                                           /* paInt24: */          PA_SELECT_CONVERTER_DITHER_( flags, Int32, Int24 ),
    196                                           /* paInt16: */          PA_SELECT_CONVERTER_DITHER_( flags, Int32, Int16 ),
    197                                           /* paInt8: */           PA_SELECT_CONVERTER_DITHER_( flags, Int32, Int8 ),
    198                                           /* paUInt8: */          PA_SELECT_CONVERTER_DITHER_( flags, Int32, UInt8 )
    199                                         ),
    200                        /* paInt24: */
    201                        PA_SELECT_FORMAT_( destinationFormat,
    202                                           /* paFloat32: */        PA_USE_CONVERTER_( Int24, Float32 ),
    203                                           /* paInt32: */          PA_USE_CONVERTER_( Int24, Int32 ),
    204                                           /* paInt24: */          PA_UNITY_CONVERSION_( 24 ),
    205                                           /* paInt16: */          PA_SELECT_CONVERTER_DITHER_( flags, Int24, Int16 ),
    206                                           /* paInt8: */           PA_SELECT_CONVERTER_DITHER_( flags, Int24, Int8 ),
    207                                           /* paUInt8: */          PA_SELECT_CONVERTER_DITHER_( flags, Int24, UInt8 )
    208                                         ),
    209                        /* paInt16: */
    210                        PA_SELECT_FORMAT_( destinationFormat,
    211                                           /* paFloat32: */        PA_USE_CONVERTER_( Int16, Float32 ),
    212                                           /* paInt32: */          PA_USE_CONVERTER_( Int16, Int32 ),
    213                                           /* paInt24: */          PA_USE_CONVERTER_( Int16, Int24 ),
    214                                           /* paInt16: */          PA_UNITY_CONVERSION_( 16 ),
    215                                           /* paInt8: */           PA_SELECT_CONVERTER_DITHER_( flags, Int16, Int8 ),
    216                                           /* paUInt8: */          PA_SELECT_CONVERTER_DITHER_( flags, Int16, UInt8 )
    217                                         ),
    218                        /* paInt8: */
    219                        PA_SELECT_FORMAT_( destinationFormat,
    220                                           /* paFloat32: */        PA_USE_CONVERTER_( Int8, Float32 ),
    221                                           /* paInt32: */          PA_USE_CONVERTER_( Int8, Int32 ),
    222                                           /* paInt24: */          PA_USE_CONVERTER_( Int8, Int24 ),
    223                                           /* paInt16: */          PA_USE_CONVERTER_( Int8, Int16 ),
    224                                           /* paInt8: */           PA_UNITY_CONVERSION_( 8 ),
    225                                           /* paUInt8: */          PA_USE_CONVERTER_( Int8, UInt8 )
    226                                         ),
    227                        /* paUInt8: */
    228                        PA_SELECT_FORMAT_( destinationFormat,
    229                                           /* paFloat32: */        PA_USE_CONVERTER_( UInt8, Float32 ),
    230                                           /* paInt32: */          PA_USE_CONVERTER_( UInt8, Int32 ),
    231                                           /* paInt24: */          PA_USE_CONVERTER_( UInt8, Int24 ),
    232                                           /* paInt16: */          PA_USE_CONVERTER_( UInt8, Int16 ),
    233                                           /* paInt8: */           PA_USE_CONVERTER_( UInt8, Int8 ),
    234                                           /* paUInt8: */          PA_UNITY_CONVERSION_( 8 )
    235                                         )
    236                      )
    237 }
    238 
    239 /* -------------------------------------------------------------------------- */
    240 
    241 #ifdef PA_NO_STANDARD_CONVERTERS
    242 
    243 /* -------------------------------------------------------------------------- */
    244 
    245 PaUtilConverterTable paConverters = {
    246     0, /* PaUtilConverter *Float32_To_Int32; */
    247     0, /* PaUtilConverter *Float32_To_Int32_Dither; */
    248     0, /* PaUtilConverter *Float32_To_Int32_Clip; */
    249     0, /* PaUtilConverter *Float32_To_Int32_DitherClip; */
    250 
    251     0, /* PaUtilConverter *Float32_To_Int24; */
    252     0, /* PaUtilConverter *Float32_To_Int24_Dither; */
    253     0, /* PaUtilConverter *Float32_To_Int24_Clip; */
    254     0, /* PaUtilConverter *Float32_To_Int24_DitherClip; */
    255 
    256     0, /* PaUtilConverter *Float32_To_Int16; */
    257     0, /* PaUtilConverter *Float32_To_Int16_Dither; */
    258     0, /* PaUtilConverter *Float32_To_Int16_Clip; */
    259     0, /* PaUtilConverter *Float32_To_Int16_DitherClip; */
    260 
    261     0, /* PaUtilConverter *Float32_To_Int8; */
    262     0, /* PaUtilConverter *Float32_To_Int8_Dither; */
    263     0, /* PaUtilConverter *Float32_To_Int8_Clip; */
    264     0, /* PaUtilConverter *Float32_To_Int8_DitherClip; */
    265 
    266     0, /* PaUtilConverter *Float32_To_UInt8; */
    267     0, /* PaUtilConverter *Float32_To_UInt8_Dither; */
    268     0, /* PaUtilConverter *Float32_To_UInt8_Clip; */
    269     0, /* PaUtilConverter *Float32_To_UInt8_DitherClip; */
    270 
    271     0, /* PaUtilConverter *Int32_To_Float32; */
    272     0, /* PaUtilConverter *Int32_To_Int24; */
    273     0, /* PaUtilConverter *Int32_To_Int24_Dither; */
    274     0, /* PaUtilConverter *Int32_To_Int16; */
    275     0, /* PaUtilConverter *Int32_To_Int16_Dither; */
    276     0, /* PaUtilConverter *Int32_To_Int8; */
    277     0, /* PaUtilConverter *Int32_To_Int8_Dither; */
    278     0, /* PaUtilConverter *Int32_To_UInt8; */
    279     0, /* PaUtilConverter *Int32_To_UInt8_Dither; */
    280 
    281     0, /* PaUtilConverter *Int24_To_Float32; */
    282     0, /* PaUtilConverter *Int24_To_Int32; */
    283     0, /* PaUtilConverter *Int24_To_Int16; */
    284     0, /* PaUtilConverter *Int24_To_Int16_Dither; */
    285     0, /* PaUtilConverter *Int24_To_Int8; */
    286     0, /* PaUtilConverter *Int24_To_Int8_Dither; */
    287     0, /* PaUtilConverter *Int24_To_UInt8; */
    288     0, /* PaUtilConverter *Int24_To_UInt8_Dither; */
    289     
    290     0, /* PaUtilConverter *Int16_To_Float32; */
    291     0, /* PaUtilConverter *Int16_To_Int32; */
    292     0, /* PaUtilConverter *Int16_To_Int24; */
    293     0, /* PaUtilConverter *Int16_To_Int8; */
    294     0, /* PaUtilConverter *Int16_To_Int8_Dither; */
    295     0, /* PaUtilConverter *Int16_To_UInt8; */
    296     0, /* PaUtilConverter *Int16_To_UInt8_Dither; */
    297 
    298     0, /* PaUtilConverter *Int8_To_Float32; */
    299     0, /* PaUtilConverter *Int8_To_Int32; */
    300     0, /* PaUtilConverter *Int8_To_Int24 */
    301     0, /* PaUtilConverter *Int8_To_Int16; */
    302     0, /* PaUtilConverter *Int8_To_UInt8; */
    303 
    304     0, /* PaUtilConverter *UInt8_To_Float32; */
    305     0, /* PaUtilConverter *UInt8_To_Int32; */
    306     0, /* PaUtilConverter *UInt8_To_Int24; */
    307     0, /* PaUtilConverter *UInt8_To_Int16; */
    308     0, /* PaUtilConverter *UInt8_To_Int8; */
    309 
    310     0, /* PaUtilConverter *Copy_8_To_8; */
    311     0, /* PaUtilConverter *Copy_16_To_16; */
    312     0, /* PaUtilConverter *Copy_24_To_24; */
    313     0  /* PaUtilConverter *Copy_32_To_32; */
    314 };
    315 
    316 /* -------------------------------------------------------------------------- */
    317 
    318 #else /* PA_NO_STANDARD_CONVERTERS is not defined */
    319 
    320 /* -------------------------------------------------------------------------- */
    321 
    322 #define PA_CLIP_( val, min, max )\
    323     { val = ((val) < (min)) ? (min) : (((val) > (max)) ? (max) : (val)); }
    324 
    325 
    326 static const float const_1_div_128_ = 1.0f / 128.0f;  /* 8 bit multiplier */
    327 
    328 static const float const_1_div_32768_ = 1.0f / 32768.f; /* 16 bit multiplier */
    329 
    330 static const double const_1_div_2147483648_ = 1.0 / 2147483648.0; /* 32 bit multiplier */
    331 
    332 /* -------------------------------------------------------------------------- */
    333 
    334 static void Float32_To_Int32(
    335     void *destinationBuffer, signed int destinationStride,
    336     void *sourceBuffer, signed int sourceStride,
    337     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    338 {
    339     float *src = (float*)sourceBuffer;
    340     PaInt32 *dest =  (PaInt32*)destinationBuffer;
    341     (void)ditherGenerator; /* unused parameter */
    342 
    343     while( count-- )
    344     {
    345         /* REVIEW */
    346 #ifdef PA_USE_C99_LRINTF
    347         float scaled = *src * 0x7FFFFFFF;
    348         *dest = lrintf(scaled-0.5f);
    349 #else
    350         double scaled = *src * 0x7FFFFFFF;
    351         *dest = (PaInt32) scaled;        
    352 #endif
    353         
    354         src += sourceStride;
    355         dest += destinationStride;
    356     }
    357 }
    358 
    359 /* -------------------------------------------------------------------------- */
    360 
    361 static void Float32_To_Int32_Dither(
    362     void *destinationBuffer, signed int destinationStride,
    363     void *sourceBuffer, signed int sourceStride,
    364     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    365 {
    366     float *src = (float*)sourceBuffer;
    367     PaInt32 *dest =  (PaInt32*)destinationBuffer;
    368 
    369     while( count-- )
    370     {
    371         /* REVIEW */
    372 #ifdef PA_USE_C99_LRINTF
    373         float dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    374         /* use smaller scaler to prevent overflow when we add the dither */
    375         float dithered = ((float)*src * (2147483646.0f)) + dither;
    376         *dest = lrintf(dithered - 0.5f);
    377 #else
    378         double dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    379         /* use smaller scaler to prevent overflow when we add the dither */
    380         double dithered = ((double)*src * (2147483646.0)) + dither;
    381         *dest = (PaInt32) dithered;
    382 #endif
    383         src += sourceStride;
    384         dest += destinationStride;
    385     }
    386 }
    387 
    388 /* -------------------------------------------------------------------------- */
    389 
    390 static void Float32_To_Int32_Clip(
    391     void *destinationBuffer, signed int destinationStride,
    392     void *sourceBuffer, signed int sourceStride,
    393     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    394 {
    395     float *src = (float*)sourceBuffer;
    396     PaInt32 *dest =  (PaInt32*)destinationBuffer;
    397     (void) ditherGenerator; /* unused parameter */
    398     
    399     while( count-- )
    400     {
    401         /* REVIEW */
    402 #ifdef PA_USE_C99_LRINTF
    403         float scaled = *src * 0x7FFFFFFF;
    404         PA_CLIP_( scaled, -2147483648.f, 2147483647.f  );
    405         *dest = lrintf(scaled-0.5f);
    406 #else
    407         double scaled = *src * 0x7FFFFFFF;
    408         PA_CLIP_( scaled, -2147483648., 2147483647.  );
    409         *dest = (PaInt32) scaled;
    410 #endif
    411 
    412         src += sourceStride;
    413         dest += destinationStride;
    414     }
    415 }
    416 
    417 /* -------------------------------------------------------------------------- */
    418 
    419 static void Float32_To_Int32_DitherClip(
    420     void *destinationBuffer, signed int destinationStride,
    421     void *sourceBuffer, signed int sourceStride,
    422     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    423 {
    424     float *src = (float*)sourceBuffer;
    425     PaInt32 *dest =  (PaInt32*)destinationBuffer;
    426 
    427     while( count-- )
    428     {
    429         /* REVIEW */
    430 #ifdef PA_USE_C99_LRINTF
    431         float dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    432         /* use smaller scaler to prevent overflow when we add the dither */
    433         float dithered = ((float)*src * (2147483646.0f)) + dither;
    434         PA_CLIP_( dithered, -2147483648.f, 2147483647.f  );
    435         *dest = lrintf(dithered-0.5f);
    436 #else
    437         double dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    438         /* use smaller scaler to prevent overflow when we add the dither */
    439         double dithered = ((double)*src * (2147483646.0)) + dither;
    440         PA_CLIP_( dithered, -2147483648., 2147483647.  );
    441         *dest = (PaInt32) dithered;
    442 #endif
    443 
    444         src += sourceStride;
    445         dest += destinationStride;
    446     }
    447 }
    448 
    449 /* -------------------------------------------------------------------------- */
    450 
    451 static void Float32_To_Int24(
    452     void *destinationBuffer, signed int destinationStride,
    453     void *sourceBuffer, signed int sourceStride,
    454     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    455 {
    456     float *src = (float*)sourceBuffer;
    457     unsigned char *dest = (unsigned char*)destinationBuffer;
    458     PaInt32 temp;
    459 
    460     (void) ditherGenerator; /* unused parameter */
    461     
    462     while( count-- )
    463     {
    464         /* convert to 32 bit and drop the low 8 bits */
    465         double scaled = (double)(*src) * 2147483647.0;
    466         temp = (PaInt32) scaled;
    467         
    468 #if defined(PA_LITTLE_ENDIAN)
    469         dest[0] = (unsigned char)(temp >> 8);
    470         dest[1] = (unsigned char)(temp >> 16);
    471         dest[2] = (unsigned char)(temp >> 24);
    472 #elif defined(PA_BIG_ENDIAN)
    473         dest[0] = (unsigned char)(temp >> 24);
    474         dest[1] = (unsigned char)(temp >> 16);
    475         dest[2] = (unsigned char)(temp >> 8);
    476 #endif
    477 
    478         src += sourceStride;
    479         dest += destinationStride * 3;
    480     }
    481 }
    482 
    483 /* -------------------------------------------------------------------------- */
    484 
    485 static void Float32_To_Int24_Dither(
    486     void *destinationBuffer, signed int destinationStride,
    487     void *sourceBuffer, signed int sourceStride,
    488     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    489 {
    490     float *src = (float*)sourceBuffer;
    491     unsigned char *dest = (unsigned char*)destinationBuffer;
    492     PaInt32 temp;
    493 
    494     while( count-- )
    495     {
    496         /* convert to 32 bit and drop the low 8 bits */
    497 
    498         double dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    499         /* use smaller scaler to prevent overflow when we add the dither */
    500         double dithered = ((double)*src * (2147483646.0)) + dither;
    501         
    502         temp = (PaInt32) dithered;
    503 
    504 #if defined(PA_LITTLE_ENDIAN)
    505         dest[0] = (unsigned char)(temp >> 8);
    506         dest[1] = (unsigned char)(temp >> 16);
    507         dest[2] = (unsigned char)(temp >> 24);
    508 #elif defined(PA_BIG_ENDIAN)
    509         dest[0] = (unsigned char)(temp >> 24);
    510         dest[1] = (unsigned char)(temp >> 16);
    511         dest[2] = (unsigned char)(temp >> 8);
    512 #endif
    513 
    514         src += sourceStride;
    515         dest += destinationStride * 3;
    516     }
    517 }
    518 
    519 /* -------------------------------------------------------------------------- */
    520 
    521 static void Float32_To_Int24_Clip(
    522     void *destinationBuffer, signed int destinationStride,
    523     void *sourceBuffer, signed int sourceStride,
    524     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    525 {
    526     float *src = (float*)sourceBuffer;
    527     unsigned char *dest = (unsigned char*)destinationBuffer;
    528     PaInt32 temp;
    529 
    530     (void) ditherGenerator; /* unused parameter */
    531     
    532     while( count-- )
    533     {
    534         /* convert to 32 bit and drop the low 8 bits */
    535         double scaled = *src * 0x7FFFFFFF;
    536         PA_CLIP_( scaled, -2147483648., 2147483647.  );
    537         temp = (PaInt32) scaled;
    538 
    539 #if defined(PA_LITTLE_ENDIAN)
    540         dest[0] = (unsigned char)(temp >> 8);
    541         dest[1] = (unsigned char)(temp >> 16);
    542         dest[2] = (unsigned char)(temp >> 24);
    543 #elif defined(PA_BIG_ENDIAN)
    544         dest[0] = (unsigned char)(temp >> 24);
    545         dest[1] = (unsigned char)(temp >> 16);
    546         dest[2] = (unsigned char)(temp >> 8);
    547 #endif
    548 
    549         src += sourceStride;
    550         dest += destinationStride * 3;
    551     }
    552 }
    553 
    554 /* -------------------------------------------------------------------------- */
    555 
    556 static void Float32_To_Int24_DitherClip(
    557     void *destinationBuffer, signed int destinationStride,
    558     void *sourceBuffer, signed int sourceStride,
    559     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    560 {
    561     float *src = (float*)sourceBuffer;
    562     unsigned char *dest = (unsigned char*)destinationBuffer;
    563     PaInt32 temp;
    564     
    565     while( count-- )
    566     {
    567         /* convert to 32 bit and drop the low 8 bits */
    568         
    569         double dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    570         /* use smaller scaler to prevent overflow when we add the dither */
    571         double dithered = ((double)*src * (2147483646.0)) + dither;
    572         PA_CLIP_( dithered, -2147483648., 2147483647.  );
    573         
    574         temp = (PaInt32) dithered;
    575 
    576 #if defined(PA_LITTLE_ENDIAN)
    577         dest[0] = (unsigned char)(temp >> 8);
    578         dest[1] = (unsigned char)(temp >> 16);
    579         dest[2] = (unsigned char)(temp >> 24);
    580 #elif defined(PA_BIG_ENDIAN)
    581         dest[0] = (unsigned char)(temp >> 24);
    582         dest[1] = (unsigned char)(temp >> 16);
    583         dest[2] = (unsigned char)(temp >> 8);
    584 #endif
    585 
    586         src += sourceStride;
    587         dest += destinationStride * 3;
    588     }
    589 }
    590 
    591 /* -------------------------------------------------------------------------- */
    592 
    593 static void Float32_To_Int16(
    594     void *destinationBuffer, signed int destinationStride,
    595     void *sourceBuffer, signed int sourceStride,
    596     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    597 {
    598     float *src = (float*)sourceBuffer;
    599     PaInt16 *dest =  (PaInt16*)destinationBuffer;
    600     (void)ditherGenerator; /* unused parameter */
    601 
    602     while( count-- )
    603     {
    604 #ifdef PA_USE_C99_LRINTF
    605         float tempf = (*src * (32767.0f)) ;
    606         *dest = lrintf(tempf-0.5f);
    607 #else
    608         short samp = (short) (*src * (32767.0f));
    609         *dest = samp;
    610 #endif
    611 
    612         src += sourceStride;
    613         dest += destinationStride;
    614     }
    615 }
    616 
    617 /* -------------------------------------------------------------------------- */
    618 
    619 static void Float32_To_Int16_Dither(
    620     void *destinationBuffer, signed int destinationStride,
    621     void *sourceBuffer, signed int sourceStride,
    622     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    623 {
    624     float *src = (float*)sourceBuffer;
    625     PaInt16 *dest = (PaInt16*)destinationBuffer;
    626 
    627     while( count-- )
    628     {
    629 
    630         float dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    631         /* use smaller scaler to prevent overflow when we add the dither */
    632         float dithered = (*src * (32766.0f)) + dither;
    633 
    634 #ifdef PA_USE_C99_LRINTF
    635         *dest = lrintf(dithered-0.5f);
    636 #else
    637         *dest = (PaInt16) dithered;
    638 #endif
    639 
    640         src += sourceStride;
    641         dest += destinationStride;
    642     }
    643 }
    644 
    645 /* -------------------------------------------------------------------------- */
    646 
    647 static void Float32_To_Int16_Clip(
    648     void *destinationBuffer, signed int destinationStride,
    649     void *sourceBuffer, signed int sourceStride,
    650     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    651 {
    652     float *src = (float*)sourceBuffer;
    653     PaInt16 *dest =  (PaInt16*)destinationBuffer;
    654     (void)ditherGenerator; /* unused parameter */
    655 
    656     while( count-- )
    657     {
    658 #ifdef PA_USE_C99_LRINTF
    659         long samp = lrintf((*src * (32767.0f)) -0.5f);
    660 #else
    661         long samp = (PaInt32) (*src * (32767.0f));
    662 #endif
    663         PA_CLIP_( samp, -0x8000, 0x7FFF );
    664         *dest = (PaInt16) samp;
    665 
    666         src += sourceStride;
    667         dest += destinationStride;
    668     }
    669 }
    670 
    671 /* -------------------------------------------------------------------------- */
    672 
    673 static void Float32_To_Int16_DitherClip(
    674     void *destinationBuffer, signed int destinationStride,
    675     void *sourceBuffer, signed int sourceStride,
    676     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    677 {
    678     float *src = (float*)sourceBuffer;
    679     PaInt16 *dest =  (PaInt16*)destinationBuffer;
    680     (void)ditherGenerator; /* unused parameter */
    681 
    682     while( count-- )
    683     {
    684 
    685         float dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    686         /* use smaller scaler to prevent overflow when we add the dither */
    687         float dithered = (*src * (32766.0f)) + dither;
    688         PaInt32 samp = (PaInt32) dithered;
    689         PA_CLIP_( samp, -0x8000, 0x7FFF );
    690 #ifdef PA_USE_C99_LRINTF
    691         *dest = lrintf(samp-0.5f);
    692 #else
    693         *dest = (PaInt16) samp;
    694 #endif
    695 
    696         src += sourceStride;
    697         dest += destinationStride;
    698     }
    699 }
    700 
    701 /* -------------------------------------------------------------------------- */
    702 
    703 static void Float32_To_Int8(
    704     void *destinationBuffer, signed int destinationStride,
    705     void *sourceBuffer, signed int sourceStride,
    706     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    707 {
    708     float *src = (float*)sourceBuffer;
    709     signed char *dest =  (signed char*)destinationBuffer;
    710     (void)ditherGenerator; /* unused parameter */
    711 
    712     while( count-- )
    713     {
    714         signed char samp = (signed char) (*src * (127.0f));
    715         *dest = samp;
    716 
    717         src += sourceStride;
    718         dest += destinationStride;
    719     }
    720 }
    721 
    722 /* -------------------------------------------------------------------------- */
    723 
    724 static void Float32_To_Int8_Dither(
    725     void *destinationBuffer, signed int destinationStride,
    726     void *sourceBuffer, signed int sourceStride,
    727     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    728 {
    729     float *src = (float*)sourceBuffer;
    730     signed char *dest =  (signed char*)destinationBuffer;
    731     
    732     while( count-- )
    733     {
    734         float dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    735         /* use smaller scaler to prevent overflow when we add the dither */
    736         float dithered = (*src * (126.0f)) + dither;
    737         PaInt32 samp = (PaInt32) dithered;
    738         *dest = (signed char) samp;
    739 
    740         src += sourceStride;
    741         dest += destinationStride;
    742     }
    743 }
    744 
    745 /* -------------------------------------------------------------------------- */
    746 
    747 static void Float32_To_Int8_Clip(
    748     void *destinationBuffer, signed int destinationStride,
    749     void *sourceBuffer, signed int sourceStride,
    750     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    751 {
    752     float *src = (float*)sourceBuffer;
    753     signed char *dest =  (signed char*)destinationBuffer;
    754     (void)ditherGenerator; /* unused parameter */
    755 
    756     while( count-- )
    757     {
    758         PaInt32 samp = (PaInt32)(*src * (127.0f));
    759         PA_CLIP_( samp, -0x80, 0x7F );
    760         *dest = (signed char) samp;
    761 
    762         src += sourceStride;
    763         dest += destinationStride;
    764     }
    765 }
    766 
    767 /* -------------------------------------------------------------------------- */
    768 
    769 static void Float32_To_Int8_DitherClip(
    770     void *destinationBuffer, signed int destinationStride,
    771     void *sourceBuffer, signed int sourceStride,
    772     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    773 {
    774     float *src = (float*)sourceBuffer;
    775     signed char *dest =  (signed char*)destinationBuffer;
    776     (void)ditherGenerator; /* unused parameter */
    777 
    778     while( count-- )
    779     {
    780         float dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    781         /* use smaller scaler to prevent overflow when we add the dither */
    782         float dithered = (*src * (126.0f)) + dither;
    783         PaInt32 samp = (PaInt32) dithered;
    784         PA_CLIP_( samp, -0x80, 0x7F );
    785         *dest = (signed char) samp;
    786 
    787         src += sourceStride;
    788         dest += destinationStride;
    789     }
    790 }
    791 
    792 /* -------------------------------------------------------------------------- */
    793 
    794 static void Float32_To_UInt8(
    795     void *destinationBuffer, signed int destinationStride,
    796     void *sourceBuffer, signed int sourceStride,
    797     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    798 {
    799     float *src = (float*)sourceBuffer;
    800     unsigned char *dest =  (unsigned char*)destinationBuffer;
    801     (void)ditherGenerator; /* unused parameter */
    802 
    803     while( count-- )
    804     {
    805         unsigned char samp = (unsigned char)(128 + ((unsigned char) (*src * (127.0f))));
    806         *dest = samp;
    807 
    808         src += sourceStride;
    809         dest += destinationStride;
    810     }
    811 }
    812 
    813 /* -------------------------------------------------------------------------- */
    814 
    815 static void Float32_To_UInt8_Dither(
    816     void *destinationBuffer, signed int destinationStride,
    817     void *sourceBuffer, signed int sourceStride,
    818     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    819 {
    820     float *src = (float*)sourceBuffer;
    821     unsigned char *dest =  (unsigned char*)destinationBuffer;
    822     
    823     while( count-- )
    824     {
    825         float dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    826         /* use smaller scaler to prevent overflow when we add the dither */
    827         float dithered = (*src * (126.0f)) + dither;
    828         PaInt32 samp = (PaInt32) dithered;
    829         *dest = (unsigned char) (128 + samp);
    830         
    831         src += sourceStride;
    832         dest += destinationStride;
    833     }
    834 }
    835 
    836 /* -------------------------------------------------------------------------- */
    837 
    838 static void Float32_To_UInt8_Clip(
    839     void *destinationBuffer, signed int destinationStride,
    840     void *sourceBuffer, signed int sourceStride,
    841     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    842 {
    843     float *src = (float*)sourceBuffer;
    844     unsigned char *dest =  (unsigned char*)destinationBuffer;
    845     (void)ditherGenerator; /* unused parameter */
    846 
    847     while( count-- )
    848     {
    849         PaInt32 samp = 128 + (PaInt32)(*src * (127.0f));
    850         PA_CLIP_( samp, 0x0000, 0x00FF );
    851         *dest = (unsigned char) samp;
    852 
    853         src += sourceStride;
    854         dest += destinationStride;
    855     }
    856 }
    857 
    858 /* -------------------------------------------------------------------------- */
    859 
    860 static void Float32_To_UInt8_DitherClip(
    861     void *destinationBuffer, signed int destinationStride,
    862     void *sourceBuffer, signed int sourceStride,
    863     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    864 {
    865     float *src = (float*)sourceBuffer;
    866     unsigned char *dest =  (unsigned char*)destinationBuffer;
    867     (void)ditherGenerator; /* unused parameter */
    868 
    869     while( count-- )
    870     {
    871         float dither  = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
    872         /* use smaller scaler to prevent overflow when we add the dither */
    873         float dithered = (*src * (126.0f)) + dither;
    874         PaInt32 samp = 128 + (PaInt32) dithered;
    875         PA_CLIP_( samp, 0x0000, 0x00FF );
    876         *dest = (unsigned char) samp;
    877 
    878         src += sourceStride;
    879         dest += destinationStride;
    880     }
    881 }
    882 
    883 /* -------------------------------------------------------------------------- */
    884 
    885 static void Int32_To_Float32(
    886     void *destinationBuffer, signed int destinationStride,
    887     void *sourceBuffer, signed int sourceStride,
    888     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    889 {
    890     PaInt32 *src = (PaInt32*)sourceBuffer;
    891     float *dest =  (float*)destinationBuffer;
    892     (void)ditherGenerator; /* unused parameter */
    893 
    894     while( count-- )
    895     {
    896         *dest = (float) ((double)*src * const_1_div_2147483648_);
    897 
    898         src += sourceStride;
    899         dest += destinationStride;
    900     }
    901 }
    902 
    903 /* -------------------------------------------------------------------------- */
    904 
    905 static void Int32_To_Int24(
    906     void *destinationBuffer, signed int destinationStride,
    907     void *sourceBuffer, signed int sourceStride,
    908     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    909 {
    910     PaInt32 *src    = (PaInt32*)sourceBuffer;
    911     unsigned char *dest = (unsigned char*)destinationBuffer;
    912     (void) ditherGenerator; /* unused parameter */
    913     
    914 	while( count-- )
    915     {
    916 		/* REVIEW */
    917 #if defined(PA_LITTLE_ENDIAN)
    918         dest[0] = (unsigned char)(*src >> 8);
    919         dest[1] = (unsigned char)(*src >> 16);
    920         dest[2] = (unsigned char)(*src >> 24);
    921 #elif defined(PA_BIG_ENDIAN)
    922         dest[0] = (unsigned char)(*src >> 24);
    923         dest[1] = (unsigned char)(*src >> 16);
    924         dest[2] = (unsigned char)(*src >> 8);
    925 #endif
    926         src += sourceStride;
    927         dest += destinationStride * 3;
    928     }
    929 }
    930 
    931 /* -------------------------------------------------------------------------- */
    932 
    933 static void Int32_To_Int24_Dither(
    934     void *destinationBuffer, signed int destinationStride,
    935     void *sourceBuffer, signed int sourceStride,
    936     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    937 {
    938     (void) destinationBuffer; /* unused parameters */
    939     (void) destinationStride; /* unused parameters */
    940     (void) sourceBuffer; /* unused parameters */
    941     (void) sourceStride; /* unused parameters */
    942     (void) count; /* unused parameters */
    943     (void) ditherGenerator; /* unused parameters */
    944     /* IMPLEMENT ME */
    945 }
    946 
    947 /* -------------------------------------------------------------------------- */
    948 
    949 static void Int32_To_Int16(
    950     void *destinationBuffer, signed int destinationStride,
    951     void *sourceBuffer, signed int sourceStride,
    952     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    953 {
    954     PaInt32 *src = (PaInt32*)sourceBuffer;
    955     PaInt16 *dest =  (PaInt16*)destinationBuffer;
    956     (void)ditherGenerator; /* unused parameter */
    957 
    958     while( count-- )
    959     {
    960         *dest = (PaInt16) ((*src) >> 16);
    961 
    962         src += sourceStride;
    963         dest += destinationStride;
    964     }
    965 }
    966 
    967 /* -------------------------------------------------------------------------- */
    968 
    969 static void Int32_To_Int16_Dither(
    970     void *destinationBuffer, signed int destinationStride,
    971     void *sourceBuffer, signed int sourceStride,
    972     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    973 {
    974     PaInt32 *src = (PaInt32*)sourceBuffer;
    975     PaInt16 *dest =  (PaInt16*)destinationBuffer;
    976     PaInt32 dither;
    977 
    978     while( count-- )
    979     {
    980         /* REVIEW */
    981         dither = PaUtil_Generate16BitTriangularDither( ditherGenerator );
    982         *dest = (PaInt16) ((((*src)>>1) + dither) >> 15);
    983 
    984         src += sourceStride;
    985         dest += destinationStride;
    986     }
    987 }
    988 
    989 /* -------------------------------------------------------------------------- */
    990 
    991 static void Int32_To_Int8(
    992     void *destinationBuffer, signed int destinationStride,
    993     void *sourceBuffer, signed int sourceStride,
    994     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
    995 {
    996     PaInt32 *src = (PaInt32*)sourceBuffer;
    997     signed char *dest =  (signed char*)destinationBuffer;
    998     (void)ditherGenerator; /* unused parameter */
    999 
   1000     while( count-- )
   1001     {
   1002         *dest = (signed char) ((*src) >> 24);
   1003 
   1004         src += sourceStride;
   1005         dest += destinationStride;
   1006     }
   1007 }
   1008 
   1009 /* -------------------------------------------------------------------------- */
   1010 
   1011 static void Int32_To_Int8_Dither(
   1012     void *destinationBuffer, signed int destinationStride,
   1013     void *sourceBuffer, signed int sourceStride,
   1014     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1015 {
   1016     PaInt32 *src = (PaInt32*)sourceBuffer;
   1017     signed char *dest =  (signed char*)destinationBuffer;
   1018     PaInt32 dither;
   1019 
   1020     while( count-- )
   1021     {
   1022         /* REVIEW */
   1023         dither = PaUtil_Generate16BitTriangularDither( ditherGenerator );
   1024         *dest = (signed char) ((((*src)>>1) + dither) >> 23);
   1025 
   1026         src += sourceStride;
   1027         dest += destinationStride;
   1028     }
   1029 }
   1030 
   1031 /* -------------------------------------------------------------------------- */
   1032 
   1033 static void Int32_To_UInt8(
   1034     void *destinationBuffer, signed int destinationStride,
   1035     void *sourceBuffer, signed int sourceStride,
   1036     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1037 {
   1038     PaInt32 *src = (PaInt32*)sourceBuffer;
   1039     unsigned char *dest =  (unsigned char*)destinationBuffer;
   1040     (void)ditherGenerator; /* unused parameter */
   1041 
   1042     while( count-- )
   1043     {
   1044 		(*dest) = (unsigned char)(((*src) >> 24) + 128); 
   1045 
   1046         src += sourceStride;
   1047         dest += destinationStride;
   1048     }
   1049 }
   1050 
   1051 /* -------------------------------------------------------------------------- */
   1052 
   1053 static void Int32_To_UInt8_Dither(
   1054     void *destinationBuffer, signed int destinationStride,
   1055     void *sourceBuffer, signed int sourceStride,
   1056     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1057 {
   1058     PaInt32 *src = (PaInt32*)sourceBuffer;
   1059     unsigned char *dest =  (unsigned char*)destinationBuffer;
   1060     (void)ditherGenerator; /* unused parameter */
   1061 
   1062     while( count-- )
   1063     {
   1064         /* IMPLEMENT ME */
   1065 
   1066         src += sourceStride;
   1067         dest += destinationStride;
   1068     }
   1069 }
   1070 
   1071 /* -------------------------------------------------------------------------- */
   1072 
   1073 static void Int24_To_Float32(
   1074     void *destinationBuffer, signed int destinationStride,
   1075     void *sourceBuffer, signed int sourceStride,
   1076     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1077 {
   1078     unsigned char *src = (unsigned char*)sourceBuffer;
   1079     float *dest = (float*)destinationBuffer;
   1080     PaInt32 temp;
   1081 
   1082     (void) ditherGenerator; /* unused parameter */
   1083     
   1084     while( count-- )
   1085     {
   1086 
   1087 #if defined(PA_LITTLE_ENDIAN)
   1088         temp = (((PaInt32)src[0]) << 8);  
   1089         temp = temp | (((PaInt32)src[1]) << 16);
   1090         temp = temp | (((PaInt32)src[2]) << 24);
   1091 #elif defined(PA_BIG_ENDIAN)
   1092         temp = (((PaInt32)src[0]) << 24);
   1093         temp = temp | (((PaInt32)src[1]) << 16);
   1094         temp = temp | (((PaInt32)src[2]) << 8);
   1095 #endif
   1096 
   1097         *dest = (float) ((double)temp * const_1_div_2147483648_);
   1098 
   1099         src += sourceStride * 3;
   1100         dest += destinationStride;
   1101     }
   1102 }
   1103 
   1104 /* -------------------------------------------------------------------------- */
   1105 
   1106 static void Int24_To_Int32(
   1107     void *destinationBuffer, signed int destinationStride,
   1108     void *sourceBuffer, signed int sourceStride,
   1109     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1110 {
   1111     unsigned char *src  = (unsigned char*)sourceBuffer;
   1112     PaInt32 *dest = (PaInt32*)  destinationBuffer;
   1113     PaInt32 temp;
   1114 
   1115     (void) ditherGenerator; /* unused parameter */
   1116     
   1117     while( count-- )
   1118     {
   1119 
   1120 #if defined(PA_LITTLE_ENDIAN)
   1121         temp = (((PaInt32)src[0]) << 8);  
   1122         temp = temp | (((PaInt32)src[1]) << 16);
   1123         temp = temp | (((PaInt32)src[2]) << 24);
   1124 #elif defined(PA_BIG_ENDIAN)
   1125         temp = (((PaInt32)src[0]) << 24);
   1126         temp = temp | (((PaInt32)src[1]) << 16);
   1127         temp = temp | (((PaInt32)src[2]) << 8);
   1128 #endif
   1129 
   1130         *dest = temp;
   1131 
   1132         src += sourceStride * 3;
   1133         dest += destinationStride;
   1134     }
   1135 }
   1136 
   1137 /* -------------------------------------------------------------------------- */
   1138 
   1139 static void Int24_To_Int16(
   1140     void *destinationBuffer, signed int destinationStride,
   1141     void *sourceBuffer, signed int sourceStride,
   1142     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1143 {
   1144     unsigned char *src = (unsigned char*)sourceBuffer;
   1145     PaInt16 *dest = (PaInt16*)destinationBuffer;
   1146     
   1147     PaInt16 temp;
   1148 
   1149     (void) ditherGenerator; /* unused parameter */
   1150         
   1151     while( count-- )
   1152     {
   1153 		
   1154 #if defined(PA_LITTLE_ENDIAN)
   1155 		/* src[0] is discarded */
   1156         temp = (((PaInt16)src[1]));
   1157         temp = temp | (PaInt16)(((PaInt16)src[2]) << 8);
   1158 #elif defined(PA_BIG_ENDIAN)
   1159 		/* src[2] is discarded */
   1160         temp = (PaInt16)(((PaInt16)src[0]) << 8);
   1161         temp = temp | (((PaInt16)src[1]));
   1162 #endif
   1163 
   1164         *dest = temp;
   1165 
   1166         src += sourceStride * 3;
   1167         dest += destinationStride;
   1168     }
   1169 }
   1170 
   1171 /* -------------------------------------------------------------------------- */
   1172 
   1173 static void Int24_To_Int16_Dither(
   1174     void *destinationBuffer, signed int destinationStride,
   1175     void *sourceBuffer, signed int sourceStride,
   1176     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1177 {
   1178     unsigned char *src = (unsigned char*)sourceBuffer;
   1179     PaInt16 *dest = (PaInt16*)destinationBuffer;
   1180 
   1181     PaInt32 temp, dither;
   1182 
   1183     while( count-- )
   1184     {
   1185 
   1186 #if defined(PA_LITTLE_ENDIAN)
   1187         temp = (((PaInt32)src[0]) << 8);  
   1188         temp = temp | (((PaInt32)src[1]) << 16);
   1189         temp = temp | (((PaInt32)src[2]) << 24);
   1190 #elif defined(PA_BIG_ENDIAN)
   1191         temp = (((PaInt32)src[0]) << 24);
   1192         temp = temp | (((PaInt32)src[1]) << 16);
   1193         temp = temp | (((PaInt32)src[2]) << 8);
   1194 #endif
   1195 
   1196         /* REVIEW */
   1197         dither = PaUtil_Generate16BitTriangularDither( ditherGenerator );
   1198         *dest = (PaInt16) (((temp >> 1) + dither) >> 15);
   1199 
   1200         src  += sourceStride * 3;
   1201         dest += destinationStride;
   1202     }
   1203 }
   1204 
   1205 /* -------------------------------------------------------------------------- */
   1206 
   1207 static void Int24_To_Int8(
   1208     void *destinationBuffer, signed int destinationStride,
   1209     void *sourceBuffer, signed int sourceStride,
   1210     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1211 {
   1212     unsigned char *src = (unsigned char*)sourceBuffer;
   1213     signed char  *dest = (signed char*)destinationBuffer;
   1214     
   1215     (void) ditherGenerator; /* unused parameter */
   1216         
   1217     while( count-- )
   1218     {	
   1219 	
   1220 #if defined(PA_LITTLE_ENDIAN)
   1221 		/* src[0] is discarded */
   1222 		/* src[1] is discarded */
   1223         *dest = src[2];
   1224 #elif defined(PA_BIG_ENDIAN)
   1225 		/* src[2] is discarded */
   1226 		/* src[1] is discarded */
   1227 		*dest = src[0];
   1228 #endif
   1229 
   1230         src += sourceStride * 3;
   1231         dest += destinationStride;
   1232     }
   1233 }
   1234 
   1235 /* -------------------------------------------------------------------------- */
   1236 
   1237 static void Int24_To_Int8_Dither(
   1238     void *destinationBuffer, signed int destinationStride,
   1239     void *sourceBuffer, signed int sourceStride,
   1240     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1241 {
   1242     unsigned char *src = (unsigned char*)sourceBuffer;
   1243     signed char  *dest = (signed char*)destinationBuffer;
   1244     
   1245     PaInt32 temp, dither;
   1246 
   1247     while( count-- )
   1248     {
   1249 
   1250 #if defined(PA_LITTLE_ENDIAN)
   1251         temp = (((PaInt32)src[0]) << 8);  
   1252         temp = temp | (((PaInt32)src[1]) << 16);
   1253         temp = temp | (((PaInt32)src[2]) << 24);
   1254 #elif defined(PA_BIG_ENDIAN)
   1255         temp = (((PaInt32)src[0]) << 24);
   1256         temp = temp | (((PaInt32)src[1]) << 16);
   1257         temp = temp | (((PaInt32)src[2]) << 8);
   1258 #endif
   1259 
   1260         /* REVIEW */
   1261         dither = PaUtil_Generate16BitTriangularDither( ditherGenerator );
   1262         *dest = (signed char) (((temp >> 1) + dither) >> 23);
   1263 
   1264         src += sourceStride * 3;
   1265         dest += destinationStride;
   1266     }
   1267 }
   1268 
   1269 /* -------------------------------------------------------------------------- */
   1270 
   1271 static void Int24_To_UInt8(
   1272     void *destinationBuffer, signed int destinationStride,
   1273     void *sourceBuffer, signed int sourceStride,
   1274     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1275 {
   1276     unsigned char *src = (unsigned char*)sourceBuffer;
   1277     unsigned char *dest = (unsigned char*)destinationBuffer;
   1278     
   1279     (void) ditherGenerator; /* unused parameter */
   1280         
   1281     while( count-- )
   1282     {
   1283 		
   1284 #if defined(PA_LITTLE_ENDIAN)
   1285 		/* src[0] is discarded */
   1286 		/* src[1] is discarded */
   1287         *dest = (unsigned char)(src[2] + 128);
   1288 #elif defined(PA_BIG_ENDIAN)
   1289         *dest = (unsigned char)(src[0] + 128);
   1290 		/* src[1] is discarded */
   1291 		/* src[2] is discarded */		
   1292 #endif
   1293 
   1294         src += sourceStride * 3;
   1295         dest += destinationStride;
   1296     }
   1297 }
   1298 
   1299 /* -------------------------------------------------------------------------- */
   1300 
   1301 static void Int24_To_UInt8_Dither(
   1302     void *destinationBuffer, signed int destinationStride,
   1303     void *sourceBuffer, signed int sourceStride,
   1304     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1305 {
   1306     (void) destinationBuffer; /* unused parameters */
   1307     (void) destinationStride; /* unused parameters */
   1308     (void) sourceBuffer; /* unused parameters */
   1309     (void) sourceStride; /* unused parameters */
   1310     (void) count; /* unused parameters */
   1311     (void) ditherGenerator; /* unused parameters */
   1312     /* IMPLEMENT ME */
   1313 }
   1314 
   1315 /* -------------------------------------------------------------------------- */
   1316 
   1317 static void Int16_To_Float32(
   1318     void *destinationBuffer, signed int destinationStride,
   1319     void *sourceBuffer, signed int sourceStride,
   1320     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1321 {
   1322     PaInt16 *src = (PaInt16*)sourceBuffer;
   1323     float *dest =  (float*)destinationBuffer;
   1324     (void)ditherGenerator; /* unused parameter */
   1325 
   1326     while( count-- )
   1327     {
   1328         float samp = *src * const_1_div_32768_; /* FIXME: i'm concerned about this being asymetrical with float->int16 -rb */
   1329         *dest = samp;
   1330 
   1331         src += sourceStride;
   1332         dest += destinationStride;
   1333     }
   1334 }
   1335 
   1336 /* -------------------------------------------------------------------------- */
   1337 
   1338 static void Int16_To_Int32(
   1339     void *destinationBuffer, signed int destinationStride,
   1340     void *sourceBuffer, signed int sourceStride,
   1341     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1342 {
   1343     PaInt16 *src = (PaInt16*)sourceBuffer;
   1344     PaInt32 *dest =  (PaInt32*)destinationBuffer;
   1345     (void)ditherGenerator; /* unused parameter */
   1346 
   1347     while( count-- )
   1348     {
   1349         /* REVIEW: we should consider something like
   1350             (*src << 16) | (*src & 0xFFFF)
   1351         */
   1352         
   1353         *dest = *src << 16;
   1354 
   1355         src += sourceStride;
   1356         dest += destinationStride;
   1357     }
   1358 }
   1359 
   1360 /* -------------------------------------------------------------------------- */
   1361 
   1362 static void Int16_To_Int24(
   1363     void *destinationBuffer, signed int destinationStride,
   1364     void *sourceBuffer, signed int sourceStride,
   1365     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1366 {
   1367     PaInt16 *src   = (PaInt16*) sourceBuffer;
   1368     unsigned char *dest = (unsigned char*)destinationBuffer;
   1369     PaInt16 temp;
   1370 
   1371     (void) ditherGenerator; /* unused parameter */
   1372     
   1373     while( count-- )
   1374     {
   1375         temp = *src;
   1376         
   1377 #if defined(PA_LITTLE_ENDIAN)
   1378         dest[0] = 0;
   1379         dest[1] = (unsigned char)(temp);
   1380         dest[2] = (unsigned char)(temp >> 8);
   1381 #elif defined(PA_BIG_ENDIAN)
   1382         dest[0] = (unsigned char)(temp >> 8);
   1383         dest[1] = (unsigned char)(temp);
   1384         dest[2] = 0;
   1385 #endif
   1386 
   1387         src += sourceStride;
   1388         dest += destinationStride * 3;
   1389     }
   1390 }
   1391 
   1392 /* -------------------------------------------------------------------------- */
   1393 
   1394 static void Int16_To_Int8(
   1395     void *destinationBuffer, signed int destinationStride,
   1396     void *sourceBuffer, signed int sourceStride,
   1397     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1398 {
   1399     PaInt16 *src = (PaInt16*)sourceBuffer;
   1400     signed char *dest =  (signed char*)destinationBuffer;
   1401     (void)ditherGenerator; /* unused parameter */
   1402 
   1403     while( count-- )
   1404     {
   1405         (*dest) = (signed char)((*src) >> 8);
   1406 
   1407         src += sourceStride;
   1408         dest += destinationStride;
   1409     }
   1410 }
   1411 
   1412 /* -------------------------------------------------------------------------- */
   1413 
   1414 static void Int16_To_Int8_Dither(
   1415     void *destinationBuffer, signed int destinationStride,
   1416     void *sourceBuffer, signed int sourceStride,
   1417     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1418 {
   1419     PaInt16 *src = (PaInt16*)sourceBuffer;
   1420     signed char *dest =  (signed char*)destinationBuffer;
   1421     (void)ditherGenerator; /* unused parameter */
   1422 
   1423     while( count-- )
   1424     {
   1425         /* IMPLEMENT ME */
   1426 
   1427         src += sourceStride;
   1428         dest += destinationStride;
   1429     }
   1430 }
   1431 
   1432 /* -------------------------------------------------------------------------- */
   1433 
   1434 static void Int16_To_UInt8(
   1435     void *destinationBuffer, signed int destinationStride,
   1436     void *sourceBuffer, signed int sourceStride,
   1437     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1438 {
   1439     PaInt16 *src = (PaInt16*)sourceBuffer;
   1440     unsigned char *dest =  (unsigned char*)destinationBuffer;
   1441     (void)ditherGenerator; /* unused parameter */
   1442 
   1443     while( count-- )
   1444     {
   1445 		(*dest) = (unsigned char)(((*src) >> 8) + 128); 
   1446 
   1447         src += sourceStride;
   1448         dest += destinationStride;
   1449     }
   1450 }
   1451 
   1452 /* -------------------------------------------------------------------------- */
   1453 
   1454 static void Int16_To_UInt8_Dither(
   1455     void *destinationBuffer, signed int destinationStride,
   1456     void *sourceBuffer, signed int sourceStride,
   1457     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1458 {
   1459     PaInt16 *src = (PaInt16*)sourceBuffer;
   1460     unsigned char *dest =  (unsigned char*)destinationBuffer;
   1461     (void)ditherGenerator; /* unused parameter */
   1462 
   1463     while( count-- )
   1464     {
   1465         /* IMPLEMENT ME */
   1466 
   1467         src += sourceStride;
   1468         dest += destinationStride;
   1469     }
   1470 }
   1471 
   1472 /* -------------------------------------------------------------------------- */
   1473 
   1474 static void Int8_To_Float32(
   1475     void *destinationBuffer, signed int destinationStride,
   1476     void *sourceBuffer, signed int sourceStride,
   1477     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1478 {
   1479     signed char *src = (signed char*)sourceBuffer;
   1480     float *dest =  (float*)destinationBuffer;
   1481     (void)ditherGenerator; /* unused parameter */
   1482 
   1483     while( count-- )
   1484     {
   1485         float samp = *src * const_1_div_128_;
   1486         *dest = samp;
   1487 
   1488         src += sourceStride;
   1489         dest += destinationStride;
   1490     }
   1491 }
   1492 
   1493 /* -------------------------------------------------------------------------- */
   1494 
   1495 static void Int8_To_Int32(
   1496     void *destinationBuffer, signed int destinationStride,
   1497     void *sourceBuffer, signed int sourceStride,
   1498     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1499 {
   1500     signed char *src = (signed char*)sourceBuffer;
   1501     PaInt32 *dest =  (PaInt32*)destinationBuffer;
   1502     (void)ditherGenerator; /* unused parameter */
   1503 
   1504     while( count-- )
   1505     {
   1506 		(*dest) = (*src) << 24;
   1507 
   1508         src += sourceStride;
   1509         dest += destinationStride;
   1510     }
   1511 }
   1512 
   1513 /* -------------------------------------------------------------------------- */
   1514 
   1515 static void Int8_To_Int24(
   1516     void *destinationBuffer, signed int destinationStride,
   1517     void *sourceBuffer, signed int sourceStride,
   1518     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1519 {
   1520     signed char *src = (signed char*)sourceBuffer;
   1521     unsigned char *dest =  (unsigned char*)destinationBuffer;
   1522     (void)ditherGenerator; /* unused parameter */
   1523 
   1524     while( count-- )
   1525     {
   1526 
   1527 #if defined(PA_LITTLE_ENDIAN)
   1528         dest[0] = 0;
   1529         dest[1] = 0;
   1530         dest[2] = (*src);
   1531 #elif defined(PA_BIG_ENDIAN)
   1532         dest[0] = (*src);
   1533         dest[1] = 0;
   1534         dest[2] = 0;
   1535 #endif
   1536 
   1537         src += sourceStride;
   1538         dest += destinationStride * 3;
   1539     }
   1540 }
   1541 
   1542 /* -------------------------------------------------------------------------- */
   1543 
   1544 static void Int8_To_Int16(
   1545     void *destinationBuffer, signed int destinationStride,
   1546     void *sourceBuffer, signed int sourceStride,
   1547     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1548 {
   1549     signed char *src = (signed char*)sourceBuffer;
   1550     PaInt16 *dest =  (PaInt16*)destinationBuffer;
   1551     (void)ditherGenerator; /* unused parameter */
   1552 
   1553     while( count-- )
   1554     {
   1555         (*dest) = (PaInt16)((*src) << 8);
   1556 
   1557         src += sourceStride;
   1558         dest += destinationStride;
   1559     }
   1560 }
   1561 
   1562 /* -------------------------------------------------------------------------- */
   1563 
   1564 static void Int8_To_UInt8(
   1565     void *destinationBuffer, signed int destinationStride,
   1566     void *sourceBuffer, signed int sourceStride,
   1567     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1568 {
   1569     signed char *src = (signed char*)sourceBuffer;
   1570     unsigned char *dest =  (unsigned char*)destinationBuffer;
   1571     (void)ditherGenerator; /* unused parameter */
   1572 
   1573     while( count-- )
   1574     {
   1575         (*dest) = (unsigned char)(*src + 128);
   1576 
   1577         src += sourceStride;
   1578         dest += destinationStride;
   1579     }
   1580 }
   1581 
   1582 /* -------------------------------------------------------------------------- */
   1583 
   1584 static void UInt8_To_Float32(
   1585     void *destinationBuffer, signed int destinationStride,
   1586     void *sourceBuffer, signed int sourceStride,
   1587     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1588 {
   1589     unsigned char *src = (unsigned char*)sourceBuffer;
   1590     float *dest =  (float*)destinationBuffer;
   1591     (void)ditherGenerator; /* unused parameter */
   1592 
   1593     while( count-- )
   1594     {
   1595         float samp = (*src - 128) * const_1_div_128_;
   1596         *dest = samp;
   1597 
   1598         src += sourceStride;
   1599         dest += destinationStride;
   1600     }
   1601 }
   1602 
   1603 /* -------------------------------------------------------------------------- */
   1604 
   1605 static void UInt8_To_Int32(
   1606     void *destinationBuffer, signed int destinationStride,
   1607     void *sourceBuffer, signed int sourceStride,
   1608     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1609 {
   1610     unsigned char *src = (unsigned char*)sourceBuffer;
   1611     PaInt32 *dest = (PaInt32*)destinationBuffer;
   1612     (void)ditherGenerator; /* unused parameter */
   1613 
   1614     while( count-- )
   1615     {
   1616 		(*dest) = (*src - 128) << 24;
   1617 
   1618         src += sourceStride;
   1619         dest += destinationStride;
   1620     }
   1621 }
   1622 
   1623 /* -------------------------------------------------------------------------- */
   1624 
   1625 static void UInt8_To_Int24(
   1626     void *destinationBuffer, signed int destinationStride,
   1627     void *sourceBuffer, signed int sourceStride,
   1628     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1629 {
   1630 	unsigned char *src  = (unsigned char*)sourceBuffer;
   1631     unsigned char *dest = (unsigned char*)destinationBuffer;
   1632     (void) ditherGenerator; /* unused parameters */
   1633     
   1634 	while( count-- )
   1635     {
   1636 
   1637 #if defined(PA_LITTLE_ENDIAN)
   1638         dest[0] = 0;
   1639         dest[1] = 0;
   1640         dest[2] = (unsigned char)(*src - 128);
   1641 #elif defined(PA_BIG_ENDIAN)
   1642         dest[0] = (unsigned char)(*src - 128);
   1643         dest[1] = 0;
   1644         dest[2] = 0;
   1645 #endif
   1646 		
   1647         src += sourceStride;
   1648         dest += destinationStride * 3;    
   1649 	}
   1650 }
   1651 
   1652 /* -------------------------------------------------------------------------- */
   1653 
   1654 static void UInt8_To_Int16(
   1655     void *destinationBuffer, signed int destinationStride,
   1656     void *sourceBuffer, signed int sourceStride,
   1657     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1658 {
   1659     unsigned char *src = (unsigned char*)sourceBuffer;
   1660     PaInt16 *dest =  (PaInt16*)destinationBuffer;
   1661     (void)ditherGenerator; /* unused parameter */
   1662 
   1663     while( count-- )
   1664     {
   1665         (*dest) = (PaInt16)((*src - 128) << 8);
   1666 
   1667         src += sourceStride;
   1668         dest += destinationStride;
   1669     }
   1670 }
   1671 
   1672 /* -------------------------------------------------------------------------- */
   1673 
   1674 static void UInt8_To_Int8(
   1675     void *destinationBuffer, signed int destinationStride,
   1676     void *sourceBuffer, signed int sourceStride,
   1677     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1678 {
   1679     unsigned char *src = (unsigned char*)sourceBuffer;
   1680     signed char  *dest = (signed char*)destinationBuffer;
   1681     (void)ditherGenerator; /* unused parameter */
   1682 
   1683     while( count-- )
   1684     {
   1685         (*dest) = (signed char)(*src - 128);
   1686 
   1687         src += sourceStride;
   1688         dest += destinationStride;
   1689     }
   1690 }
   1691 
   1692 /* -------------------------------------------------------------------------- */
   1693 
   1694 static void Copy_8_To_8(
   1695     void *destinationBuffer, signed int destinationStride,
   1696     void *sourceBuffer, signed int sourceStride,
   1697     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1698 {
   1699     unsigned char *src = (unsigned char*)sourceBuffer;
   1700     unsigned char *dest = (unsigned char*)destinationBuffer;
   1701                                                       
   1702     (void) ditherGenerator; /* unused parameter */
   1703 
   1704     while( count-- )
   1705     {
   1706         *dest = *src;
   1707 
   1708         src += sourceStride;
   1709         dest += destinationStride;
   1710     }
   1711 }
   1712 
   1713 /* -------------------------------------------------------------------------- */
   1714 
   1715 static void Copy_16_To_16(
   1716     void *destinationBuffer, signed int destinationStride,
   1717     void *sourceBuffer, signed int sourceStride,
   1718     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1719 {
   1720     PaUint16 *src = (PaUint16 *)sourceBuffer;
   1721     PaUint16 *dest = (PaUint16 *)destinationBuffer;
   1722                                                         
   1723     (void) ditherGenerator; /* unused parameter */
   1724     
   1725     while( count-- )
   1726     {
   1727         *dest = *src;
   1728 
   1729         src += sourceStride;
   1730         dest += destinationStride;
   1731     }
   1732 }
   1733 
   1734 /* -------------------------------------------------------------------------- */
   1735 
   1736 static void Copy_24_To_24(
   1737     void *destinationBuffer, signed int destinationStride,
   1738     void *sourceBuffer, signed int sourceStride,
   1739     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1740 {
   1741     unsigned char *src = (unsigned char*)sourceBuffer;
   1742     unsigned char *dest = (unsigned char*)destinationBuffer;
   1743 
   1744     (void) ditherGenerator; /* unused parameter */
   1745     
   1746     while( count-- )
   1747     {
   1748         dest[0] = src[0];
   1749         dest[1] = src[1];
   1750         dest[2] = src[2];
   1751 
   1752         src += sourceStride * 3;
   1753         dest += destinationStride * 3;
   1754     }
   1755 }
   1756 
   1757 /* -------------------------------------------------------------------------- */
   1758 
   1759 static void Copy_32_To_32(
   1760     void *destinationBuffer, signed int destinationStride,
   1761     void *sourceBuffer, signed int sourceStride,
   1762     unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
   1763 {
   1764     PaUint32 *dest = (PaUint32 *)destinationBuffer;
   1765     PaUint32 *src = (PaUint32 *)sourceBuffer;
   1766 
   1767     (void) ditherGenerator; /* unused parameter */
   1768     
   1769     while( count-- )
   1770     {
   1771         *dest = *src;
   1772 
   1773         src += sourceStride;
   1774         dest += destinationStride;
   1775     }
   1776 }
   1777 
   1778 /* -------------------------------------------------------------------------- */
   1779 
   1780 PaUtilConverterTable paConverters = {
   1781     Float32_To_Int32,              /* PaUtilConverter *Float32_To_Int32; */
   1782     Float32_To_Int32_Dither,       /* PaUtilConverter *Float32_To_Int32_Dither; */
   1783     Float32_To_Int32_Clip,         /* PaUtilConverter *Float32_To_Int32_Clip; */
   1784     Float32_To_Int32_DitherClip,   /* PaUtilConverter *Float32_To_Int32_DitherClip; */
   1785 
   1786     Float32_To_Int24,              /* PaUtilConverter *Float32_To_Int24; */
   1787     Float32_To_Int24_Dither,       /* PaUtilConverter *Float32_To_Int24_Dither; */
   1788     Float32_To_Int24_Clip,         /* PaUtilConverter *Float32_To_Int24_Clip; */
   1789     Float32_To_Int24_DitherClip,   /* PaUtilConverter *Float32_To_Int24_DitherClip; */
   1790     
   1791     Float32_To_Int16,              /* PaUtilConverter *Float32_To_Int16; */
   1792     Float32_To_Int16_Dither,       /* PaUtilConverter *Float32_To_Int16_Dither; */
   1793     Float32_To_Int16_Clip,         /* PaUtilConverter *Float32_To_Int16_Clip; */
   1794     Float32_To_Int16_DitherClip,   /* PaUtilConverter *Float32_To_Int16_DitherClip; */
   1795 
   1796     Float32_To_Int8,               /* PaUtilConverter *Float32_To_Int8; */
   1797     Float32_To_Int8_Dither,        /* PaUtilConverter *Float32_To_Int8_Dither; */
   1798     Float32_To_Int8_Clip,          /* PaUtilConverter *Float32_To_Int8_Clip; */
   1799     Float32_To_Int8_DitherClip,    /* PaUtilConverter *Float32_To_Int8_DitherClip; */
   1800 
   1801     Float32_To_UInt8,              /* PaUtilConverter *Float32_To_UInt8; */
   1802     Float32_To_UInt8_Dither,       /* PaUtilConverter *Float32_To_UInt8_Dither; */
   1803     Float32_To_UInt8_Clip,         /* PaUtilConverter *Float32_To_UInt8_Clip; */
   1804     Float32_To_UInt8_DitherClip,   /* PaUtilConverter *Float32_To_UInt8_DitherClip; */
   1805 
   1806     Int32_To_Float32,              /* PaUtilConverter *Int32_To_Float32; */
   1807     Int32_To_Int24,                /* PaUtilConverter *Int32_To_Int24; */
   1808     Int32_To_Int24_Dither,         /* PaUtilConverter *Int32_To_Int24_Dither; */
   1809     Int32_To_Int16,                /* PaUtilConverter *Int32_To_Int16; */
   1810     Int32_To_Int16_Dither,         /* PaUtilConverter *Int32_To_Int16_Dither; */
   1811     Int32_To_Int8,                 /* PaUtilConverter *Int32_To_Int8; */
   1812     Int32_To_Int8_Dither,          /* PaUtilConverter *Int32_To_Int8_Dither; */
   1813     Int32_To_UInt8,                /* PaUtilConverter *Int32_To_UInt8; */
   1814     Int32_To_UInt8_Dither,         /* PaUtilConverter *Int32_To_UInt8_Dither; */
   1815 
   1816     Int24_To_Float32,              /* PaUtilConverter *Int24_To_Float32; */
   1817     Int24_To_Int32,                /* PaUtilConverter *Int24_To_Int32; */
   1818     Int24_To_Int16,                /* PaUtilConverter *Int24_To_Int16; */
   1819     Int24_To_Int16_Dither,         /* PaUtilConverter *Int24_To_Int16_Dither; */
   1820     Int24_To_Int8,                 /* PaUtilConverter *Int24_To_Int8; */
   1821     Int24_To_Int8_Dither,          /* PaUtilConverter *Int24_To_Int8_Dither; */
   1822     Int24_To_UInt8,                /* PaUtilConverter *Int24_To_UInt8; */
   1823     Int24_To_UInt8_Dither,         /* PaUtilConverter *Int24_To_UInt8_Dither; */
   1824 
   1825     Int16_To_Float32,              /* PaUtilConverter *Int16_To_Float32; */
   1826     Int16_To_Int32,                /* PaUtilConverter *Int16_To_Int32; */
   1827     Int16_To_Int24,                /* PaUtilConverter *Int16_To_Int24; */
   1828     Int16_To_Int8,                 /* PaUtilConverter *Int16_To_Int8; */
   1829     Int16_To_Int8_Dither,          /* PaUtilConverter *Int16_To_Int8_Dither; */
   1830     Int16_To_UInt8,                /* PaUtilConverter *Int16_To_UInt8; */
   1831     Int16_To_UInt8_Dither,         /* PaUtilConverter *Int16_To_UInt8_Dither; */
   1832 
   1833     Int8_To_Float32,               /* PaUtilConverter *Int8_To_Float32; */
   1834     Int8_To_Int32,                 /* PaUtilConverter *Int8_To_Int32; */
   1835     Int8_To_Int24,                 /* PaUtilConverter *Int8_To_Int24 */
   1836     Int8_To_Int16,                 /* PaUtilConverter *Int8_To_Int16; */
   1837     Int8_To_UInt8,                 /* PaUtilConverter *Int8_To_UInt8; */
   1838 
   1839     UInt8_To_Float32,              /* PaUtilConverter *UInt8_To_Float32; */
   1840     UInt8_To_Int32,                /* PaUtilConverter *UInt8_To_Int32; */
   1841     UInt8_To_Int24,                /* PaUtilConverter *UInt8_To_Int24; */
   1842     UInt8_To_Int16,                /* PaUtilConverter *UInt8_To_Int16; */
   1843     UInt8_To_Int8,                 /* PaUtilConverter *UInt8_To_Int8; */
   1844 
   1845     Copy_8_To_8,                   /* PaUtilConverter *Copy_8_To_8; */
   1846     Copy_16_To_16,                 /* PaUtilConverter *Copy_16_To_16; */
   1847     Copy_24_To_24,                 /* PaUtilConverter *Copy_24_To_24; */
   1848     Copy_32_To_32                  /* PaUtilConverter *Copy_32_To_32; */
   1849 };
   1850 
   1851 /* -------------------------------------------------------------------------- */
   1852 
   1853 #endif /* PA_NO_STANDARD_CONVERTERS */
   1854 
   1855 /* -------------------------------------------------------------------------- */
   1856 
   1857 PaUtilZeroer* PaUtil_SelectZeroer( PaSampleFormat destinationFormat )
   1858 {
   1859     switch( destinationFormat & ~paNonInterleaved ){
   1860     case paFloat32:
   1861         return paZeroers.Zero32;
   1862     case paInt32:
   1863         return paZeroers.Zero32;
   1864     case paInt24:
   1865         return paZeroers.Zero24;
   1866     case paInt16:
   1867         return paZeroers.Zero16;
   1868     case paInt8:
   1869         return paZeroers.Zero8;
   1870     case paUInt8:
   1871         return paZeroers.ZeroU8;
   1872     default: return 0;
   1873     }
   1874 }
   1875 
   1876 /* -------------------------------------------------------------------------- */
   1877 
   1878 #ifdef PA_NO_STANDARD_ZEROERS
   1879 
   1880 /* -------------------------------------------------------------------------- */
   1881 
   1882 PaUtilZeroerTable paZeroers = {
   1883     0,  /* PaUtilZeroer *ZeroU8; */
   1884     0,  /* PaUtilZeroer *Zero8; */
   1885     0,  /* PaUtilZeroer *Zero16; */
   1886     0,  /* PaUtilZeroer *Zero24; */
   1887     0,  /* PaUtilZeroer *Zero32; */
   1888 };
   1889 
   1890 /* -------------------------------------------------------------------------- */
   1891 
   1892 #else /* PA_NO_STANDARD_ZEROERS is not defined */
   1893 
   1894 /* -------------------------------------------------------------------------- */
   1895 
   1896 static void ZeroU8( void *destinationBuffer, signed int destinationStride,
   1897         unsigned int count )
   1898 {
   1899     unsigned char *dest = (unsigned char*)destinationBuffer;
   1900 
   1901     while( count-- )
   1902     {
   1903         *dest = 128;
   1904 
   1905         dest += destinationStride;
   1906     }
   1907 }
   1908 
   1909 /* -------------------------------------------------------------------------- */
   1910 
   1911 static void Zero8( void *destinationBuffer, signed int destinationStride,
   1912         unsigned int count )
   1913 {
   1914     unsigned char *dest = (unsigned char*)destinationBuffer;
   1915 
   1916     while( count-- )
   1917     {
   1918         *dest = 0;
   1919 
   1920         dest += destinationStride;
   1921     }
   1922 }
   1923 
   1924 /* -------------------------------------------------------------------------- */
   1925 
   1926 static void Zero16( void *destinationBuffer, signed int destinationStride,
   1927         unsigned int count )
   1928 {
   1929     PaUint16 *dest = (PaUint16 *)destinationBuffer;
   1930 
   1931     while( count-- )
   1932     {
   1933         *dest = 0;
   1934 
   1935         dest += destinationStride;
   1936     }
   1937 }
   1938 
   1939 /* -------------------------------------------------------------------------- */
   1940 
   1941 static void Zero24( void *destinationBuffer, signed int destinationStride,
   1942         unsigned int count )
   1943 {
   1944     unsigned char *dest = (unsigned char*)destinationBuffer;
   1945 
   1946     while( count-- )
   1947     {
   1948         dest[0] = 0;
   1949         dest[1] = 0;
   1950         dest[2] = 0;
   1951 
   1952         dest += destinationStride * 3;
   1953     }
   1954 }
   1955 
   1956 /* -------------------------------------------------------------------------- */
   1957 
   1958 static void Zero32( void *destinationBuffer, signed int destinationStride,
   1959         unsigned int count )
   1960 {
   1961     PaUint32 *dest = (PaUint32 *)destinationBuffer;
   1962 
   1963     while( count-- )
   1964     {
   1965         *dest = 0;
   1966 
   1967         dest += destinationStride;
   1968     }
   1969 }
   1970 
   1971 /* -------------------------------------------------------------------------- */
   1972 
   1973 PaUtilZeroerTable paZeroers = {
   1974     ZeroU8,  /* PaUtilZeroer *ZeroU8; */
   1975     Zero8,  /* PaUtilZeroer *Zero8; */
   1976     Zero16,  /* PaUtilZeroer *Zero16; */
   1977     Zero24,  /* PaUtilZeroer *Zero24; */
   1978     Zero32,  /* PaUtilZeroer *Zero32; */
   1979 };
   1980 
   1981 /* -------------------------------------------------------------------------- */
   1982 
   1983 #endif /* PA_NO_STANDARD_ZEROERS */