~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/third_party/portaudio/src/common/pa_converters.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

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