6d06b4bb03175095539764167540e30f27088c30
2 ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU Lesser General Public License as published by
6 ** the Free Software Foundation; either version 2.1 of the License, or
7 ** (at your option) any later version.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU Lesser General Public License for more details.
14 ** You should have received a copy of the GNU Lesser General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 static sf_count_t
alaw_read_alaw2s (SF_PRIVATE
*psf
, short *ptr
, sf_count_t len
) ;
27 static sf_count_t
alaw_read_alaw2i (SF_PRIVATE
*psf
, int *ptr
, sf_count_t len
) ;
28 static sf_count_t
alaw_read_alaw2f (SF_PRIVATE
*psf
, float *ptr
, sf_count_t len
) ;
29 static sf_count_t
alaw_read_alaw2d (SF_PRIVATE
*psf
, double *ptr
, sf_count_t len
) ;
31 static sf_count_t
alaw_write_s2alaw (SF_PRIVATE
*psf
, const short *ptr
, sf_count_t len
) ;
32 static sf_count_t
alaw_write_i2alaw (SF_PRIVATE
*psf
, const int *ptr
, sf_count_t len
) ;
33 static sf_count_t
alaw_write_f2alaw (SF_PRIVATE
*psf
, const float *ptr
, sf_count_t len
) ;
34 static sf_count_t
alaw_write_d2alaw (SF_PRIVATE
*psf
, const double *ptr
, sf_count_t len
) ;
36 static void alaw2s_array (unsigned char *buffer
, int count
, short *ptr
) ;
37 static void alaw2i_array (unsigned char *buffer
, int count
, int *ptr
) ;
38 static void alaw2f_array (unsigned char *buffer
, int count
, float *ptr
, float normfact
) ;
39 static void alaw2d_array (unsigned char *buffer
, int count
, double *ptr
, double normfact
) ;
41 static void s2alaw_array (const short *buffer
, int count
, unsigned char *ptr
) ;
42 static void i2alaw_array (const int *buffer
, int count
, unsigned char *ptr
) ;
43 static void f2alaw_array (const float *buffer
, int count
, unsigned char *ptr
, float normfact
) ;
44 static void d2alaw_array (const double *buffer
, int count
, unsigned char *ptr
, double normfact
) ;
48 alaw_init (SF_PRIVATE
*psf
)
50 if (psf
->file
.mode
== SFM_READ
|| psf
->file
.mode
== SFM_RDWR
)
51 { psf
->read_short
= alaw_read_alaw2s
;
52 psf
->read_int
= alaw_read_alaw2i
;
53 psf
->read_float
= alaw_read_alaw2f
;
54 psf
->read_double
= alaw_read_alaw2d
;
57 if (psf
->file
.mode
== SFM_WRITE
|| psf
->file
.mode
== SFM_RDWR
)
58 { psf
->write_short
= alaw_write_s2alaw
;
59 psf
->write_int
= alaw_write_i2alaw
;
60 psf
->write_float
= alaw_write_f2alaw
;
61 psf
->write_double
= alaw_write_d2alaw
;
65 psf
->blockwidth
= psf
->sf
.channels
;
67 if (psf
->filelength
> psf
->dataoffset
)
68 psf
->datalength
= (psf
->dataend
) ? psf
->dataend
- psf
->dataoffset
: psf
->filelength
- psf
->dataoffset
;
72 psf
->sf
.frames
= psf
->blockwidth
> 0 ? psf
->datalength
/ psf
->blockwidth
: 0 ;
77 /*==============================================================================
78 * Private static functions and data.
82 short alaw_decode
[256] =
83 { -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
84 -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
85 -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
86 -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392,
87 -22016, -20992, -24064, -23040, -17920, -16896, -19968, -18944,
88 -30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136,
89 -11008, -10496, -12032, -11520, -8960, -8448, -9984, -9472,
90 -15104, -14592, -16128, -15616, -13056, -12544, -14080, -13568,
91 -344, -328, -376, -360, -280, -264, -312, -296,
92 -472, -456, -504, -488, -408, -392, -440, -424,
93 -88, -72, -120, -104, -24, -8, -56, -40,
94 -216, -200, -248, -232, -152, -136, -184, -168,
95 -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184,
96 -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696,
97 -688, -656, -752, -720, -560, -528, -624, -592,
98 -944, -912, -1008, -976, -816, -784, -880, -848,
99 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
100 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
101 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
102 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
103 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
104 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
105 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
106 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
107 344, 328, 376, 360, 280, 264, 312, 296,
108 472, 456, 504, 488, 408, 392, 440, 424,
109 88, 72, 120, 104, 24, 8, 56, 40,
110 216, 200, 248, 232, 152, 136, 184, 168,
111 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
112 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
113 688, 656, 752, 720, 560, 528, 624, 592,
114 944, 912, 1008, 976, 816, 784, 880, 848
115 } ; /* alaw_decode */
118 unsigned char alaw_encode
[2048 + 1] =
119 { 0xd5, 0xd4, 0xd7, 0xd6, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde,
120 0xd9, 0xd8, 0xdb, 0xda, 0xc5, 0xc4, 0xc7, 0xc6, 0xc1, 0xc0, 0xc3, 0xc2,
121 0xcd, 0xcc, 0xcf, 0xce, 0xc9, 0xc8, 0xcb, 0xca, 0xf5, 0xf5, 0xf4, 0xf4,
122 0xf7, 0xf7, 0xf6, 0xf6, 0xf1, 0xf1, 0xf0, 0xf0, 0xf3, 0xf3, 0xf2, 0xf2,
123 0xfd, 0xfd, 0xfc, 0xfc, 0xff, 0xff, 0xfe, 0xfe, 0xf9, 0xf9, 0xf8, 0xf8,
124 0xfb, 0xfb, 0xfa, 0xfa, 0xe5, 0xe5, 0xe5, 0xe5, 0xe4, 0xe4, 0xe4, 0xe4,
125 0xe7, 0xe7, 0xe7, 0xe7, 0xe6, 0xe6, 0xe6, 0xe6, 0xe1, 0xe1, 0xe1, 0xe1,
126 0xe0, 0xe0, 0xe0, 0xe0, 0xe3, 0xe3, 0xe3, 0xe3, 0xe2, 0xe2, 0xe2, 0xe2,
127 0xed, 0xed, 0xed, 0xed, 0xec, 0xec, 0xec, 0xec, 0xef, 0xef, 0xef, 0xef,
128 0xee, 0xee, 0xee, 0xee, 0xe9, 0xe9, 0xe9, 0xe9, 0xe8, 0xe8, 0xe8, 0xe8,
129 0xeb, 0xeb, 0xeb, 0xeb, 0xea, 0xea, 0xea, 0xea, 0x95, 0x95, 0x95, 0x95,
130 0x95, 0x95, 0x95, 0x95, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94,
131 0x97, 0x97, 0x97, 0x97, 0x97, 0x97, 0x97, 0x97, 0x96, 0x96, 0x96, 0x96,
132 0x96, 0x96, 0x96, 0x96, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91,
133 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x93, 0x93, 0x93, 0x93,
134 0x93, 0x93, 0x93, 0x93, 0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0x92,
135 0x9d, 0x9d, 0x9d, 0x9d, 0x9d, 0x9d, 0x9d, 0x9d, 0x9c, 0x9c, 0x9c, 0x9c,
136 0x9c, 0x9c, 0x9c, 0x9c, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f,
137 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x99, 0x99, 0x99, 0x99,
138 0x99, 0x99, 0x99, 0x99, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98,
139 0x9b, 0x9b, 0x9b, 0x9b, 0x9b, 0x9b, 0x9b, 0x9b, 0x9a, 0x9a, 0x9a, 0x9a,
140 0x9a, 0x9a, 0x9a, 0x9a, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85,
141 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x84, 0x84, 0x84, 0x84,
142 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84,
143 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87,
144 0x87, 0x87, 0x87, 0x87, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86,
145 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x81, 0x81, 0x81, 0x81,
146 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
147 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
148 0x80, 0x80, 0x80, 0x80, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83,
149 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x82, 0x82, 0x82, 0x82,
150 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82,
151 0x8d, 0x8d, 0x8d, 0x8d, 0x8d, 0x8d, 0x8d, 0x8d, 0x8d, 0x8d, 0x8d, 0x8d,
152 0x8d, 0x8d, 0x8d, 0x8d, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c,
153 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8f, 0x8f, 0x8f, 0x8f,
154 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8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xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
239 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
240 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3,
241 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa3, 0xa2, 0xa2, 0xa2, 0xa2,
242 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2,
243 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2,
244 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2,
245 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2,
246 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2, 0xa2,
247 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad,
248 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad,
249 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad,
250 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad,
251 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad,
252 0xad, 0xad, 0xad, 0xad, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac,
253 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac,
254 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac,
255 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac,
256 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac,
257 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xaf, 0xaf, 0xaf, 0xaf,
258 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf,
259 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf,
260 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf,
261 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf,
262 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf, 0xaf,
263 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
264 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
265 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
266 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
267 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
268 0xae, 0xae, 0xae, 0xae, 0xa9, 0xa9, 0xa9, 0xa9, 0xa9, 0xa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 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
284 0xab, 0xab, 0xab, 0xab, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
285 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
286 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
287 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
288 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
289 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x2a
290 } ; /* alaw_encode */
293 alaw2s_array (unsigned char *buffer
, int count
, short *ptr
)
294 { while (--count
>= 0)
295 ptr
[count
] = alaw_decode
[(int) buffer
[count
]] ;
299 alaw2i_array (unsigned char *buffer
, int count
, int *ptr
)
300 { while (--count
>= 0)
301 ptr
[count
] = alaw_decode
[(int) buffer
[count
]] << 16 ;
305 alaw2f_array (unsigned char *buffer
, int count
, float *ptr
, float normfact
)
306 { while (--count
>= 0)
307 ptr
[count
] = normfact
* alaw_decode
[(int) buffer
[count
]] ;
311 alaw2d_array (unsigned char *buffer
, int count
, double *ptr
, double normfact
)
312 { while (--count
>= 0)
313 ptr
[count
] = normfact
* alaw_decode
[(int) buffer
[count
]] ;
317 s2alaw_array (const short *ptr
, int count
, unsigned char *buffer
)
318 { while (--count
>= 0)
319 { if (ptr
[count
] >= 0)
320 buffer
[count
] = alaw_encode
[ptr
[count
] / 16] ;
322 buffer
[count
] = 0x7F & alaw_encode
[ptr
[count
] / -16] ;
327 i2alaw_array (const int *ptr
, int count
, unsigned char *buffer
)
328 { while (--count
>= 0)
329 { if (ptr
[count
] >= 0)
330 buffer
[count
] = alaw_encode
[ptr
[count
] >> (16 + 4)] ;
332 buffer
[count
] = 0x7F & alaw_encode
[- ptr
[count
] >> (16 + 4)] ;
337 f2alaw_array (const float *ptr
, int count
, unsigned char *buffer
, float normfact
)
338 { while (--count
>= 0)
339 { if (ptr
[count
] >= 0)
340 buffer
[count
] = alaw_encode
[lrintf (normfact
* ptr
[count
])] ;
342 buffer
[count
] = 0x7F & alaw_encode
[- lrintf (normfact
* ptr
[count
])] ;
347 d2alaw_array (const double *ptr
, int count
, unsigned char *buffer
, double normfact
)
348 { while (--count
>= 0)
349 { if (ptr
[count
] >= 0)
350 buffer
[count
] = alaw_encode
[lrint (normfact
* ptr
[count
])] ;
352 buffer
[count
] = 0x7F & alaw_encode
[- lrint (normfact
* ptr
[count
])] ;
356 /*==============================================================================
360 alaw_read_alaw2s (SF_PRIVATE
*psf
, short *ptr
, sf_count_t len
)
361 { int bufferlen
, readcount
;
362 sf_count_t total
= 0 ;
364 bufferlen
= ARRAY_LEN (psf
->u
.ucbuf
) ;
367 { if (len
< bufferlen
)
368 bufferlen
= (int) len
;
369 readcount
= psf_fread (psf
->u
.ucbuf
, 1, bufferlen
, psf
) ;
370 alaw2s_array (psf
->u
.ucbuf
, readcount
, ptr
+ total
) ;
372 if (readcount
< bufferlen
)
378 } /* alaw_read_alaw2s */
381 alaw_read_alaw2i (SF_PRIVATE
*psf
, int *ptr
, sf_count_t len
)
382 { int bufferlen
, readcount
;
383 sf_count_t total
= 0 ;
385 bufferlen
= ARRAY_LEN (psf
->u
.ucbuf
) ;
388 { if (len
< bufferlen
)
389 bufferlen
= (int) len
;
390 readcount
= psf_fread (psf
->u
.ucbuf
, 1, bufferlen
, psf
) ;
391 alaw2i_array (psf
->u
.ucbuf
, readcount
, ptr
+ total
) ;
393 if (readcount
< bufferlen
)
399 } /* alaw_read_alaw2i */
402 alaw_read_alaw2f (SF_PRIVATE
*psf
, float *ptr
, sf_count_t len
)
403 { int bufferlen
, readcount
;
404 sf_count_t total
= 0 ;
407 normfact
= (psf
->norm_float
== SF_TRUE
) ? 1.0 / ((float) 0x8000) : 1.0 ;
409 bufferlen
= ARRAY_LEN (psf
->u
.ucbuf
) ;
412 { if (len
< bufferlen
)
413 bufferlen
= (int) len
;
414 readcount
= psf_fread (psf
->u
.ucbuf
, 1, bufferlen
, psf
) ;
415 alaw2f_array (psf
->u
.ucbuf
, readcount
, ptr
+ total
, normfact
) ;
417 if (readcount
< bufferlen
)
423 } /* alaw_read_alaw2f */
426 alaw_read_alaw2d (SF_PRIVATE
*psf
, double *ptr
, sf_count_t len
)
427 { int bufferlen
, readcount
;
428 sf_count_t total
= 0 ;
431 normfact
= (psf
->norm_double
) ? 1.0 / ((double) 0x8000) : 1.0 ;
432 bufferlen
= ARRAY_LEN (psf
->u
.ucbuf
) ;
435 { if (len
< bufferlen
)
436 bufferlen
= (int) len
;
437 readcount
= psf_fread (psf
->u
.ucbuf
, 1, bufferlen
, psf
) ;
438 alaw2d_array (psf
->u
.ucbuf
, readcount
, ptr
+ total
, normfact
) ;
440 if (readcount
< bufferlen
)
446 } /* alaw_read_alaw2d */
448 /*=============================================================================================
452 alaw_write_s2alaw (SF_PRIVATE
*psf
, const short *ptr
, sf_count_t len
)
453 { int bufferlen
, writecount
;
454 sf_count_t total
= 0 ;
456 bufferlen
= ARRAY_LEN (psf
->u
.ucbuf
) ;
459 { if (len
< bufferlen
)
460 bufferlen
= (int) len
;
461 s2alaw_array (ptr
+ total
, bufferlen
, psf
->u
.ucbuf
) ;
462 writecount
= psf_fwrite (psf
->u
.ucbuf
, 1, bufferlen
, psf
) ;
463 total
+= writecount
;
464 if (writecount
< bufferlen
)
470 } /* alaw_write_s2alaw */
473 alaw_write_i2alaw (SF_PRIVATE
*psf
, const int *ptr
, sf_count_t len
)
474 { int bufferlen
, writecount
;
475 sf_count_t total
= 0 ;
477 bufferlen
= ARRAY_LEN (psf
->u
.ucbuf
) ;
480 { if (len
< bufferlen
)
481 bufferlen
= (int) len
;
482 i2alaw_array (ptr
+ total
, bufferlen
, psf
->u
.ucbuf
) ;
483 writecount
= psf_fwrite (psf
->u
.ucbuf
, 1, bufferlen
, psf
) ;
484 total
+= writecount
;
485 if (writecount
< bufferlen
)
491 } /* alaw_write_i2alaw */
494 alaw_write_f2alaw (SF_PRIVATE
*psf
, const float *ptr
, sf_count_t len
)
495 { int bufferlen
, writecount
;
496 sf_count_t total
= 0 ;
499 normfact
= (psf
->norm_float
== SF_TRUE
) ? (1.0 * 0x7FFF) / 16.0 : 1.0 / 16 ;
501 bufferlen
= ARRAY_LEN (psf
->u
.ucbuf
) ;
504 { if (len
< bufferlen
)
505 bufferlen
= (int) len
;
506 f2alaw_array (ptr
+ total
, bufferlen
, psf
->u
.ucbuf
, normfact
) ;
507 writecount
= psf_fwrite (psf
->u
.ucbuf
, 1, bufferlen
, psf
) ;
508 total
+= writecount
;
509 if (writecount
< bufferlen
)
515 } /* alaw_write_f2alaw */
518 alaw_write_d2alaw (SF_PRIVATE
*psf
, const double *ptr
, sf_count_t len
)
519 { int bufferlen
, writecount
;
520 sf_count_t total
= 0 ;
523 normfact
= (psf
->norm_double
) ? (1.0 * 0x7FFF) / 16.0 : 1.0 / 16.0 ;
525 bufferlen
= ARRAY_LEN (psf
->u
.ucbuf
) ;
528 { if (len
< bufferlen
)
529 bufferlen
= (int) len
;
530 d2alaw_array (ptr
+ total
, bufferlen
, psf
->u
.ucbuf
, normfact
) ;
531 writecount
= psf_fwrite (psf
->u
.ucbuf
, 1, bufferlen
, psf
) ;
532 total
+= writecount
;
533 if (writecount
< bufferlen
)
539 } /* alaw_write_d2alaw */