1 /* libSoX Library Public Interface
3 * Copyright 1999-2012 Chris Bagwell and SoX Contributors.
5 * This source code is freely redistributable and may be used for
6 * any purpose. This copyright notice must be maintained.
7 * Chris Bagwell And SoX Contributors are not responsible for
8 * the consequences of using this software.
12 Contains the interface exposed to clients of the libSoX library.
13 Symbols starting with "sox_" or "SOX_" are part of the public interface for
14 libSoX clients (applications that consume libSoX). Symbols starting with
15 "lsx_" or "LSX_" are internal use by libSoX and plugins.
16 LSX_ and lsx_ symbols should not be used by libSoX-based applications.
20 #define SOX_H /**< Client API: This macro is defined if sox.h has been included. */
27 #if defined(__cplusplus)
31 /* Suppress warnings from use of type long long. */
33 #pragma GCC system_header
37 #define LSX_GCC(maj, min) \
38 ((__GNUC__ > (maj)) || (__GNUC__ == (maj) && __GNUC_MINOR__ >= (min)))
40 #define LSX_GCC(maj, min) 0
44 #define _Ret_ __attribute__ ((returns_nonnull))
45 #define _Ret_valid_ _Ret_
49 /*****************************************************************************
50 API decoration macros:
51 Mostly for documentation purposes. For some compilers, decorations also affect
52 code generation, influence compiler warnings or activate compiler
54 *****************************************************************************/
58 Attribute required on all functions exported by libSoX and on all function
59 pointer types used by the libSoX API.
61 #if defined __GNUC__ && defined __i386__
62 #define LSX_API __attribute__ ((cdecl)) /* libSoX function */
64 #define LSX_API __cdecl /* libSoX function */
66 #define LSX_API /* libSoX function */
71 Attribute applied to a parameter or local variable to suppress warnings about
72 the variable being unused (especially in macro-generated code).
75 #define LSX_UNUSED __attribute__ ((unused)) /* Parameter or local variable is intentionally unused. */
77 #define LSX_UNUSED /* Parameter or local variable is intentionally unused. */
82 LSX_PRINTF12: Attribute applied to a function to indicate that it requires
83 a printf-style format string for arg1 and that printf parameters start at
87 #define LSX_PRINTF12 __attribute__ ((format (printf, 1, 2))) /* Function has printf-style arguments. */
89 #define LSX_PRINTF12 /* Function has printf-style arguments. */
94 Attribute applied to a function to indicate that it has no side effects and
95 depends only its input parameters and global memory. If called repeatedly, it
96 returns the same result each time.
99 #define LSX_RETURN_PURE __attribute__ ((pure)) /* Function is pure. */
101 #define LSX_RETURN_PURE /* Function is pure. */
106 Attribute applied to a function to indicate that the
107 return value is always a pointer to a valid object (never NULL).
110 #define LSX_RETURN_VALID _Ret_ /* Function always returns a valid object (never NULL). */
112 #define LSX_RETURN_VALID /* Function always returns a valid object (never NULL). */
117 Attribute applied to a function to indicate that the return value is always a
118 pointer to a valid array (never NULL).
121 #define LSX_RETURN_ARRAY _Ret_valid_ /* Function always returns a valid array (never NULL). */
123 #define LSX_RETURN_ARRAY /* Function always returns a valid array (never NULL). */
128 Attribute applied to a function to indicate that the return value is always a
129 pointer to a valid 0-terminated array (never NULL).
132 #define LSX_RETURN_VALID_Z _Ret_z_ /* Function always returns a 0-terminated array (never NULL). */
134 #define LSX_RETURN_VALID_Z /* Function always returns a 0-terminated array (never NULL). */
139 Attribute applied to a function to indicate that the returned pointer may be
143 #define LSX_RETURN_OPT _Ret_opt_ /* Function may return NULL. */
145 #define LSX_RETURN_OPT /* Function may return NULL. */
150 Attribute applied to a parameter to indicate that the parameter is a valid
151 pointer to one const element of the pointed-to type (never NULL).
154 #define LSX_PARAM_IN _In_ /* Required const pointer to a valid object (never NULL). */
156 #define LSX_PARAM_IN /* Required const pointer to a valid object (never NULL). */
161 Attribute applied to a parameter to indicate that the parameter is a valid
162 pointer to a const 0-terminated string (never NULL).
165 #define LSX_PARAM_IN_Z _In_z_ /* Required const pointer to 0-terminated string (never NULL). */
167 #define LSX_PARAM_IN_Z /* Required const pointer to 0-terminated string (never NULL). */
172 Attribute applied to a parameter to indicate that the parameter is a const
173 pointer to a 0-terminated printf format string.
175 #ifdef _Printf_format_string_
176 #define LSX_PARAM_IN_PRINTF _Printf_format_string_ /* Required const pointer to 0-terminated printf format string (never NULL). */
178 #define LSX_PARAM_IN_PRINTF /* Required const pointer to 0-terminated printf format string (never NULL). */
183 Attribute applied to a parameter to indicate that the parameter is a valid
184 pointer to (len) const initialized elements of the pointed-to type, where
185 (len) is the name of another parameter.
186 @param len The parameter that contains the number of elements in the array.
189 #define LSX_PARAM_IN_COUNT(len) _In_count_(len) /* Required const pointer to (len) valid objects (never NULL). */
191 #define LSX_PARAM_IN_COUNT(len) /* Required const pointer to (len) valid objects (never NULL). */
196 Attribute applied to a parameter to indicate that the parameter is a valid
197 pointer to (len) const bytes of initialized data, where (len) is the name of
199 @param len The parameter that contains the number of bytes in the array.
201 #ifdef _In_bytecount_
202 #define LSX_PARAM_IN_BYTECOUNT(len) _In_bytecount_(len) /* Required const pointer to (len) bytes of data (never NULL). */
204 #define LSX_PARAM_IN_BYTECOUNT(len) /* Required const pointer to (len) bytes of data (never NULL). */
209 Attribute applied to a parameter to indicate that the parameter is either NULL
210 or a valid pointer to one const element of the pointed-to type.
213 #define LSX_PARAM_IN_OPT _In_opt_ /* Optional const pointer to a valid object (may be NULL). */
215 #define LSX_PARAM_IN_OPT /* Optional const pointer to a valid object (may be NULL). */
220 Attribute applied to a parameter to indicate that the parameter is either NULL
221 or a valid pointer to a const 0-terminated string.
224 #define LSX_PARAM_IN_OPT_Z _In_opt_z_ /* Optional const pointer to 0-terminated string (may be NULL). */
226 #define LSX_PARAM_IN_OPT_Z /* Optional const pointer to 0-terminated string (may be NULL). */
231 Attribute applied to a parameter to indicate that the parameter is a valid
232 pointer to one initialized element of the pointed-to type (never NULL). The
233 function may modify the element.
236 #define LSX_PARAM_INOUT _Inout_ /* Required pointer to a valid object (never NULL). */
238 #define LSX_PARAM_INOUT /* Required pointer to a valid object (never NULL). */
243 Attribute applied to a parameter to indicate that the parameter is a valid
244 pointer to (len) initialized elements of the pointed-to type (never NULL). The
245 function may modify the elements.
246 @param len The parameter that contains the number of elements in the array.
248 #ifdef _Inout_count_x_
249 #define LSX_PARAM_INOUT_COUNT(len) _Inout_count_x_(len) /* Required pointer to (len) valid objects (never NULL). */
251 #define LSX_PARAM_INOUT_COUNT(len) /* Required pointer to (len) valid objects (never NULL). */
256 Attribute applied to a parameter to indicate that the parameter is a valid
257 pointer to memory sufficient for one element of the pointed-to type (never
258 NULL). The function will initialize the element.
261 #define LSX_PARAM_OUT _Out_ /* Required pointer to an object to be initialized (never NULL). */
263 #define LSX_PARAM_OUT /* Required pointer to an object to be initialized (never NULL). */
268 Attribute applied to a parameter to indicate that the parameter is a valid
269 pointer to memory sufficient for (len) bytes of data (never NULL), where (len)
270 is the name of another parameter. The function may write up to len bytes of
272 @param len The parameter that contains the number of bytes in the array.
275 #define LSX_PARAM_OUT_BYTECAP(len) _Out_bytecap_(len) /* Required pointer to writable buffer with room for len bytes. */
277 #define LSX_PARAM_OUT_BYTECAP(len) /* Required pointer to writable buffer with room for len bytes. */
282 Attribute applied to a parameter to indicate that the parameter is a valid
283 pointer to memory sufficient for (len) elements of the pointed-to type (never
284 NULL), where (len) is the name of another parameter. On return, (filled)
285 elements will have been initialized, where (filled) is either the dereference
286 of another pointer parameter (for example "*written") or the "return"
287 parameter (indicating that the function returns the number of elements
289 @param len The parameter that contains the number of elements in the array.
290 @param filled The dereference of the parameter that receives the number of elements written to the array, or "return" if the value is returned.
292 #ifdef _Out_cap_post_count_
293 #define LSX_PARAM_OUT_CAP_POST_COUNT(len,filled) _Out_cap_post_count_(len,filled) /* Required pointer to buffer for (len) elements (never NULL); on return, (filled) elements will have been initialized. */
295 #define LSX_PARAM_OUT_CAP_POST_COUNT(len,filled) /* Required pointer to buffer for (len) elements (never NULL); on return, (filled) elements will have been initialized. */
300 Attribute applied to a parameter to indicate that the parameter is a valid
301 pointer to memory sufficient for (len) elements of the pointed-to type (never
302 NULL), where (len) is the name of another parameter. On return, (filled+1)
303 elements will have been initialized, with the last element having been
304 initialized to 0, where (filled) is either the dereference of another pointer
305 parameter (for example, "*written") or the "return" parameter (indicating that
306 the function returns the number of elements written).
307 @param len The parameter that contains the number of elements in the array.
308 @param filled The dereference of the parameter that receives the number of elements written to the array (not counting the terminating null), or "return" if the value is returned.
310 #ifdef _Out_z_cap_post_count_
311 #define LSX_PARAM_OUT_Z_CAP_POST_COUNT(len,filled) _Out_z_cap_post_count_(len,filled) /* Required pointer to buffer for (len) elements (never NULL); on return, (filled+1) elements will have been initialized, and the array will be 0-terminated. */
313 #define LSX_PARAM_OUT_Z_CAP_POST_COUNT(len,filled) /* Required pointer to buffer for (len) elements (never NULL); on return, (filled+1) elements will have been initialized, and the array will be 0-terminated. */
318 Attribute applied to a parameter to indicate that the parameter is either NULL
319 or a valid pointer to memory sufficient for one element of the pointed-to
320 type. The function will initialize the element.
323 #define LSX_PARAM_OUT_OPT _Out_opt_ /* Optional pointer to an object to be initialized (may be NULL). */
325 #define LSX_PARAM_OUT_OPT /* Optional pointer to an object to be initialized (may be NULL). */
330 Attribute applied to a parameter to indicate that the parameter is a valid
331 pointer (never NULL) to another pointer which may be NULL when the function is
334 #ifdef _Deref_pre_maybenull_
335 #define LSX_PARAM_DEREF_PRE_MAYBENULL _Deref_pre_maybenull_ /* Required pointer (never NULL) to another pointer (may be NULL). */
337 #define LSX_PARAM_DEREF_PRE_MAYBENULL /* Required pointer (never NULL) to another pointer (may be NULL). */
342 Attribute applied to a parameter to indicate that the parameter is a valid
343 pointer (never NULL) to another pointer which will be NULL when the function
346 #ifdef _Deref_post_null_
347 #define LSX_PARAM_DEREF_POST_NULL _Deref_post_null_ /* Required pointer (never NULL) to another pointer, which will be NULL on exit. */
349 #define LSX_PARAM_DEREF_POST_NULL /* Required pointer (never NULL) to another pointer, which will be NULL on exit. */
354 Attribute applied to a parameter to indicate that the parameter is a valid
355 pointer (never NULL) to another pointer which will be non-NULL when the
358 #ifdef _Deref_post_notnull_
359 #define LSX_PARAM_DEREF_POST_NOTNULL _Deref_post_notnull_ /* Required pointer (never NULL) to another pointer, which will be valid (not NULL) on exit. */
361 #define LSX_PARAM_DEREF_POST_NOTNULL /* Required pointer (never NULL) to another pointer, which will be valid (not NULL) on exit. */
366 Expression that "uses" a potentially-unused variable to avoid compiler
367 warnings (especially in macro-generated code).
370 #define LSX_USE_VAR(x) ((void)(x=0)) /* During static analysis, initialize unused variables to 0. */
372 #define LSX_USE_VAR(x) ((void)(x)) /* Parameter or variable is intentionally unused. */
377 Compile-time assertion. Causes a compile error if the expression is false.
378 @param e The expression to test. If expression is false, compilation will fail.
379 @param f A unique identifier for the test, for example foo_must_not_be_zero.
381 #define lsx_static_assert(e,f) enum {lsx_static_assert_##f = 1/((e) ? 1 : 0)}
383 /*****************************************************************************
385 *****************************************************************************/
389 Signed twos-complement 8-bit type. Typically defined as signed char.
391 typedef int8_t sox_int8_t
;
395 Unsigned 8-bit type. Typically defined as unsigned char.
397 typedef uint8_t sox_uint8_t
;
401 Signed twos-complement 16-bit type. Typically defined as short.
403 typedef int16_t sox_int16_t
;
407 Unsigned 16-bit type. Typically defined as unsigned short.
409 typedef uint16_t sox_uint16_t
;
413 Signed twos-complement 32-bit type. Typically defined as int.
415 typedef int32_t sox_int32_t
;
419 Unsigned 32-bit type. Typically defined as unsigned int.
421 typedef uint32_t sox_uint32_t
;
425 Signed twos-complement 64-bit type. Typically defined as long or long long.
427 typedef int64_t sox_int64_t
;
431 Unsigned 64-bit type. Typically defined as unsigned long or unsigned long long.
433 typedef uint64_t sox_uint64_t
;
437 Alias for sox_int32_t (beware of the extra byte).
439 typedef sox_int32_t sox_int24_t
;
443 Alias for sox_uint32_t (beware of the extra byte).
445 typedef sox_uint32_t sox_uint24_t
;
449 Native SoX audio sample type (alias for sox_int32_t).
451 typedef sox_int32_t sox_sample_t
;
455 Samples per second is stored as a double.
457 typedef double sox_rate_t
;
461 File's metadata, access via sox_*_comments functions.
463 typedef char * * sox_comments_t
;
465 /*****************************************************************************
467 *****************************************************************************/
471 Boolean type, assignment (but not necessarily binary) compatible with C++ bool.
473 typedef enum sox_bool
{
474 sox_bool_dummy
= -1, /* Ensure a signed type */
475 sox_false
, /**< False = 0. */
476 sox_true
/**< True = 1. */
481 no, yes, or default (default usually implies some kind of auto-detect logic).
483 typedef enum sox_option_t
{
484 sox_option_no
, /**< Option specified as no = 0. */
485 sox_option_yes
, /**< Option specified as yes = 1. */
486 sox_option_default
/**< Option unspecified = 2. */
491 The libSoX-specific error codes.
492 libSoX functions may return these codes or others that map from errno codes.
495 SOX_SUCCESS
= 0, /**< Function succeeded = 0 */
496 SOX_EOF
= -1, /**< End Of File or other error = -1 */
497 SOX_EHDR
= 2000, /**< Invalid Audio Header = 2000 */
498 SOX_EFMT
, /**< Unsupported data format = 2001 */
499 SOX_ENOMEM
, /**< Can't alloc memory = 2002 */
500 SOX_EPERM
, /**< Operation not permitted = 2003 */
501 SOX_ENOTSUP
, /**< Operation not supported = 2004 */
502 SOX_EINVAL
/**< Invalid argument = 2005 */
507 Flags indicating whether optional features are present in this build of libSoX.
509 typedef enum sox_version_flags_t
{
510 sox_version_none
= 0, /**< No special features = 0. */
511 sox_version_have_popen
= 1, /**< popen = 1. */
512 sox_version_have_magic
= 2, /**< magic = 2. */
513 sox_version_have_threads
= 4, /**< threads = 4. */
514 sox_version_have_memopen
= 8 /**< memopen = 8. */
515 } sox_version_flags_t
;
519 Format of sample data.
521 typedef enum sox_encoding_t
{
522 SOX_ENCODING_UNKNOWN
, /**< encoding has not yet been determined */
524 SOX_ENCODING_SIGN2
, /**< signed linear 2's comp: Mac */
525 SOX_ENCODING_UNSIGNED
, /**< unsigned linear: Sound Blaster */
526 SOX_ENCODING_FLOAT
, /**< floating point (binary format) */
527 SOX_ENCODING_FLOAT_TEXT
, /**< floating point (text format) */
528 SOX_ENCODING_FLAC
, /**< FLAC compression */
529 SOX_ENCODING_HCOM
, /**< Mac FSSD files with Huffman compression */
530 SOX_ENCODING_WAVPACK
, /**< WavPack with integer samples */
531 SOX_ENCODING_WAVPACKF
, /**< WavPack with float samples */
532 SOX_ENCODING_ULAW
, /**< u-law signed logs: US telephony, SPARC */
533 SOX_ENCODING_ALAW
, /**< A-law signed logs: non-US telephony, Psion */
534 SOX_ENCODING_G721
, /**< G.721 4-bit ADPCM */
535 SOX_ENCODING_G723
, /**< G.723 3 or 5 bit ADPCM */
536 SOX_ENCODING_CL_ADPCM
, /**< Creative Labs 8 --> 2,3,4 bit Compressed PCM */
537 SOX_ENCODING_CL_ADPCM16
, /**< Creative Labs 16 --> 4 bit Compressed PCM */
538 SOX_ENCODING_MS_ADPCM
, /**< Microsoft Compressed PCM */
539 SOX_ENCODING_IMA_ADPCM
, /**< IMA Compressed PCM */
540 SOX_ENCODING_OKI_ADPCM
, /**< Dialogic/OKI Compressed PCM */
541 SOX_ENCODING_DPCM
, /**< Differential PCM: Fasttracker 2 (xi) */
542 SOX_ENCODING_DWVW
, /**< Delta Width Variable Word */
543 SOX_ENCODING_DWVWN
, /**< Delta Width Variable Word N-bit */
544 SOX_ENCODING_GSM
, /**< GSM 6.10 33byte frame lossy compression */
545 SOX_ENCODING_MP3
, /**< MP3 compression */
546 SOX_ENCODING_VORBIS
, /**< Vorbis compression */
547 SOX_ENCODING_AMR_WB
, /**< AMR-WB compression */
548 SOX_ENCODING_AMR_NB
, /**< AMR-NB compression */
549 SOX_ENCODING_CVSD
, /**< Continuously Variable Slope Delta modulation */
550 SOX_ENCODING_LPC10
, /**< Linear Predictive Coding */
551 SOX_ENCODING_OPUS
, /**< Opus compression */
553 SOX_ENCODINGS
/**< End of list marker */
558 Flags for sox_encodings_info_t: lossless/lossy1/lossy2.
560 typedef enum sox_encodings_flags_t
{
561 sox_encodings_none
= 0, /**< no flags specified (implies lossless encoding) = 0. */
562 sox_encodings_lossy1
= 1, /**< encode, decode: lossy once = 1. */
563 sox_encodings_lossy2
= 2 /**< encode, decode, encode, decode: lossy twice = 2. */
564 } sox_encodings_flags_t
;
570 typedef enum sox_plot_t
{
571 sox_plot_off
, /**< No plot = 0. */
572 sox_plot_octave
, /**< Octave plot = 1. */
573 sox_plot_gnuplot
, /**< Gnuplot plot = 2. */
574 sox_plot_data
/**< Plot data = 3. */
579 Loop modes: upper 4 bits mask the loop blass, lower 4 bits describe
580 the loop behaviour, for example single shot, bidirectional etc.
582 enum sox_loop_flags_t
{
583 sox_loop_none
= 0, /**< single-shot = 0 */
584 sox_loop_forward
= 1, /**< forward loop = 1 */
585 sox_loop_forward_back
= 2, /**< forward/back loop = 2 */
586 sox_loop_8
= 32, /**< 8 loops (??) = 32 */
587 sox_loop_sustain_decay
= 64 /**< AIFF style, one sustain & one decay loop = 64 */
592 Is file a real file, a pipe, or a url?
594 typedef enum lsx_io_type
596 lsx_io_file
, /**< File is a real file = 0. */
597 lsx_io_pipe
, /**< File is a pipe (no seeking) = 1. */
598 lsx_io_url
/**< File is a URL (no seeking) = 2. */
601 /*****************************************************************************
603 *****************************************************************************/
607 Compute a 32-bit integer API version from three 8-bit parts.
608 @param a Major version.
609 @param b Minor version.
610 @param c Revision or build number.
611 @returns 32-bit integer API version 0x000a0b0c.
613 #define SOX_LIB_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
617 The API version of the sox.h file. It is not meant to follow the version
618 number of SoX but it has historically. Please do not count on
619 SOX_LIB_VERSION_CODE staying in sync with the libSoX version.
621 #define SOX_LIB_VERSION_CODE SOX_LIB_VERSION(14, 4, 2)
625 Returns the smallest (negative) value storable in a twos-complement signed
626 integer with the specified number of bits, cast to an unsigned integer;
627 for example, SOX_INT_MIN(8) = 0x80, SOX_INT_MIN(16) = 0x8000, etc.
628 @param bits Size of value for which to calculate minimum.
629 @returns the smallest (negative) value storable in a twos-complement signed
630 integer with the specified number of bits, cast to an unsigned integer.
632 #define SOX_INT_MIN(bits) (1 <<((bits)-1))
636 Returns the largest (positive) value storable in a twos-complement signed
637 integer with the specified number of bits, cast to an unsigned integer;
638 for example, SOX_INT_MAX(8) = 0x7F, SOX_INT_MAX(16) = 0x7FFF, etc.
639 @param bits Size of value for which to calculate maximum.
640 @returns the largest (positive) value storable in a twos-complement signed
641 integer with the specified number of bits, cast to an unsigned integer.
643 #define SOX_INT_MAX(bits) (((unsigned)-1)>>(33-(bits)))
647 Returns the largest value storable in an unsigned integer with the specified
648 number of bits; for example, SOX_UINT_MAX(8) = 0xFF,
649 SOX_UINT_MAX(16) = 0xFFFF, etc.
650 @param bits Size of value for which to calculate maximum.
651 @returns the largest value storable in an unsigned integer with the specified
654 #define SOX_UINT_MAX(bits) (SOX_INT_MIN(bits)|SOX_INT_MAX(bits))
660 #define SOX_INT8_MAX SOX_INT_MAX(8)
666 #define SOX_INT16_MAX SOX_INT_MAX(16)
672 #define SOX_INT24_MAX SOX_INT_MAX(24)
678 #define SOX_INT32_MAX SOX_INT_MAX(32)
682 Bits in a sox_sample_t = 32.
684 #define SOX_SAMPLE_PRECISION 32
688 Max value for sox_sample_t = 0x7FFFFFFF.
690 #define SOX_SAMPLE_MAX (sox_sample_t)SOX_INT_MAX(32)
694 Min value for sox_sample_t = 0x80000000.
696 #define SOX_SAMPLE_MIN (sox_sample_t)SOX_INT_MIN(32)
699 /* Conversions: Linear PCM <--> sox_sample_t
701 * I/O Input sox_sample_t Clips? Input sox_sample_t Clips?
702 * Format Minimum Minimum I O Maximum Maximum I O
703 * ------ --------- ------------ -- -- -------- ------------ -- --
704 * Float -inf -1 y n inf 1 - 5e-10 y n
705 * Int8 -128 -128 n n 127 127.9999999 n y
706 * Int16 -32768 -32768 n n 32767 32767.99998 n y
707 * Int24 -8388608 -8388608 n n 8388607 8388607.996 n y
708 * Int32 -2147483648 -2147483648 n n 2147483647 2147483647 n n
710 * Conversions are as accurate as possible (with rounding).
712 * Rounding: halves toward +inf, all others to nearest integer.
714 * Clips? shows whether on not there is the possibility of a conversion
715 * clipping to the minimum or maximum value when inputing from or outputing
718 * Unsigned integers are converted to and from signed integers by flipping
719 * the upper-most bit then treating them as signed integers.
724 Declares the temporary local variables that are required when using SOX
727 #define SOX_SAMPLE_LOCALS sox_sample_t sox_macro_temp_sample LSX_UNUSED; \
728 double sox_macro_temp_double LSX_UNUSED
732 Sign bit for sox_sample_t = 0x80000000.
734 #define SOX_SAMPLE_NEG SOX_INT_MIN(32)
738 Converts sox_sample_t to an unsigned integer of width (bits).
739 @param bits Width of resulting sample (1 through 32).
740 @param d Input sample to be converted.
741 @param clips Variable that is incremented if the result is too big.
742 @returns Unsigned integer of width (bits).
744 #define SOX_SAMPLE_TO_UNSIGNED(bits,d,clips) \
745 (sox_uint##bits##_t)(SOX_SAMPLE_TO_SIGNED(bits,d,clips) ^ SOX_INT_MIN(bits))
749 Converts sox_sample_t to a signed integer of width (bits).
750 @param bits Width of resulting sample (1 through 32).
751 @param d Input sample to be converted.
752 @param clips Variable that is incremented if the result is too big.
753 @returns Signed integer of width (bits).
755 #define SOX_SAMPLE_TO_SIGNED(bits,d,clips) \
756 (sox_int##bits##_t)( \
757 LSX_USE_VAR(sox_macro_temp_double), \
758 sox_macro_temp_sample = (d), \
759 sox_macro_temp_sample > SOX_SAMPLE_MAX - (1 << (31-bits)) ? \
760 ++(clips), SOX_INT_MAX(bits) : \
761 ((sox_uint32_t)(sox_macro_temp_sample + (1 << (31-bits)))) >> (32-bits))
765 Converts signed integer of width (bits) to sox_sample_t.
766 @param bits Width of input sample (1 through 32).
767 @param d Input sample to be converted.
768 @returns SoX native sample value.
770 #define SOX_SIGNED_TO_SAMPLE(bits,d) ((sox_sample_t)(d) << (32-bits))
774 Converts unsigned integer of width (bits) to sox_sample_t.
775 @param bits Width of input sample (1 through 32).
776 @param d Input sample to be converted.
777 @returns SoX native sample value.
779 #define SOX_UNSIGNED_TO_SAMPLE(bits,d) \
780 (SOX_SIGNED_TO_SAMPLE(bits,d) ^ SOX_SAMPLE_NEG)
784 Converts unsigned 8-bit integer to sox_sample_t.
785 @param d Input sample to be converted.
786 @param clips The parameter is not used.
787 @returns SoX native sample value.
789 #define SOX_UNSIGNED_8BIT_TO_SAMPLE(d,clips) SOX_UNSIGNED_TO_SAMPLE(8,d)
793 Converts signed 8-bit integer to sox_sample_t.
794 @param d Input sample to be converted.
795 @param clips The parameter is not used.
796 @returns SoX native sample value.
798 #define SOX_SIGNED_8BIT_TO_SAMPLE(d,clips) SOX_SIGNED_TO_SAMPLE(8,d)
802 Converts unsigned 16-bit integer to sox_sample_t.
803 @param d Input sample to be converted.
804 @param clips The parameter is not used.
805 @returns SoX native sample value.
807 #define SOX_UNSIGNED_16BIT_TO_SAMPLE(d,clips) SOX_UNSIGNED_TO_SAMPLE(16,d)
811 Converts signed 16-bit integer to sox_sample_t.
812 @param d Input sample to be converted.
813 @param clips The parameter is not used.
814 @returns SoX native sample value.
816 #define SOX_SIGNED_16BIT_TO_SAMPLE(d,clips) SOX_SIGNED_TO_SAMPLE(16,d)
820 Converts unsigned 24-bit integer to sox_sample_t.
821 @param d Input sample to be converted.
822 @param clips The parameter is not used.
823 @returns SoX native sample value.
825 #define SOX_UNSIGNED_24BIT_TO_SAMPLE(d,clips) SOX_UNSIGNED_TO_SAMPLE(24,d)
829 Converts signed 24-bit integer to sox_sample_t.
830 @param d Input sample to be converted.
831 @param clips The parameter is not used.
832 @returns SoX native sample value.
834 #define SOX_SIGNED_24BIT_TO_SAMPLE(d,clips) SOX_SIGNED_TO_SAMPLE(24,d)
838 Converts unsigned 32-bit integer to sox_sample_t.
839 @param d Input sample to be converted.
840 @param clips The parameter is not used.
841 @returns SoX native sample value.
843 #define SOX_UNSIGNED_32BIT_TO_SAMPLE(d,clips) \
844 ((sox_sample_t)(d) ^ SOX_SAMPLE_NEG)
848 Converts signed 32-bit integer to sox_sample_t.
849 @param d Input sample to be converted.
850 @param clips The parameter is not used.
851 @returns SoX native sample value.
853 #define SOX_SIGNED_32BIT_TO_SAMPLE(d,clips) (sox_sample_t)(d)
857 Converts 32-bit float to sox_sample_t.
858 @param d Input sample to be converted, range [-1, 1).
859 @param clips Variable to increment if the input sample is too large or too small.
860 @returns SoX native sample value.
862 #define SOX_FLOAT_32BIT_TO_SAMPLE(d,clips) SOX_FLOAT_64BIT_TO_SAMPLE(d, clips)
866 Converts 64-bit float to sox_sample_t.
867 @param d Input sample to be converted, range [-1, 1).
868 @param clips Variable to increment if the input sample is too large or too small.
869 @returns SoX native sample value.
871 #define SOX_FLOAT_64BIT_TO_SAMPLE(d, clips) \
873 LSX_USE_VAR(sox_macro_temp_sample), \
874 sox_macro_temp_double = (d) * (SOX_SAMPLE_MAX + 1.0), \
875 sox_macro_temp_double < 0 ? \
876 sox_macro_temp_double <= SOX_SAMPLE_MIN - 0.5 ? \
877 ++(clips), SOX_SAMPLE_MIN : \
878 sox_macro_temp_double - 0.5 : \
879 sox_macro_temp_double >= SOX_SAMPLE_MAX + 0.5 ? \
880 sox_macro_temp_double > SOX_SAMPLE_MAX + 1.0 ? \
881 ++(clips), SOX_SAMPLE_MAX : \
883 sox_macro_temp_double + 0.5 \
888 Converts SoX native sample to an unsigned 8-bit integer.
889 @param d Input sample to be converted.
890 @param clips Variable to increment if input sample is too large.
892 #define SOX_SAMPLE_TO_UNSIGNED_8BIT(d,clips) SOX_SAMPLE_TO_UNSIGNED(8,d,clips)
896 Converts SoX native sample to an signed 8-bit integer.
897 @param d Input sample to be converted.
898 @param clips Variable to increment if input sample is too large.
900 #define SOX_SAMPLE_TO_SIGNED_8BIT(d,clips) SOX_SAMPLE_TO_SIGNED(8,d,clips)
904 Converts SoX native sample to an unsigned 16-bit integer.
905 @param d Input sample to be converted.
906 @param clips Variable to increment if input sample is too large.
908 #define SOX_SAMPLE_TO_UNSIGNED_16BIT(d,clips) SOX_SAMPLE_TO_UNSIGNED(16,d,clips)
912 Converts SoX native sample to a signed 16-bit integer.
913 @param d Input sample to be converted.
914 @param clips Variable to increment if input sample is too large.
916 #define SOX_SAMPLE_TO_SIGNED_16BIT(d,clips) SOX_SAMPLE_TO_SIGNED(16,d,clips)
920 Converts SoX native sample to an unsigned 24-bit integer.
921 @param d Input sample to be converted.
922 @param clips Variable to increment if input sample is too large.
924 #define SOX_SAMPLE_TO_UNSIGNED_24BIT(d,clips) SOX_SAMPLE_TO_UNSIGNED(24,d,clips)
928 Converts SoX native sample to a signed 24-bit integer.
929 @param d Input sample to be converted.
930 @param clips Variable to increment if input sample is too large.
932 #define SOX_SAMPLE_TO_SIGNED_24BIT(d,clips) SOX_SAMPLE_TO_SIGNED(24,d,clips)
936 Converts SoX native sample to an unsigned 32-bit integer.
937 @param d Input sample to be converted.
938 @param clips The parameter is not used.
940 #define SOX_SAMPLE_TO_UNSIGNED_32BIT(d,clips) (sox_uint32_t)((d)^SOX_SAMPLE_NEG)
944 Converts SoX native sample to a signed 32-bit integer.
945 @param d Input sample to be converted.
946 @param clips The parameter is not used.
948 #define SOX_SAMPLE_TO_SIGNED_32BIT(d,clips) (sox_int32_t)(d)
952 Converts SoX native sample to a 32-bit float.
953 @param d Input sample to be converted.
954 @param clips The parameter is not used.
956 #define SOX_SAMPLE_TO_FLOAT_32BIT(d,clips) ((d)*(1.0 / (SOX_SAMPLE_MAX + 1.0)))
960 Converts SoX native sample to a 64-bit float.
961 @param d Input sample to be converted.
962 @param clips The parameter is not used.
964 #define SOX_SAMPLE_TO_FLOAT_64BIT(d,clips) ((d)*(1.0 / (SOX_SAMPLE_MAX + 1.0)))
968 Clips a value of a type that is larger then sox_sample_t (for example, int64)
969 to sox_sample_t's limits and increment a counter if clipping occurs.
970 @param samp Value (lvalue) to be clipped, updated as necessary.
971 @param clips Value (lvalue) that is incremented if clipping is needed.
973 #define SOX_SAMPLE_CLIP_COUNT(samp, clips) \
975 if (samp > SOX_SAMPLE_MAX) \
976 { samp = SOX_SAMPLE_MAX; clips++; } \
977 else if (samp < SOX_SAMPLE_MIN) \
978 { samp = SOX_SAMPLE_MIN; clips++; } \
983 Clips a value of a type that is larger then sox_sample_t (for example, int64)
984 to sox_sample_t's limits and increment a counter if clipping occurs.
985 @param d Value (rvalue) to be clipped.
986 @param clips Value (lvalue) that is incremented if clipping is needed.
987 @returns Clipped value.
989 #define SOX_ROUND_CLIP_COUNT(d, clips) \
990 ((d) < 0? (d) <= SOX_SAMPLE_MIN - 0.5? ++(clips), SOX_SAMPLE_MIN: (d) - 0.5 \
991 : (d) >= SOX_SAMPLE_MAX + 0.5? ++(clips), SOX_SAMPLE_MAX: (d) + 0.5)
995 Clips a value to the limits of a signed integer of the specified width
996 and increment a counter if clipping occurs.
997 @param bits Width (in bits) of target integer type.
998 @param i Value (rvalue) to be clipped.
999 @param clips Value (lvalue) that is incremented if clipping is needed.
1000 @returns Clipped value.
1002 #define SOX_INTEGER_CLIP_COUNT(bits,i,clips) ( \
1003 (i) >(1 << ((bits)-1))- 1? ++(clips),(1 << ((bits)-1))- 1 : \
1004 (i) <-1 << ((bits)-1) ? ++(clips),-1 << ((bits)-1) : (i))
1008 Clips a value to the limits of a 16-bit signed integer and increment a counter
1010 @param i Value (rvalue) to be clipped.
1011 @param clips Value (lvalue) that is incremented if clipping is needed.
1012 @returns Clipped value.
1014 #define SOX_16BIT_CLIP_COUNT(i,clips) SOX_INTEGER_CLIP_COUNT(16,i,clips)
1018 Clips a value to the limits of a 24-bit signed integer and increment a counter
1020 @param i Value (rvalue) to be clipped.
1021 @param clips Value (lvalue) that is incremented if clipping is needed.
1022 @returns Clipped value.
1024 #define SOX_24BIT_CLIP_COUNT(i,clips) SOX_INTEGER_CLIP_COUNT(24,i,clips)
1026 #define SOX_SIZE_MAX ((size_t)(-1)) /**< Client API: Maximum value of size_t. */
1028 #define SOX_UNSPEC 0 /**< Client API: Members of sox_signalinfo_t are set to SOX_UNSPEC (= 0) if the actual value is not yet known. */
1029 #define SOX_UNKNOWN_LEN (sox_uint64_t)(-1) /**< Client API: sox_signalinfo_t.length is set to SOX_UNKNOWN_LEN (= -1) within the effects chain if the actual length is not known. Format handlers currently use SOX_UNSPEC instead. */
1030 #define SOX_IGNORE_LENGTH (sox_uint64_t)(-2) /**< Client API: sox_signalinfo_t.length is set to SOX_IGNORE_LENGTH (= -2) to indicate that a format handler should ignore length information in file headers. */
1032 #define SOX_DEFAULT_CHANNELS 2 /**< Client API: Default channel count is 2 (stereo). */
1033 #define SOX_DEFAULT_RATE 48000 /**< Client API: Default rate is 48000Hz. */
1034 #define SOX_DEFAULT_PRECISION 16 /**< Client API: Default precision is 16 bits per sample. */
1035 #define SOX_DEFAULT_ENCODING SOX_ENCODING_SIGN2 /**< Client API: Default encoding is SIGN2 (linear 2's complement PCM). */
1037 #define SOX_LOOP_NONE ((unsigned char)sox_loop_none) /**< Client API: single-shot = 0 */
1038 #define SOX_LOOP_8 ((unsigned char)sox_loop_8) /**< Client API: 8 loops = 32 */
1039 #define SOX_LOOP_SUSTAIN_DECAY ((unsigned char)sox_loop_sustain_decay) /**< Client API: AIFF style, one sustain & one decay loop = 64 */
1041 #define SOX_MAX_NLOOPS 8 /**< Client API: Maximum number of loops supported by sox_oob_t = 8. */
1043 #define SOX_FILE_NOSTDIO 0x0001 /**< Client API: Does not use stdio routines */
1044 #define SOX_FILE_DEVICE 0x0002 /**< Client API: File is an audio device */
1045 #define SOX_FILE_PHONY 0x0004 /**< Client API: Phony file/device (for example /dev/null) */
1046 #define SOX_FILE_REWIND 0x0008 /**< Client API: File should be rewound to write header */
1047 #define SOX_FILE_BIT_REV 0x0010 /**< Client API: Is file bit-reversed? */
1048 #define SOX_FILE_NIB_REV 0x0020 /**< Client API: Is file nibble-reversed? */
1049 #define SOX_FILE_ENDIAN 0x0040 /**< Client API: Is file format endian? */
1050 #define SOX_FILE_ENDBIG 0x0080 /**< Client API: For endian file format, is it big endian? */
1051 #define SOX_FILE_MONO 0x0100 /**< Client API: Do channel restrictions allow mono? */
1052 #define SOX_FILE_STEREO 0x0200 /**< Client API: Do channel restrictions allow stereo? */
1053 #define SOX_FILE_QUAD 0x0400 /**< Client API: Do channel restrictions allow quad? */
1055 #define SOX_FILE_CHANS (SOX_FILE_MONO | SOX_FILE_STEREO | SOX_FILE_QUAD) /**< Client API: No channel restrictions */
1056 #define SOX_FILE_LIT_END (SOX_FILE_ENDIAN | 0) /**< Client API: File is little-endian */
1057 #define SOX_FILE_BIG_END (SOX_FILE_ENDIAN | SOX_FILE_ENDBIG) /**< Client API: File is big-endian */
1059 #define SOX_EFF_CHAN 1 /**< Client API: Effect might alter the number of channels */
1060 #define SOX_EFF_RATE 2 /**< Client API: Effect might alter sample rate */
1061 #define SOX_EFF_PREC 4 /**< Client API: Effect does its own calculation of output sample precision (otherwise a default value is taken, depending on the presence of SOX_EFF_MODIFY) */
1062 #define SOX_EFF_LENGTH 8 /**< Client API: Effect might alter audio length (as measured in time units, not necessarily in samples) */
1063 #define SOX_EFF_MCHAN 16 /**< Client API: Effect handles multiple channels internally */
1064 #define SOX_EFF_NULL 32 /**< Client API: Effect does nothing (can be optimized out of chain) */
1065 #define SOX_EFF_DEPRECATED 64 /**< Client API: Effect will soon be removed from SoX */
1066 #define SOX_EFF_GAIN 128 /**< Client API: Effect does not support gain -r */
1067 #define SOX_EFF_MODIFY 256 /**< Client API: Effect does not modify sample values (but might remove or duplicate samples or insert zeros) */
1068 #define SOX_EFF_ALPHA 512 /**< Client API: Effect is experimental/incomplete */
1069 #define SOX_EFF_INTERNAL 1024 /**< Client API: Effect present in libSoX but not valid for use by SoX command-line tools */
1073 When used as the "whence" parameter of sox_seek, indicates that the specified
1074 offset is relative to the beginning of the file.
1076 #define SOX_SEEK_SET 0
1078 /*****************************************************************************
1079 Forward declarations:
1080 *****************************************************************************/
1082 typedef struct sox_format_t sox_format_t
;
1083 typedef struct sox_effect_t sox_effect_t
;
1084 typedef struct sox_effect_handler_t sox_effect_handler_t
;
1085 typedef struct sox_format_handler_t sox_format_handler_t
;
1087 /*****************************************************************************
1089 *****************************************************************************/
1093 Callback to write a message to an output device (console or log file),
1094 used by sox_globals_t.output_message_handler.
1096 typedef void (LSX_API
* sox_output_message_handler_t
)(
1097 unsigned level
, /**< 1 = FAIL, 2 = WARN, 3 = INFO, 4 = DEBUG, 5 = DEBUG_MORE, 6 = DEBUG_MOST. */
1098 LSX_PARAM_IN_Z
char const * filename
, /**< Source code __FILENAME__ from which message originates. */
1099 LSX_PARAM_IN_PRINTF
char const * fmt
, /**< Message format string. */
1100 LSX_PARAM_IN
va_list ap
/**< Message format parameters. */
1105 Callback to retrieve information about a format handler,
1106 used by sox_format_tab_t.fn.
1107 @returns format handler information.
1109 typedef sox_format_handler_t
const * (LSX_API
* sox_format_fn_t
)(void);
1113 Callback to get information about an effect handler,
1114 used by the table returned from sox_get_effect_fns(void).
1115 @returns Pointer to information about an effect handler.
1117 typedef sox_effect_handler_t
const * (LSX_API
*sox_effect_fn_t
)(void);
1121 Callback to initialize reader (decoder), used by
1122 sox_format_handler.startread.
1123 @returns SOX_SUCCESS if successful.
1125 typedef int (LSX_API
* sox_format_handler_startread
)(
1126 LSX_PARAM_INOUT sox_format_t
* ft
/**< Format pointer. */
1131 Callback to read (decode) a block of samples,
1132 used by sox_format_handler.read.
1133 @returns number of samples read, or 0 if unsuccessful.
1135 typedef size_t (LSX_API
* sox_format_handler_read
)(
1136 LSX_PARAM_INOUT sox_format_t
* ft
, /**< Format pointer. */
1137 LSX_PARAM_OUT_CAP_POST_COUNT(len
,return) sox_sample_t
*buf
, /**< Buffer from which to read samples. */
1138 size_t len
/**< Number of samples available in buf. */
1143 Callback to close reader (decoder),
1144 used by sox_format_handler.stopread.
1145 @returns SOX_SUCCESS if successful.
1147 typedef int (LSX_API
* sox_format_handler_stopread
)(
1148 LSX_PARAM_INOUT sox_format_t
* ft
/**< Format pointer. */
1153 Callback to initialize writer (encoder),
1154 used by sox_format_handler.startwrite.
1155 @returns SOX_SUCCESS if successful.
1157 typedef int (LSX_API
* sox_format_handler_startwrite
)(
1158 LSX_PARAM_INOUT sox_format_t
* ft
/**< Format pointer. */
1163 Callback to write (encode) a block of samples,
1164 used by sox_format_handler.write.
1165 @returns number of samples written, or 0 if unsuccessful.
1167 typedef size_t (LSX_API
* sox_format_handler_write
)(
1168 LSX_PARAM_INOUT sox_format_t
* ft
, /**< Format pointer. */
1169 LSX_PARAM_IN_COUNT(len
) sox_sample_t
const * buf
, /**< Buffer to which samples are written. */
1170 size_t len
/**< Capacity of buf, measured in samples. */
1175 Callback to close writer (decoder),
1176 used by sox_format_handler.stopwrite.
1177 @returns SOX_SUCCESS if successful.
1179 typedef int (LSX_API
* sox_format_handler_stopwrite
)(
1180 LSX_PARAM_INOUT sox_format_t
* ft
/**< Format pointer. */
1185 Callback to reposition reader,
1186 used by sox_format_handler.seek.
1187 @returns SOX_SUCCESS if successful.
1189 typedef int (LSX_API
* sox_format_handler_seek
)(
1190 LSX_PARAM_INOUT sox_format_t
* ft
, /**< Format pointer. */
1191 sox_uint64_t offset
/**< Sample offset to which reader should be positioned. */
1196 Callback to parse command-line arguments (called once per effect),
1197 used by sox_effect_handler.getopts.
1198 @returns SOX_SUCCESS if successful.
1200 typedef int (LSX_API
* sox_effect_handler_getopts
)(
1201 LSX_PARAM_INOUT sox_effect_t
* effp
, /**< Effect pointer. */
1202 int argc
, /**< Number of arguments in argv. */
1203 LSX_PARAM_IN_COUNT(argc
) char *argv
[] /**< Array of command-line arguments. */
1208 Callback to initialize effect (called once per flow),
1209 used by sox_effect_handler.start.
1210 @returns SOX_SUCCESS if successful.
1212 typedef int (LSX_API
* sox_effect_handler_start
)(
1213 LSX_PARAM_INOUT sox_effect_t
* effp
/**< Effect pointer. */
1218 Callback to process samples,
1219 used by sox_effect_handler.flow.
1220 @returns SOX_SUCCESS if successful.
1222 typedef int (LSX_API
* sox_effect_handler_flow
)(
1223 LSX_PARAM_INOUT sox_effect_t
* effp
, /**< Effect pointer. */
1224 LSX_PARAM_IN_COUNT(*isamp
) sox_sample_t
const * ibuf
, /**< Buffer from which to read samples. */
1225 LSX_PARAM_OUT_CAP_POST_COUNT(*osamp
,*osamp
) sox_sample_t
* obuf
, /**< Buffer to which samples are written. */
1226 LSX_PARAM_INOUT
size_t *isamp
, /**< On entry, contains capacity of ibuf; on exit, contains number of samples consumed. */
1227 LSX_PARAM_INOUT
size_t *osamp
/**< On entry, contains capacity of obuf; on exit, contains number of samples written. */
1232 Callback to finish getting output after input is complete,
1233 used by sox_effect_handler.drain.
1234 @returns SOX_SUCCESS if successful.
1236 typedef int (LSX_API
* sox_effect_handler_drain
)(
1237 LSX_PARAM_INOUT sox_effect_t
* effp
, /**< Effect pointer. */
1238 LSX_PARAM_OUT_CAP_POST_COUNT(*osamp
,*osamp
) sox_sample_t
*obuf
, /**< Buffer to which samples are written. */
1239 LSX_PARAM_INOUT
size_t *osamp
/**< On entry, contains capacity of obuf; on exit, contains number of samples written. */
1244 Callback to shut down effect (called once per flow),
1245 used by sox_effect_handler.stop.
1246 @returns SOX_SUCCESS if successful.
1248 typedef int (LSX_API
* sox_effect_handler_stop
)(
1249 LSX_PARAM_INOUT sox_effect_t
* effp
/**< Effect pointer. */
1254 Callback to shut down effect (called once per effect),
1255 used by sox_effect_handler.kill.
1256 @returns SOX_SUCCESS if successful.
1258 typedef int (LSX_API
* sox_effect_handler_kill
)(
1259 LSX_PARAM_INOUT sox_effect_t
* effp
/**< Effect pointer. */
1264 Callback called while flow is running (called once per buffer),
1265 used by sox_flow_effects.callback.
1266 @returns SOX_SUCCESS to continue, other value to abort flow.
1268 typedef int (LSX_API
* sox_flow_effects_callback
)(
1275 Callback for enumerating the contents of a playlist,
1276 used by the sox_parse_playlist function.
1277 @returns SOX_SUCCESS if successful, any other value to abort playlist enumeration.
1279 typedef int (LSX_API
* sox_playlist_callback_t
)(
1280 void * callback_data
,
1281 LSX_PARAM_IN_Z
char const * filename
1284 /*****************************************************************************
1286 *****************************************************************************/
1290 Information about a build of libSoX, returned from the sox_version_info
1293 typedef struct sox_version_info_t
{
1294 size_t size
; /**< structure size = sizeof(sox_version_info_t) */
1295 sox_version_flags_t flags
; /**< feature flags = popen | magic | threads | memopen */
1296 sox_uint32_t version_code
; /**< version number = 0x140400 */
1297 char const * version
; /**< version string = sox_version(), for example, "14.4.0" */
1298 char const * version_extra
;/**< version extra info or null = "PACKAGE_EXTRA", for example, "beta" */
1299 char const * time
; /**< build time = "__DATE__ __TIME__", for example, "Jan 7 2010 03:31:50" */
1300 char const * distro
; /**< distro or null = "DISTRO", for example, "Debian" */
1301 char const * compiler
; /**< compiler info or null, for example, "msvc 160040219" */
1302 char const * arch
; /**< arch, for example, "1248 48 44 L OMP" */
1303 /* new info should be added at the end for version backwards-compatibility. */
1304 } sox_version_info_t
;
1308 Global parameters (for effects & formats), returned from the sox_get_globals
1311 typedef struct sox_globals_t
{
1313 unsigned verbosity
; /**< messages are only written if globals.verbosity >= message.level */
1314 sox_output_message_handler_t output_message_handler
; /**< client-specified message output callback */
1315 sox_bool repeatable
; /**< true to use pre-determined timestamps and PRNG seed */
1318 Default size (in bytes) used by libSoX for blocks of sample data.
1319 Plugins should use similarly-sized buffers to get best performance.
1324 Default size (in bytes) used by libSoX for blocks of input sample data.
1325 Plugins should use similarly-sized buffers to get best performance.
1327 size_t input_bufsiz
;
1329 sox_int32_t ranqd1
; /**< Can be used to re-seed libSoX's PRNG */
1331 char const * stdin_in_use_by
; /**< Private: tracks the name of the handler currently using stdin */
1332 char const * stdout_in_use_by
; /**< Private: tracks the name of the handler currently using stdout */
1333 char const * subsystem
; /**< Private: tracks the name of the handler currently writing an output message */
1334 char * tmp_path
; /**< Private: client-configured path to use for temporary files */
1335 sox_bool use_magic
; /**< Private: true if client has requested use of 'magic' file-type detection */
1336 sox_bool use_threads
; /**< Private: true if client has requested parallel effects processing */
1339 Log to base 2 of minimum size (in bytes) used by libSoX for DFT (filtering).
1340 Plugins should use similarly-sized DFTs to get best performance.
1342 size_t log2_dft_min_size
;
1347 Signal parameters; members should be set to SOX_UNSPEC (= 0) if unknown.
1349 typedef struct sox_signalinfo_t
{
1350 sox_rate_t rate
; /**< samples per second, 0 if unknown */
1351 unsigned channels
; /**< number of sound channels, 0 if unknown */
1352 unsigned precision
; /**< bits per sample, 0 if unknown */
1353 sox_uint64_t length
; /**< samples * chans in file, 0 if unknown, -1 if unspecified */
1354 double * mult
; /**< Effects headroom multiplier; may be null */
1359 Basic information about an encoding.
1361 typedef struct sox_encodings_info_t
{
1362 sox_encodings_flags_t flags
; /**< lossy once (lossy1), lossy twice (lossy2), or lossless (none). */
1363 char const * name
; /**< encoding name. */
1364 char const * desc
; /**< encoding description. */
1365 } sox_encodings_info_t
;
1369 Encoding parameters.
1371 typedef struct sox_encodinginfo_t
{
1372 sox_encoding_t encoding
; /**< format of sample numbers */
1373 unsigned bits_per_sample
;/**< 0 if unknown or variable; uncompressed value if lossless; compressed value if lossy */
1374 double compression
; /**< compression factor (where applicable) */
1377 Should bytes be reversed? If this is default during sox_open_read or
1378 sox_open_write, libSoX will set them to either no or yes according to the
1379 machine or format default.
1381 sox_option_t reverse_bytes
;
1384 Should nibbles be reversed? If this is default during sox_open_read or
1385 sox_open_write, libSoX will set them to either no or yes according to the
1386 machine or format default.
1388 sox_option_t reverse_nibbles
;
1391 Should bits be reversed? If this is default during sox_open_read or
1392 sox_open_write, libSoX will set them to either no or yes according to the
1393 machine or format default.
1395 sox_option_t reverse_bits
;
1398 If set to true, the format should reverse its default endianness.
1400 sox_bool opposite_endian
;
1401 } sox_encodinginfo_t
;
1405 Looping parameters (out-of-band data).
1407 typedef struct sox_loopinfo_t
{
1408 sox_uint64_t start
; /**< first sample */
1409 sox_uint64_t length
; /**< length */
1410 unsigned count
; /**< number of repeats, 0=forever */
1411 unsigned char type
; /**< 0=no, 1=forward, 2=forward/back (see sox_loop_* for valid values). */
1416 Instrument information.
1418 typedef struct sox_instrinfo_t
{
1419 signed char MIDInote
; /**< for unity pitch playback */
1420 signed char MIDIlow
; /**< MIDI pitch-bend low range */
1421 signed char MIDIhi
; /**< MIDI pitch-bend high range */
1422 unsigned char loopmode
; /**< 0=no, 1=forward, 2=forward/back (see sox_loop_* values) */
1423 unsigned nloops
; /**< number of active loops (max SOX_MAX_NLOOPS). */
1428 File buffer info. Holds info so that data can be read in blocks.
1430 typedef struct sox_fileinfo_t
{
1431 char *buf
; /**< Pointer to data buffer */
1432 size_t size
; /**< Size of buffer in bytes */
1433 size_t count
; /**< Count read into buffer */
1434 size_t pos
; /**< Position in buffer */
1439 Handler structure defined by each format.
1441 struct sox_format_handler_t
{
1442 unsigned sox_lib_version_code
; /**< Checked on load; must be 1st in struct*/
1443 char const * description
; /**< short description of format */
1444 char const * const * names
; /**< null-terminated array of filename extensions that are handled by this format */
1445 unsigned int flags
; /**< File flags (SOX_FILE_* values). */
1446 sox_format_handler_startread startread
; /**< called to initialize reader (decoder) */
1447 sox_format_handler_read read
; /**< called to read (decode) a block of samples */
1448 sox_format_handler_stopread stopread
; /**< called to close reader (decoder); may be null if no closing necessary */
1449 sox_format_handler_startwrite startwrite
; /**< called to initialize writer (encoder) */
1450 sox_format_handler_write write
; /**< called to write (encode) a block of samples */
1451 sox_format_handler_stopwrite stopwrite
; /**< called to close writer (decoder); may be null if no closing necessary */
1452 sox_format_handler_seek seek
; /**< called to reposition reader; may be null if not supported */
1455 Array of values indicating the encodings and precisions supported for
1456 writing (encoding). Precisions specified with default precision first.
1457 Encoding, precision, precision, ..., 0, repeat. End with one more 0.
1459 unsigned const * formats = {
1460 SOX_ENCODING_SIGN2, 16, 24, 0, // Support SIGN2 at 16 and 24 bits, default to 16 bits.
1461 SOX_ENCODING_UNSIGNED, 8, 0, // Support UNSIGNED at 8 bits, default to 8 bits.
1462 0 // No more supported encodings.
1465 unsigned const * write_formats
;
1468 Array of sample rates (samples per second) supported for writing (encoding).
1469 NULL if all (or almost all) rates are supported. End with 0.
1471 sox_rate_t
const * write_rates
;
1474 SoX will automatically allocate a buffer in which the handler can store data.
1475 Specify the size of the buffer needed here. Usually this will be sizeof(your_struct).
1476 The buffer will be allocated and zeroed before the call to startread/startwrite.
1477 The buffer will be freed after the call to stopread/stopwrite.
1478 The buffer will be provided via format.priv in each call to the handler.
1485 Comments, instrument info, loop info (out-of-band data).
1487 typedef struct sox_oob_t
{
1489 sox_comments_t comments
; /**< Comment strings in id=value format. */
1490 sox_instrinfo_t instr
; /**< Instrument specification */
1491 sox_loopinfo_t loops
[SOX_MAX_NLOOPS
]; /**< Looping specification */
1493 /* TBD: Non-decoded chunks, etc: */
1498 Data passed to/from the format handler
1500 struct sox_format_t
{
1501 char * filename
; /**< File name */
1504 Signal specifications for reader (decoder) or writer (encoder):
1505 sample rate, number of channels, precision, length, headroom multiplier.
1506 Any info specified by the user is here on entry to startread or
1507 startwrite. Info will be SOX_UNSPEC if the user provided no info.
1508 At exit from startread, should be completely filled in, using
1509 either data from the file's headers (if available) or whatever
1510 the format is guessing/assuming (if header data is not available).
1511 At exit from startwrite, should be completely filled in, using
1512 either the data that was specified, or values chosen by the format
1513 based on the format's defaults or capabilities.
1515 sox_signalinfo_t signal
;
1518 Encoding specifications for reader (decoder) or writer (encoder):
1519 encoding (sample format), bits per sample, compression rate, endianness.
1520 Should be filled in by startread. Values specified should be used
1521 by startwrite when it is configuring the encoding parameters.
1523 sox_encodinginfo_t encoding
;
1525 char * filetype
; /**< Type of file, as determined by header inspection or libmagic. */
1526 sox_oob_t oob
; /**< comments, instrument info, loop info (out-of-band data) */
1527 sox_bool seekable
; /**< Can seek on this file */
1528 char mode
; /**< Read or write mode ('r' or 'w') */
1529 sox_uint64_t olength
; /**< Samples * chans written to file */
1530 sox_uint64_t clips
; /**< Incremented if clipping occurs */
1531 int sox_errno
; /**< Failure error code */
1532 char sox_errstr
[256]; /**< Failure error text */
1533 void * fp
; /**< File stream pointer */
1534 lsx_io_type io_type
; /**< Stores whether this is a file, pipe or URL */
1535 sox_uint64_t tell_off
; /**< Current offset within file */
1536 sox_uint64_t data_start
; /**< Offset at which headers end and sound data begins (set by lsx_check_read_params) */
1537 sox_format_handler_t handler
; /**< Format handler for this file */
1538 void * priv
; /**< Format handler's private data area */
1543 Information about a loaded format handler, including the format name and a
1544 function pointer that can be invoked to get additional information about the
1547 typedef struct sox_format_tab_t
{
1548 char *name
; /**< Name of format handler */
1549 sox_format_fn_t fn
; /**< Function to call to get format handler's information */
1554 Global parameters for effects.
1556 typedef struct sox_effects_globals_t
{
1557 sox_plot_t plot
; /**< To help the user choose effect & options */
1558 sox_globals_t
* global_info
; /**< Pointer to associated SoX globals */
1559 } sox_effects_globals_t
;
1563 Effect handler information.
1565 struct sox_effect_handler_t
{
1566 char const * name
; /**< Effect name */
1567 char const * usage
; /**< Short explanation of parameters accepted by effect */
1568 unsigned int flags
; /**< Combination of SOX_EFF_* flags */
1569 sox_effect_handler_getopts getopts
; /**< Called to parse command-line arguments (called once per effect). */
1570 sox_effect_handler_start start
; /**< Called to initialize effect (called once per flow). */
1571 sox_effect_handler_flow flow
; /**< Called to process samples. */
1572 sox_effect_handler_drain drain
; /**< Called to finish getting output after input is complete. */
1573 sox_effect_handler_stop stop
; /**< Called to shut down effect (called once per flow). */
1574 sox_effect_handler_kill kill
; /**< Called to shut down effect (called once per effect). */
1575 size_t priv_size
; /**< Size of private data SoX should pre-allocate for effect */
1582 struct sox_effect_t
{
1583 sox_effects_globals_t
* global_info
; /**< global effect parameters */
1584 sox_signalinfo_t in_signal
; /**< Information about the incoming data stream */
1585 sox_signalinfo_t out_signal
; /**< Information about the outgoing data stream */
1586 sox_encodinginfo_t
const * in_encoding
; /**< Information about the incoming data encoding */
1587 sox_encodinginfo_t
const * out_encoding
; /**< Information about the outgoing data encoding */
1588 sox_effect_handler_t handler
; /**< The handler for this effect */
1589 sox_uint64_t clips
; /**< increment if clipping occurs */
1590 size_t flows
; /**< 1 if MCHAN, number of chans otherwise */
1591 size_t flow
; /**< flow number */
1592 void * priv
; /**< Effect's private data area (each flow has a separate copy) */
1593 /* The following items are private to the libSoX effects chain functions. */
1594 sox_sample_t
* obuf
; /**< output buffer */
1595 size_t obeg
; /**< output buffer: start of valid data section */
1596 size_t oend
; /**< output buffer: one past valid data section (oend-obeg is length of current content) */
1597 size_t imin
; /**< minimum input buffer content required for calling this effect's flow function; set via lsx_effect_set_imin() */
1602 Chain of effects to be applied to a stream.
1604 typedef struct sox_effects_chain_t
{
1605 sox_effect_t
**effects
; /**< Table of effects to be applied to a stream */
1606 size_t length
; /**< Number of effects to be applied */
1607 sox_effects_globals_t global_info
; /**< Copy of global effects settings */
1608 sox_encodinginfo_t
const * in_enc
; /**< Input encoding */
1609 sox_encodinginfo_t
const * out_enc
; /**< Output encoding */
1610 /* The following items are private to the libSoX effects chain functions. */
1611 size_t table_size
; /**< Size of effects table (including unused entries) */
1612 sox_sample_t
*il_buf
; /**< Channel interleave buffer */
1613 } sox_effects_chain_t
;
1615 /*****************************************************************************
1617 *****************************************************************************/
1621 Returns version number string of libSoX, for example, "14.4.0".
1622 @returns The version number string of libSoX, for example, "14.4.0".
1624 LSX_RETURN_VALID_Z LSX_RETURN_PURE
1631 Returns information about this build of libsox.
1632 @returns Pointer to a version information structure.
1634 LSX_RETURN_VALID LSX_RETURN_PURE
1635 sox_version_info_t
const *
1637 sox_version_info(void);
1641 Returns a pointer to the structure with libSoX's global settings.
1642 @returns a pointer to the structure with libSoX's global settings.
1644 LSX_RETURN_VALID LSX_RETURN_PURE
1647 sox_get_globals(void);
1651 Deprecated macro that returns the structure with libSoX's global settings
1654 #define sox_globals (*sox_get_globals())
1658 Returns a pointer to the list of available encodings.
1659 End of list indicated by name == NULL.
1660 @returns pointer to the list of available encodings.
1662 LSX_RETURN_ARRAY LSX_RETURN_PURE
1663 sox_encodings_info_t
const *
1665 sox_get_encodings_info(void);
1669 Deprecated macro that returns the list of available encodings.
1670 End of list indicated by name == NULL.
1672 #define sox_encodings_info (sox_get_encodings_info())
1676 Fills in an encodinginfo with default values.
1680 sox_init_encodinginfo(
1681 LSX_PARAM_OUT sox_encodinginfo_t
* e
/**< Pointer to uninitialized encoding info structure to be initialized. */
1686 Given an encoding (for example, SIGN2) and the encoded bits_per_sample (for
1687 example, 16), returns the number of useful bits per sample in the decoded data
1688 (for example, 16), or returns 0 to indicate that the value returned by the
1689 format handler should be used instead of a pre-determined precision.
1690 @returns the number of useful bits per sample in the decoded data (for example
1691 16), or returns 0 to indicate that the value returned by the format handler
1692 should be used instead of a pre-determined precision.
1698 sox_encoding_t encoding
, /**< Encoding for which to lookup precision information. */
1699 unsigned bits_per_sample
/**< The number of encoded bits per sample. */
1704 Returns the number of items in the metadata block.
1705 @returns the number of items in the metadata block.
1710 LSX_PARAM_IN_OPT sox_comments_t comments
/**< Metadata block. */
1715 Adds an "id=value" item to the metadata block.
1720 LSX_PARAM_DEREF_PRE_MAYBENULL LSX_PARAM_DEREF_POST_NOTNULL sox_comments_t
* comments
, /**< Metadata block. */
1721 LSX_PARAM_IN_Z
char const * item
/**< Item to be added in "id=value" format. */
1726 Adds a newline-delimited list of "id=value" items to the metadata block.
1730 sox_append_comments(
1731 LSX_PARAM_DEREF_PRE_MAYBENULL LSX_PARAM_DEREF_POST_NOTNULL sox_comments_t
* comments
, /**< Metadata block. */
1732 LSX_PARAM_IN_Z
char const * items
/**< Newline-separated list of items to be added, for example "id1=value1\\nid2=value2". */
1737 Duplicates the metadata block.
1738 @returns the copied metadata block.
1744 LSX_PARAM_IN_OPT sox_comments_t comments
/**< Metadata block to copy. */
1749 Frees the metadata block.
1753 sox_delete_comments(
1754 LSX_PARAM_DEREF_PRE_MAYBENULL LSX_PARAM_DEREF_POST_NULL sox_comments_t
* comments
/**< Metadata block. */
1759 If "id=value" is found, return value, else return null.
1760 @returns value, or null if value not found.
1766 LSX_PARAM_IN_OPT sox_comments_t comments
, /**< Metadata block in which to search. */
1767 LSX_PARAM_IN_Z
char const * id
/**< Id for which to search */
1772 Find and load format handler plugins.
1773 @returns SOX_SUCCESS if successful.
1777 sox_format_init(void);
1781 Unload format handler plugins.
1785 sox_format_quit(void);
1789 Initialize effects library.
1790 @returns SOX_SUCCESS if successful.
1798 Close effects library and unload format handler plugins.
1799 @returns SOX_SUCCESS if successful.
1807 Returns the table of format handler names and functions.
1808 @returns the table of format handler names and functions.
1810 LSX_RETURN_ARRAY LSX_RETURN_PURE
1811 sox_format_tab_t
const *
1813 sox_get_format_fns(void);
1817 Deprecated macro that returns the table of format handler names and functions.
1819 #define sox_format_fns (sox_get_format_fns())
1823 Opens a decoding session for a file. Returned handle must be closed with sox_close().
1824 @returns The handle for the new session, or null on failure.
1830 LSX_PARAM_IN_Z
char const * path
, /**< Path to file to be opened (required). */
1831 LSX_PARAM_IN_OPT sox_signalinfo_t
const * signal
, /**< Information already known about audio stream, or NULL if none. */
1832 LSX_PARAM_IN_OPT sox_encodinginfo_t
const * encoding
, /**< Information already known about sample encoding, or NULL if none. */
1833 LSX_PARAM_IN_OPT_Z
char const * filetype
/**< Previously-determined file type, or NULL to auto-detect. */
1838 Opens a decoding session for a memory buffer. Returned handle must be closed with sox_close().
1839 @returns The handle for the new session, or null on failure.
1845 LSX_PARAM_IN_BYTECOUNT(buffer_size
) void * buffer
, /**< Pointer to audio data buffer (required). */
1846 size_t buffer_size
,/**< Number of bytes to read from audio data buffer. */
1847 LSX_PARAM_IN_OPT sox_signalinfo_t
const * signal
, /**< Information already known about audio stream, or NULL if none. */
1848 LSX_PARAM_IN_OPT sox_encodinginfo_t
const * encoding
, /**< Information already known about sample encoding, or NULL if none. */
1849 LSX_PARAM_IN_OPT_Z
char const * filetype
/**< Previously-determined file type, or NULL to auto-detect. */
1854 Returns true if the format handler for the specified file type supports the specified encoding.
1855 @returns true if the format handler for the specified file type supports the specified encoding.
1859 sox_format_supports_encoding(
1860 LSX_PARAM_IN_OPT_Z
char const * path
, /**< Path to file to be examined (required if filetype is NULL). */
1861 LSX_PARAM_IN_OPT_Z
char const * filetype
, /**< Previously-determined file type, or NULL to use extension from path. */
1862 LSX_PARAM_IN sox_encodinginfo_t
const * encoding
/**< Encoding for which format handler should be queried. */
1867 Gets the format handler for a specified file type.
1868 @returns The found format handler, or null if not found.
1871 sox_format_handler_t
const *
1874 LSX_PARAM_IN_OPT_Z
char const * path
, /**< Path to file (required if filetype is NULL). */
1875 LSX_PARAM_IN_OPT_Z
char const * filetype
, /**< Filetype for which handler is needed, or NULL to use extension from path. */
1876 LSX_PARAM_OUT_OPT
char const * * filetype1
/**< Receives the filetype that was detected. Pass NULL if not needed. */
1881 Opens an encoding session for a file. Returned handle must be closed with sox_close().
1882 @returns The new session handle, or null on failure.
1888 LSX_PARAM_IN_Z
char const * path
, /**< Path to file to be written (required). */
1889 LSX_PARAM_IN sox_signalinfo_t
const * signal
, /**< Information about desired audio stream (required). */
1890 LSX_PARAM_IN_OPT sox_encodinginfo_t
const * encoding
, /**< Information about desired sample encoding, or NULL to use defaults. */
1891 LSX_PARAM_IN_OPT_Z
char const * filetype
, /**< Previously-determined file type, or NULL to auto-detect. */
1892 LSX_PARAM_IN_OPT sox_oob_t
const * oob
, /**< Out-of-band data to add to file, or NULL if none. */
1893 LSX_PARAM_IN_OPT
sox_bool (LSX_API
* overwrite_permitted
)(LSX_PARAM_IN_Z
char const * filename
) /**< Called if file exists to determine whether overwrite is ok. */
1898 Opens an encoding session for a memory buffer. Returned handle must be closed with sox_close().
1899 @returns The new session handle, or null on failure.
1905 LSX_PARAM_OUT_BYTECAP(buffer_size
) void * buffer
, /**< Pointer to audio data buffer that receives data (required). */
1906 LSX_PARAM_IN
size_t buffer_size
, /**< Maximum number of bytes to write to audio data buffer. */
1907 LSX_PARAM_IN sox_signalinfo_t
const * signal
, /**< Information about desired audio stream (required). */
1908 LSX_PARAM_IN_OPT sox_encodinginfo_t
const * encoding
, /**< Information about desired sample encoding, or NULL to use defaults. */
1909 LSX_PARAM_IN_OPT_Z
char const * filetype
, /**< Previously-determined file type, or NULL to auto-detect. */
1910 LSX_PARAM_IN_OPT sox_oob_t
const * oob
/**< Out-of-band data to add to file, or NULL if none. */
1915 Opens an encoding session for a memstream buffer. Returned handle must be closed with sox_close().
1916 @returns The new session handle, or null on failure.
1921 sox_open_memstream_write(
1922 LSX_PARAM_OUT
char * * buffer_ptr
, /**< Receives pointer to audio data buffer that receives data (required). */
1923 LSX_PARAM_OUT
size_t * buffer_size_ptr
, /**< Receives size of data written to audio data buffer (required). */
1924 LSX_PARAM_IN sox_signalinfo_t
const * signal
, /**< Information about desired audio stream (required). */
1925 LSX_PARAM_IN_OPT sox_encodinginfo_t
const * encoding
, /**< Information about desired sample encoding, or NULL to use defaults. */
1926 LSX_PARAM_IN_OPT_Z
char const * filetype
, /**< Previously-determined file type, or NULL to auto-detect. */
1927 LSX_PARAM_IN_OPT sox_oob_t
const * oob
/**< Out-of-band data to add to file, or NULL if none. */
1932 Reads samples from a decoding session into a sample buffer.
1933 @returns Number of samples decoded, or 0 for EOF.
1938 LSX_PARAM_INOUT sox_format_t
* ft
, /**< Format pointer. */
1939 LSX_PARAM_OUT_CAP_POST_COUNT(len
,return) sox_sample_t
*buf
, /**< Buffer from which to read samples. */
1940 size_t len
/**< Number of samples available in buf. */
1945 Writes samples to an encoding session from a sample buffer.
1946 @returns Number of samples encoded.
1951 LSX_PARAM_INOUT sox_format_t
* ft
, /**< Format pointer. */
1952 LSX_PARAM_IN_COUNT(len
) sox_sample_t
const * buf
, /**< Buffer from which to read samples. */
1953 size_t len
/**< Number of samples available in buf. */
1958 Closes an encoding or decoding session.
1959 @returns SOX_SUCCESS if successful.
1964 LSX_PARAM_INOUT sox_format_t
* ft
/**< Format pointer. */
1969 Sets the location at which next samples will be decoded. Returns SOX_SUCCESS if successful.
1970 @returns SOX_SUCCESS if successful.
1975 LSX_PARAM_INOUT sox_format_t
* ft
, /**< Format pointer. */
1976 sox_uint64_t offset
, /**< Sample offset at which to position reader. */
1977 int whence
/**< Set to SOX_SEEK_SET. */
1982 Finds a format handler by name.
1983 @returns Format handler data, or null if not found.
1986 sox_format_handler_t
const *
1989 LSX_PARAM_IN_Z
char const * name
, /**< Name of format handler to find. */
1990 sox_bool ignore_devices
/**< Set to true to ignore device names. */
1995 Returns global parameters for effects
1996 @returns global parameters for effects.
1998 LSX_RETURN_VALID LSX_RETURN_PURE
1999 sox_effects_globals_t
*
2001 sox_get_effects_globals(void);
2005 Deprecated macro that returns global parameters for effects.
2007 #define sox_effects_globals (*sox_get_effects_globals())
2011 Finds the effect handler with the given name.
2012 @returns Effect pointer, or null if not found.
2014 LSX_RETURN_OPT LSX_RETURN_PURE
2015 sox_effect_handler_t
const *
2018 LSX_PARAM_IN_Z
char const * name
/**< Name of effect to find. */
2023 Creates an effect using the given handler.
2024 @returns The new effect, or null if not found.
2030 LSX_PARAM_IN sox_effect_handler_t
const * eh
/**< Handler to use for effect. */
2035 Applies the command-line options to the effect.
2036 @returns the number of arguments consumed.
2041 LSX_PARAM_IN sox_effect_t
*effp
, /**< Effect pointer on which to set options. */
2042 int argc
, /**< Number of arguments in argv. */
2043 LSX_PARAM_IN_COUNT(argc
) char * const argv
[] /**< Array of command-line options. */
2048 Returns an array containing the known effect handlers.
2049 @returns An array containing the known effect handlers.
2051 LSX_RETURN_VALID_Z LSX_RETURN_PURE
2052 sox_effect_fn_t
const *
2054 sox_get_effect_fns(void);
2058 Deprecated macro that returns an array containing the known effect handlers.
2060 #define sox_effect_fns (sox_get_effect_fns())
2064 Initializes an effects chain. Returned handle must be closed with sox_delete_effects_chain().
2065 @returns Handle, or null on failure.
2068 sox_effects_chain_t
*
2070 sox_create_effects_chain(
2071 LSX_PARAM_IN sox_encodinginfo_t
const * in_enc
, /**< Input encoding. */
2072 LSX_PARAM_IN sox_encodinginfo_t
const * out_enc
/**< Output encoding. */
2077 Closes an effects chain.
2081 sox_delete_effects_chain(
2082 LSX_PARAM_INOUT sox_effects_chain_t
*ecp
/**< Effects chain pointer. */
2087 Adds an effect to the effects chain, returns SOX_SUCCESS if successful.
2088 @returns SOX_SUCCESS if successful.
2093 LSX_PARAM_INOUT sox_effects_chain_t
* chain
, /**< Effects chain to which effect should be added . */
2094 LSX_PARAM_INOUT sox_effect_t
* effp
, /**< Effect to be added. */
2095 LSX_PARAM_INOUT sox_signalinfo_t
* in
, /**< Input format. */
2096 LSX_PARAM_IN sox_signalinfo_t
const * out
/**< Output format. */
2101 Runs the effects chain, returns SOX_SUCCESS if successful.
2102 @returns SOX_SUCCESS if successful.
2107 LSX_PARAM_INOUT sox_effects_chain_t
* chain
, /**< Effects chain to run. */
2108 LSX_PARAM_IN_OPT sox_flow_effects_callback callback
, /**< Callback for monitoring flow progress. */
2109 LSX_PARAM_IN_OPT
void * client_data
/**< Data to pass into callback. */
2114 Gets the number of clips that occurred while running an effects chain.
2115 @returns the number of clips that occurred while running an effects chain.
2120 LSX_PARAM_IN sox_effects_chain_t
* chain
/**< Effects chain from which to read clip information. */
2125 Shuts down an effect (calls stop on each of its flows).
2126 @returns the number of clips from all flows.
2131 LSX_PARAM_INOUT_COUNT(effp
->flows
) sox_effect_t
* effp
/**< Effect to stop. */
2136 Adds an already-initialized effect to the end of the chain.
2140 sox_push_effect_last(
2141 LSX_PARAM_INOUT sox_effects_chain_t
* chain
, /**< Effects chain to which effect should be added. */
2142 LSX_PARAM_INOUT sox_effect_t
* effp
/**< Effect to be added. */
2147 Removes and returns an effect from the end of the chain.
2148 @returns the removed effect, or null if no effects.
2153 sox_pop_effect_last(
2154 LSX_PARAM_INOUT sox_effects_chain_t
*chain
/**< Effects chain from which to remove an effect. */
2159 Shut down and delete an effect.
2164 LSX_PARAM_INOUT_COUNT(effp
->flows
) sox_effect_t
*effp
/**< Effect to be deleted. */
2169 Shut down and delete the last effect in the chain.
2173 sox_delete_effect_last(
2174 LSX_PARAM_INOUT sox_effects_chain_t
*chain
/**< Effects chain from which to remove the last effect. */
2179 Shut down and delete all effects in the chain.
2184 LSX_PARAM_INOUT sox_effects_chain_t
*chain
/**< Effects chain from which to delete effects. */
2189 Gets the sample offset of the start of the trim, useful for efficiently
2190 skipping the part that will be trimmed anyway (get trim start, seek, then
2192 @returns the sample offset of the start of the trim.
2197 LSX_PARAM_IN sox_effect_t
* effp
/**< Trim effect. */
2202 Clears the start of the trim to 0.
2206 sox_trim_clear_start(
2207 LSX_PARAM_INOUT sox_effect_t
* effp
/**< Trim effect. */
2212 Returns true if the specified file is a known playlist file type.
2213 @returns true if the specified file is a known playlist file type.
2218 LSX_PARAM_IN_Z
char const * filename
/**< Name of file to examine. */
2223 Parses the specified playlist file.
2224 @returns SOX_SUCCESS if successful.
2229 LSX_PARAM_IN sox_playlist_callback_t callback
, /**< Callback to call for each item in the playlist. */
2230 void * p
, /**< Data to pass to callback. */
2231 LSX_PARAM_IN
char const * const listname
/**< Filename of playlist file. */
2236 Converts a SoX error code into an error string.
2237 @returns error string corresponding to the specified error code,
2238 or a generic message if the error code is not recognized.
2240 LSX_RETURN_VALID_Z LSX_RETURN_PURE
2244 int sox_errno
/**< Error code to look up. */
2249 Gets the basename of the specified file; for example, the basename of
2250 "/a/b/c.d" would be "c".
2251 @returns the number of characters written to base_buffer, excluding the null,
2257 LSX_PARAM_OUT_Z_CAP_POST_COUNT(base_buffer_len
,return) char * base_buffer
, /**< Buffer into which basename should be written. */
2258 size_t base_buffer_len
, /**< Size of base_buffer, in bytes. */
2259 LSX_PARAM_IN_Z
char const * filename
/**< Filename from which to extract basename. */
2262 /*****************************************************************************
2264 WARNING - The items in this section are subject to instability. They only
2265 exist in the public header because sox (the application) currently uses them.
2266 These may be changed or removed in future versions of libSoX.
2267 *****************************************************************************/
2271 Print a fatal error in libSoX.
2276 LSX_PARAM_IN_PRINTF
char const * fmt
, /**< printf-style format string. */
2282 Print a warning in libSoX.
2287 LSX_PARAM_IN_PRINTF
char const * fmt
, /**< printf-style format string. */
2293 Print an informational message in libSoX.
2298 LSX_PARAM_IN_PRINTF
char const * fmt
, /**< printf-style format string. */
2304 Print a debug message in libSoX.
2309 LSX_PARAM_IN_PRINTF
char const * fmt
, /**< printf-style format string. */
2315 Report a fatal error in libSoX; printf-style arguments must follow.
2317 #define lsx_fail sox_get_globals()->subsystem=__FILE__,lsx_fail_impl
2321 Report a warning in libSoX; printf-style arguments must follow.
2323 #define lsx_warn sox_get_globals()->subsystem=__FILE__,lsx_warn_impl
2327 Report an informational message in libSoX; printf-style arguments must follow.
2329 #define lsx_report sox_get_globals()->subsystem=__FILE__,lsx_report_impl
2333 Report a debug message in libSoX; printf-style arguments must follow.
2335 #define lsx_debug sox_get_globals()->subsystem=__FILE__,lsx_debug_impl
2339 String name and integer values for enumerated types (type metadata), for use
2340 with LSX_ENUM_ITEM, lsx_find_enum_text, and lsx_find_enum_value.
2342 typedef struct lsx_enum_item
{
2343 char const *text
; /**< String name of enumeration. */
2344 unsigned value
; /**< Integer value of enumeration. */
2349 Declares a static instance of an lsx_enum_item structure in format
2350 { "item", prefixitem }, for use in declaring lsx_enum_item[] arrays.
2351 @param prefix The prefix to prepend to the item in the enumeration symbolic name.
2352 @param item The user-visible text name of the item (must also be a valid C symbol name).
2354 #define LSX_ENUM_ITEM(prefix, item) {#item, prefix##item},
2358 Flags for use with lsx_find_enum_item.
2362 lsx_find_enum_item_none
= 0, /**< Default parameters (case-insensitive). */
2363 lsx_find_enum_item_case_sensitive
= 1 /**< Enable case-sensitive search. */
2368 Looks up an enumeration by name in an array of lsx_enum_items.
2369 @returns the corresponding item, or null if not found.
2371 LSX_RETURN_OPT LSX_RETURN_PURE
2372 lsx_enum_item
const *
2375 LSX_PARAM_IN_Z
char const * text
, /**< Name of enumeration to find. */
2376 LSX_PARAM_IN lsx_enum_item
const * lsx_enum_items
, /**< Array of items to search, with text == NULL for last item. */
2377 int flags
/**< Search flags: 0 (case-insensitive) or lsx_find_enum_item_case_sensitive (case-sensitive). */
2382 Looks up an enumeration by value in an array of lsx_enum_items.
2383 @returns the corresponding item, or null if not found.
2385 LSX_RETURN_OPT LSX_RETURN_PURE
2386 lsx_enum_item
const *
2388 lsx_find_enum_value(
2389 unsigned value
, /**< Enumeration value to find. */
2390 LSX_PARAM_IN lsx_enum_item
const * lsx_enum_items
/**< Array of items to search, with text == NULL for last item. */
2395 Looks up a command-line argument in a set of enumeration names, showing an
2396 error message if the argument is not found in the set of names.
2397 @returns The enumeration value corresponding to the matching enumeration, or
2398 INT_MAX if the argument does not match any enumeration name.
2404 int c
, /**< Option character to which arg is associated, for example with -a, c would be 'a'. */
2405 LSX_PARAM_IN_Z
char const * arg
, /**< Argument to find in enumeration list. */
2406 LSX_PARAM_IN lsx_enum_item
const * items
/**< Array of items to search, with text == NULL for last item. */
2411 Determines whether the specified string ends with the specified suffix (case-sensitive).
2412 @returns true if the specified string ends with the specified suffix.
2418 LSX_PARAM_IN_Z
char const * str
, /**< String to search. */
2419 LSX_PARAM_IN_Z
char const * end
/**< Suffix to search for. */
2424 Finds the file extension for a filename.
2425 @returns the file extension, not including the '.', or null if filename does
2426 not have an extension.
2428 LSX_RETURN_OPT LSX_RETURN_PURE
2431 lsx_find_file_extension(
2432 LSX_PARAM_IN_Z
char const * pathname
/**< Filename to search for extension. */
2437 Formats the specified number with up to three significant figures and adds a
2438 metric suffix in place of the exponent, such as 1.23G.
2439 @returns A static buffer with the formatted number, valid until the next time
2440 this function is called (note: not thread safe).
2446 double number
/**< Number to be formatted. */
2451 Formats the specified number as a percentage, showing up to three significant
2453 @returns A static buffer with the formatted number, valid until the next time
2454 this function is called (note: not thread safe).
2460 double percentage
/**< Number to be formatted. */
2465 Allocates, deallocates, or resizes; like C's realloc, except that this version
2466 terminates the running application if unable to allocate the requested memory.
2467 @returns New buffer, or null if buffer was freed.
2473 LSX_PARAM_IN_OPT
void *ptr
, /**< Pointer to be freed or resized, or null if allocating a new buffer. */
2474 size_t newsize
/**< New size for buffer, or 0 to free the buffer. */
2479 Like strcmp, except that the characters are compared without regard to case.
2480 @returns 0 (s1 == s2), negative (s1 < s2), or positive (s1 > s2).
2486 LSX_PARAM_IN_Z
char const * s1
, /**< First string. */
2487 LSX_PARAM_IN_Z
char const * s2
/**< Second string. */
2493 Like strncmp, except that the characters are compared without regard to case.
2494 @returns 0 (s1 == s2), negative (s1 < s2), or positive (s1 > s2).
2500 LSX_PARAM_IN_Z
char const * s1
, /**< First string. */
2501 LSX_PARAM_IN_Z
char const * s2
, /**< Second string. */
2502 size_t n
/**< Maximum number of characters to examine. */
2507 Is option argument unsupported, required, or optional.
2509 typedef enum lsx_option_arg_t
{
2510 lsx_option_arg_none
, /**< Option does not have an argument. */
2511 lsx_option_arg_required
, /**< Option requires an argument. */
2512 lsx_option_arg_optional
/**< Option can optionally be followed by an argument. */
2517 lsx_getopt_init options.
2519 typedef enum lsx_getopt_flags_t
{
2520 lsx_getopt_flag_none
= 0, /**< no flags (no output, not long-only) */
2521 lsx_getopt_flag_opterr
= 1, /**< if set, invalid options trigger lsx_warn output */
2522 lsx_getopt_flag_longonly
= 2 /**< if set, recognize -option as a long option */
2523 } lsx_getopt_flags_t
;
2527 lsx_getopt long option descriptor.
2529 typedef struct lsx_option_t
{
2530 char const * name
; /**< Name of the long option. */
2531 lsx_option_arg_t has_arg
; /**< Whether the long option supports an argument and, if so, whether the argument is required or optional. */
2532 int * flag
; /**< Flag to set if argument is present. */
2533 int val
; /**< Value to put in flag if argument is present. */
2538 lsx_getopt session information (initialization data and state).
2540 typedef struct lsx_getopt_t
{
2541 int argc
; /**< IN argc: Number of arguments in argv */
2542 char * const * argv
; /**< IN argv: Array of arguments */
2543 char const * shortopts
;/**< IN shortopts: Short option characters */
2544 lsx_option_t
const * longopts
; /**< IN longopts: Array of long option descriptors */
2545 lsx_getopt_flags_t flags
; /**< IN flags: Flags for longonly and opterr */
2546 char const * curpos
; /**< INOUT curpos: Maintains state between calls to lsx_getopt */
2547 int ind
; /**< INOUT optind: Maintains the index of next element to be processed */
2548 int opt
; /**< OUT optopt: Receives the option character that caused error */
2549 char const * arg
; /**< OUT optarg: Receives the value of the option's argument */
2550 int lngind
; /**< OUT lngind: Receives the index of the matched long option or -1 if not a long option */
2555 Initializes an lsx_getopt_t structure for use with lsx_getopt.
2560 LSX_PARAM_IN
int argc
, /**< Number of arguments in argv */
2561 LSX_PARAM_IN_COUNT(argc
) char * const * argv
, /**< Array of arguments */
2562 LSX_PARAM_IN_Z
char const * shortopts
, /**< Short options, for example ":abc:def::ghi" (+/- not supported) */
2563 LSX_PARAM_IN_OPT lsx_option_t
const * longopts
, /**< Array of long option descriptors */
2564 LSX_PARAM_IN lsx_getopt_flags_t flags
, /**< Flags for longonly and opterr */
2565 LSX_PARAM_IN
int first
, /**< First argv to check (usually 1) */
2566 LSX_PARAM_OUT lsx_getopt_t
* state
/**< State object to be initialized */
2571 Gets the next option. Options are parameters that start with "-" or "--".
2572 If no more options, returns -1. If unrecognized short option, returns '?'.
2573 If a recognized short option is missing a required argument,
2574 return (shortopts[0]==':' ? ':' : '?'). If successfully recognized short
2575 option, return the recognized character. If successfully recognized long
2576 option, returns (option.flag ? 0 : option.val).
2577 Note: lsx_getopt does not permute the non-option arguments.
2578 @returns option character (short), val or 0 (long), or -1 (no more).
2583 LSX_PARAM_INOUT lsx_getopt_t
* state
/**< The getopt state pointer. */
2588 Gets the file length, or 0 if the file is not seekable/normal.
2589 @returns The file length, or 0 if the file is not seekable/normal.
2594 LSX_PARAM_IN sox_format_t
* ft
2599 #if defined(__cplusplus)