Coverage Report

Created: 2025-07-18 06:14

/src/libsndfile/src/common.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
** Copyright (C) 1999-2018 Erik de Castro Lopo <erikd@mega-nerd.com>
3
**
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.
8
**
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.
13
**
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.
17
*/
18
19
#ifndef SNDFILE_COMMON_H
20
#define SNDFILE_COMMON_H
21
22
#include "sfconfig.h"
23
24
#include <stdlib.h>
25
#include <string.h>
26
#if HAVE_STDBOOL_H
27
#include <stdbool.h>
28
#endif
29
30
#if HAVE_INTTYPES_H
31
#include <inttypes.h>
32
#elif HAVE_STDINT_H
33
#include <stdint.h>
34
#endif
35
#if HAVE_SYS_TYPES_H
36
#include <sys/types.h>
37
#endif
38
39
#ifndef SNDFILE_H
40
#include "sndfile.h"
41
#endif
42
43
#include <math.h>
44
45
#ifdef USE_SSE2
46
# ifdef _MSC_VER
47
#   include <intrin.h>
48
# else
49
#   include <immintrin.h>
50
# endif
51
#endif
52
53
#ifdef __cplusplus
54
#error "This code is not designed to be compiled with a C++ compiler."
55
#endif
56
57
58
59
/*
60
** Inspiration : http://sourcefrog.net/weblog/software/languages/C/unused.html
61
*/
62
#ifdef UNUSED
63
#elif defined (__GNUC__)
64
# define UNUSED(x) UNUSED_ ## x __attribute__ ((unused))
65
#elif defined (__LCLINT__)
66
# define UNUSED(x) /*@unused@*/ x
67
#else
68
# define UNUSED(x) x
69
#endif
70
71
#ifdef __GNUC__
72
# define WARN_UNUSED  __attribute__ ((warn_unused_result))
73
#else
74
# define WARN_UNUSED
75
#endif
76
77
1.81k
#define SF_BUFFER_LEN     (8192)
78
#define SF_FILENAME_LEN     (1024)
79
#define SF_SYSERR_LEN     (256)
80
311k
#define SF_MAX_STRINGS      (32)
81
#define SF_PARSELOG_LEN     (2048)
82
83
6
#define PSF_SEEK_ERROR      ((sf_count_t) -1)
84
85
96.9k
#define BITWIDTH2BYTES(x) (((x) + 7) / 8)
86
87
/*  For some reason sizeof returns an unsigned  value which causes
88
**  a warning when that value is added or subtracted from a signed
89
**  value. Use SIGNED_SIZEOF instead.
90
*/
91
822M
#define   SIGNED_SIZEOF(x)  ((int) sizeof (x))
92
93
12.2M
#define   ARRAY_LEN(x)  ((int) (sizeof (x) / sizeof ((x) [0])))
94
95
2.99k
#define   SF_MAX(a, b)  ((a) > (b) ? (a) : (b))
96
30.3k
#define   SF_MIN(a, b)  ((a) < (b) ? (a) : (b))
97
98
99
#define   COMPILE_TIME_ASSERT(e)  (sizeof (struct { int : - !! (e) ; }))
100
101
102
21.2k
#define   SF_MAX_CHANNELS   1024
103
104
/*
105
* Macros for splitting the format file of SF_INFO into container type,
106
**  codec type and endian-ness.
107
*/
108
84.8k
#define SF_CONTAINER(x)   ((x) & SF_FORMAT_TYPEMASK)
109
42.2k
#define SF_CODEC(x)     ((x) & SF_FORMAT_SUBMASK)
110
2.03k
#define SF_ENDIAN(x)    ((x) & SF_FORMAT_ENDMASK)
111
112
/*
113
**  Binheader cast macros.
114
*/
115
116
0
#define BHW1(x) ((uint8_t) (x))
117
0
#define BHW2(x) ((uint16_t) (x))
118
0
#define BHW3(x) ((uint32_t) (x))
119
0
#define BHW4(x) ((uint32_t) (x))
120
0
#define BHW8(x) ((uint64_t) (x))
121
122
0
#define BHWm(x) ((uint32_t) (x))
123
0
#define BHWS(x) ((char *) (x))
124
125
0
#define BHWf(x) ((double) (x))
126
0
#define BHWd(x) ((double) (x))
127
128
0
#define BHWh(x) ((void *) (x))
129
19
#define BHWj(x) ((size_t) (x))
130
0
#define BHWp(x) ((char *) (x))
131
0
#define BHWo(x) ((size_t) (x))
132
0
#define BHWs(x) ((char *) (x))
133
88
#define BHWv(x) ((const void *) (x))
134
88
#define BHWz(x) ((size_t) (x))
135
136
/*------------------------------------------------------------------------------
137
*/
138
139
enum
140
{ /* PEAK chunk location. */
141
  SF_PEAK_START   = 42,
142
  SF_PEAK_END     = 43,
143
144
  /* PEAK chunk location. */
145
  SF_SCALE_MAX    = 52,
146
  SF_SCALE_MIN    = 53,
147
148
  /* str_flags values. */
149
  SF_STR_ALLOW_START  = 0x0100,
150
  SF_STR_ALLOW_END  = 0x0200,
151
152
  /* Location of strings. */
153
  SF_STR_LOCATE_START = 0x0400,
154
  SF_STR_LOCATE_END = 0x0800,
155
156
  SFD_TYPEMASK    = 0x0FFFFFFF
157
} ;
158
159
0
#define   SFM_MASK  (SFM_READ | SFM_WRITE | SFM_RDWR)
160
#define   SFM_UNMASK  (~SFM_MASK)
161
162
/*---------------------------------------------------------------------------------------
163
** Formats that may be supported at some time in the future.
164
** When support is finalised, these values move to src/sndfile.h.
165
*/
166
167
enum
168
{ /* Work in progress. */
169
  SF_FORMAT_SPEEX     = 0x5000000,
170
  SF_FORMAT_OGGFLAC   = 0x5000001,
171
172
  /* Formats supported read only. */
173
  SF_FORMAT_TXW     = 0x4030000,    /* Yamaha TX16 sampler file */
174
  SF_FORMAT_DWD     = 0x4040000,    /* DiamondWare Digirized */
175
176
  /* Following are detected but not supported. */
177
  SF_FORMAT_REX     = 0x40A0000,    /* Propellorheads Rex/Rcy */
178
  SF_FORMAT_REX2      = 0x40D0000,    /* Propellorheads Rex2 */
179
  SF_FORMAT_KRZ     = 0x40E0000,    /* Kurzweil sampler file */
180
  SF_FORMAT_WMA     = 0x4100000,    /* Windows Media Audio. */
181
  SF_FORMAT_SHN     = 0x4110000,    /* Shorten. */
182
183
  /* Unsupported encodings. */
184
  SF_FORMAT_SVX_FIB   = 0x1020,     /* SVX Fibonacci Delta encoding. */
185
  SF_FORMAT_SVX_EXP   = 0x1021,     /* SVX Exponential Delta encoding. */
186
187
  SF_FORMAT_PCM_N     = 0x1030
188
} ;
189
190
/*---------------------------------------------------------------------------------------
191
*/
192
193
typedef struct
194
{ unsigned  kuki_offset ;
195
  unsigned  pakt_offset ;
196
197
  unsigned  bits_per_sample ;
198
  unsigned  frames_per_packet ;
199
200
  int64_t   packets ;
201
  int64_t   valid_frames ;
202
  int32_t   priming_frames ;
203
  int32_t   remainder_frames ;
204
} ALAC_DECODER_INFO ;
205
206
/*---------------------------------------------------------------------------------------
207
**  PEAK_CHUNK - This chunk type is common to both AIFF and WAVE files although their
208
**  endian encodings are different.
209
*/
210
211
typedef struct
212
{ double    value ;   /* signed value of peak */
213
  sf_count_t  position ;  /* the sample frame for the peak */
214
} PEAK_POS ;
215
216
typedef struct
217
{ /* libsndfile internal : write a PEAK chunk at the start or end of the file? */
218
  int       peak_loc ;
219
220
  /* WAV/AIFF */
221
  unsigned int  version ; /* version of the PEAK chunk */
222
  unsigned int  timestamp ; /* secs since 1/1/1970  */
223
224
  /* CAF */
225
  unsigned int  edit_number ;
226
227
  /* the per channel peak info */
228
  PEAK_POS    peaks [] ;
229
} PEAK_INFO ;
230
231
static inline PEAK_INFO *
232
peak_info_calloc (int channels)
233
8.53k
{ return calloc (1, sizeof (PEAK_INFO) + channels * sizeof (PEAK_POS)) ;
234
8.53k
} /* peak_info_calloc */
Unexecuted instantiation: sndfile.c:peak_info_calloc
aiff.c:peak_info_calloc
Line
Count
Source
233
260
{ return calloc (1, sizeof (PEAK_INFO) + channels * sizeof (PEAK_POS)) ;
234
260
} /* peak_info_calloc */
Unexecuted instantiation: au.c:peak_info_calloc
Unexecuted instantiation: avr.c:peak_info_calloc
caf.c:peak_info_calloc
Line
Count
Source
233
257
{ return calloc (1, sizeof (PEAK_INFO) + channels * sizeof (PEAK_POS)) ;
234
257
} /* peak_info_calloc */
Unexecuted instantiation: dwd.c:peak_info_calloc
Unexecuted instantiation: flac.c:peak_info_calloc
Unexecuted instantiation: g72x.c:peak_info_calloc
Unexecuted instantiation: htk.c:peak_info_calloc
Unexecuted instantiation: ircam.c:peak_info_calloc
Unexecuted instantiation: mat4.c:peak_info_calloc
Unexecuted instantiation: mat5.c:peak_info_calloc
Unexecuted instantiation: nist.c:peak_info_calloc
Unexecuted instantiation: paf.c:peak_info_calloc
Unexecuted instantiation: pvf.c:peak_info_calloc
Unexecuted instantiation: raw.c:peak_info_calloc
Unexecuted instantiation: rx2.c:peak_info_calloc
Unexecuted instantiation: sd2.c:peak_info_calloc
Unexecuted instantiation: sds.c:peak_info_calloc
Unexecuted instantiation: svx.c:peak_info_calloc
Unexecuted instantiation: txw.c:peak_info_calloc
Unexecuted instantiation: voc.c:peak_info_calloc
Unexecuted instantiation: wve.c:peak_info_calloc
Unexecuted instantiation: w64.c:peak_info_calloc
wavlike.c:peak_info_calloc
Line
Count
Source
233
8.02k
{ return calloc (1, sizeof (PEAK_INFO) + channels * sizeof (PEAK_POS)) ;
234
8.02k
} /* peak_info_calloc */
Unexecuted instantiation: wav.c:peak_info_calloc
Unexecuted instantiation: xi.c:peak_info_calloc
Unexecuted instantiation: mpc2k.c:peak_info_calloc
Unexecuted instantiation: rf64.c:peak_info_calloc
Unexecuted instantiation: ogg.c:peak_info_calloc
Unexecuted instantiation: mpeg.c:peak_info_calloc
Unexecuted instantiation: alac.c:peak_info_calloc
Unexecuted instantiation: alaw.c:peak_info_calloc
Unexecuted instantiation: audio_detect.c:peak_info_calloc
Unexecuted instantiation: broadcast.c:peak_info_calloc
Unexecuted instantiation: cart.c:peak_info_calloc
Unexecuted instantiation: chanmap.c:peak_info_calloc
Unexecuted instantiation: chunk.c:peak_info_calloc
Unexecuted instantiation: command.c:peak_info_calloc
Unexecuted instantiation: common.c:peak_info_calloc
Unexecuted instantiation: dither.c:peak_info_calloc
Unexecuted instantiation: double64.c:peak_info_calloc
Unexecuted instantiation: dwvw.c:peak_info_calloc
Unexecuted instantiation: file_io.c:peak_info_calloc
Unexecuted instantiation: float32.c:peak_info_calloc
Unexecuted instantiation: gsm610.c:peak_info_calloc
Unexecuted instantiation: id3.c:peak_info_calloc
Unexecuted instantiation: ima_adpcm.c:peak_info_calloc
Unexecuted instantiation: ms_adpcm.c:peak_info_calloc
Unexecuted instantiation: nms_adpcm.c:peak_info_calloc
Unexecuted instantiation: pcm.c:peak_info_calloc
Unexecuted instantiation: strings.c:peak_info_calloc
Unexecuted instantiation: ulaw.c:peak_info_calloc
Unexecuted instantiation: vox_adpcm.c:peak_info_calloc
Unexecuted instantiation: ima_oki_adpcm.c:peak_info_calloc
235
236
typedef struct
237
{ int   type ;
238
  int   flags ;
239
  size_t  offset ;
240
} STR_DATA ;
241
242
typedef struct
243
{ uint64_t  hash ;
244
  char    id [64] ;
245
  unsigned  id_size ;
246
  uint32_t  mark32 ;
247
  sf_count_t  offset ;
248
  uint32_t  len ;
249
} READ_CHUNK ;
250
251
typedef struct
252
{ uint64_t  hash ;
253
  uint32_t  mark32 ;
254
  uint32_t  len ;
255
  void    *data ;
256
} WRITE_CHUNK ;
257
258
typedef struct
259
{ uint32_t  count ;
260
  uint32_t  used ;
261
  READ_CHUNK  *chunks ;
262
} READ_CHUNKS ;
263
typedef struct
264
{ uint32_t  count ;
265
  uint32_t  used ;
266
  WRITE_CHUNK *chunks ;
267
} WRITE_CHUNKS ;
268
269
struct SF_CHUNK_ITERATOR
270
{ uint32_t  current ;
271
  int64_t   hash ;
272
  char    id [64] ;
273
  unsigned  id_size ;
274
  SNDFILE   *sndfile ;
275
} ;
276
277
static inline size_t
278
make_size_t (int x)
279
5.91k
{ return (size_t) x ;
280
5.91k
} /* make_size_t */
Unexecuted instantiation: sndfile.c:make_size_t
aiff.c:make_size_t
Line
Count
Source
279
3.52k
{ return (size_t) x ;
280
3.52k
} /* make_size_t */
Unexecuted instantiation: au.c:make_size_t
Unexecuted instantiation: avr.c:make_size_t
Unexecuted instantiation: caf.c:make_size_t
Unexecuted instantiation: dwd.c:make_size_t
Unexecuted instantiation: flac.c:make_size_t
Unexecuted instantiation: g72x.c:make_size_t
Unexecuted instantiation: htk.c:make_size_t
Unexecuted instantiation: ircam.c:make_size_t
Unexecuted instantiation: mat4.c:make_size_t
Unexecuted instantiation: mat5.c:make_size_t
Unexecuted instantiation: nist.c:make_size_t
Unexecuted instantiation: paf.c:make_size_t
Unexecuted instantiation: pvf.c:make_size_t
Unexecuted instantiation: raw.c:make_size_t
Unexecuted instantiation: rx2.c:make_size_t
Unexecuted instantiation: sd2.c:make_size_t
Unexecuted instantiation: sds.c:make_size_t
Unexecuted instantiation: svx.c:make_size_t
Unexecuted instantiation: txw.c:make_size_t
Unexecuted instantiation: voc.c:make_size_t
Unexecuted instantiation: wve.c:make_size_t
Unexecuted instantiation: w64.c:make_size_t
wavlike.c:make_size_t
Line
Count
Source
279
2.36k
{ return (size_t) x ;
280
2.36k
} /* make_size_t */
Unexecuted instantiation: wav.c:make_size_t
Unexecuted instantiation: xi.c:make_size_t
mpc2k.c:make_size_t
Line
Count
Source
279
22
{ return (size_t) x ;
280
22
} /* make_size_t */
Unexecuted instantiation: rf64.c:make_size_t
Unexecuted instantiation: ogg.c:make_size_t
Unexecuted instantiation: mpeg.c:make_size_t
Unexecuted instantiation: alac.c:make_size_t
Unexecuted instantiation: alaw.c:make_size_t
Unexecuted instantiation: audio_detect.c:make_size_t
Unexecuted instantiation: broadcast.c:make_size_t
Unexecuted instantiation: cart.c:make_size_t
Unexecuted instantiation: chanmap.c:make_size_t
Unexecuted instantiation: chunk.c:make_size_t
Unexecuted instantiation: command.c:make_size_t
Unexecuted instantiation: common.c:make_size_t
Unexecuted instantiation: dither.c:make_size_t
Unexecuted instantiation: double64.c:make_size_t
Unexecuted instantiation: dwvw.c:make_size_t
Unexecuted instantiation: file_io.c:make_size_t
Unexecuted instantiation: float32.c:make_size_t
Unexecuted instantiation: gsm610.c:make_size_t
Unexecuted instantiation: id3.c:make_size_t
Unexecuted instantiation: ima_adpcm.c:make_size_t
Unexecuted instantiation: ms_adpcm.c:make_size_t
Unexecuted instantiation: nms_adpcm.c:make_size_t
Unexecuted instantiation: pcm.c:make_size_t
Unexecuted instantiation: strings.c:make_size_t
Unexecuted instantiation: ulaw.c:make_size_t
Unexecuted instantiation: vox_adpcm.c:make_size_t
Unexecuted instantiation: ima_oki_adpcm.c:make_size_t
281
282
typedef SF_BROADCAST_INFO_VAR (16 * 1024) SF_BROADCAST_INFO_16K ;
283
284
typedef SF_CART_INFO_VAR (16 * 1024) SF_CART_INFO_16K ;
285
286
typedef struct
287
{ sf_count_t  offset ;
288
  sf_count_t  len ;
289
  unsigned  minor_version ;
290
} ID3V2_HEADER_INFO ;
291
292
#if SIZEOF_WCHAR_T == 2
293
typedef wchar_t sfwchar_t ;
294
#else
295
typedef int16_t sfwchar_t ;
296
#endif
297
298
299
void *psf_memdup (const void *src, size_t n) ;
300
301
/*
302
**  This version of isprint specifically ignores any locale info. Its used for
303
**  determining which characters can be printed in things like hexdumps.
304
*/
305
int psf_isprint (int ch) ;
306
307
/*=======================================================================================
308
**  SF_PRIVATE struct - a pointer to this struct is passed back to the caller of the
309
**  sf_open_XXXX functions. The caller however has no knowledge of the struct's
310
**  contents.
311
*/
312
313
typedef struct
314
{
315
  char  path [SF_FILENAME_LEN] ;
316
  char  dir [SF_FILENAME_LEN] ;
317
  char  name [SF_FILENAME_LEN / 4] ;
318
319
#if USE_WINDOWS_API
320
  /*
321
  **  These fields can only be used in src/file_io.c.
322
  **  They are basically the same as a windows file HANDLE.
323
  */
324
  void  *handle, *hsaved ;
325
#else
326
  /* These fields can only be used in src/file_io.c. */
327
  int   filedes, savedes ;
328
#endif
329
330
  int   do_not_close_descriptor ;
331
  int   mode ;      /* Open mode : SFM_READ, SFM_WRITE or SFM_RDWR. */
332
} PSF_FILE ;
333
334
335
336
typedef union
337
{ double      dbuf  [SF_BUFFER_LEN / sizeof (double)] ;
338
#if (defined (SIZEOF_INT64_T) && (SIZEOF_INT64_T == 8))
339
  int64_t     lbuf  [SF_BUFFER_LEN / sizeof (int64_t)] ;
340
#else
341
  long      lbuf  [SF_BUFFER_LEN / sizeof (double)] ;
342
#endif
343
  float     fbuf  [SF_BUFFER_LEN / sizeof (float)] ;
344
  int       ibuf  [SF_BUFFER_LEN / sizeof (int)] ;
345
  short     sbuf  [SF_BUFFER_LEN / sizeof (short)] ;
346
  char      cbuf  [SF_BUFFER_LEN / sizeof (char)] ;
347
  signed char   scbuf [SF_BUFFER_LEN / sizeof (signed char)] ;
348
  unsigned char ucbuf [SF_BUFFER_LEN / sizeof (signed char)] ;
349
} BUF_UNION ;
350
351
352
353
typedef struct sf_private_tag
354
{
355
  PSF_FILE    file, rsrc ;
356
357
  char      syserr    [SF_SYSERR_LEN] ;
358
359
  /* parselog and indx should only be changed within the logging functions
360
  ** of common.c
361
  */
362
  struct
363
  { char      buf [SF_PARSELOG_LEN] ;
364
    int       indx ;
365
  } parselog ;
366
367
368
  struct
369
  { unsigned char * ptr ;
370
    sf_count_t    indx, end, len ;
371
  } header ;
372
373
  int       rwf_endian ;  /* Header endian-ness flag. */
374
375
  /* Storage and housekeeping data for adding/reading strings from
376
  ** sound files.
377
  */
378
  struct
379
  { STR_DATA  data [SF_MAX_STRINGS] ;
380
    char    *storage ;
381
    size_t    storage_len ;
382
    size_t    storage_used ;
383
    uint32_t  flags ;
384
  } strings ;
385
386
  /* Guard value. If this changes the buffers above have overflowed. */
387
  int       Magick ;
388
389
  unsigned    unique_id ;
390
391
  int       error ;
392
393
  int       endian ;    /* File endianness : SF_ENDIAN_LITTLE or SF_ENDIAN_BIG. */
394
  int       data_endswap ;  /* Need to endswap data? */
395
396
  /*
397
  ** Maximum float value for calculating the multiplier for
398
  ** float/double to short/int conversions.
399
  */
400
  int       float_int_mult ;
401
  float     float_max ;
402
403
  int       scale_int_float ;
404
405
  /* Variables for handling pipes. */
406
  int       is_pipe ;   /* True if file is a pipe. */
407
  sf_count_t    pipeoffset ;  /* Number of bytes read from a pipe. */
408
409
  /* True if clipping must be performed on float->int conversions. */
410
  int       add_clipping ;
411
412
  SF_INFO     sf ;
413
414
  int       have_written ;  /* Has a single write been done to the file? */
415
  PEAK_INFO   *peak_info ;
416
417
  /* Cue Marker Info */
418
  SF_CUES   *cues ;
419
420
  /* Loop Info */
421
  SF_LOOP_INFO  *loop_info ;
422
  SF_INSTRUMENT *instrument ;
423
424
  /* Broadcast (EBU) Info */
425
  SF_BROADCAST_INFO_16K *broadcast_16k ;
426
427
  /* Cart (AES46) Info */
428
  SF_CART_INFO_16K *cart_16k ;
429
430
  /* Channel map data (if present) : an array of ints. */
431
  int       *channel_map ;
432
433
  sf_count_t    filelength ;  /* Overall length of (embedded) file. */
434
  sf_count_t    fileoffset ;  /* Offset in number of bytes from beginning of file. */
435
436
  sf_count_t    rsrclength ;  /* Length of the resource fork (if it exists). */
437
438
  sf_count_t    dataoffset ;  /* Offset in number of bytes from beginning of file. */
439
  sf_count_t    datalength ;  /* Length in bytes of the audio data. */
440
  sf_count_t    dataend ;   /* Offset to file tailer. */
441
442
  sf_count_t    blockwidth ;  /* Size in bytes of one set of interleaved samples. */
443
  int       bytewidth ;   /* Size in bytes of one sample (one channel). */
444
445
  void      *dither ;
446
  void      *interleave ;
447
448
  int       last_op ;   /* Last operation; either SFM_READ or SFM_WRITE */
449
  sf_count_t    read_current ;
450
  sf_count_t    write_current ;
451
452
  void      *container_data ; /*  This is a pointer to dynamically allocated file
453
                    **  container format specific data.
454
                    */
455
456
  void      *codec_data ;   /*  This is a pointer to dynamically allocated file
457
                    **  codec format specific data.
458
                    */
459
460
  SF_DITHER_INFO  write_dither ;
461
  SF_DITHER_INFO  read_dither ;
462
463
  int       norm_double ;
464
  int       norm_float ;
465
466
  int       auto_header ;
467
468
  int       ieee_replace ;
469
470
  /* A set of file specific function pointers */
471
  sf_count_t    (*read_short) (struct sf_private_tag*, short *ptr, sf_count_t len) ;
472
  sf_count_t    (*read_int)   (struct sf_private_tag*, int *ptr, sf_count_t len) ;
473
  sf_count_t    (*read_float) (struct sf_private_tag*, float *ptr, sf_count_t len) ;
474
  sf_count_t    (*read_double)  (struct sf_private_tag*, double *ptr, sf_count_t len) ;
475
476
  sf_count_t    (*write_short)  (struct sf_private_tag*, const short *ptr, sf_count_t len) ;
477
  sf_count_t    (*write_int)  (struct sf_private_tag*, const int *ptr, sf_count_t len) ;
478
  sf_count_t    (*write_float)  (struct sf_private_tag*, const float *ptr, sf_count_t len) ;
479
  sf_count_t    (*write_double) (struct sf_private_tag*, const double *ptr, sf_count_t len) ;
480
481
  sf_count_t    (*seek)     (struct sf_private_tag*, int mode, sf_count_t samples_from_start) ;
482
  int       (*write_header) (struct sf_private_tag*, int calc_length) ;
483
  int       (*command)    (struct sf_private_tag*, int command, void *data, int datasize) ;
484
  int       (*byterate)   (struct sf_private_tag*) ;
485
486
  /*
487
  **  Separate close functions for the codec and the container.
488
  **  The codec close function is always called first.
489
  */
490
  int       (*codec_close)    (struct sf_private_tag*) ;
491
  int       (*container_close)  (struct sf_private_tag*) ;
492
493
  char      *format_desc ;
494
495
  /* Virtual I/O functions. */
496
  int         virtual_io ;
497
  SF_VIRTUAL_IO   vio ;
498
  void        *vio_user_data ;
499
500
  /* Chunk get/set. */
501
  SF_CHUNK_ITERATOR *iterator ;
502
503
  READ_CHUNKS     rchunks ;
504
  WRITE_CHUNKS    wchunks ;
505
506
  int         (*set_chunk)    (struct sf_private_tag*, const SF_CHUNK_INFO * chunk_info) ;
507
  SF_CHUNK_ITERATOR * (*next_chunk_iterator)  (struct sf_private_tag*, SF_CHUNK_ITERATOR * iterator) ;
508
  int         (*get_chunk_size) (struct sf_private_tag*, const SF_CHUNK_ITERATOR * iterator, SF_CHUNK_INFO * chunk_info) ;
509
  int         (*get_chunk_data) (struct sf_private_tag*, const SF_CHUNK_ITERATOR * iterator, SF_CHUNK_INFO * chunk_info) ;
510
511
  int cpu_flags ;
512
513
  ID3V2_HEADER_INFO id3_header ;
514
} SF_PRIVATE ;
515
516
517
518
enum
519
{ SFE_NO_ERROR        = SF_ERR_NO_ERROR,
520
  SFE_BAD_OPEN_FORMAT     = SF_ERR_UNRECOGNISED_FORMAT,
521
  SFE_SYSTEM          = SF_ERR_SYSTEM,
522
  SFE_MALFORMED_FILE      = SF_ERR_MALFORMED_FILE,
523
  SFE_UNSUPPORTED_ENCODING  = SF_ERR_UNSUPPORTED_ENCODING,
524
525
  SFE_ZERO_MAJOR_FORMAT,
526
  SFE_ZERO_MINOR_FORMAT,
527
  SFE_BAD_FILE,
528
  SFE_BAD_FILE_READ,
529
  SFE_OPEN_FAILED,
530
  SFE_BAD_SNDFILE_PTR,
531
  SFE_BAD_SF_INFO_PTR,
532
  SFE_BAD_SF_INCOMPLETE,
533
  SFE_BAD_FILE_PTR,
534
  SFE_BAD_INT_PTR,
535
  SFE_BAD_STAT_SIZE,
536
  SFE_NO_TEMP_DIR,
537
  SFE_MALLOC_FAILED,
538
  SFE_UNIMPLEMENTED,
539
  SFE_BAD_READ_ALIGN,
540
  SFE_BAD_WRITE_ALIGN,
541
  SFE_NOT_READMODE,
542
  SFE_NOT_WRITEMODE,
543
  SFE_BAD_MODE_RW,
544
  SFE_BAD_SF_INFO,
545
  SFE_BAD_OFFSET,
546
  SFE_NO_EMBED_SUPPORT,
547
  SFE_NO_EMBEDDED_RDWR,
548
  SFE_NO_PIPE_WRITE,
549
550
  SFE_INTERNAL,
551
  SFE_BAD_COMMAND_PARAM,
552
  SFE_BAD_ENDIAN,
553
  SFE_CHANNEL_COUNT_ZERO,
554
  SFE_CHANNEL_COUNT,
555
  SFE_CHANNEL_COUNT_BAD,
556
557
  SFE_BAD_VIRTUAL_IO,
558
559
  SFE_INTERLEAVE_MODE,
560
  SFE_INTERLEAVE_SEEK,
561
  SFE_INTERLEAVE_READ,
562
563
  SFE_BAD_SEEK,
564
  SFE_NOT_SEEKABLE,
565
  SFE_AMBIGUOUS_SEEK,
566
  SFE_WRONG_SEEK,
567
  SFE_SEEK_FAILED,
568
569
  SFE_BAD_OPEN_MODE,
570
  SFE_OPEN_PIPE_RDWR,
571
  SFE_RDWR_POSITION,
572
  SFE_RDWR_BAD_HEADER,
573
  SFE_CMD_HAS_DATA,
574
  SFE_BAD_BROADCAST_INFO_SIZE,
575
  SFE_BAD_BROADCAST_INFO_TOO_BIG,
576
  SFE_BAD_CART_INFO_SIZE,
577
  SFE_BAD_CART_INFO_TOO_BIG,
578
579
  SFE_STR_NO_SUPPORT,
580
  SFE_STR_NOT_WRITE,
581
  SFE_STR_MAX_DATA,
582
  SFE_STR_MAX_COUNT,
583
  SFE_STR_BAD_TYPE,
584
  SFE_STR_NO_ADD_END,
585
  SFE_STR_BAD_STRING,
586
  SFE_STR_WEIRD,
587
588
  SFE_WAV_NO_RIFF,
589
  SFE_WAV_NO_WAVE,
590
  SFE_WAV_NO_FMT,
591
  SFE_WAV_BAD_FMT,
592
  SFE_WAV_FMT_SHORT,
593
  SFE_WAV_BAD_FACT,
594
  SFE_WAV_BAD_PEAK,
595
  SFE_WAV_PEAK_B4_FMT,
596
  SFE_WAV_BAD_FORMAT,
597
  SFE_WAV_BAD_BLOCKALIGN,
598
  SFE_WAV_NO_DATA,
599
  SFE_WAV_BAD_LIST,
600
  SFE_WAV_ADPCM_NOT4BIT,
601
  SFE_WAV_ADPCM_CHANNELS,
602
  SFE_WAV_ADPCM_SAMPLES,
603
  SFE_WAV_GSM610_FORMAT,
604
  SFE_WAV_UNKNOWN_CHUNK,
605
  SFE_WAV_WVPK_DATA,
606
  SFE_WAV_NMS_FORMAT,
607
608
  SFE_AIFF_NO_FORM,
609
  SFE_AIFF_AIFF_NO_FORM,
610
  SFE_AIFF_COMM_NO_FORM,
611
  SFE_AIFF_SSND_NO_COMM,
612
  SFE_AIFF_UNKNOWN_CHUNK,
613
  SFE_AIFF_COMM_CHUNK_SIZE,
614
  SFE_AIFF_BAD_COMM_CHUNK,
615
  SFE_AIFF_PEAK_B4_COMM,
616
  SFE_AIFF_BAD_PEAK,
617
  SFE_AIFF_NO_SSND,
618
  SFE_AIFF_NO_DATA,
619
  SFE_AIFF_RW_SSND_NOT_LAST,
620
621
  SFE_AU_UNKNOWN_FORMAT,
622
  SFE_AU_NO_DOTSND,
623
  SFE_AU_EMBED_BAD_LEN,
624
625
  SFE_RAW_READ_BAD_SPEC,
626
  SFE_RAW_BAD_BITWIDTH,
627
  SFE_RAW_BAD_FORMAT,
628
629
  SFE_PAF_NO_MARKER,
630
  SFE_PAF_VERSION,
631
  SFE_PAF_UNKNOWN_FORMAT,
632
  SFE_PAF_SHORT_HEADER,
633
  SFE_PAF_BAD_CHANNELS,
634
635
  SFE_SVX_NO_FORM,
636
  SFE_SVX_NO_BODY,
637
  SFE_SVX_NO_DATA,
638
  SFE_SVX_BAD_COMP,
639
  SFE_SVX_BAD_NAME_LENGTH,
640
641
  SFE_NIST_BAD_HEADER,
642
  SFE_NIST_CRLF_CONVERISON,
643
  SFE_NIST_BAD_ENCODING,
644
645
  SFE_VOC_NO_CREATIVE,
646
  SFE_VOC_BAD_FORMAT,
647
  SFE_VOC_BAD_VERSION,
648
  SFE_VOC_BAD_MARKER,
649
  SFE_VOC_BAD_SECTIONS,
650
  SFE_VOC_MULTI_SAMPLERATE,
651
  SFE_VOC_MULTI_SECTION,
652
  SFE_VOC_MULTI_PARAM,
653
  SFE_VOC_SECTION_COUNT,
654
  SFE_VOC_NO_PIPE,
655
656
  SFE_IRCAM_NO_MARKER,
657
  SFE_IRCAM_BAD_CHANNELS,
658
  SFE_IRCAM_UNKNOWN_FORMAT,
659
660
  SFE_W64_64_BIT,
661
  SFE_W64_NO_RIFF,
662
  SFE_W64_NO_WAVE,
663
  SFE_W64_NO_DATA,
664
  SFE_W64_ADPCM_NOT4BIT,
665
  SFE_W64_ADPCM_CHANNELS,
666
  SFE_W64_GSM610_FORMAT,
667
668
  SFE_MAT4_BAD_NAME,
669
  SFE_MAT4_NO_SAMPLERATE,
670
671
  SFE_MAT5_BAD_ENDIAN,
672
  SFE_MAT5_NO_BLOCK,
673
  SFE_MAT5_SAMPLE_RATE,
674
675
  SFE_PVF_NO_PVF1,
676
  SFE_PVF_BAD_HEADER,
677
  SFE_PVF_BAD_BITWIDTH,
678
679
  SFE_DWVW_BAD_BITWIDTH,
680
  SFE_G72X_NOT_MONO,
681
  SFE_NMS_ADPCM_NOT_MONO,
682
683
  SFE_XI_BAD_HEADER,
684
  SFE_XI_EXCESS_SAMPLES,
685
  SFE_XI_NO_PIPE,
686
687
  SFE_HTK_NO_PIPE,
688
689
  SFE_SDS_NOT_SDS,
690
  SFE_SDS_BAD_BIT_WIDTH,
691
692
  SFE_SD2_FD_DISALLOWED,
693
  SFE_SD2_BAD_DATA_OFFSET,
694
  SFE_SD2_BAD_MAP_OFFSET,
695
  SFE_SD2_BAD_DATA_LENGTH,
696
  SFE_SD2_BAD_MAP_LENGTH,
697
  SFE_SD2_BAD_RSRC,
698
  SFE_SD2_BAD_SAMPLE_SIZE,
699
700
  SFE_FLAC_BAD_HEADER,
701
  SFE_FLAC_NEW_DECODER,
702
  SFE_FLAC_INIT_DECODER,
703
  SFE_FLAC_LOST_SYNC,
704
  SFE_FLAC_BAD_SAMPLE_RATE,
705
  SFE_FLAC_CHANNEL_COUNT_CHANGED,
706
  SFE_FLAC_UNKOWN_ERROR,
707
708
  SFE_WVE_NOT_WVE,
709
  SFE_WVE_NO_PIPE,
710
711
  SFE_VORBIS_ENCODER_BUG,
712
713
  SFE_RF64_NOT_RF64,
714
  SFE_RF64_PEAK_B4_FMT,
715
  SFE_RF64_NO_DATA,
716
717
  SFE_BAD_CHUNK_PTR,
718
  SFE_UNKNOWN_CHUNK,
719
  SFE_BAD_CHUNK_FORMAT,
720
  SFE_BAD_CHUNK_MARKER,
721
  SFE_BAD_CHUNK_DATA_PTR,
722
  SFE_ALAC_FAIL_TMPFILE,
723
  SFE_FILENAME_TOO_LONG,
724
  SFE_NEGATIVE_RW_LEN,
725
726
  SFE_OPUS_BAD_SAMPLERATE,
727
728
  SFE_CAF_NOT_CAF,
729
  SFE_CAF_NO_DESC,
730
  SFE_CAF_BAD_PEAK,
731
732
  SFE_AVR_NOT_AVR,
733
  SFE_AVR_BAD_REZ_SIGN,
734
735
  SFE_MPC_NO_MARKER,
736
737
  SFE_MPEG_BAD_SAMPLERATE,
738
739
  SFE_MAX_ERROR     /* This must be last in list. */
740
} ;
741
742
/* Allocate and initialize the SF_PRIVATE struct. */
743
SF_PRIVATE * psf_allocate (void) ;
744
745
int subformat_to_bytewidth (int format) ;
746
int s_bitwidth_to_subformat (int bits) ;
747
int u_bitwidth_to_subformat (int bits) ;
748
749
/*  Functions for reading and writing floats and doubles on processors
750
**  with non-IEEE floats/doubles.
751
*/
752
float float32_be_read   (const unsigned char *cptr) ;
753
float float32_le_read   (const unsigned char *cptr) ;
754
void  float32_be_write  (float in, unsigned char *out) ;
755
void  float32_le_write  (float in, unsigned char *out) ;
756
757
double  double64_be_read  (const unsigned char *cptr) ;
758
double  double64_le_read  (const unsigned char *cptr) ;
759
void  double64_be_write (double in, unsigned char *out) ;
760
void  double64_le_write (double in, unsigned char *out) ;
761
762
/* Functions for writing to the internal logging buffer. */
763
764
void  psf_log_printf    (SF_PRIVATE *psf, const char *format, ...) ;
765
void  psf_log_SF_INFO   (SF_PRIVATE *psf) ;
766
767
int32_t psf_rand_int32 (void) ;
768
769
void append_snprintf (char * dest, size_t maxlen, const char * fmt, ...) ;
770
void psf_strlcpy_crlf (char *dest, const char *src, size_t destmax, size_t srcmax) ;
771
772
sf_count_t psf_decode_frame_count (SF_PRIVATE *psf) ;
773
774
/* Functions used when writing file headers. */
775
776
int   psf_binheader_writef  (SF_PRIVATE *psf, const char *format, ...) ;
777
void  psf_asciiheader_printf  (SF_PRIVATE *psf, const char *format, ...) ;
778
779
/* Functions used when reading file headers. */
780
781
int   psf_binheader_readf (SF_PRIVATE *psf, char const *format, ...) ;
782
783
/* Functions used in the write function for updating the peak chunk. */
784
785
void  peak_update_short (SF_PRIVATE *psf, short *ptr, size_t items) ;
786
void  peak_update_int   (SF_PRIVATE *psf, int *ptr, size_t items) ;
787
void  peak_update_double  (SF_PRIVATE *psf, double *ptr, size_t items) ;
788
789
/* Functions defined in command.c. */
790
791
int   psf_get_format_simple_count (void) ;
792
int   psf_get_format_simple   (SF_FORMAT_INFO *data) ;
793
794
int   psf_get_format_info     (SF_FORMAT_INFO *data) ;
795
796
int   psf_get_format_major_count  (void) ;
797
int   psf_get_format_major    (SF_FORMAT_INFO *data) ;
798
799
int   psf_get_format_subtype_count  (void) ;
800
int   psf_get_format_subtype    (SF_FORMAT_INFO *data) ;
801
802
void  psf_generate_format_desc (SF_PRIVATE *psf) ;
803
804
double  psf_calc_signal_max     (SF_PRIVATE *psf, int normalize) ;
805
int   psf_calc_max_all_channels (SF_PRIVATE *psf, double *peaks, int normalize) ;
806
807
int   psf_get_signal_max      (SF_PRIVATE *psf, double *peak) ;
808
int   psf_get_max_all_channels  (SF_PRIVATE *psf, double *peaks) ;
809
810
/* Functions in strings.c. */
811
812
const char* psf_get_string (SF_PRIVATE *psf, int str_type) ;
813
int psf_set_string (SF_PRIVATE *psf, int str_type, const char *str) ;
814
int psf_store_string (SF_PRIVATE *psf, int str_type, const char *str) ;
815
int psf_location_string_count (const SF_PRIVATE * psf, int location) ;
816
817
/* Default seek function. Use for PCM and float encoded data. */
818
sf_count_t  psf_default_seek (SF_PRIVATE *psf, int mode, sf_count_t samples_from_start) ;
819
820
int macos_guess_file_type (SF_PRIVATE *psf, const char *filename) ;
821
822
/*------------------------------------------------------------------------------------
823
**  File I/O functions which will allow access to large files (> 2 Gig) on
824
**  some 32 bit OSes. Implementation in file_io.c.
825
*/
826
827
int psf_fopen (SF_PRIVATE *psf) ;
828
int psf_set_stdio (SF_PRIVATE *psf) ;
829
int psf_file_valid (SF_PRIVATE *psf) ;
830
void psf_set_file (SF_PRIVATE *psf, int fd) ;
831
void psf_init_files (SF_PRIVATE *psf) ;
832
void psf_use_rsrc (SF_PRIVATE *psf, int on_off) ;
833
834
SNDFILE * psf_open_file (SF_PRIVATE *psf, SF_INFO *sfinfo) ;
835
836
sf_count_t psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence) ;
837
sf_count_t psf_fread (void *ptr, sf_count_t bytes, sf_count_t count, SF_PRIVATE *psf) ;
838
sf_count_t psf_fwrite (const void *ptr, sf_count_t bytes, sf_count_t count, SF_PRIVATE *psf) ;
839
sf_count_t psf_fgets (char *buffer, sf_count_t bufsize, SF_PRIVATE *psf) ;
840
sf_count_t psf_ftell (SF_PRIVATE *psf) ;
841
sf_count_t psf_get_filelen (SF_PRIVATE *psf) ;
842
843
void psf_fsync (SF_PRIVATE *psf) ;
844
845
int psf_is_pipe (SF_PRIVATE *psf) ;
846
847
int psf_ftruncate (SF_PRIVATE *psf, sf_count_t len) ;
848
int psf_fclose (SF_PRIVATE *psf) ;
849
850
/* Open and close the resource fork of a file. */
851
int psf_open_rsrc (SF_PRIVATE *psf) ;
852
int psf_close_rsrc (SF_PRIVATE *psf) ;
853
854
int psf_copy_filename (SF_PRIVATE *psf, const char *path) ;
855
856
/*
857
void psf_fclearerr (SF_PRIVATE *psf) ;
858
int psf_ferror (SF_PRIVATE *psf) ;
859
*/
860
861
/*------------------------------------------------------------------------------------
862
** Functions for reading and writing different file formats.
863
*/
864
865
int   aiff_open (SF_PRIVATE *psf) ;
866
int   au_open   (SF_PRIVATE *psf) ;
867
int   avr_open  (SF_PRIVATE *psf) ;
868
int   htk_open  (SF_PRIVATE *psf) ;
869
int   ircam_open  (SF_PRIVATE *psf) ;
870
int   mat4_open (SF_PRIVATE *psf) ;
871
int   mat5_open (SF_PRIVATE *psf) ;
872
int   nist_open (SF_PRIVATE *psf) ;
873
int   paf_open  (SF_PRIVATE *psf) ;
874
int   pvf_open  (SF_PRIVATE *psf) ;
875
int   raw_open  (SF_PRIVATE *psf) ;
876
int   sd2_open  (SF_PRIVATE *psf) ;
877
int   sds_open  (SF_PRIVATE *psf) ;
878
int   svx_open  (SF_PRIVATE *psf) ;
879
int   voc_open  (SF_PRIVATE *psf) ;
880
int   w64_open  (SF_PRIVATE *psf) ;
881
int   wav_open  (SF_PRIVATE *psf) ;
882
int   xi_open   (SF_PRIVATE *psf) ;
883
int   flac_open (SF_PRIVATE *psf) ;
884
int   caf_open  (SF_PRIVATE *psf) ;
885
int   mpc2k_open  (SF_PRIVATE *psf) ;
886
int   rf64_open (SF_PRIVATE *psf) ;
887
888
int   ogg_vorbis_open (SF_PRIVATE *psf) ;
889
int   ogg_speex_open  (SF_PRIVATE *psf) ;
890
int   ogg_pcm_open  (SF_PRIVATE *psf) ;
891
int   ogg_opus_open (SF_PRIVATE *psf) ;
892
int   ogg_open  (SF_PRIVATE *psf) ;
893
894
int   mpeg_open (SF_PRIVATE *psf) ;
895
896
/* In progress. Do not currently work. */
897
898
int   rx2_open  (SF_PRIVATE *psf) ;
899
int   txw_open  (SF_PRIVATE *psf) ;
900
int   wve_open  (SF_PRIVATE *psf) ;
901
int   dwd_open  (SF_PRIVATE *psf) ;
902
903
/*------------------------------------------------------------------------------------
904
**  Init functions for a number of common data encodings.
905
*/
906
907
int   pcm_init    (SF_PRIVATE *psf) ;
908
int   ulaw_init   (SF_PRIVATE *psf) ;
909
int   alaw_init   (SF_PRIVATE *psf) ;
910
int   float32_init  (SF_PRIVATE *psf) ;
911
int   double64_init (SF_PRIVATE *psf) ;
912
int   dwvw_init   (SF_PRIVATE *psf, int bitwidth) ;
913
int   gsm610_init   (SF_PRIVATE *psf) ;
914
int   nms_adpcm_init  (SF_PRIVATE *psf) ;
915
int   vox_adpcm_init  (SF_PRIVATE *psf) ;
916
int   flac_init   (SF_PRIVATE *psf) ;
917
int   g72x_init     (SF_PRIVATE * psf) ;
918
int   alac_init   (SF_PRIVATE *psf, const ALAC_DECODER_INFO * info) ;
919
int   mpeg_init   (SF_PRIVATE *psf, int bitrate_mode, int write_metadata) ;
920
921
int   dither_init   (SF_PRIVATE *psf, int mode) ;
922
923
int   wavlike_ima_init (SF_PRIVATE *psf, int blockalign, int samplesperblock) ;
924
int   wavlike_msadpcm_init (SF_PRIVATE *psf, int blockalign, int samplesperblock) ;
925
926
int   aiff_ima_init (SF_PRIVATE *psf, int blockalign, int samplesperblock) ;
927
928
int   interleave_init (SF_PRIVATE *psf) ;
929
930
/*------------------------------------------------------------------------------------
931
** Chunk logging functions.
932
*/
933
934
SF_CHUNK_ITERATOR * psf_get_chunk_iterator (SF_PRIVATE * psf, const char * marker_str) ;
935
SF_CHUNK_ITERATOR * psf_next_chunk_iterator (const READ_CHUNKS * pchk , SF_CHUNK_ITERATOR *iterator) ;
936
int   psf_store_read_chunk_u32 (READ_CHUNKS * pchk, uint32_t marker, sf_count_t offset, uint32_t len) ;
937
int   psf_store_read_chunk_str (READ_CHUNKS * pchk, const char * marker, sf_count_t offset, uint32_t len) ;
938
int   psf_save_write_chunk (WRITE_CHUNKS * pchk, const SF_CHUNK_INFO * chunk_info) ;
939
int   psf_find_read_chunk_str (const READ_CHUNKS * pchk, const char * marker) ;
940
int   psf_find_read_chunk_m32 (const READ_CHUNKS * pchk, uint32_t marker) ;
941
int   psf_find_read_chunk_iterator (const READ_CHUNKS * pchk, const SF_CHUNK_ITERATOR * marker) ;
942
943
int   psf_find_write_chunk (WRITE_CHUNKS * pchk, const char * marker) ;
944
945
/*------------------------------------------------------------------------------------
946
** Functions that work like OpenBSD's strlcpy/strlcat to replace strncpy/strncat.
947
**
948
** See : http://www.gratisoft.us/todd/papers/strlcpy.html
949
**
950
** These functions are available on *BSD, but are not available everywhere so we
951
** implement them here.
952
**
953
** The argument order has been changed to that of strncpy/strncat to cause
954
** compiler errors if code is carelessly converted from one to the other.
955
*/
956
957
void psf_strlcat (char *dest, size_t n, const char *src) ;
958
void psf_strlcpy (char *dest, size_t n, const char *src) ;
959
960
/*------------------------------------------------------------------------------------
961
** SIMD optimized math functions.
962
*/
963
964
static inline int psf_lrintf (float x)
965
2.95M
{
966
2.95M
  #ifdef USE_SSE2
967
2.95M
    return _mm_cvtss_si32 (_mm_load_ss (&x)) ;
968
  #else
969
    return lrintf (x) ;
970
  #endif
971
2.95M
} /* psf_lrintf */
Unexecuted instantiation: sndfile.c:psf_lrintf
Unexecuted instantiation: aiff.c:psf_lrintf
Unexecuted instantiation: au.c:psf_lrintf
Unexecuted instantiation: avr.c:psf_lrintf
Unexecuted instantiation: caf.c:psf_lrintf
Unexecuted instantiation: dwd.c:psf_lrintf
Unexecuted instantiation: flac.c:psf_lrintf
Unexecuted instantiation: g72x.c:psf_lrintf
Unexecuted instantiation: htk.c:psf_lrintf
Unexecuted instantiation: ircam.c:psf_lrintf
Unexecuted instantiation: mat4.c:psf_lrintf
Unexecuted instantiation: mat5.c:psf_lrintf
Unexecuted instantiation: nist.c:psf_lrintf
Unexecuted instantiation: paf.c:psf_lrintf
Unexecuted instantiation: pvf.c:psf_lrintf
Unexecuted instantiation: raw.c:psf_lrintf
Unexecuted instantiation: rx2.c:psf_lrintf
Unexecuted instantiation: sd2.c:psf_lrintf
Unexecuted instantiation: sds.c:psf_lrintf
Unexecuted instantiation: svx.c:psf_lrintf
Unexecuted instantiation: txw.c:psf_lrintf
Unexecuted instantiation: voc.c:psf_lrintf
Unexecuted instantiation: wve.c:psf_lrintf
Unexecuted instantiation: w64.c:psf_lrintf
Unexecuted instantiation: wavlike.c:psf_lrintf
Unexecuted instantiation: wav.c:psf_lrintf
Unexecuted instantiation: xi.c:psf_lrintf
Unexecuted instantiation: mpc2k.c:psf_lrintf
Unexecuted instantiation: rf64.c:psf_lrintf
Unexecuted instantiation: ogg.c:psf_lrintf
Unexecuted instantiation: mpeg.c:psf_lrintf
Unexecuted instantiation: alac.c:psf_lrintf
Unexecuted instantiation: alaw.c:psf_lrintf
Unexecuted instantiation: audio_detect.c:psf_lrintf
Unexecuted instantiation: broadcast.c:psf_lrintf
Unexecuted instantiation: cart.c:psf_lrintf
Unexecuted instantiation: chanmap.c:psf_lrintf
Unexecuted instantiation: chunk.c:psf_lrintf
Unexecuted instantiation: command.c:psf_lrintf
Unexecuted instantiation: common.c:psf_lrintf
Unexecuted instantiation: dither.c:psf_lrintf
Unexecuted instantiation: double64.c:psf_lrintf
Unexecuted instantiation: dwvw.c:psf_lrintf
Unexecuted instantiation: file_io.c:psf_lrintf
float32.c:psf_lrintf
Line
Count
Source
965
2.95M
{
966
2.95M
  #ifdef USE_SSE2
967
2.95M
    return _mm_cvtss_si32 (_mm_load_ss (&x)) ;
968
  #else
969
    return lrintf (x) ;
970
  #endif
971
2.95M
} /* psf_lrintf */
Unexecuted instantiation: gsm610.c:psf_lrintf
Unexecuted instantiation: id3.c:psf_lrintf
Unexecuted instantiation: ima_adpcm.c:psf_lrintf
Unexecuted instantiation: ms_adpcm.c:psf_lrintf
Unexecuted instantiation: nms_adpcm.c:psf_lrintf
Unexecuted instantiation: pcm.c:psf_lrintf
Unexecuted instantiation: strings.c:psf_lrintf
Unexecuted instantiation: ulaw.c:psf_lrintf
Unexecuted instantiation: vox_adpcm.c:psf_lrintf
Unexecuted instantiation: ima_oki_adpcm.c:psf_lrintf
972
973
static inline int psf_lrint (double x)
974
1.71M
{
975
1.71M
  #ifdef USE_SSE2
976
1.71M
    return _mm_cvtsd_si32 (_mm_load_sd (&x)) ;
977
  #else
978
    return lrint (x) ;
979
  #endif
980
1.71M
} /* psf_lrintf */
Unexecuted instantiation: sndfile.c:psf_lrint
Unexecuted instantiation: aiff.c:psf_lrint
Unexecuted instantiation: au.c:psf_lrint
Unexecuted instantiation: avr.c:psf_lrint
caf.c:psf_lrint
Line
Count
Source
974
2.49k
{
975
2.49k
  #ifdef USE_SSE2
976
2.49k
    return _mm_cvtsd_si32 (_mm_load_sd (&x)) ;
977
  #else
978
    return lrint (x) ;
979
  #endif
980
2.49k
} /* psf_lrintf */
Unexecuted instantiation: dwd.c:psf_lrint
Unexecuted instantiation: flac.c:psf_lrint
Unexecuted instantiation: g72x.c:psf_lrint
Unexecuted instantiation: htk.c:psf_lrint
Unexecuted instantiation: ircam.c:psf_lrint
mat4.c:psf_lrint
Line
Count
Source
974
651
{
975
651
  #ifdef USE_SSE2
976
651
    return _mm_cvtsd_si32 (_mm_load_sd (&x)) ;
977
  #else
978
    return lrint (x) ;
979
  #endif
980
651
} /* psf_lrintf */
mat5.c:psf_lrint
Line
Count
Source
974
1
{
975
1
  #ifdef USE_SSE2
976
1
    return _mm_cvtsd_si32 (_mm_load_sd (&x)) ;
977
  #else
978
    return lrint (x) ;
979
  #endif
980
1
} /* psf_lrintf */
Unexecuted instantiation: nist.c:psf_lrint
Unexecuted instantiation: paf.c:psf_lrint
Unexecuted instantiation: pvf.c:psf_lrint
Unexecuted instantiation: raw.c:psf_lrint
Unexecuted instantiation: rx2.c:psf_lrint
Unexecuted instantiation: sd2.c:psf_lrint
Unexecuted instantiation: sds.c:psf_lrint
Unexecuted instantiation: svx.c:psf_lrint
Unexecuted instantiation: txw.c:psf_lrint
Unexecuted instantiation: voc.c:psf_lrint
Unexecuted instantiation: wve.c:psf_lrint
Unexecuted instantiation: w64.c:psf_lrint
Unexecuted instantiation: wavlike.c:psf_lrint
Unexecuted instantiation: wav.c:psf_lrint
Unexecuted instantiation: xi.c:psf_lrint
Unexecuted instantiation: mpc2k.c:psf_lrint
Unexecuted instantiation: rf64.c:psf_lrint
Unexecuted instantiation: ogg.c:psf_lrint
Unexecuted instantiation: mpeg.c:psf_lrint
Unexecuted instantiation: alac.c:psf_lrint
Unexecuted instantiation: alaw.c:psf_lrint
Unexecuted instantiation: audio_detect.c:psf_lrint
Unexecuted instantiation: broadcast.c:psf_lrint
Unexecuted instantiation: cart.c:psf_lrint
Unexecuted instantiation: chanmap.c:psf_lrint
Unexecuted instantiation: chunk.c:psf_lrint
Unexecuted instantiation: command.c:psf_lrint
Unexecuted instantiation: common.c:psf_lrint
Unexecuted instantiation: dither.c:psf_lrint
double64.c:psf_lrint
Line
Count
Source
974
1.70M
{
975
1.70M
  #ifdef USE_SSE2
976
1.70M
    return _mm_cvtsd_si32 (_mm_load_sd (&x)) ;
977
  #else
978
    return lrint (x) ;
979
  #endif
980
1.70M
} /* psf_lrintf */
Unexecuted instantiation: dwvw.c:psf_lrint
Unexecuted instantiation: file_io.c:psf_lrint
Unexecuted instantiation: float32.c:psf_lrint
Unexecuted instantiation: gsm610.c:psf_lrint
Unexecuted instantiation: id3.c:psf_lrint
Unexecuted instantiation: ima_adpcm.c:psf_lrint
Unexecuted instantiation: ms_adpcm.c:psf_lrint
Unexecuted instantiation: nms_adpcm.c:psf_lrint
Unexecuted instantiation: pcm.c:psf_lrint
Unexecuted instantiation: strings.c:psf_lrint
Unexecuted instantiation: ulaw.c:psf_lrint
Unexecuted instantiation: vox_adpcm.c:psf_lrint
Unexecuted instantiation: ima_oki_adpcm.c:psf_lrint
981
982
/*------------------------------------------------------------------------------------
983
** Other helper functions.
984
*/
985
986
void  *psf_memset (void *s, int c, sf_count_t n) ;
987
988
SF_CUES * psf_cues_dup (const void * ptr, size_t datasize) ;
989
SF_CUES * psf_cues_alloc (uint32_t cue_count) ;
990
void psf_get_cues (SF_PRIVATE * psf, void * data, size_t datasize) ;
991
992
SF_INSTRUMENT * psf_instrument_alloc (void) ;
993
994
void  psf_sanitize_string (char * cptr, int len) ;
995
996
/* Generate the current date as a string. */
997
void  psf_get_date_str (char *str, int maxlen) ;
998
999
SF_BROADCAST_INFO_16K * broadcast_var_alloc (void) ;
1000
int   broadcast_var_set (SF_PRIVATE *psf, const SF_BROADCAST_INFO * data, size_t datasize) ;
1001
int   broadcast_var_get (SF_PRIVATE *psf, SF_BROADCAST_INFO * data, size_t datasize) ;
1002
1003
1004
SF_CART_INFO_16K * cart_var_alloc (void) ;
1005
int     cart_var_set (SF_PRIVATE *psf, const SF_CART_INFO * date, size_t datasize) ;
1006
int   cart_var_get (SF_PRIVATE *psf, SF_CART_INFO * data, size_t datasize) ;
1007
1008
typedef struct
1009
{ int channels ;
1010
  int endianness ;
1011
} AUDIO_DETECT ;
1012
1013
int audio_detect (SF_PRIVATE * psf, AUDIO_DETECT *ad, const unsigned char * data, int datalen) ;
1014
int id3_skip (SF_PRIVATE * psf) ;
1015
const char *id3_lookup_v1_genre (int number) ;
1016
1017
void  alac_get_desc_chunk_items (int subformat, uint32_t *fmt_flags, uint32_t *frames_per_packet) ;
1018
1019
FILE *  psf_open_tmpfile (char * fname, size_t fnamelen) ;
1020
1021
/*------------------------------------------------------------------------------------
1022
** Helper/debug functions.
1023
*/
1024
1025
void  psf_hexdump (const void *ptr, int len) ;
1026
1027
const char * str_of_major_format (int format) ;
1028
const char * str_of_minor_format (int format) ;
1029
const char * str_of_open_mode (int mode) ;
1030
const char * str_of_endianness (int end) ;
1031
1032
/*------------------------------------------------------------------------------------
1033
** Extra commands for sf_command(). Not for public use yet.
1034
*/
1035
1036
enum
1037
{ SFC_TEST_AIFF_ADD_INST_CHUNK  = 0x2000,
1038
  SFC_TEST_WAV_ADD_INFO_CHUNK   = 0x2010
1039
} ;
1040
1041
/*
1042
** Maybe, one day, make these functions or something like them, public.
1043
**
1044
** Buffer to buffer dithering. Pointer in and out are allowed to point
1045
** to the same buffer for in-place dithering.
1046
*/
1047
1048
#if 0
1049
int sf_dither_short   (const SF_DITHER_INFO *dither, const short *in, short *out, int count) ;
1050
int sf_dither_int   (const SF_DITHER_INFO *dither, const int *in, int *out, int count) ;
1051
int sf_dither_float   (const SF_DITHER_INFO *dither, const float *in, float *out, int count) ;
1052
int sf_dither_double  (const SF_DITHER_INFO *dither, const double *in, double *out, int count) ;
1053
#endif
1054
1055
/*------------------------------------------------------------------------------------
1056
** Data conversion functions.
1057
*/
1058
1059
void psf_f2s_array (const float *src, short *dest, int count, int normalize) ;
1060
void psf_f2s_clip_array (const float *src, short *dest, int count, int normalize) ;
1061
1062
void psf_d2s_array (const double *src, short *dest, int count, int normalize) ;
1063
void psf_d2s_clip_array (const double *src, short *dest, int count, int normalize) ;
1064
1065
void psf_f2i_array (const float *src, int *dest, int count, int normalize) ;
1066
void psf_f2i_clip_array (const float *src, int *dest, int count, int normalize) ;
1067
1068
void psf_d2i_array (const double *src, int *dest, int count, int normalize) ;
1069
void psf_d2i_clip_array (const double *src, int *dest, int count, int normalize) ;
1070
1071
1072
/*------------------------------------------------------------------------------------
1073
** Left and right shift on int. According to the C standard, the left and right
1074
** shift operations applied to a negative integer results in undefined behavior.
1075
** These twp functions work around that.
1076
*/
1077
1078
#if __GNUC__
1079
#define ALWAYS_INLINE   __attribute__ ((always_inline))
1080
#else
1081
#define ALWAYS_INLINE
1082
#endif
1083
1084
static inline int32_t ALWAYS_INLINE
1085
arith_shift_left (int32_t x, int shift)
1086
282M
{ return (int32_t) (((uint32_t) x) << shift) ;
1087
282M
} /* arith_shift_left */
Unexecuted instantiation: sndfile.c:arith_shift_left
Unexecuted instantiation: aiff.c:arith_shift_left
Unexecuted instantiation: au.c:arith_shift_left
avr.c:arith_shift_left
Line
Count
Source
1086
138
{ return (int32_t) (((uint32_t) x) << shift) ;
1087
138
} /* arith_shift_left */
Unexecuted instantiation: caf.c:arith_shift_left
Unexecuted instantiation: dwd.c:arith_shift_left
Unexecuted instantiation: flac.c:arith_shift_left
g72x.c:arith_shift_left
Line
Count
Source
1086
2.53M
{ return (int32_t) (((uint32_t) x) << shift) ;
1087
2.53M
} /* arith_shift_left */
Unexecuted instantiation: htk.c:arith_shift_left
Unexecuted instantiation: ircam.c:arith_shift_left
Unexecuted instantiation: mat4.c:arith_shift_left
Unexecuted instantiation: mat5.c:arith_shift_left
Unexecuted instantiation: nist.c:arith_shift_left
Unexecuted instantiation: paf.c:arith_shift_left
Unexecuted instantiation: pvf.c:arith_shift_left
Unexecuted instantiation: raw.c:arith_shift_left
Unexecuted instantiation: rx2.c:arith_shift_left
Unexecuted instantiation: sd2.c:arith_shift_left
sds.c:arith_shift_left
Line
Count
Source
1086
218M
{ return (int32_t) (((uint32_t) x) << shift) ;
1087
218M
} /* arith_shift_left */
Unexecuted instantiation: svx.c:arith_shift_left
Unexecuted instantiation: txw.c:arith_shift_left
Unexecuted instantiation: voc.c:arith_shift_left
Unexecuted instantiation: wve.c:arith_shift_left
Unexecuted instantiation: w64.c:arith_shift_left
Unexecuted instantiation: wavlike.c:arith_shift_left
Unexecuted instantiation: wav.c:arith_shift_left
xi.c:arith_shift_left
Line
Count
Source
1086
8.52M
{ return (int32_t) (((uint32_t) x) << shift) ;
1087
8.52M
} /* arith_shift_left */
Unexecuted instantiation: mpc2k.c:arith_shift_left
Unexecuted instantiation: rf64.c:arith_shift_left
Unexecuted instantiation: ogg.c:arith_shift_left
Unexecuted instantiation: mpeg.c:arith_shift_left
Unexecuted instantiation: alac.c:arith_shift_left
Unexecuted instantiation: alaw.c:arith_shift_left
Unexecuted instantiation: audio_detect.c:arith_shift_left
Unexecuted instantiation: broadcast.c:arith_shift_left
Unexecuted instantiation: cart.c:arith_shift_left
Unexecuted instantiation: chanmap.c:arith_shift_left
Unexecuted instantiation: chunk.c:arith_shift_left
Unexecuted instantiation: command.c:arith_shift_left
Unexecuted instantiation: common.c:arith_shift_left
Unexecuted instantiation: dither.c:arith_shift_left
Unexecuted instantiation: double64.c:arith_shift_left
dwvw.c:arith_shift_left
Line
Count
Source
1086
25.2M
{ return (int32_t) (((uint32_t) x) << shift) ;
1087
25.2M
} /* arith_shift_left */
Unexecuted instantiation: file_io.c:arith_shift_left
Unexecuted instantiation: float32.c:arith_shift_left
gsm610.c:arith_shift_left
Line
Count
Source
1086
8.29M
{ return (int32_t) (((uint32_t) x) << shift) ;
1087
8.29M
} /* arith_shift_left */
Unexecuted instantiation: id3.c:arith_shift_left
ima_adpcm.c:arith_shift_left
Line
Count
Source
1086
2.29M
{ return (int32_t) (((uint32_t) x) << shift) ;
1087
2.29M
} /* arith_shift_left */
ms_adpcm.c:arith_shift_left
Line
Count
Source
1086
4.28M
{ return (int32_t) (((uint32_t) x) << shift) ;
1087
4.28M
} /* arith_shift_left */
nms_adpcm.c:arith_shift_left
Line
Count
Source
1086
2.70M
{ return (int32_t) (((uint32_t) x) << shift) ;
1087
2.70M
} /* arith_shift_left */
pcm.c:arith_shift_left
Line
Count
Source
1086
10.5M
{ return (int32_t) (((uint32_t) x) << shift) ;
1087
10.5M
} /* arith_shift_left */
Unexecuted instantiation: strings.c:arith_shift_left
Unexecuted instantiation: ulaw.c:arith_shift_left
Unexecuted instantiation: vox_adpcm.c:arith_shift_left
Unexecuted instantiation: ima_oki_adpcm.c:arith_shift_left
1088
1089
static inline int32_t ALWAYS_INLINE
1090
arith_shift_right (int32_t x, int shift)
1091
0
{ if (x >= 0)
1092
0
    return x >> shift ;
1093
0
  return ~ ((~x) >> shift) ;
1094
0
} /* arith_shift_right */
Unexecuted instantiation: sndfile.c:arith_shift_right
Unexecuted instantiation: aiff.c:arith_shift_right
Unexecuted instantiation: au.c:arith_shift_right
Unexecuted instantiation: avr.c:arith_shift_right
Unexecuted instantiation: caf.c:arith_shift_right
Unexecuted instantiation: dwd.c:arith_shift_right
Unexecuted instantiation: flac.c:arith_shift_right
Unexecuted instantiation: g72x.c:arith_shift_right
Unexecuted instantiation: htk.c:arith_shift_right
Unexecuted instantiation: ircam.c:arith_shift_right
Unexecuted instantiation: mat4.c:arith_shift_right
Unexecuted instantiation: mat5.c:arith_shift_right
Unexecuted instantiation: nist.c:arith_shift_right
Unexecuted instantiation: paf.c:arith_shift_right
Unexecuted instantiation: pvf.c:arith_shift_right
Unexecuted instantiation: raw.c:arith_shift_right
Unexecuted instantiation: rx2.c:arith_shift_right
Unexecuted instantiation: sd2.c:arith_shift_right
Unexecuted instantiation: sds.c:arith_shift_right
Unexecuted instantiation: svx.c:arith_shift_right
Unexecuted instantiation: txw.c:arith_shift_right
Unexecuted instantiation: voc.c:arith_shift_right
Unexecuted instantiation: wve.c:arith_shift_right
Unexecuted instantiation: w64.c:arith_shift_right
Unexecuted instantiation: wavlike.c:arith_shift_right
Unexecuted instantiation: wav.c:arith_shift_right
Unexecuted instantiation: xi.c:arith_shift_right
Unexecuted instantiation: mpc2k.c:arith_shift_right
Unexecuted instantiation: rf64.c:arith_shift_right
Unexecuted instantiation: ogg.c:arith_shift_right
Unexecuted instantiation: mpeg.c:arith_shift_right
Unexecuted instantiation: alac.c:arith_shift_right
Unexecuted instantiation: alaw.c:arith_shift_right
Unexecuted instantiation: audio_detect.c:arith_shift_right
Unexecuted instantiation: broadcast.c:arith_shift_right
Unexecuted instantiation: cart.c:arith_shift_right
Unexecuted instantiation: chanmap.c:arith_shift_right
Unexecuted instantiation: chunk.c:arith_shift_right
Unexecuted instantiation: command.c:arith_shift_right
Unexecuted instantiation: common.c:arith_shift_right
Unexecuted instantiation: dither.c:arith_shift_right
Unexecuted instantiation: double64.c:arith_shift_right
Unexecuted instantiation: dwvw.c:arith_shift_right
Unexecuted instantiation: file_io.c:arith_shift_right
Unexecuted instantiation: float32.c:arith_shift_right
Unexecuted instantiation: gsm610.c:arith_shift_right
Unexecuted instantiation: id3.c:arith_shift_right
Unexecuted instantiation: ima_adpcm.c:arith_shift_right
Unexecuted instantiation: ms_adpcm.c:arith_shift_right
Unexecuted instantiation: nms_adpcm.c:arith_shift_right
Unexecuted instantiation: pcm.c:arith_shift_right
Unexecuted instantiation: strings.c:arith_shift_right
Unexecuted instantiation: ulaw.c:arith_shift_right
Unexecuted instantiation: vox_adpcm.c:arith_shift_right
Unexecuted instantiation: ima_oki_adpcm.c:arith_shift_right
1095
1096
#endif /* SNDFILE_COMMON_H */