├── src ├── G72x │ ├── README │ ├── ChangeLog │ ├── README.original │ ├── g72x.h │ ├── g723_24.c │ ├── g72x_priv.h │ ├── g721.c │ ├── g723_16.c │ ├── g723_40.c │ └── g72x_test.c ├── GSM610 │ ├── gsm_destroy.c │ ├── COPYRIGHT │ ├── gsm_create.c │ ├── config.h │ ├── gsm_option.c │ ├── gsm.h │ ├── README │ ├── decode.c │ ├── ChangeLog │ ├── table.c │ ├── code.c │ └── preprocess.c ├── version-metadata.rc ├── ALAC │ ├── shift.h │ ├── EndianPortable.h │ ├── dplib.h │ ├── aglib.h │ ├── ALACBitUtilities.h │ ├── alac_codec.h │ └── matrixlib.h ├── chanmap.h ├── test_main.h ├── macos.c ├── ogg.h ├── test_binheader_writef.c ├── test_strncpy_crlf.c ├── ima_oki_adpcm.h ├── test_main.c ├── id3.c ├── sf_unistd.h ├── sflrint.h ├── sfconfig.h ├── windows.c ├── test_cart_var.c ├── raw.c ├── audio_detect.c ├── test_float.c ├── cart.c ├── test_conversions.c ├── test_broadcast_var.c ├── ogg_opus.c ├── ogg_pcm.c ├── test_log_printf.c ├── test_audio_detect.c ├── pvf.c ├── test_ima_oki_adpcm.c └── strings.c ├── doc ├── vorbis.AUTHORS.txt ├── ogg.AUTHORS.txt ├── ogg.COPYING.txt ├── vorbis.COPYING.txt ├── flac.COPYING.txt ├── flac.AUTHORS.txt └── vorbis.README.txt ├── .gitignore ├── libsndfile_VS2017.props ├── mkdocs.cmd ├── AUTHORS.txt ├── examples ├── example_VS2013.vcxproj.filters ├── example_VS2015.vcxproj.filters ├── example_VS2017.vcxproj.filters ├── src │ └── main.cpp ├── example_VS2013.vcxproj ├── example_VS2015.vcxproj └── example_VS2017.vcxproj ├── libsndfile_VS2013.sln ├── libsndfile_VS2015.sln ├── libsndfile_VS2017.sln ├── README.txt └── README.md /src/G72x/README: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/vorbis.AUTHORS.txt: -------------------------------------------------------------------------------- 1 | Monty 2 | 3 | and the rest of the Xiph.org Foundation. 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /out 2 | /obj 3 | /lib 4 | /include 5 | /examples/obj 6 | /examples/bin 7 | /.vs 8 | *.user 9 | *.suo 10 | *.sdf 11 | *.opensdf 12 | *.opendb 13 | *.html 14 | *.VC.db 15 | -------------------------------------------------------------------------------- /doc/ogg.AUTHORS.txt: -------------------------------------------------------------------------------- 1 | Monty 2 | Greg Maxwell 3 | Ralph Giles 4 | Cristian Adam 5 | Tim Terriberry 6 | 7 | and the rest of the Xiph.Org Foundation. 8 | -------------------------------------------------------------------------------- /libsndfile_VS2017.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | 9 | 10 | 11 | $(XPDeprecationWarning) 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/GSM610/gsm_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische 3 | * Universitaet Berlin. See the accompanying file "COPYRIGHT" for 4 | * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 5 | */ 6 | 7 | #include "gsm.h" 8 | #include "config.h" 9 | 10 | #ifdef HAS_STDLIB_H 11 | # include 12 | #else 13 | # ifdef HAS_MALLOC_H 14 | # include 15 | # else 16 | extern void free () ; 17 | # endif 18 | #endif 19 | 20 | void gsm_destroy (gsm S) 21 | { 22 | if (S) 23 | free ((char *) S) ; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /mkdocs.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if not exist "%JAVA_HOME%\bin\java.exe" ( 4 | echo Java could not be found, please make sure JAVA_HOME is set correctly! 5 | pause && goto:eof 6 | ) 7 | 8 | "%~dp0\..\Prerequisites\Pandoc\pandoc.exe" --from markdown --to html5 --toc -N --standalone --self-contained -c "%~dp0\..\Prerequisites\Pandoc\css\github-pandoc.css" --output "%~dp0\README.html" "%~dp0\README.md" 9 | 10 | "%JAVA_HOME%\bin\java.exe" -jar "%~dp0\..\Prerequisites\HTMLCompressor\bin\htmlcompressor-1.5.3.jar" --compress-css -o "%~dp0\README.min.html" "%~dp0\README.html" 11 | move /Y "%~dp0\README.min.html" "%~dp0\README.html" 12 | 13 | pause 14 | -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- 1 | The main author of libsndfile is Erik de Castro Lopo 2 | apart from code in the following directories: 3 | 4 | - src/GSM610 : Written by Jutta Degener and Carsten 5 | Bormann . They should not be contacted in relation to 6 | libsndfile or the GSM 6.10 code that is part of libsndfile. Their original 7 | code can be found at: 8 | 9 | http://kbs.cs.tu-berlin.de/~jutta/toast.html 10 | 11 | - src/G72x : Released by Sun Microsystems, Inc. to the public domain. Minor 12 | modifications were required to integrate these files into libsndfile. The 13 | changes are listed in src/G72x/ChangeLog. 14 | 15 | -------------------------------------------------------------------------------- /src/GSM610/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann, 2 | Technische Universitaet Berlin 3 | 4 | Any use of this software is permitted provided that this notice is not 5 | removed and that neither the authors nor the Technische Universitaet Berlin 6 | are deemed to have made any representations as to the suitability of this 7 | software for any purpose nor are held responsible for any defects of 8 | this software. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 9 | 10 | As a matter of courtesy, the authors request to be informed about uses 11 | this software has found, about bugs in this software, and about any 12 | improvements that may be of general interest. 13 | 14 | Berlin, 28.11.1994 15 | Jutta Degener 16 | Carsten Bormann 17 | -------------------------------------------------------------------------------- /src/GSM610/gsm_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische 3 | * Universitaet Berlin. See the accompanying file "COPYRIGHT" for 4 | * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 5 | */ 6 | 7 | #include "config.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | 15 | #include "gsm.h" 16 | #include "gsm610_priv.h" 17 | 18 | gsm gsm_create (void) 19 | { 20 | gsm r ; 21 | 22 | r = malloc (sizeof (struct gsm_state)) ; 23 | if (!r) return r ; 24 | 25 | memset ((char *) r, 0, sizeof (struct gsm_state)) ; 26 | r->nrp = 40 ; 27 | 28 | return r ; 29 | } 30 | 31 | /* Added for libsndfile : May 6, 2002. Not sure if it works. */ 32 | void gsm_init (gsm state) 33 | { 34 | memset (state, 0, sizeof (struct gsm_state)) ; 35 | state->nrp = 40 ; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/GSM610/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische 3 | * Universitaet Berlin. See the accompanying file "COPYRIGHT" for 4 | * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 5 | */ 6 | 7 | #ifndef CONFIG_H 8 | #define CONFIG_H 9 | 10 | #define HAS_STDLIB_H 1 /* /usr/include/stdlib.h */ 11 | #define HAS_FCNTL_H 1 /* /usr/include/fcntl.h */ 12 | 13 | #define HAS_FSTAT 1 /* fstat syscall */ 14 | #define HAS_FCHMOD 1 /* fchmod syscall */ 15 | #define HAS_CHMOD 1 /* chmod syscall */ 16 | #define HAS_FCHOWN 1 /* fchown syscall */ 17 | #define HAS_CHOWN 1 /* chown syscall */ 18 | 19 | #define HAS_STRING_H 1 /* /usr/include/string.h */ 20 | 21 | #define HAS_UNISTD_H 1 /* /usr/include/unistd.h */ 22 | #define HAS_UTIME 1 /* POSIX utime(path, times) */ 23 | #define HAS_UTIME_H 1 /* UTIME header file */ 24 | 25 | #endif /* CONFIG_H */ 26 | 27 | -------------------------------------------------------------------------------- /src/version-metadata.rc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_AUS 4 | 1 VERSIONINFO 5 | FILEVERSION 1,0,28,0 6 | PRODUCTVERSION 1,0,28,0 7 | FILEOS VOS__WINDOWS32 8 | FILETYPE VFT_DLL 9 | FILESUBTYPE VFT2_UNKNOWN 10 | FILEFLAGSMASK 0x00000000 11 | FILEFLAGS 0x00000000 12 | { 13 | BLOCK "StringFileInfo" 14 | { 15 | BLOCK "040904e4" 16 | { 17 | VALUE "FileDescription", "A library for reading and writing audio files." 18 | VALUE "FileVersion", "1.0.28.0\0" 19 | VALUE "Full Version", "1.0.28" 20 | VALUE "InternalName", "libsndfile" 21 | VALUE "LegalCopyright", "Copyright (C) 1999-2012, Licensed LGPL" 22 | VALUE "OriginalFilename", "libsndfile-1.dll" 23 | VALUE "ProductName", "libsndfile-1 DLL" 24 | VALUE "ProductVersion", "1.0.28.0\0" 25 | VALUE "Language", "Language Neutral" 26 | } 27 | } 28 | BLOCK "VarFileInfo" 29 | { 30 | VALUE "Translation", 0x0409, 0x04E4 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/example_VS2013.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/example_VS2015.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/example_VS2017.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/ALAC/shift.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2014 Erik de Castro Lopo 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 | #if __GNUC__ 20 | #define ALWAYS_INLINE __attribute__ ((always_inline)) 21 | #else 22 | #define ALWAYS_INLINE 23 | #endif 24 | 25 | 26 | static inline int32_t ALWAYS_INLINE 27 | arith_shift_left (int32_t x, int shift) 28 | { return (int32_t) (((uint32_t) x) << shift) ; 29 | } /* arith_shift_left */ 30 | -------------------------------------------------------------------------------- /src/ALAC/EndianPortable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Apple Inc. All rights reserved. 3 | ** Copyright (C) 2013-2014 Erik de Castro Lopo 4 | * 5 | * @APPLE_APACHE_LICENSE_HEADER_START@ 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License") ; 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * @APPLE_APACHE_LICENSE_HEADER_END@ 20 | */ 21 | 22 | // 23 | // EndianPortable.h 24 | // 25 | // Copyright 2011 Apple Inc. All rights reserved. 26 | // 27 | 28 | #ifndef _EndianPortable_h 29 | #define _EndianPortable_h 30 | 31 | #include 32 | 33 | #define Swap16NtoB(x) H2BE_16 (x) 34 | #define Swap16BtoN(x) BE2H_16 (x) 35 | 36 | #define Swap32NtoB(x) H2BE_32 (x) 37 | #define Swap32BtoN(x) BE2H_32 (x) 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/chanmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2009-2011 Erik de Castro Lopo 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 | typedef struct 20 | { /* The tag in the AIFF or CAF file. */ 21 | int channel_layout_tag ; 22 | 23 | /* The equivalent array of SF_CHANNEL_MAP_* entries. */ 24 | const int * channel_map ; 25 | 26 | const char * name ; 27 | } AIFF_CAF_CHANNEL_MAP ; 28 | 29 | 30 | int aiff_caf_find_channel_layout_tag (const int *chan_map, int channels) ; 31 | 32 | const AIFF_CAF_CHANNEL_MAP * aiff_caf_of_channel_layout_tag (int tag) ; 33 | -------------------------------------------------------------------------------- /src/GSM610/gsm_option.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische 3 | * Universitaet Berlin. See the accompanying file "COPYRIGHT" for 4 | * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 5 | */ 6 | 7 | #include "gsm610_priv.h" 8 | 9 | #include "gsm.h" 10 | 11 | int gsm_option (gsm r, int opt, int * val) 12 | { 13 | int result = -1 ; 14 | 15 | switch (opt) { 16 | case GSM_OPT_LTP_CUT: 17 | #ifdef LTP_CUT 18 | result = r->ltp_cut ; 19 | if (val) r->ltp_cut = *val ; 20 | #endif 21 | break ; 22 | 23 | case GSM_OPT_VERBOSE: 24 | #ifndef NDEBUG 25 | result = r->verbose ; 26 | if (val) r->verbose = *val ; 27 | #endif 28 | break ; 29 | 30 | case GSM_OPT_FAST: 31 | 32 | #if defined (FAST) && defined (USE_FLOAT_MUL) 33 | result = r->fast ; 34 | if (val) r->fast = !!*val ; 35 | #endif 36 | break ; 37 | 38 | case GSM_OPT_FRAME_CHAIN: 39 | 40 | #ifdef WAV49 41 | result = r->frame_chain ; 42 | if (val) r->frame_chain = *val ; 43 | #endif 44 | break ; 45 | 46 | case GSM_OPT_FRAME_INDEX: 47 | 48 | #ifdef WAV49 49 | result = r->frame_index ; 50 | if (val) r->frame_index = *val ; 51 | #endif 52 | break ; 53 | 54 | case GSM_OPT_WAV49: 55 | 56 | #ifdef WAV49 57 | result = r->wav_fmt ; 58 | if (val) r->wav_fmt = !!*val ; 59 | #endif 60 | break ; 61 | 62 | default: 63 | break ; 64 | } 65 | return result ; 66 | } 67 | -------------------------------------------------------------------------------- /src/GSM610/gsm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische 3 | * Universitaet Berlin. See the accompanying file "COPYRIGHT" for 4 | * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 5 | */ 6 | 7 | #ifndef GSM_H 8 | #define GSM_H 9 | 10 | #include /* for FILE * */ 11 | 12 | /* 13 | * Interface 14 | */ 15 | 16 | typedef struct gsm_state * gsm ; 17 | typedef short gsm_signal ; /* signed 16 bit */ 18 | typedef unsigned char gsm_byte ; 19 | typedef gsm_byte gsm_frame [33] ; /* 33 * 8 bits */ 20 | 21 | #define GSM_MAGIC 0xD /* 13 kbit/s RPE-LTP */ 22 | 23 | #define GSM_PATCHLEVEL 10 24 | #define GSM_MINOR 0 25 | #define GSM_MAJOR 1 26 | 27 | #define GSM_OPT_VERBOSE 1 28 | #define GSM_OPT_FAST 2 29 | #define GSM_OPT_LTP_CUT 3 30 | #define GSM_OPT_WAV49 4 31 | #define GSM_OPT_FRAME_INDEX 5 32 | #define GSM_OPT_FRAME_CHAIN 6 33 | 34 | gsm gsm_create (void) ; 35 | 36 | /* Added for libsndfile : May 6, 2002 */ 37 | void gsm_init (gsm) ; 38 | 39 | void gsm_destroy (gsm) ; 40 | 41 | int gsm_print (FILE *, gsm, gsm_byte *) ; 42 | int gsm_option (gsm, int, int *) ; 43 | 44 | void gsm_encode (gsm, gsm_signal *, gsm_byte *) ; 45 | int gsm_decode (gsm, gsm_byte *, gsm_signal *) ; 46 | 47 | int gsm_explode (gsm, gsm_byte *, gsm_signal *) ; 48 | void gsm_implode (gsm, gsm_signal *, gsm_byte *) ; 49 | 50 | #endif /* GSM_H */ 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/test_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2008-2016 Erik de Castro Lopo 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 | static inline void 20 | print_test_name (const char * name) 21 | { printf (" %-40s : ", name) ; 22 | fflush (stdout) ; 23 | } /* print_test_name */ 24 | 25 | 26 | 27 | void test_conversions (void) ; 28 | void test_endswap (void) ; 29 | void test_log_printf (void) ; 30 | void test_binheader_writef (void) ; 31 | void test_file_io (void) ; 32 | 33 | void test_float_convert (void) ; 34 | void test_double_convert (void) ; 35 | 36 | void test_audio_detect (void) ; 37 | void test_ima_oki_adpcm (void) ; 38 | 39 | void test_psf_strlcpy_crlf (void) ; 40 | void test_broadcast_var (void) ; 41 | 42 | void test_cart_var (void) ; 43 | -------------------------------------------------------------------------------- /src/GSM610/README: -------------------------------------------------------------------------------- 1 | GSM 06.10 13 kbit/s RPE/LTP speech codec 2 | ---------------------------------------- 3 | 4 | All the file in this directory were written by Jutta Degener 5 | and Carsten Borman for The Communications and Operating Systems 6 | Research Group (KBS) at the Technische Universitaet Berlin. 7 | 8 | Their work was released under the following license which is 9 | assumed to be compatible with The GNU Lesser General Public License. 10 | 11 | ---------------------------------------------------------------------------- 12 | 13 | Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann, 14 | Technische Universitaet Berlin 15 | 16 | Any use of this software is permitted provided that this notice is not 17 | removed and that neither the authors nor the Technische Universitaet Berlin 18 | are deemed to have made any representations as to the suitability of this 19 | software for any purpose nor are held responsible for any defects of 20 | this software. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 21 | 22 | As a matter of courtesy, the authors request to be informed about uses 23 | this software has found, about bugs in this software, and about any 24 | improvements that may be of general interest. 25 | 26 | Berlin, 28.11.1994 27 | Jutta Degener (jutta@cs.tu-berlin.de) 28 | Carsten Bormann (cabo@cs.tu-berlin.de) 29 | 30 | ---------------------------------------------------------------------------- 31 | 32 | Jutta Degener and Carsten Bormann's work can be found on their homepage 33 | at: 34 | 35 | http://kbs.cs.tu-berlin.de/~jutta/toast.html 36 | 37 | -------------------------------------------------------------------------------- /doc/ogg.COPYING.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002, Xiph.org Foundation 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | - Neither the name of the Xiph.org Foundation nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION 22 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /doc/vorbis.COPYING.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2015 Xiph.org Foundation 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | - Neither the name of the Xiph.org Foundation nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION 22 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /doc/flac.COPYING.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2000-2009 Josh Coalson 2 | Copyright (C) 2011-2014 Xiph.Org Foundation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of the Xiph.org Foundation nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 23 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /src/GSM610/decode.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische 3 | * Universitaet Berlin. See the accompanying file "COPYRIGHT" for 4 | * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 5 | */ 6 | 7 | #include 8 | 9 | #include "gsm610_priv.h" 10 | 11 | /* 12 | * 4.3 FIXED POINT IMPLEMENTATION OF THE RPE-LTP DECODER 13 | */ 14 | 15 | static void Postprocessing ( 16 | struct gsm_state * S, 17 | register int16_t * s) 18 | { 19 | register int k ; 20 | register int16_t msr = S->msr ; 21 | register int16_t tmp ; 22 | 23 | for (k = 160 ; k-- ; s++) 24 | { tmp = GSM_MULT_R (msr, 28180) ; 25 | msr = GSM_ADD (*s, tmp) ; /* Deemphasis */ 26 | *s = GSM_ADD (msr, msr) & 0xFFF8 ; /* Truncation & Upscaling */ 27 | } 28 | S->msr = msr ; 29 | } 30 | 31 | void Gsm_Decoder ( 32 | struct gsm_state * S, 33 | 34 | int16_t * LARcr, /* [0..7] IN */ 35 | 36 | int16_t * Ncr, /* [0..3] IN */ 37 | int16_t * bcr, /* [0..3] IN */ 38 | int16_t * Mcr, /* [0..3] IN */ 39 | int16_t * xmaxcr, /* [0..3] IN */ 40 | int16_t * xMcr, /* [0..13*4] IN */ 41 | 42 | int16_t * s) /* [0..159] OUT */ 43 | { 44 | int j, k ; 45 | int16_t erp [40], wt [160] ; 46 | int16_t *drp = S->dp0 + 120 ; 47 | 48 | for (j = 0 ; j <= 3 ; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) 49 | { Gsm_RPE_Decoding (/*-S,-*/ *xmaxcr, *Mcr, xMcr, erp) ; 50 | Gsm_Long_Term_Synthesis_Filtering (S, *Ncr, *bcr, erp, drp) ; 51 | 52 | for (k = 0 ; k <= 39 ; k++) wt [j * 40 + k] = drp [k] ; 53 | } 54 | 55 | Gsm_Short_Term_Synthesis_Filter (S, LARcr, wt, s) ; 56 | Postprocessing (S, s) ; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /libsndfile_VS2013.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.40629.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsndfile_VS2013", "libsndfile_VS2013.vcxproj", "{65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_VS2013", "examples\example_VS2013.vcxproj", "{43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A} = {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Win32 = Debug|Win32 16 | Release|Win32 = Release|Win32 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Debug|Win32.ActiveCfg = Debug|Win32 20 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Debug|Win32.Build.0 = Debug|Win32 21 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Release|Win32.ActiveCfg = Release|Win32 22 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Release|Win32.Build.0 = Release|Win32 23 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Debug|Win32.Build.0 = Debug|Win32 25 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Release|Win32.ActiveCfg = Release|Win32 26 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Release|Win32.Build.0 = Release|Win32 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /libsndfile_VS2015.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsndfile_VS2015", "libsndfile_VS2015.vcxproj", "{65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_VS2015", "examples\example_VS2015.vcxproj", "{43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A} = {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Win32 = Debug|Win32 16 | Release|Win32 = Release|Win32 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Debug|Win32.ActiveCfg = Debug|Win32 20 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Debug|Win32.Build.0 = Debug|Win32 21 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Release|Win32.ActiveCfg = Release|Win32 22 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Release|Win32.Build.0 = Release|Win32 23 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Debug|Win32.Build.0 = Debug|Win32 25 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Release|Win32.ActiveCfg = Release|Win32 26 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Release|Win32.Build.0 = Release|Win32 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /libsndfile_VS2017.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26430.16 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsndfile_VS2017", "libsndfile_VS2017.vcxproj", "{65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_VS2017", "examples\example_VS2017.vcxproj", "{43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A} = {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Win32 = Debug|Win32 16 | Release|Win32 = Release|Win32 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Debug|Win32.ActiveCfg = Debug|Win32 20 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Debug|Win32.Build.0 = Debug|Win32 21 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Release|Win32.ActiveCfg = Release|Win32 22 | {65B6B9E6-4D10-484B-BD8A-156FCA00DD4A}.Release|Win32.Build.0 = Release|Win32 23 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Debug|Win32.Build.0 = Debug|Win32 25 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Release|Win32.ActiveCfg = Release|Win32 26 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A}.Release|Win32.Build.0 = Release|Win32 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /src/macos.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2003-2011 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "sndfile.h" 26 | #include "sfendian.h" 27 | #include "common.h" 28 | 29 | #define STR_MARKER MAKE_MARKER ('S', 'T', 'R', ' ') 30 | 31 | int 32 | macos_guess_file_type (SF_PRIVATE * psf, const char *filename) 33 | { static char rsrc_name [1024] ; 34 | struct stat statbuf ; 35 | 36 | snprintf (rsrc_name, sizeof (rsrc_name), "%s/rsrc", filename) ; 37 | 38 | /* If there is no resource fork, just return. */ 39 | if (stat (rsrc_name, &statbuf) != 0) 40 | { psf_log_printf (psf, "No resource fork.\n") ; 41 | return 0 ; 42 | } ; 43 | 44 | if (statbuf.st_size == 0) 45 | { psf_log_printf (psf, "Have zero size resource fork.\n") ; 46 | return 0 ; 47 | } ; 48 | 49 | return 0 ; 50 | } /* macos_guess_file_type */ 51 | 52 | -------------------------------------------------------------------------------- /src/ogg.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2008-2011 Erik de Castro Lopo 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 SF_SRC_OGG_H 20 | 21 | enum 22 | { OGG_ANNODEX = 300, 23 | OGG_ANXDATA, 24 | OGG_FLAC, 25 | OGG_FLAC0, 26 | OGG_PCM, 27 | OGG_SPEEX, 28 | OGG_VORBIS, 29 | } ; 30 | 31 | typedef struct 32 | { /* Sync and verify incoming physical bitstream */ 33 | ogg_sync_state osync ; 34 | /* Take physical pages, weld into a logical stream of packets */ 35 | ogg_stream_state ostream ; 36 | /* One Ogg bitstream page. Vorbis packets are inside */ 37 | ogg_page opage ; 38 | /* One raw packet of data for decode */ 39 | ogg_packet opacket ; 40 | int eos ; 41 | int codec ; 42 | } OGG_PRIVATE ; 43 | 44 | 45 | #define readint(buf, base) (((buf [base + 3] << 24) & 0xff000000) | \ 46 | ((buf [base + 2] <<16) & 0xff0000) | \ 47 | ((buf [base + 1] << 8) & 0xff00) | \ 48 | (buf [base] & 0xff)) 49 | 50 | 51 | 52 | #endif /* SF_SRC_OGG_H */ 53 | -------------------------------------------------------------------------------- /src/test_binheader_writef.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2016 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "common.h" 28 | 29 | #include "test_main.h" 30 | 31 | void 32 | test_binheader_writef (void) 33 | { char buffer [18] ; 34 | SF_PRIVATE sf_private, *psf ; 35 | int k, errors = 0 ; 36 | 37 | print_test_name ("Testing binheader_writef") ; 38 | 39 | memset (&sf_private, 0, sizeof (sf_private)) ; 40 | 41 | psf = &sf_private ; 42 | for (k = 0 ; errors == 0 && k < 10 ; k++) 43 | { psf_strlcpy (buffer, sizeof (buffer), "abcdefghijklmnop") ; 44 | buffer [k] = 0 ; 45 | 46 | psf_binheader_writef (psf, "Ep", buffer) ; 47 | 48 | if ((psf->header.indx & 1) != 0) 49 | errors = 1 ; 50 | } ; 51 | 52 | free (psf->header.ptr) ; 53 | 54 | if (errors) 55 | { puts ("\nExiting due to errors.\n") ; 56 | exit (1) ; 57 | } ; 58 | 59 | puts ("ok") ; 60 | } /* test_log_printf */ 61 | 62 | -------------------------------------------------------------------------------- /src/ALAC/dplib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_APACHE_LICENSE_HEADER_START@ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License") ; 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * @APPLE_APACHE_LICENSE_HEADER_END@ 19 | */ 20 | 21 | /* 22 | File: dplib.h 23 | 24 | Contains: Dynamic Predictor routines 25 | 26 | Copyright: Copyright (C) 2001-2011 Apple, Inc. 27 | */ 28 | 29 | #ifndef __DPLIB_H__ 30 | #define __DPLIB_H__ 31 | 32 | #include 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | // defines 39 | 40 | #define DENSHIFT_MAX 15 41 | #define DENSHIFT_DEFAULT 9 42 | #define AINIT 38 43 | #define BINIT (-29) 44 | #define CINIT (-2) 45 | #define NUMCOEPAIRS 16 46 | 47 | // prototypes 48 | 49 | void init_coefs (int16_t * coefs, uint32_t denshift, int32_t numPairs) ; 50 | void copy_coefs (const int16_t * srcCoefs, int16_t * dstCoefs, int32_t numPairs) ; 51 | 52 | // NOTE: these routines read at least "numactive" samples so the i/o buffers must be at least that big 53 | 54 | void pc_block (int32_t * in, int32_t * pc, int32_t num, int16_t * coefs, int32_t numactive, uint32_t chanbits, uint32_t denshift) ; 55 | void unpc_block (const int32_t * pc, int32_t * out, int32_t num, int16_t * coefs, int32_t numactive, uint32_t chanbits, uint32_t denshift) ; 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* __DPLIB_H__ */ 62 | -------------------------------------------------------------------------------- /src/test_strncpy_crlf.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2010-2012 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | 24 | #include "common.h" 25 | 26 | #include "test_main.h" 27 | 28 | void 29 | test_psf_strlcpy_crlf (void) 30 | { const char *src = "a\nb\nc\n" ; 31 | char *dest ; 32 | int dest_len ; 33 | 34 | print_test_name ("Testing psf_strlcpy_crlf") ; 35 | 36 | for (dest_len = 3 ; dest_len < 30 ; dest_len++) 37 | { dest = calloc (1, dest_len + 1) ; 38 | if (dest == NULL) 39 | { printf ("\n\nLine %d: calloc failed!\n\n", __LINE__) ; 40 | exit (1) ; 41 | } ; 42 | 43 | /* This value needs to be a in the [0, 127] range to avoid tripping up 44 | ** compiles like Sun Studio 12.* 45 | */ 46 | dest [dest_len] = '\x5a' ; 47 | 48 | psf_strlcpy_crlf (dest, src, dest_len, sizeof (*src)) ; 49 | 50 | if (dest [dest_len] != '\x5a') 51 | { printf ("\n\nLine %d: buffer overrun for dest_len == %d\n\n", __LINE__, dest_len) ; 52 | exit (1) ; 53 | } ; 54 | 55 | free (dest) ; 56 | } ; 57 | 58 | puts ("ok") ; 59 | } /* test_psf_strlcpy_crlf */ 60 | -------------------------------------------------------------------------------- /src/ima_oki_adpcm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2007-2011 Erik de Castro Lopo 3 | ** Copyright (c) 2007 4 | ** 5 | ** This library is free software; you can redistribute it and/or modify it 6 | ** under the terms of the GNU Lesser General Public License as published by 7 | ** the Free Software Foundation; either version 2 of the License, or (at 8 | ** your option) any later version. 9 | ** 10 | ** This library is distributed in the hope that it will be useful, but 11 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 13 | ** General Public License for more details. 14 | ** 15 | ** You should have received a copy of the GNU Lesser General Public License 16 | ** along with this library. If not, write to the Free Software Foundation, 17 | ** Fifth Floor, 51 Franklin Street, Boston, MA 02111-1301, USA. 18 | */ 19 | 20 | /* ADPCM: IMA, OKI <==> 16-bit PCM. */ 21 | 22 | 23 | #define IMA_OKI_ADPCM_CODE_LEN 256 24 | #define IMA_OKI_ADPCM_PCM_LEN (IMA_OKI_ADPCM_CODE_LEN *2) 25 | 26 | typedef struct 27 | { 28 | /* private: */ 29 | int mask ; 30 | int last_output ; 31 | int step_index ; 32 | int max_step_index ; 33 | int const * steps ; 34 | 35 | /* public: */ 36 | int errors ; 37 | int code_count, pcm_count ; 38 | 39 | unsigned char codes [IMA_OKI_ADPCM_CODE_LEN] ; 40 | short pcm [IMA_OKI_ADPCM_PCM_LEN] ; 41 | } IMA_OKI_ADPCM ; 42 | 43 | typedef enum 44 | { IMA_OKI_ADPCM_TYPE_IMA, 45 | IMA_OKI_ADPCM_TYPE_OKI 46 | } IMA_OKI_ADPCM_TYPE ; 47 | 48 | void ima_oki_adpcm_init (IMA_OKI_ADPCM * state, IMA_OKI_ADPCM_TYPE type) ; 49 | 50 | int adpcm_decode (IMA_OKI_ADPCM * state, int /* 0..15 */ code) ; 51 | int adpcm_encode (IMA_OKI_ADPCM * state, int /* -32768..32767 */ sample) ; 52 | 53 | void ima_oki_adpcm_decode_block (IMA_OKI_ADPCM * state) ; 54 | void ima_oki_adpcm_encode_block (IMA_OKI_ADPCM * state) ; 55 | -------------------------------------------------------------------------------- /src/GSM610/ChangeLog: -------------------------------------------------------------------------------- 1 | 2004-05-12 Erik de Castro Lopo 2 | 3 | * gsm610_priv.h 4 | Replace ugly macros with inline functions. 5 | 6 | * *.c 7 | Remove temporary variables used by macros and other minor fixes required by 8 | above change. 9 | 10 | 2003-06-02 Erik de Castro Lopo 11 | 12 | * rpe.c 13 | Renamed variables "exp" to "expon" to avoid shadowed parameter warnigns. 14 | 15 | 2002-06-08 Erik de Castro Lopo 16 | 17 | * long_term.c 18 | Changes tp removed compiler warnings about shadowed parameters. 19 | 20 | 2002-06-08 Erik de Castro Lopo 21 | 22 | * private.h 23 | Made declarations of gsm_A, gsm_B, gsm_MIC etc extern. This fixed a compile 24 | problem on MacOSX. 25 | 26 | 2002-05-10 Erik de Castro Lopo 27 | 28 | * *.[ch] 29 | Removed all pre-ANSI prototype kludges. Removed proto.h and unproto.h. 30 | Started work on making GSM 6.10 files seekable. Currently they are not. 31 | 32 | * code.c private.h 33 | Function Gsm_Coder () used a statically defined array. This was obviously 34 | not re-entrant so moved it to struct gsm_state. 35 | 36 | 2001-09-16 Erik de Castro Lopo 37 | 38 | * code.c 39 | Added #includes for string.h and stdlib.h. 40 | 41 | 2000-10-27 Erik de Castro Lopo 42 | 43 | * config.h 44 | Removed some commented out #defines (ie //*efine) which were causing problems on 45 | the Sun cc compiler. 46 | 47 | 2000-02-29 Erik de Castro Lopo 48 | 49 | * private.h 50 | Added #defines to emulate normal compile time options. 51 | 52 | 2000-02-28 Erik de Castro Lopo 53 | 54 | * everthing 55 | Created this directory and copied files from libgsm. 56 | http://kbs.cs.tu-berlin.de/~jutta/toast.html 57 | -------------------------------------------------------------------------------- /src/test_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2008-2016 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "test_main.h" 28 | 29 | static void 30 | test_file_offsets_are_64_bit (void) 31 | { 32 | print_test_name ("File offsets are 64 bit") ; 33 | 34 | // The Windows specific code path uses the 64 bit file I/O APIs. 35 | if (! USE_WINDOWS_API && sizeof (off_t) != 8) 36 | { printf ("\n\nError : sizeof (off_t) is %zd (should be 8).\n\n", sizeof (off_t)) ; 37 | exit (1) ; 38 | } ; 39 | 40 | puts ("ok") ; 41 | } /* test_file_offsets_are_64_bit */ 42 | 43 | int 44 | main (void) 45 | { 46 | test_file_offsets_are_64_bit () ; 47 | test_conversions () ; 48 | test_endswap () ; 49 | test_float_convert () ; 50 | test_double_convert () ; 51 | 52 | test_log_printf () ; 53 | test_binheader_writef () ; 54 | test_file_io () ; 55 | 56 | test_audio_detect () ; 57 | test_ima_oki_adpcm () ; 58 | 59 | test_psf_strlcpy_crlf () ; 60 | test_broadcast_var () ; 61 | test_cart_var () ; 62 | 63 | return 0 ; 64 | } /* main */ 65 | 66 | -------------------------------------------------------------------------------- /src/id3.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2010-2017 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "sndfile.h" 27 | #include "sfendian.h" 28 | #include "common.h" 29 | 30 | int 31 | id3_skip (SF_PRIVATE * psf) 32 | { unsigned char buf [10] ; 33 | 34 | memset (buf, 0, sizeof (buf)) ; 35 | psf_binheader_readf (psf, "pb", 0, buf, 10) ; 36 | 37 | if (buf [0] == 'I' && buf [1] == 'D' && buf [2] == '3') 38 | { int offset = buf [6] & 0x7f ; 39 | offset = (offset << 7) | (buf [7] & 0x7f) ; 40 | offset = (offset << 7) | (buf [8] & 0x7f) ; 41 | offset = (offset << 7) | (buf [9] & 0x7f) ; 42 | 43 | psf_log_printf (psf, "ID3 length : %d\n--------------------\n", offset) ; 44 | 45 | /* Never want to jump backwards in a file. */ 46 | if (offset < 0) 47 | return 0 ; 48 | 49 | /* Calculate new file offset and position ourselves there. */ 50 | psf->fileoffset += offset + 10 ; 51 | 52 | if (psf->fileoffset < psf->filelength) 53 | { psf_binheader_readf (psf, "p", psf->fileoffset) ; 54 | return 1 ; 55 | } ; 56 | } ; 57 | 58 | return 0 ; 59 | } /* id3_skip */ 60 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | This is libsndfile, 1.0.27 2 | 3 | libsndfile is a library of C routines for reading and writing 4 | files containing sampled audio data. 5 | 6 | The src/ directory contains the source code for library itself. 7 | 8 | The doc/ directory contains the libsndfile documentation. 9 | 10 | The examples/ directory contains examples of how to write code using 11 | libsndfile. 12 | 13 | The tests/ directory contains programs which link against libsndfile 14 | and test its functionality. 15 | 16 | The src/GSM610 directory contains code written by Jutta Degener and Carsten 17 | Bormann. Their original code can be found at : 18 | http://kbs.cs.tu-berlin.de/~jutta/toast.html 19 | 20 | The src/G72x directory contains code written and released by Sun Microsystems 21 | under a suitably free license. 22 | 23 | The src/ALAC directory contains code written and released by Apple Inc and 24 | released under the Apache license. 25 | 26 | 27 | LINUX 28 | ----- 29 | Whereever possible, you should use the packages supplied by your Linux 30 | distribution. 31 | 32 | If you really do need to compile from source it should be as easy as: 33 | 34 | ./configure 35 | make 36 | make install 37 | 38 | Since libsndfile optionally links against libFLAC, libogg and libvorbis, you 39 | will need to install appropriate versions of these libraries before running 40 | configure as above. 41 | 42 | 43 | UNIX 44 | ---- 45 | Compile as for Linux. 46 | 47 | 48 | Win32/Win64 49 | ----------- 50 | The default Windows compilers are nowhere near compliant with the 1999 ISO 51 | C Standard and hence not able to compile libsndfile. 52 | 53 | Please use the libsndfile binaries available on the libsndfile web site. 54 | 55 | 56 | MacOSX 57 | ------ 58 | Building on MacOSX should be the same as building it on any other Unix. 59 | 60 | 61 | CONTACTS 62 | -------- 63 | 64 | libsndfile was written by Erik de Castro Lopo (erikd AT mega-nerd DOT com). 65 | The libsndfile home page is at : 66 | 67 | http://www.mega-nerd.com/libsndfile/ 68 | 69 | Bugs and support questions can be raised at : 70 | 71 | https://github.com/erikd/libsndfile/ 72 | -------------------------------------------------------------------------------- /src/G72x/ChangeLog: -------------------------------------------------------------------------------- 1 | 2001-06-05 Erik de Castro Lopo 2 | 3 | * g72x.c 4 | Added {} in function update () to prevent 'ambiguous else' warning messages. 5 | 6 | 2000-07-14 Erik de Castro Lopo 7 | 8 | * g72x.c 9 | Modified g72x_init_state () to fit in with the new structure of the code. 10 | Implemented g72x_encode_block () and g72x_decode_block (). 11 | 12 | 2000-07-12 Erik de Castro Lopo 13 | 14 | * g72x.h 15 | Moved nearly all definitions and function prototypes from this file have been 16 | moved to private.h. 17 | Added an enum defining the 4 different G72x ADPCM codecs. 18 | Added new function prototypes to define a cleaner interface to the encoder 19 | and decoder. This new interface also allows samples to be processed in blocks 20 | rather than on a sample by sample basis like the original code. 21 | 22 | * private.h 23 | Added prototypes moved from g72x.h. 24 | Changed struct g72x_state to a typedef struct { .. } G72x_PRIVATE. 25 | Added fields to G72x_PRIVATE required for working on blocks of samples. 26 | 27 | 2000-06-07 Erik de Castro Lopo 28 | 29 | * g72x.c 30 | Fixed all compiler warnings. 31 | Removed functions tandem_adjust() which is not required by libsndfile. 32 | 33 | * g721.c 34 | Fixed all compiler warnings. 35 | Removed functions tandem_adjust_alaw() and tandem_adjust_ulaw () which are not 36 | required by libsndfile. 37 | Removed second parameter to g721_encoder () which is not required. 38 | 39 | * g72x.h 40 | Removed in_coding and out_coding parameters from all functions. These allowed 41 | g72x encoding/decoding to/from A-law or u-law and are not required by libsndfile. 42 | Removed unneeded defines for A-law, u-law and linear encoding. 43 | 44 | * g723_16.c 45 | Removed second parameter (in_coding) for g723_16_encoder(). 46 | Removed second parameter (out_coding) for g723_16_decoder(). 47 | 48 | * private.h 49 | New file containing prototypes and tyepdefs private to G72x code. 50 | 51 | -------------------------------------------------------------------------------- /src/sf_unistd.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2002-2011 Erik de Castro Lopo 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 | /* Some defines that microsoft 'forgot' to implement. */ 20 | 21 | #ifndef S_IRWXU 22 | #define S_IRWXU 0000700 /* rwx, owner */ 23 | #endif 24 | 25 | #ifndef S_IRUSR 26 | #define S_IRUSR 0000400 /* read permission, owner */ 27 | #endif 28 | 29 | #ifndef S_IWUSR 30 | #define S_IWUSR 0000200 /* write permission, owner */ 31 | #endif 32 | 33 | #ifndef S_IXUSR 34 | #define S_IXUSR 0000100 /* execute/search permission, owner */ 35 | #endif 36 | 37 | /* Windows doesn't have group permissions so set all these to zero. */ 38 | #define S_IRWXG 0 /* rwx, group */ 39 | #define S_IRGRP 0 /* read permission, group */ 40 | #define S_IWGRP 0 /* write permission, grougroup */ 41 | #define S_IXGRP 0 /* execute/search permission, group */ 42 | 43 | /* Windows doesn't have others permissions so set all these to zero. */ 44 | #define S_IRWXO 0 /* rwx, other */ 45 | #define S_IROTH 0 /* read permission, other */ 46 | #define S_IWOTH 0 /* write permission, other */ 47 | #define S_IXOTH 0 /* execute/search permission, other */ 48 | 49 | #ifndef S_ISFIFO 50 | #define S_ISFIFO(mode) (((mode) & _S_IFMT) == _S_IFIFO) 51 | #endif 52 | 53 | #ifndef S_ISREG 54 | #define S_ISREG(mode) (((mode) & _S_IFREG) == _S_IFREG) 55 | #endif 56 | 57 | /* 58 | ** Don't know if these are still needed. 59 | ** 60 | ** #define _IFMT _S_IFMT 61 | ** #define _IFREG _S_IFREG 62 | */ 63 | 64 | -------------------------------------------------------------------------------- /src/GSM610/table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische 3 | * Universitaet Berlin. See the accompanying file "COPYRIGHT" for 4 | * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 5 | */ 6 | 7 | /* Most of these tables are inlined at their point of use. 8 | */ 9 | 10 | /* 4.4 TABLES USED IN THE FIXED POINT IMPLEMENTATION OF THE RPE-LTP 11 | * CODER AND DECODER 12 | * 13 | * (Most of them inlined, so watch out.) 14 | */ 15 | 16 | #define GSM_TABLE_C 17 | #include "gsm610_priv.h" 18 | 19 | /* Table 4.1 Quantization of the Log.-Area Ratios 20 | */ 21 | /* i 1 2 3 4 5 6 7 8 */ 22 | int16_t gsm_A [8] = { 20480, 20480, 20480, 20480, 13964, 15360, 8534, 9036 } ; 23 | int16_t gsm_B [8] = { 0, 0, 2048, -2560, 94, -1792, -341, -1144 } ; 24 | int16_t gsm_MIC [8] = { -32, -32, -16, -16, -8, -8, -4, -4 } ; 25 | int16_t gsm_MAC [8] = { 31, 31, 15, 15, 7, 7, 3, 3 } ; 26 | 27 | 28 | /* Table 4.2 Tabulation of 1/A[1..8] 29 | */ 30 | int16_t gsm_INVA [8] = { 13107, 13107, 13107, 13107, 19223, 17476, 31454, 29708 } ; 31 | 32 | 33 | /* Table 4.3a Decision level of the LTP gain quantizer 34 | */ 35 | /* bc 0 1 2 3 */ 36 | int16_t gsm_DLB [4] = { 6554, 16384, 26214, 32767 } ; 37 | 38 | 39 | /* Table 4.3b Quantization levels of the LTP gain quantizer 40 | */ 41 | /* bc 0 1 2 3 */ 42 | int16_t gsm_QLB [4] = { 3277, 11469, 21299, 32767 } ; 43 | 44 | 45 | /* Table 4.4 Coefficients of the weighting filter 46 | */ 47 | /* i 0 1 2 3 4 5 6 7 8 9 10 */ 48 | int16_t gsm_H [11] = { -134, -374, 0, 2054, 5741, 8192, 5741, 2054, 0, -374, -134 } ; 49 | 50 | 51 | /* Table 4.5 Normalized inverse mantissa used to compute xM/xmax 52 | */ 53 | /* i 0 1 2 3 4 5 6 7 */ 54 | int16_t gsm_NRFAC [8] = { 29128, 26215, 23832, 21846, 20165, 18725, 17476, 16384 } ; 55 | 56 | 57 | /* Table 4.6 Normalized direct mantissa used to compute xM/xmax 58 | */ 59 | /* i 0 1 2 3 4 5 6 7 */ 60 | int16_t gsm_FAC [8] = { 18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767 } ; 61 | -------------------------------------------------------------------------------- /src/ALAC/aglib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_APACHE_LICENSE_HEADER_START@ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License") ; 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * @APPLE_APACHE_LICENSE_HEADER_END@ 19 | */ 20 | 21 | /* 22 | File: aglib.h 23 | 24 | Copyright: (C) 2001-2011 Apple, Inc. 25 | */ 26 | 27 | #ifndef AGLIB_H 28 | #define AGLIB_H 29 | 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #define QBSHIFT 9 37 | #define QB (1 << QBSHIFT) 38 | #define PB0 40 39 | #define MB0 10 40 | #define KB0 14 41 | #define MAX_RUN_DEFAULT 255 42 | 43 | #define MMULSHIFT 2 44 | #define MDENSHIFT (QBSHIFT - MMULSHIFT - 1) 45 | #define MOFF ((1 << (MDENSHIFT - 2))) 46 | 47 | #define BITOFF 24 48 | 49 | /* Max. prefix of 1's. */ 50 | #define MAX_PREFIX_16 9 51 | #define MAX_PREFIX_TOLONG_16 15 52 | #define MAX_PREFIX_32 9 53 | 54 | /* Max. bits in 16-bit data type */ 55 | #define MAX_DATATYPE_BITS_16 16 56 | 57 | typedef struct AGParamRec 58 | { 59 | uint32_t mb, mb0, pb, kb, wb, qb ; 60 | uint32_t fw, sw ; 61 | 62 | uint32_t maxrun ; 63 | 64 | // fw = 1, sw = 1 ; 65 | 66 | } AGParamRec, *AGParamRecPtr ; 67 | 68 | struct BitBuffer ; 69 | 70 | void set_standard_ag_params (AGParamRecPtr params, uint32_t fullwidth, uint32_t sectorwidth) ; 71 | void set_ag_params (AGParamRecPtr params, uint32_t m, uint32_t p, uint32_t k, uint32_t f, uint32_t s, uint32_t maxrun) ; 72 | 73 | int32_t dyn_comp (AGParamRecPtr params, int32_t * pc, struct BitBuffer * bitstream, int32_t numSamples, int32_t bitSize, uint32_t * outNumBits) ; 74 | int32_t dyn_decomp (AGParamRecPtr params, struct BitBuffer * bitstream, int32_t * pc, int32_t numSamples, int32_t maxSize, uint32_t * outNumBits) ; 75 | 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif //#ifndef AGLIB_H 82 | -------------------------------------------------------------------------------- /doc/flac.AUTHORS.txt: -------------------------------------------------------------------------------- 1 | /* FLAC - Free Lossless Audio Codec 2 | * Copyright (C) 2001-2009 Josh Coalson 3 | * Copyright (C) 2011-2014 Xiph.Org Foundation 4 | * 5 | * This file is part the FLAC project. FLAC is comprised of several 6 | * components distributed under different licenses. The codec libraries 7 | * are distributed under Xiph.Org's BSD-like license (see the file 8 | * COPYING.Xiph in this distribution). All other programs, libraries, and 9 | * plugins are distributed under the GPL (see COPYING.GPL). The documentation 10 | * is distributed under the Gnu FDL (see COPYING.FDL). Each file in the 11 | * FLAC distribution contains at the top the terms under which it may be 12 | * distributed. 13 | * 14 | * Since this particular file is relevant to all components of FLAC, 15 | * it may be distributed under the Xiph.Org license, which is the least 16 | * restrictive of those mentioned above. See the file COPYING.Xiph in this 17 | * distribution. 18 | */ 19 | 20 | Current FLAC maintainer: Erik de Castro Lopo 21 | 22 | Original author: Josh Coalson 23 | 24 | Website : https://www.xiph.org/flac/ 25 | 26 | FLAC is an Open Source lossless audio codec originally developed by Josh Coalson 27 | between 2001 and 2009. From 2009 to 2012 FLAC was basically unmaintained. In 28 | 2012 the Erik de Castro Lopo became the chief maintainer as part of the 29 | Xiph.Org Foundation. 30 | 31 | Other major contributors and their contributions: 32 | 33 | "lvqcl" 34 | * Visual Studio build system. 35 | * Optimisations in the encoder and decoder. 36 | 37 | "Janne Hyvärinen" 38 | * Visual Studio build system. 39 | * Unicode handling on Windows. 40 | 41 | "Andrey Astafiev" 42 | * Russian translation of the HTML documentation 43 | 44 | "Miroslav Lichvar" 45 | * IA-32 assembly versions of several libFLAC routines 46 | 47 | "Brady Patterson" 48 | * AIFF file support, PPC assembly versions of libFLAC routines 49 | 50 | "Daisuke Shimamura" 51 | * i18n support in the XMMS plugin 52 | 53 | "X-Fixer" 54 | * Configuration system, tag editing, and file info in the Winamp2 plugin 55 | 56 | "Matt Zimmerman" 57 | * Libtool/autoconf/automake make system, flac man page 58 | 59 | -------------------------------------------------------------------------------- /src/sflrint.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 1999-2015 Erik de Castro Lopo 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 | /* 20 | * Workaround for forbiddingly SLOW implementation of lrint() and lrintf() functions in MSVC 21 | * The following inline implemenatation was adapted from Qt's qRound() function 22 | * Runs about ~32x faster (on my test system), compared to MSVC's built-in lrint() function! 23 | */ 24 | #if defined(_MSC_VER) && (_MSC_VER) 25 | #define _SF_LRINT_MSVC(T) \ 26 | ((d >= ((T)0.0)) ? ((long)(d + ((T)0.5))) : ((long)(d - ((long)(d - 1)) + ((T)0.5))) + ((long)(d - 1))) 27 | static __inline long SF_lrint(double d) { return _SF_LRINT_MSVC(double); } 28 | static __inline long SF_lrintf(float d) { return _SF_LRINT_MSVC(float); } 29 | #else 30 | #define SF_lrint(X) lrint((X)) 31 | #define SF_lrintf(X) lrintf((X)) 32 | #endif 33 | 34 | /*Inline assembly versions *not* currently used! 35 | #include 36 | static __inline long int SF_lrint(double flt) 37 | { 38 | int intgr; 39 | _controlfp(_RC_NEAR, _MCW_RC); 40 | _asm 41 | { 42 | fld flt 43 | fistp intgr 44 | }; 45 | return intgr; 46 | } 47 | static __inline long int SF_lrintf(float flt) 48 | { 49 | int intgr; 50 | _controlfp(_RC_NEAR, _MCW_RC); 51 | _asm 52 | { 53 | fld flt 54 | fistp intgr 55 | }; 56 | return intgr; 57 | } 58 | static __inline long long int SF_llrint(double flt) 59 | { 60 | long long int intgr; 61 | _controlfp_s(NULL, _RC_NEAR, _MCW_RC); 62 | _asm 63 | { 64 | fld flt 65 | fistp intgr 66 | }; 67 | return intgr; 68 | } 69 | static __inline long long int SF_llrintf(float flt) 70 | { 71 | long long int intgr; 72 | _controlfp_s(NULL, _RC_NEAR, _MCW_RC); 73 | _asm 74 | { 75 | fld flt 76 | fistp intgr 77 | }; 78 | return intgr; 79 | }*/ 80 | -------------------------------------------------------------------------------- /src/GSM610/code.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische 3 | * Universitaet Berlin. See the accompanying file "COPYRIGHT" for 4 | * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | #include "gsm610_priv.h" 12 | 13 | /* 14 | * 4.2 FIXED POINT IMPLEMENTATION OF THE RPE-LTP CODER 15 | */ 16 | 17 | void Gsm_Coder ( 18 | 19 | struct gsm_state * State, 20 | 21 | int16_t * s, /* [0..159] samples IN */ 22 | 23 | /* 24 | * The RPE-LTD coder works on a frame by frame basis. The length of 25 | * the frame is equal to 160 samples. Some computations are done 26 | * once per frame to produce at the output of the coder the 27 | * LARc [1..8] parameters which are the coded LAR coefficients and 28 | * also to realize the inverse filtering operation for the entire 29 | * frame (160 samples of signal d [0..159]). These parts produce at 30 | * the output of the coder: 31 | */ 32 | 33 | int16_t * LARc, /* [0..7] LAR coefficients OUT */ 34 | 35 | /* 36 | * Procedure 4.2.11 to 4.2.18 are to be executed four times per 37 | * frame. That means once for each sub-segment RPE-LTP analysis of 38 | * 40 samples. These parts produce at the output of the coder: 39 | */ 40 | 41 | int16_t *Nc, /* [0..3] LTP lag OUT */ 42 | int16_t *bc, /* [0..3] coded LTP gain OUT */ 43 | int16_t *Mc, /* [0..3] RPE grid selection OUT */ 44 | int16_t *xmaxc, /* [0..3] Coded maximum amplitude OUT */ 45 | int16_t *xMc /* [13*4] normalized RPE samples OUT */ 46 | ) 47 | { 48 | int k ; 49 | int16_t *dp = State->dp0 + 120 ; /* [-120...-1] */ 50 | int16_t *dpp = dp ; /* [0...39] */ 51 | 52 | int16_t so [160] ; 53 | 54 | Gsm_Preprocess (State, s, so) ; 55 | Gsm_LPC_Analysis (State, so, LARc) ; 56 | Gsm_Short_Term_Analysis_Filter (State, LARc, so) ; 57 | 58 | for (k = 0 ; k <= 3 ; k++, xMc += 13) 59 | { Gsm_Long_Term_Predictor (State, 60 | so+k*40, /* d [0..39] IN */ 61 | dp, /* dp [-120..-1] IN */ 62 | State->e + 5, /* e [0..39] OUT */ 63 | dpp, /* dpp [0..39] OUT */ 64 | Nc++, 65 | bc++) ; 66 | 67 | Gsm_RPE_Encoding (/*-S,-*/ 68 | State->e + 5, /* e ][0..39][IN/OUT */ 69 | xmaxc++, Mc++, xMc) ; 70 | /* 71 | * Gsm_Update_of_reconstructed_short_time_residual_signal 72 | * (dpp, State->e + 5, dp) ; 73 | */ 74 | 75 | { 76 | register int i ; 77 | for (i = 0 ; i <= 39 ; i++) 78 | dp [i] = GSM_ADD (State->e [5 + i], dpp [i]) ; 79 | } 80 | dp += 40 ; 81 | dpp += 40 ; 82 | 83 | } 84 | memcpy ((char *) State->dp0, (char *) (State->dp0 + 160), 85 | 120 * sizeof (*State->dp0)) ; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /src/GSM610/preprocess.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische 3 | * Universitaet Berlin. See the accompanying file "COPYRIGHT" for 4 | * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include "gsm610_priv.h" 11 | 12 | /* 4.2.0 .. 4.2.3 PREPROCESSING SECTION 13 | * 14 | * After A-law to linear conversion (or directly from the 15 | * Ato D converter) the following scaling is assumed for 16 | * input to the RPE-LTP algorithm: 17 | * 18 | * in: 0.1.....................12 19 | * S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.* 20 | * 21 | * Where S is the sign bit, v a valid bit, and * a "don't care" bit. 22 | * The original signal is called sop[..] 23 | * 24 | * out: 0.1................... 12 25 | * S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0 26 | */ 27 | 28 | 29 | void Gsm_Preprocess ( 30 | struct gsm_state * S, 31 | int16_t * s, 32 | int16_t * so) /* [0..159] IN/OUT */ 33 | { 34 | 35 | int16_t z1 = S->z1 ; 36 | int32_t L_z2 = S->L_z2 ; 37 | int16_t mp = S->mp ; 38 | 39 | int16_t s1 ; 40 | int32_t L_s2 ; 41 | 42 | int32_t L_temp ; 43 | 44 | int16_t msp, lsp ; 45 | int16_t SO ; 46 | 47 | register int k = 160 ; 48 | 49 | while (k--) 50 | { 51 | 52 | /* 4.2.1 Downscaling of the input signal */ 53 | SO = arith_shift_left (SASR_W (*s, 3), 2) ; 54 | s++ ; 55 | 56 | assert (SO >= -0x4000) ; /* downscaled by */ 57 | assert (SO <= 0x3FFC) ; /* previous routine. */ 58 | 59 | 60 | /* 4.2.2 Offset compensation 61 | * 62 | * This part implements a high-pass filter and requires extended 63 | * arithmetic precision for the recursive part of this filter. 64 | * The input of this procedure is the array so[0...159] and the 65 | * output the array sof[ 0...159 ]. 66 | */ 67 | 68 | /* Compute the non-recursive part */ 69 | 70 | s1 = SO - z1 ; /* s1 = gsm_sub (*so, z1) ; */ 71 | z1 = SO ; 72 | 73 | assert (s1 != MIN_WORD) ; 74 | 75 | /* Compute the recursive part */ 76 | L_s2 = s1 ; 77 | L_s2 = arith_shift_left (L_s2, 15) ; 78 | 79 | /* Execution of a 31 bv 16 bits multiplication */ 80 | 81 | msp = SASR_L (L_z2, 15) ; 82 | lsp = L_z2 - arith_shift_left ((int32_t) msp, 15) ; /* gsm_L_sub (L_z2,(msp<<15)) ; */ 83 | 84 | L_s2 += GSM_MULT_R (lsp, 32735) ; 85 | L_temp = (int32_t) msp * 32735 ; /* GSM_L_MULT (msp,32735) >> 1 ;*/ 86 | L_z2 = GSM_L_ADD (L_temp, L_s2) ; 87 | 88 | /* Compute sof[k] with rounding */ 89 | L_temp = GSM_L_ADD (L_z2, 16384) ; 90 | 91 | /* 4.2.3 Preemphasis */ 92 | 93 | msp = GSM_MULT_R (mp, -28180) ; 94 | mp = SASR_L (L_temp, 15) ; 95 | *so++ = GSM_ADD (mp, msp) ; 96 | } 97 | 98 | S->z1 = z1 ; 99 | S->L_z2 = L_z2 ; 100 | S->mp = mp ; 101 | } 102 | -------------------------------------------------------------------------------- /src/sfconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2005-2014 Erik de Castro Lopo 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 | /* 20 | ** Autoconf leaves many config parameters undefined. 21 | ** Here we change then from being undefined to defining them to 0. 22 | ** This allows things like: 23 | ** 24 | ** #if HAVE_CONFIG_PARAM 25 | ** 26 | ** and 27 | ** 28 | ** if (HAVE_CONFIG_PARAM) 29 | ** do_something () ; 30 | */ 31 | 32 | #ifndef SFCONFIG_H 33 | #define SFCONFIG_H 34 | 35 | /* Include the Autoconf generated file. */ 36 | #include "config.h" 37 | 38 | /* Now fiddle the values. */ 39 | 40 | #ifndef HAVE_ALSA_ASOUNDLIB_H 41 | #define HAVE_ALSA_ASOUNDLIB_H 0 42 | #endif 43 | 44 | #ifndef HAVE_BYTESWAP_H 45 | #define HAVE_BYTESWAP_H 0 46 | #endif 47 | 48 | #ifndef HAVE_DECL_S_IRGRP 49 | #define HAVE_DECL_S_IRGRP 0 50 | #endif 51 | 52 | #ifndef HAVE_ENDIAN_H 53 | #define HAVE_ENDIAN_H 0 54 | #endif 55 | 56 | #ifndef HAVE_FSTAT64 57 | #define HAVE_FSTAT64 0 58 | #endif 59 | 60 | #ifndef HAVE_FSYNC 61 | #define HAVE_FSYNC 0 62 | #endif 63 | 64 | #ifndef HAVE_LOCALE_H 65 | #define HAVE_LOCALE_H 0 66 | #endif 67 | 68 | #ifndef HAVE_LRINT 69 | #define HAVE_LRINT 0 70 | #endif 71 | 72 | #ifndef HAVE_LRINTF 73 | #define HAVE_LRINTF 0 74 | #endif 75 | 76 | #ifndef HAVE_MMAP 77 | #define HAVE_MMAP 0 78 | #endif 79 | 80 | #ifndef HAVE_SETLOCALE 81 | #define HAVE_SETLOCALE 0 82 | #endif 83 | 84 | #ifndef HAVE_SQLITE3 85 | #define HAVE_SQLITE3 0 86 | #endif 87 | 88 | #ifndef HAVE_STDINT_H 89 | #define HAVE_STDINT_H 0 90 | #endif 91 | 92 | #ifndef HAVE_SYS_WAIT_H 93 | #define HAVE_SYS_WAIT_H 0 94 | #endif 95 | 96 | #ifndef HAVE_SYS_TIME_H 97 | #define HAVE_SYS_TIME_H 0 98 | #endif 99 | 100 | #ifndef HAVE_UNISTD_H 101 | #define HAVE_UNISTD_H 0 102 | #endif 103 | 104 | #ifndef HAVE_PIPE 105 | #define HAVE_PIPE 0 106 | #endif 107 | 108 | #ifndef HAVE_WAITPID 109 | #define HAVE_WAITPID 0 110 | #endif 111 | 112 | #ifndef HAVE_X86INTRIN_H 113 | #define HAVE_X86INTRIN_H 0 114 | #endif 115 | 116 | #define CPU_IS_X86 (defined __i486__ || defined __i586__ || defined __i686__ || defined __x86_64__) 117 | #define CPU_IS_X86_64 (defined __x86_64__) 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /src/windows.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2009-2017 Erik de Castro Lopo 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 | /* 20 | ** This needs to be a separate file so that we don't have to include 21 | ** elsewhere (too many symbol clashes). 22 | */ 23 | 24 | 25 | #include "sfconfig.h" 26 | 27 | #if OS_IS_WIN32 28 | #include 29 | 30 | #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1 31 | #include "sndfile.h" 32 | #include "common.h" 33 | 34 | extern int sf_errno ; 35 | 36 | static void copy_filename (SF_PRIVATE * psf, LPCWSTR wpath) ; 37 | 38 | SNDFILE_API 39 | SNDFILE* 40 | sf_wchar_open (LPCWSTR wpath, int mode, SF_INFO *sfinfo) 41 | { SF_PRIVATE *psf ; 42 | char utf8name [512] ; 43 | 44 | if ((psf = psf_allocate ()) == NULL) 45 | { sf_errno = SFE_MALLOC_FAILED ; 46 | return NULL ; 47 | } ; 48 | 49 | psf_init_files (psf) ; 50 | 51 | if (WideCharToMultiByte (CP_UTF8, 0, wpath, -1, utf8name, sizeof (utf8name), NULL, NULL) == 0) 52 | psf->file.path.wc [0] = 0 ; 53 | 54 | psf_log_printf (psf, "File : '%s' (utf-8 converted from ucs-2)\n", utf8name) ; 55 | 56 | copy_filename (psf, wpath) ; 57 | psf->file.use_wchar = SF_TRUE ; 58 | psf->file.mode = mode ; 59 | 60 | psf->error = psf_fopen (psf) ; 61 | 62 | return psf_open_file (psf, sfinfo) ; 63 | } /* sf_wchar_open */ 64 | 65 | 66 | static void 67 | copy_filename (SF_PRIVATE *psf, LPCWSTR wpath) 68 | { const wchar_t *cwcptr ; 69 | wchar_t *wcptr ; 70 | 71 | wcsncpy (psf->file.path.wc, wpath, ARRAY_LEN (psf->file.path.wc)) ; 72 | psf->file.path.wc [ARRAY_LEN (psf->file.path.wc) - 1] = 0 ; 73 | if ((cwcptr = wcsrchr (wpath, '/')) || (cwcptr = wcsrchr (wpath, '\\'))) 74 | cwcptr ++ ; 75 | else 76 | cwcptr = wpath ; 77 | 78 | wcsncpy (psf->file.name.wc, cwcptr, ARRAY_LEN (psf->file.name.wc)) ; 79 | psf->file.name.wc [ARRAY_LEN (psf->file.name.wc) - 1] = 0 ; 80 | 81 | /* Now grab the directory. */ 82 | wcsncpy (psf->file.dir.wc, wpath, ARRAY_LEN (psf->file.dir.wc)) ; 83 | psf->file.dir.wc [ARRAY_LEN (psf->file.dir.wc) - 1] = 0 ; 84 | 85 | if ((wcptr = wcsrchr (psf->file.dir.wc, '/')) || (wcptr = wcsrchr (psf->file.dir.wc, '\\'))) 86 | wcptr [1] = 0 ; 87 | else 88 | psf->file.dir.wc [0] = 0 ; 89 | 90 | return ; 91 | } /* copy_filename */ 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /src/test_cart_var.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2010-2013 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "common.h" 26 | 27 | #include "test_main.h" 28 | 29 | #define CART_MAX 512 30 | 31 | typedef SF_CART_INFO_VAR (CART_MAX) SF_CART_INFO_512 ; 32 | 33 | static void 34 | fill_tag_text (SF_CART_INFO_512 * ci) 35 | { static const char *lines [] = 36 | { "Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit.", 37 | "Donec dignissim erat\nvehicula libero condimentum\ndictum porta augue faucibus.", 38 | "Maecenas nec turpis\nsit amet quam\nfaucibus adipiscing.", 39 | "Mauris aliquam,\nlectus interdum\ntincidunt luctus.", 40 | "\n\n\n\n\n\n\n\n\n\n\n\n", 41 | "In auctor lorem\nvel est euismod\ncondimentum.", 42 | "\n\n\n\n\n\n\n\n\n\n\n\n", 43 | "Ut vitae magna\nid dui placerat vehicula\nin id lectus.", 44 | "\n\n\n\n\n\n\n\n\n\n\n\n", 45 | "Sed lacus leo,\nmolestie et luctus ac,\ntincidunt sit amet nisi.", 46 | "\n\n\n\n\n\n\n\n\n\n\n\n", 47 | "Sed ligula neque,\ngravida semper vulputate laoreet,\ngravida eu tellus.", 48 | "Donec dolor dolor,\nscelerisque in consequat ornare,\ntempor nec nisl." 49 | } ; 50 | int k ; 51 | 52 | ci->tag_text [0] = 0 ; 53 | 54 | for (k = 0 ; strlen (ci->tag_text) < ci->tag_text_size - 1 ; k ++) 55 | append_snprintf (ci->tag_text, ci->tag_text_size, "%s\n", lines [k % ARRAY_LEN (lines)]) ; 56 | 57 | return ; 58 | } /* fill_tag_text */ 59 | 60 | void 61 | test_cart_var (void) 62 | { SF_PRIVATE sf_private, *psf ; 63 | SF_CART_TIMER timer ; 64 | int k ; 65 | 66 | psf = &sf_private ; 67 | memset (psf, 0, sizeof (sf_private)) ; 68 | 69 | print_test_name ("Testing cart_var_set ") ; 70 | 71 | for (k = 64 ; k < CART_MAX ; k++) 72 | { 73 | SF_CART_INFO_512 ci ; 74 | 75 | memset (&ci, 0, sizeof (ci)) ; 76 | 77 | memset (&timer, 0, sizeof (timer)) ; 78 | memcpy (ci.post_timers, &timer, sizeof (timer)) ; 79 | 80 | ci.tag_text_size = k ; 81 | fill_tag_text (&ci) ; 82 | ci.tag_text_size -- ; 83 | 84 | cart_var_set (psf, (SF_CART_INFO*) &ci, sizeof (ci)) ; 85 | } ; 86 | 87 | if (psf->cart_16k != NULL) 88 | free (psf->cart_16k) ; 89 | 90 | puts ("ok") ; 91 | } /* test_cart_var */ 92 | -------------------------------------------------------------------------------- /src/raw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 1999-2011 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | 23 | #include "sndfile.h" 24 | #include "common.h" 25 | 26 | /*------------------------------------------------------------------------------ 27 | ** Public function. 28 | */ 29 | 30 | int 31 | raw_open (SF_PRIVATE *psf) 32 | { int subformat, error = SFE_NO_ERROR ; 33 | 34 | subformat = SF_CODEC (psf->sf.format) ; 35 | 36 | psf->endian = SF_ENDIAN (psf->sf.format) ; 37 | 38 | if (CPU_IS_BIG_ENDIAN && (psf->endian == 0 || psf->endian == SF_ENDIAN_CPU)) 39 | psf->endian = SF_ENDIAN_BIG ; 40 | else if (CPU_IS_LITTLE_ENDIAN && (psf->endian == 0 || psf->endian == SF_ENDIAN_CPU)) 41 | psf->endian = SF_ENDIAN_LITTLE ; 42 | 43 | psf->blockwidth = psf->bytewidth * psf->sf.channels ; 44 | psf->dataoffset = 0 ; 45 | psf->datalength = psf->filelength ; 46 | 47 | switch (subformat) 48 | { case SF_FORMAT_PCM_S8 : 49 | error = pcm_init (psf) ; 50 | break ; 51 | 52 | case SF_FORMAT_PCM_U8 : 53 | error = pcm_init (psf) ; 54 | break ; 55 | 56 | case SF_FORMAT_PCM_16 : 57 | case SF_FORMAT_PCM_24 : 58 | case SF_FORMAT_PCM_32 : 59 | error = pcm_init (psf) ; 60 | break ; 61 | 62 | case SF_FORMAT_ULAW : 63 | error = ulaw_init (psf) ; 64 | break ; 65 | 66 | case SF_FORMAT_ALAW : 67 | error = alaw_init (psf) ; 68 | break ; 69 | 70 | case SF_FORMAT_GSM610 : 71 | error = gsm610_init (psf) ; 72 | break ; 73 | 74 | /* Lite remove start */ 75 | case SF_FORMAT_FLOAT : 76 | error = float32_init (psf) ; 77 | break ; 78 | 79 | case SF_FORMAT_DOUBLE : 80 | error = double64_init (psf) ; 81 | break ; 82 | 83 | case SF_FORMAT_DWVW_12 : 84 | error = dwvw_init (psf, 12) ; 85 | break ; 86 | 87 | case SF_FORMAT_DWVW_16 : 88 | error = dwvw_init (psf, 16) ; 89 | break ; 90 | 91 | case SF_FORMAT_DWVW_24 : 92 | error = dwvw_init (psf, 24) ; 93 | break ; 94 | 95 | case SF_FORMAT_VOX_ADPCM : 96 | error = vox_adpcm_init (psf) ; 97 | break ; 98 | /* Lite remove end */ 99 | 100 | default : return SFE_BAD_OPEN_FORMAT ; 101 | } ; 102 | 103 | return error ; 104 | } /* raw_open */ 105 | -------------------------------------------------------------------------------- /src/audio_detect.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 1999-2012 Erik de Castro Lopo 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 | 20 | #include "sfconfig.h" 21 | 22 | #include 23 | #include 24 | 25 | #if HAVE_UNISTD_H 26 | #include 27 | #endif 28 | 29 | #include 30 | #include 31 | 32 | #include "common.h" 33 | 34 | typedef struct 35 | { int le_float ; 36 | int be_float ; 37 | int le_int_24_32 ; 38 | int be_int_24_32 ; 39 | } VOTE ; 40 | 41 | 42 | static void vote_for_format (VOTE * vote, const unsigned char * data, int datalen) ; 43 | 44 | int 45 | audio_detect (SF_PRIVATE * psf, AUDIO_DETECT *ad, const unsigned char * data, int datalen) 46 | { VOTE vote ; 47 | 48 | if (psf == NULL) 49 | return 0 ; 50 | 51 | if (ad == NULL || datalen < 256) 52 | return 0 ; 53 | 54 | vote_for_format (&vote, data, datalen) ; 55 | 56 | psf_log_printf (psf, "audio_detect :\n" 57 | " le_float : %d\n" 58 | " be_float : %d\n" 59 | " le_int_24_32 : %d\n" 60 | " be_int_24_32 : %d\n", 61 | vote.le_float, vote.be_float, vote.le_int_24_32, vote.be_int_24_32) ; 62 | 63 | if (0) puts (psf->parselog.buf) ; 64 | 65 | if (ad->endianness == SF_ENDIAN_LITTLE && vote.le_float > (3 * datalen) / 4) 66 | { /* Almost certainly 32 bit floats. */ 67 | return SF_FORMAT_FLOAT ; 68 | } ; 69 | 70 | if (ad->endianness == SF_ENDIAN_LITTLE && vote.le_int_24_32 > (3 * datalen) / 4) 71 | { /* Almost certainly 24 bit data stored in 32 bit ints. */ 72 | return SF_FORMAT_PCM_32 ; 73 | } ; 74 | 75 | return 0 ; 76 | } /* data_detect */ 77 | 78 | static void 79 | vote_for_format (VOTE * vote, const unsigned char * data, int datalen) 80 | { 81 | int k ; 82 | 83 | memset (vote, 0, sizeof (VOTE)) ; 84 | 85 | datalen -= datalen % 4 ; 86 | 87 | for (k = 0 ; k < datalen ; k ++) 88 | { if ((k % 4) == 0) 89 | { if (data [k] == 0 && data [k + 1] != 0) 90 | vote->le_int_24_32 += 4 ; 91 | 92 | if (data [2] != 0 && data [3] == 0) 93 | vote->le_int_24_32 += 4 ; 94 | 95 | if (data [0] != 0 && data [3] > 0x43 && data [3] < 0x4B) 96 | vote->le_float += 4 ; 97 | 98 | if (data [3] != 0 && data [0] > 0x43 && data [0] < 0x4B) 99 | vote->be_float += 4 ; 100 | } ; 101 | } ; 102 | 103 | return ; 104 | } /* vote_for_format */ 105 | 106 | -------------------------------------------------------------------------------- /src/ALAC/ALACBitUtilities.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_APACHE_LICENSE_HEADER_START@ 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License") ; 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * @APPLE_APACHE_LICENSE_HEADER_END@ 19 | */ 20 | 21 | /*============================================================================= 22 | File: ALACBitUtilities.h 23 | 24 | $NoKeywords: $ 25 | =============================================================================*/ 26 | 27 | #ifndef __ALACBITUTILITIES_H 28 | #define __ALACBITUTILITIES_H 29 | 30 | #include 31 | 32 | #ifndef MIN 33 | #define MIN(x, y) ((x) < (y) ? (x) : (y)) 34 | #endif // MIN 35 | #ifndef MAX 36 | #define MAX(x, y) ((x) > (y) ? (x) : (y)) 37 | #endif // MAX 38 | 39 | #define RequireAction(condition, action) if (! (condition)) { action } 40 | #define RequireActionSilent(condition, action) if (! (condition)) { action } 41 | #define RequireNoErr(condition, action) if (condition) { action } 42 | 43 | enum 44 | { 45 | ALAC_noErr = 0 46 | } ; 47 | 48 | 49 | typedef enum 50 | { ID_SCE = 0, /* Single Channel Element */ 51 | ID_CPE = 1, /* Channel Pair Element */ 52 | ID_CCE = 2, /* Coupling Channel Element */ 53 | ID_LFE = 3, /* LFE Channel Element */ 54 | ID_DSE = 4, /* not yet supported */ 55 | ID_PCE = 5, 56 | ID_FIL = 6, 57 | ID_END = 7 58 | } ELEMENT_TYPE ; 59 | 60 | // types 61 | typedef struct BitBuffer 62 | { 63 | uint8_t * cur ; 64 | uint8_t * end ; 65 | uint32_t bitIndex ; 66 | uint32_t byteSize ; 67 | 68 | } BitBuffer ; 69 | 70 | /* 71 | BitBuffer routines 72 | - these routines take a fixed size buffer and read/write to it 73 | - bounds checking must be done by the client 74 | */ 75 | void BitBufferInit (BitBuffer * bits, uint8_t * buffer, uint32_t byteSize) ; 76 | uint32_t BitBufferRead (BitBuffer * bits, uint8_t numBits) ; // note: cannot read more than 16 bits at a time 77 | uint8_t BitBufferReadSmall (BitBuffer * bits, uint8_t numBits) ; 78 | uint8_t BitBufferReadOne (BitBuffer * bits) ; 79 | uint32_t BitBufferPeek (BitBuffer * bits, uint8_t numBits) ; // note: cannot read more than 16 bits at a time 80 | uint32_t BitBufferPeekOne (BitBuffer * bits) ; 81 | uint32_t BitBufferUnpackBERSize (BitBuffer * bits) ; 82 | uint32_t BitBufferGetPosition (BitBuffer * bits) ; 83 | void BitBufferByteAlign (BitBuffer * bits, int32_t addZeros) ; 84 | void BitBufferAdvance (BitBuffer * bits, uint32_t numBits) ; 85 | void BitBufferRewind (BitBuffer * bits, uint32_t numBits) ; 86 | void BitBufferWrite (BitBuffer * bits, uint32_t value, uint32_t numBits) ; 87 | void BitBufferReset (BitBuffer * bits) ; 88 | 89 | #endif /* __BITUTILITIES_H */ 90 | -------------------------------------------------------------------------------- /src/test_float.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2006-2012 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "common.h" 29 | #include "test_main.h" 30 | 31 | void 32 | test_float_convert (void) 33 | { static float data [] = 34 | { 0.0, 1.0, -1.0, 1.0 * M_PI, -1.0 * M_PI, 35 | 1e9, -1e9, 1e-9, -1e-9, 1e-10, -1e-10, 36 | 1e-19, -1e-19, 1e19, -1e19, 1e-20, -1e-20, 37 | } ; 38 | 39 | int k ; 40 | 41 | print_test_name (__func__) ; 42 | 43 | for (k = 0 ; k < ARRAY_LEN (data) ; k++) 44 | { unsigned char bytes [4] ; 45 | float test ; 46 | 47 | float32_le_write (data [k], bytes) ; 48 | test = float32_le_read (bytes) ; 49 | 50 | if (fabs (data [k] - test) > 1e-20) 51 | { printf ("\n\nLine %d : Test %d, little endian error %.15g -> %.15g.\n\n", __LINE__, k, data [k], test) ; 52 | exit (1) ; 53 | } ; 54 | 55 | float32_be_write (data [k], bytes) ; 56 | test = float32_be_read (bytes) ; 57 | 58 | if (fabs (data [k] - test) > 1e-20) 59 | { printf ("\n\nLine %d : Test %d, big endian error %.15g -> %.15g.\n\n", __LINE__, k, data [k], test) ; 60 | exit (1) ; 61 | } ; 62 | 63 | } ; 64 | 65 | puts ("ok") ; 66 | } /* test_float_convert */ 67 | 68 | void 69 | test_double_convert (void) 70 | { static double data [] = 71 | { 0.0, 1.0, -1.0, 1.0 * M_PI, -1.0 * M_PI, 72 | 1e9, -1e9, 1e-9, -1e-9, 1e-10, -1e-10, 73 | 1e-19, -1e-19, 1e19, -1e19, 1e-20, -1e-20, 74 | } ; 75 | 76 | int k ; 77 | 78 | print_test_name (__func__) ; 79 | 80 | for (k = 0 ; k < ARRAY_LEN (data) ; k++) 81 | { unsigned char bytes [8] ; 82 | double test ; 83 | 84 | double64_le_write (data [k], bytes) ; 85 | test = double64_le_read (bytes) ; 86 | 87 | if (fabs (data [k] - test) > 1e-20) 88 | { printf ("\n\nLine %d : Test %d, little endian error %.15g -> %.15g.\n\n", __LINE__, k, data [k], test) ; 89 | exit (1) ; 90 | } ; 91 | 92 | double64_be_write (data [k], bytes) ; 93 | test = double64_be_read (bytes) ; 94 | 95 | if (fabs (data [k] - test) > 1e-20) 96 | { printf ("\n\nLine %d : Test %d, big endian error %.15g -> %.15g.\n\n", __LINE__, k, data [k], test) ; 97 | exit (1) ; 98 | } ; 99 | 100 | } ; 101 | 102 | puts ("ok") ; 103 | } /* test_double_convert */ 104 | 105 | -------------------------------------------------------------------------------- /src/cart.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2012 Chris Roberts 3 | ** Copyright (C) 2006-2013 Erik de Castro Lopo 4 | ** Copyright (C) 2006 Paul Davis 5 | ** 6 | ** This program is free software; you can redistribute it and/or modify 7 | ** it under the terms of the GNU Lesser General Public License as published by 8 | ** the Free Software Foundation; either version 2.1 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** This program is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU Lesser General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU Lesser General Public License 17 | ** along with this program; if not, write to the Free Software 18 | ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | #include "sfconfig.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "common.h" 28 | 29 | 30 | 31 | static inline size_t 32 | cart_min_size (const SF_CART_INFO* info) 33 | { if (info == NULL) 34 | return 0 ; 35 | 36 | return offsetof (SF_CART_INFO, tag_text) + info->tag_text_size ; 37 | } /* cart_min_size */ 38 | 39 | SF_CART_INFO_16K* 40 | cart_var_alloc (void) 41 | { SF_CART_INFO_16K* thing ; 42 | thing = malloc (sizeof (SF_CART_INFO_16K)) ; 43 | return thing ; 44 | } /* cart_var_alloc */ 45 | 46 | int 47 | cart_var_set (SF_PRIVATE *psf, const SF_CART_INFO * info, size_t datasize) 48 | { size_t len ; 49 | 50 | if (info == NULL) 51 | return SF_FALSE ; 52 | 53 | if (cart_min_size (info) > datasize) 54 | { psf->error = SFE_BAD_CART_INFO_SIZE ; 55 | return SF_FALSE ; 56 | } ; 57 | 58 | if (datasize >= sizeof (SF_CART_INFO_16K)) 59 | { psf->error = SFE_BAD_CART_INFO_TOO_BIG ; 60 | return SF_FALSE ; 61 | } ; 62 | 63 | if (psf->cart_16k == NULL) 64 | { if ((psf->cart_16k = cart_var_alloc ()) == NULL) 65 | { psf->error = SFE_MALLOC_FAILED ; 66 | return SF_FALSE ; 67 | } ; 68 | } ; 69 | 70 | memcpy (psf->cart_16k, info, offsetof (SF_CART_INFO, tag_text)) ; 71 | psf_strlcpy_crlf (psf->cart_16k->tag_text, info->tag_text, sizeof (psf->cart_16k->tag_text), datasize - offsetof (SF_CART_INFO, tag_text)) ; 72 | 73 | len = strlen (psf->cart_16k->tag_text) ; 74 | 75 | if (len > 0 && psf->cart_16k->tag_text [len - 1] != '\n') 76 | psf_strlcat (psf->cart_16k->tag_text, sizeof (psf->cart_16k->tag_text), "\r\n") ; 77 | 78 | /* Force tag_text_size to be even. */ 79 | len = strlen (psf->cart_16k->tag_text) ; 80 | len += (len & 1) ? 1 : 2 ; 81 | 82 | psf->cart_16k->tag_text_size = len ; 83 | 84 | return SF_TRUE ; 85 | } /* cart_var_set */ 86 | 87 | 88 | int 89 | cart_var_get (SF_PRIVATE *psf, SF_CART_INFO * data, size_t datasize) 90 | { size_t size ; 91 | if (psf->cart_16k == NULL) 92 | return SF_FALSE ; 93 | 94 | size = SF_MIN (datasize, cart_min_size ((const SF_CART_INFO *) psf->cart_16k)) ; 95 | 96 | memcpy (data, psf->cart_16k, size) ; 97 | 98 | return SF_TRUE ; 99 | } /* cart_var_get */ 100 | 101 | 102 | -------------------------------------------------------------------------------- /src/G72x/README.original: -------------------------------------------------------------------------------- 1 | The files in this directory comprise ANSI-C language reference implementations 2 | of the CCITT (International Telegraph and Telephone Consultative Committee) 3 | G.711, G.721 and G.723 voice compressions. They have been tested on Sun 4 | SPARCstations and passed 82 out of 84 test vectors published by CCITT 5 | (Dec. 20, 1988) for G.721 and G.723. [The two remaining test vectors, 6 | which the G.721 decoder implementation for u-law samples did not pass, 7 | may be in error because they are identical to two other vectors for G.723_40.] 8 | 9 | This source code is released by Sun Microsystems, Inc. to the public domain. 10 | Please give your acknowledgement in product literature if this code is used 11 | in your product implementation. 12 | 13 | Sun Microsystems supports some CCITT audio formats in Solaris 2.0 system 14 | software. However, Sun's implementations have been optimized for higher 15 | performance on SPARCstations. 16 | 17 | 18 | The source files for CCITT conversion routines in this directory are: 19 | 20 | g72x.h header file for g721.c, g723_24.c and g723_40.c 21 | g711.c CCITT G.711 u-law and A-law compression 22 | g72x.c common denominator of G.721 and G.723 ADPCM codes 23 | g721.c CCITT G.721 32Kbps ADPCM coder (with g72x.c) 24 | g723_24.c CCITT G.723 24Kbps ADPCM coder (with g72x.c) 25 | g723_40.c CCITT G.723 40Kbps ADPCM coder (with g72x.c) 26 | 27 | 28 | Simple conversions between u-law, A-law, and 16-bit linear PCM are invoked 29 | as follows: 30 | 31 | unsigned char ucode, acode; 32 | short pcm_val; 33 | 34 | ucode = linear2ulaw(pcm_val); 35 | ucode = alaw2ulaw(acode); 36 | 37 | acode = linear2alaw(pcm_val); 38 | acode = ulaw2alaw(ucode); 39 | 40 | pcm_val = ulaw2linear(ucode); 41 | pcm_val = alaw2linear(acode); 42 | 43 | 44 | The other CCITT compression routines are invoked as follows: 45 | 46 | #include "g72x.h" 47 | 48 | struct g72x_state state; 49 | int sample, code; 50 | 51 | g72x_init_state(&state); 52 | code = {g721,g723_24,g723_40}_encoder(sample, coding, &state); 53 | sample = {g721,g723_24,g723_40}_decoder(code, coding, &state); 54 | 55 | where 56 | coding = AUDIO_ENCODING_ULAW for 8-bit u-law samples 57 | AUDIO_ENCODING_ALAW for 8-bit A-law samples 58 | AUDIO_ENCODING_LINEAR for 16-bit linear PCM samples 59 | 60 | 61 | 62 | This directory also includes the following sample programs: 63 | 64 | encode.c CCITT ADPCM encoder 65 | decode.c CCITT ADPCM decoder 66 | Makefile makefile for the sample programs 67 | 68 | 69 | The sample programs contain examples of how to call the various compression 70 | routines and pack/unpack the bits. The sample programs read byte streams from 71 | stdin and write to stdout. The input/output data is raw data (no file header 72 | or other identifying information is embedded). The sample programs are 73 | invoked as follows: 74 | 75 | encode [-3|4|5] [-a|u|l] outfile 76 | decode [-3|4|5] [-a|u|l] outfile 77 | where: 78 | -3 encode to (decode from) G.723 24kbps (3-bit) data 79 | -4 encode to (decode from) G.721 32kbps (4-bit) data [the default] 80 | -5 encode to (decode from) G.723 40kbps (5-bit) data 81 | -a encode from (decode to) A-law data 82 | -u encode from (decode to) u-law data [the default] 83 | -l encode from (decode to) 16-bit linear data 84 | 85 | Examples: 86 | # Read 16-bit linear and output G.721 87 | encode -4 -l g721file 88 | 89 | # Read 40Kbps G.723 and output A-law 90 | decode -5 -a alawfile 91 | 92 | # Compress and then decompress u-law data using 24Kbps G.723 93 | encode -3 ulawout 94 | 95 | -------------------------------------------------------------------------------- /src/ALAC/alac_codec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Apple Inc. All rights reserved. 3 | * Copyright (C) 2012-2014 Erik de Castro Lopo 4 | * 5 | * @APPLE_APACHE_LICENSE_HEADER_START@ 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License") ; 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * @APPLE_APACHE_LICENSE_HEADER_END@ 20 | */ 21 | 22 | /* 23 | File: alac_codec.h 24 | */ 25 | 26 | #ifndef ALAC_CODEC_H 27 | #define ALAC_CODEC_H 28 | 29 | #include 30 | 31 | #include "ALACAudioTypes.h" 32 | 33 | #define ALAC_FRAME_LENGTH 4096 34 | 35 | struct BitBuffer ; 36 | 37 | typedef struct alac_decoder_s 38 | { 39 | // decoding parameters (public for use in the analyzer) 40 | ALACSpecificConfig mConfig ; 41 | 42 | uint16_t mActiveElements ; 43 | 44 | // decoding buffers 45 | int32_t mMixBufferU [ALAC_FRAME_LENGTH] ; 46 | int32_t mMixBufferV [ALAC_FRAME_LENGTH] ; 47 | union 48 | { 49 | int32_t mPredictor [ALAC_FRAME_LENGTH] ; 50 | uint16_t mShiftBuffer [ALAC_FRAME_LENGTH] ; 51 | } ; 52 | uint32_t mNumChannels ; 53 | } ALAC_DECODER ; 54 | 55 | typedef struct alac_encoder_s 56 | { 57 | // ALAC encoder parameters 58 | int16_t mBitDepth ; 59 | 60 | // encoding state 61 | int16_t mLastMixRes [kALACMaxChannels] ; 62 | 63 | int32_t mFastMode ; 64 | 65 | // encoding buffers 66 | int32_t mMixBufferU [ALAC_FRAME_LENGTH] ; 67 | int32_t mMixBufferV [ALAC_FRAME_LENGTH] ; 68 | int32_t mPredictorU [ALAC_FRAME_LENGTH] ; 69 | int32_t mPredictorV [ALAC_FRAME_LENGTH] ; 70 | uint16_t mShiftBufferUV [2 * ALAC_FRAME_LENGTH] ; 71 | uint8_t mWorkBuffer [4 * ALAC_FRAME_LENGTH] ; 72 | 73 | // per-channel coefficients buffers 74 | int16_t mCoefsU [kALACMaxChannels][kALACMaxSearches][kALACMaxCoefs] ; 75 | int16_t mCoefsV [kALACMaxChannels][kALACMaxSearches][kALACMaxCoefs] ; 76 | 77 | // encoding statistics 78 | uint32_t mTotalBytesGenerated ; 79 | uint32_t mAvgBitRate ; 80 | uint32_t mMaxFrameBytes ; 81 | uint32_t mFrameSize ; 82 | uint32_t mMaxOutputBytes ; 83 | uint32_t mNumChannels ; 84 | uint32_t mOutputSampleRate ; 85 | } ALAC_ENCODER ; 86 | 87 | 88 | int32_t alac_decoder_init (ALAC_DECODER *p, void * inMagicCookie, uint32_t inMagicCookieSize) ; 89 | int32_t alac_encoder_init (ALAC_ENCODER *p, uint32_t samplerate, uint32_t channels, uint32_t format_flags, uint32_t frameSize) ; 90 | 91 | int32_t alac_decode (ALAC_DECODER *, struct BitBuffer * bits, int32_t * sampleBuffer, 92 | uint32_t numSamples, uint32_t * outNumSamples) ; 93 | 94 | int32_t alac_encode (ALAC_ENCODER *p, uint32_t numSamples, 95 | const int32_t * theReadBuffer, unsigned char * theWriteBuffer, 96 | uint32_t * ioNumBytes) ; 97 | 98 | void alac_set_fastmode (ALAC_ENCODER * p, int32_t fast) ; 99 | 100 | uint32_t alac_get_magic_cookie_size (uint32_t inNumChannels) ; 101 | void alac_get_magic_cookie (ALAC_ENCODER *p, void * config, uint32_t * ioSize) ; 102 | void alac_get_source_format (ALAC_ENCODER *p, const AudioFormatDescription * source, AudioFormatDescription * output) ; 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /src/G72x/g72x.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 1999-2011 Erik de Castro Lopo 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 | /* 20 | ** This file is not the same as the original file from Sun Microsystems. Nearly 21 | ** all the original definitions and function prototypes that were in the file 22 | ** of this name have been moved to g72x_priv.h. 23 | */ 24 | 25 | #ifndef G72X_HEADER_FILE 26 | #define G72X_HEADER_FILE 27 | 28 | /* 29 | ** Number of samples per block to process. 30 | ** Must be a common multiple of possible bits per sample : 2, 3, 4, 5 and 8. 31 | */ 32 | #define G72x_BLOCK_SIZE (3 * 5 * 8) 33 | 34 | /* 35 | ** Identifiers for the differing kinds of G72x ADPCM codecs. 36 | ** The identifiers also define the number of encoded bits per sample. 37 | */ 38 | 39 | enum 40 | { G723_16_BITS_PER_SAMPLE = 2, 41 | G723_24_BITS_PER_SAMPLE = 3, 42 | G723_40_BITS_PER_SAMPLE = 5, 43 | 44 | G721_32_BITS_PER_SAMPLE = 4, 45 | G721_40_BITS_PER_SAMPLE = 5, 46 | 47 | G723_16_SAMPLES_PER_BLOCK = G72x_BLOCK_SIZE, 48 | G723_24_SAMPLES_PER_BLOCK = G723_24_BITS_PER_SAMPLE * (G72x_BLOCK_SIZE / G723_24_BITS_PER_SAMPLE), 49 | G723_40_SAMPLES_PER_BLOCK = G723_40_BITS_PER_SAMPLE * (G72x_BLOCK_SIZE / G723_40_BITS_PER_SAMPLE), 50 | 51 | G721_32_SAMPLES_PER_BLOCK = G72x_BLOCK_SIZE, 52 | G721_40_SAMPLES_PER_BLOCK = G721_40_BITS_PER_SAMPLE * (G72x_BLOCK_SIZE / G721_40_BITS_PER_SAMPLE), 53 | 54 | G723_16_BYTES_PER_BLOCK = (G723_16_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8, 55 | G723_24_BYTES_PER_BLOCK = (G723_24_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8, 56 | G723_40_BYTES_PER_BLOCK = (G723_40_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8, 57 | 58 | G721_32_BYTES_PER_BLOCK = (G721_32_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8, 59 | G721_40_BYTES_PER_BLOCK = (G721_40_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8 60 | } ; 61 | 62 | /* Forward declaration of of g72x_state. */ 63 | 64 | struct g72x_state ; 65 | 66 | /* External function definitions. */ 67 | 68 | struct g72x_state * g72x_reader_init (int codec, int *blocksize, int *samplesperblock) ; 69 | struct g72x_state * g72x_writer_init (int codec, int *blocksize, int *samplesperblock) ; 70 | /* 71 | ** Initialize the ADPCM state table for the given codec. 72 | ** Return 0 on success, 1 on fail. 73 | */ 74 | 75 | int g72x_decode_block (struct g72x_state *pstate, const unsigned char *block, short *samples) ; 76 | /* 77 | ** The caller fills data->block with data->bytes bytes before calling the 78 | ** function. The value data->bytes must be an integer multiple of 79 | ** data->blocksize and be <= data->max_bytes. 80 | ** When it returns, the caller can read out data->samples samples. 81 | */ 82 | 83 | int g72x_encode_block (struct g72x_state *pstate, short *samples, unsigned char *block) ; 84 | /* 85 | ** The caller fills state->samples some integer multiple data->samples_per_block 86 | ** (up to G72x_BLOCK_SIZE) samples before calling the function. 87 | ** When it returns, the caller can read out bytes encoded bytes. 88 | */ 89 | 90 | #endif /* !G72X_HEADER_FILE */ 91 | 92 | -------------------------------------------------------------------------------- /src/test_conversions.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2006-2016 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "common.h" 29 | #include "test_main.h" 30 | 31 | 32 | /* 33 | ** This is a bit rough, but it is the nicest way to do it. 34 | */ 35 | 36 | #define cmp_test(line, ival, tval, str) \ 37 | if (ival != tval) \ 38 | { printf (str, line, ival, tval) ; \ 39 | exit (1) ; \ 40 | } ; 41 | 42 | static void 43 | conversion_test (char endian) 44 | { 45 | SF_PRIVATE sf_private, *psf ; 46 | const char * filename = "conversion.bin" ; 47 | int64_t i64 = SF_PLATFORM_S64 (0x0123456789abcdef), t64 = 0 ; 48 | char format_str [16] ; 49 | char test_name [64] ; 50 | char i8 = 12, t8 = 0 ; 51 | short i16 = 0x123, t16 = 0 ; 52 | int i24 = 0x23456, t24 = 0 ; 53 | int i32 = 0x0a0b0c0d, t32 = 0 ; 54 | int bytes ; 55 | 56 | snprintf (format_str, sizeof (format_str), "%c12348", endian) ; 57 | 58 | snprintf (test_name, sizeof (test_name), "Testing %s conversions", endian == 'e' ? "little endian" : "big endian") ; 59 | print_test_name (test_name) ; 60 | 61 | psf = &sf_private ; 62 | memset (psf, 0, sizeof (sf_private)) ; 63 | 64 | psf->file.mode = SFM_WRITE ; 65 | snprintf (psf->file.path.c, sizeof (psf->file.path.c), "%s", filename) ; 66 | 67 | if (psf_fopen (psf) != 0) 68 | { printf ("\n\nError : failed to open file '%s' for write.\n\n", filename) ; 69 | exit (1) ; 70 | } ; 71 | 72 | psf_binheader_writef (psf, format_str, i8, i16, i24, i32, i64) ; 73 | psf_fwrite (psf->header.ptr, 1, psf->header.indx, psf) ; 74 | free (psf->header.ptr) ; 75 | psf_fclose (psf) ; 76 | 77 | memset (psf, 0, sizeof (sf_private)) ; 78 | 79 | psf->file.mode = SFM_READ ; 80 | snprintf (psf->file.path.c, sizeof (psf->file.path.c), "%s", filename) ; 81 | 82 | if (psf_fopen (psf) != 0) 83 | { printf ("\n\nError : failed to open file '%s' for read.\n\n", filename) ; 84 | exit (1) ; 85 | } ; 86 | 87 | bytes = psf_binheader_readf (psf, format_str, &t8, &t16, &t24, &t32, &t64) ; 88 | free (psf->header.ptr) ; 89 | psf_fclose (psf) ; 90 | 91 | if (bytes != 18) 92 | { printf ("\n\nLine %d : read %d bytes.\n\n", __LINE__, bytes) ; 93 | exit (1) ; 94 | } ; 95 | 96 | cmp_test (__LINE__, i8, t8, "\n\nLine %d : 8 bit int failed %d -> %d.\n\n") ; 97 | cmp_test (__LINE__, i16, t16, "\n\nLine %d : 16 bit int failed 0x%x -> 0x%x.\n\n") ; 98 | cmp_test (__LINE__, i24, t24, "\n\nLine %d : 24 bit int failed 0x%x -> 0x%x.\n\n") ; 99 | cmp_test (__LINE__, i32, t32, "\n\nLine %d : 32 bit int failed 0x%x -> 0x%x.\n\n") ; 100 | cmp_test (__LINE__, i64, t64, "\n\nLine %d : 64 bit int failed 0x%" PRIx64 "x -> 0x%" PRIx64 "x.\n\n") ; 101 | 102 | remove (filename) ; 103 | puts ("ok") ; 104 | } /* conversion_test */ 105 | 106 | void 107 | test_conversions (void) 108 | { 109 | conversion_test ('E') ; 110 | conversion_test ('e') ; 111 | } /* test_conversion */ 112 | 113 | -------------------------------------------------------------------------------- /src/ALAC/matrixlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Apple Inc. All rights reserved. 3 | * Copyright (C) 2012-2014 Erik de Castro Lopo 4 | * 5 | * @APPLE_APACHE_LICENSE_HEADER_START@ 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License") ; 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * @APPLE_APACHE_LICENSE_HEADER_END@ 20 | */ 21 | 22 | /* 23 | File: matrixlib.h 24 | 25 | Contains: ALAC mixing/matrixing routines to/from 32-bit predictor buffers. 26 | 27 | Copyright: Copyright (C) 2004 to 2011 Apple, Inc. 28 | */ 29 | 30 | #ifndef __MATRIXLIB_H 31 | #define __MATRIXLIB_H 32 | 33 | #pragma once 34 | 35 | #include 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | // 16-bit routines 42 | void mix16 (const int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples, int32_t mixbits, int32_t mixres) ; 43 | void unmix16 (const int32_t * u, int32_t * v, int32_t * out, uint32_t stride, int32_t numSamples, int32_t mixbits, int32_t mixres) ; 44 | 45 | // 20-bit routines 46 | void mix20 (const int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples, int32_t mixbits, int32_t mixres) ; 47 | void unmix20 (const int32_t * u, int32_t * v, int32_t * out, uint32_t stride, int32_t numSamples, int32_t mixbits, int32_t mixres) ; 48 | 49 | // 24-bit routines 50 | // - 24-bit data sometimes compresses better by shifting off the bottom byte so these routines deal with 51 | // the specified "unused lower bytes" in the combined "shift" buffer 52 | void mix24 (const int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples, 53 | int32_t mixbits, int32_t mixres, uint16_t * shiftUV, int32_t bytesShifted) ; 54 | void unmix24 (const int32_t * u, int32_t * v, int32_t * out, uint32_t stride, int32_t numSamples, 55 | int32_t mixbits, int32_t mixres, uint16_t * shiftUV, int32_t bytesShifted) ; 56 | 57 | // 32-bit routines 58 | // - note that these really expect the internal data width to be < 32-bit but the arrays are 32-bit 59 | // - otherwise, the calculations might overflow into the 33rd bit and be lost 60 | // - therefore, these routines deal with the specified "unused lower" bytes in the combined "shift" buffer 61 | void mix32 (const int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples, 62 | int32_t mixbits, int32_t mixres, uint16_t * shiftUV, int32_t bytesShifted) ; 63 | void unmix32 (const int32_t * u, int32_t * v, int32_t * out, uint32_t stride, int32_t numSamples, 64 | int32_t mixbits, int32_t mixres, uint16_t * shiftUV, int32_t bytesShifted) ; 65 | 66 | // 20/24/32-bit <-> 32-bit helper routines (not really matrixing but convenient to put here) 67 | void copy20ToPredictor (const int32_t * in, uint32_t stride, int32_t * out, int32_t numSamples) ; 68 | void copy24ToPredictor (const int32_t * in, uint32_t stride, int32_t * out, int32_t numSamples) ; 69 | 70 | void copyPredictorTo24 (const int32_t * in, int32_t * out, uint32_t stride, int32_t numSamples) ; 71 | void copyPredictorTo24Shift (const int32_t * in, uint16_t * shift, int32_t * out, uint32_t stride, int32_t numSamples, int32_t bytesShifted) ; 72 | void copyPredictorTo20 (const int32_t * in, int32_t * out, uint32_t stride, int32_t numSamples) ; 73 | 74 | void copyPredictorTo32 (const int32_t * in, int32_t * out, uint32_t stride, int32_t numSamples) ; 75 | void copyPredictorTo32Shift (const int32_t * in, uint16_t * shift, int32_t * out, uint32_t stride, int32_t numSamples, int32_t bytesShifted) ; 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* __MATRIXLIB_H */ 82 | -------------------------------------------------------------------------------- /src/test_broadcast_var.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2010-2012 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "common.h" 26 | 27 | #include "test_main.h" 28 | 29 | #define BCAST_MAX 512 30 | 31 | typedef SF_BROADCAST_INFO_VAR (BCAST_MAX) SF_BROADCAST_INFO_512 ; 32 | 33 | static void 34 | fill_coding_history (SF_BROADCAST_INFO_512 * bi) 35 | { static const char *lines [] = 36 | { "Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit.", 37 | "Donec dignissim erat\nvehicula libero condimentum\ndictum porta augue faucibus.", 38 | "Maecenas nec turpis\nsit amet quam\nfaucibus adipiscing.", 39 | "Mauris aliquam,\nlectus interdum\ntincidunt luctus.", 40 | "\n\n\n\n\n\n\n\n\n\n\n\n", 41 | "In auctor lorem\nvel est euismod\ncondimentum.", 42 | "\n\n\n\n\n\n\n\n\n\n\n\n", 43 | "Ut vitae magna\nid dui placerat vehicula\nin id lectus.", 44 | "\n\n\n\n\n\n\n\n\n\n\n\n", 45 | "Sed lacus leo,\nmolestie et luctus ac,\ntincidunt sit amet nisi.", 46 | "\n\n\n\n\n\n\n\n\n\n\n\n", 47 | "Sed ligula neque,\ngravida semper vulputate laoreet,\ngravida eu tellus.", 48 | "Donec dolor dolor,\nscelerisque in consequat ornare,\ntempor nec nisl." 49 | } ; 50 | int k ; 51 | 52 | bi->coding_history [0] = 0 ; 53 | 54 | for (k = 0 ; strlen (bi->coding_history) < bi->coding_history_size - 1 ; k ++) 55 | append_snprintf (bi->coding_history, bi->coding_history_size, "%s\n", lines [k % ARRAY_LEN (lines)]) ; 56 | 57 | return ; 58 | } /* fill_coding_listory */ 59 | 60 | static void 61 | test_broadcast_var_set (void) 62 | { SF_PRIVATE sf_private, *psf ; 63 | int k ; 64 | 65 | psf = &sf_private ; 66 | memset (psf, 0, sizeof (sf_private)) ; 67 | 68 | print_test_name ("Testing broadcast_var_set ") ; 69 | 70 | for (k = 64 ; k < BCAST_MAX ; k++) 71 | { 72 | SF_BROADCAST_INFO_512 bi ; 73 | 74 | memset (&bi, 0, sizeof (bi)) ; 75 | 76 | bi.coding_history_size = k ; 77 | fill_coding_history (&bi) ; 78 | bi.coding_history_size -- ; 79 | 80 | broadcast_var_set (psf, (SF_BROADCAST_INFO*) &bi, sizeof (bi)) ; 81 | } ; 82 | 83 | if (psf->broadcast_16k != NULL) 84 | free (psf->broadcast_16k) ; 85 | 86 | puts ("ok") ; 87 | } /* test_broadcast_var_set */ 88 | 89 | static void 90 | test_broadcast_var_zero (void) 91 | { SF_PRIVATE sf_private, *psf ; 92 | SF_BROADCAST_INFO_VAR (0) bi ; 93 | 94 | psf = &sf_private ; 95 | memset (psf, 0, sizeof (sf_private)) ; 96 | psf->file.mode = SFM_RDWR ; 97 | 98 | print_test_name ("Testing broadcast_var_zero ") ; 99 | 100 | memset (&bi, 0, sizeof (bi)) ; 101 | 102 | broadcast_var_set (psf, (SF_BROADCAST_INFO*) &bi, sizeof (bi)) ; 103 | 104 | if (psf->broadcast_16k->coding_history_size != 0) 105 | { printf ("\n\nLine %d: coding_history_size %d should be zero.\n\n", __LINE__, psf->broadcast_16k->coding_history_size) ; 106 | exit (1) ; 107 | } ; 108 | 109 | if (psf->broadcast_16k != NULL) 110 | free (psf->broadcast_16k) ; 111 | 112 | puts ("ok") ; 113 | } /* test_broadcast_var_zero */ 114 | 115 | void 116 | test_broadcast_var (void) 117 | { test_broadcast_var_set () ; 118 | test_broadcast_var_zero () ; 119 | } /* test_broadcast_var */ 120 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | % libsndfile for MSVC 2 | 3 | 4 | # About # 5 | 6 | Static **libsndfile** for use with *Microsoft Visual C++*, ported by LoRd_MuldeR <> 7 | 8 | ## Details ## 9 | 10 | [**Libsndfile**](http://www.mega-nerd.com/libsndfile/) is a C library for reading and writing files containing sampled sound (such as MS Windows WAV and the Apple/SGI AIFF format) through one standard library interface. Unfortunately, the "official" version of *libsndfile* does **not** currently support building the library with *Microsoft Visual C++* (MSVC). It is still possible to build a Windows DLL of *libsndfile* with [MinGW/GCC](http://mingw-w64.sourceforge.net/) and then link the MinGW-compiled DLL against your MSVC-compiled program files. However, to the best of my knowledge, this method does **not** work if you intend to link *libsndfile* as a ***static*** library! At least I never got it to work ;-) 11 | 12 | The purpose of this repository is providing solution/project files that can be used to compile the latest version of *libsndfile* under MSVC, resulting in a "native" MSVC library that allows for **static** linking with MSVC-compiled programs. The code in this repository is identical to the "official" *libsndfile* codebase, except that solution/project files for MSVC have been added and that config.h has been adjusted. Furthermore, a few compatibility (build) fixes were required for MSVC, some of which were backported from the [Qt Framework](https://www.qt.io/). In my tests, the MSVC binary of *libsndfile* is only slightly slower than the MinGW one. 13 | 14 | My project/solution files have been tested to build smoothly under Visual Studio 2013 (MSVC 12.0) or 2015 (MSVC 14.0). 15 | 16 | 17 | # Legal Notice # 18 | 19 | **Libsndfile** was created by *Erik de Castro Lopo* <> and is released under the terms of the *GNU Lesser General Public License*. For details, please refer to the official *libsndfile* web-site! 20 | 21 | Support for **Ogg**, **Vorbis** and **FLAC** is enabled using "extra" libraries created by *Monty* <> and the rest of the [Xiph.org Foundation](https://www.xiph.org/). Those libraries are released under the "BSD-style" license. 22 | 23 | ## Warning ## 24 | 25 | Even though *libsndfile* is released under the *GNU Lesser General Public License*, which explicitly *does* allow linking the library (i.e. libsndfile) against proprietary programs, this is *only* applicable as long as the library (i.e. libsndfile) remains *separate* from the proprietary portion of the program – in the form of a **shared** library. However, as soon as the library (i.e. libsndfile) is linked **statically** into your program, your program *as a whole* **must** be released under the *GNU General Public License*! 26 | 27 | 28 | # Build Prerequisites 29 | 30 | In order to build libsndfile-MSVC with Vorbis and FLAC support enabled, you need the "extra" libraries by Xiph.org: 31 | ``` 32 | BaseDirectory\ 33 | ├─ libsndfile-MSVC\ 34 | │ ├─ libsndfile_VS2015.sln 35 | │ ├─ libsndfile_VS2015.vcxproj 36 | │ └─ [...] 37 | └─ Prerequisites\ 38 | └─ XiphAudioLibs\ 39 | ├─ include\ 40 | │ ├─ FLAC\ 41 | │ │ ├─ stream_decoder.h 42 | │ │ ├─ stream_encoder.h 43 | │ │ └─ metadata.h 44 | │ ├─ ogg\ 45 | │ │ ├─ ogg.h 46 | │ │ └─ os_types.h 47 | │ └─ vorbis\ 48 | │ ├─ codec.h 49 | │ ├─ vorbisenc.h 50 | │ └─ vorbisfile.h 51 | └─ lib\ 52 | └─ Win32\ 53 | └─ static\ 54 | ├─ libFLAC_static.v140_xp.lib 55 | ├─ libogg_static.v140_xp.lib 56 | └─ libvorbis_static.v140_xp.lib 57 | ``` 58 | 59 | # Source Code # 60 | 61 | The source code of **libsndfile for MSVC** is available from our *Git* mirrors: 62 | 63 | * https://github.com/lordmulder/libsndfile-MSVC.git – [[Browse]](https://github.com/lordmulder/libsndfile-MSVC) 64 | 65 | * https://bitbucket.org/muldersoft/libsndfile-msvc.git – [[Browse]](https://bitbucket.org/muldersoft/libsndfile-msvc) 66 | 67 | * https://gitlab.com/lord_mulder/libsndfile-MSVC.git – [[Browse]](https://gitlab.com/lord_mulder/libsndfile-MSVC) 68 | 69 |   70 | 71 | e.o.f. 72 | -------------------------------------------------------------------------------- /src/ogg_opus.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2013-2016 Erik de Castro Lopo 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 | 20 | #include "sfconfig.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #if HAVE_UNISTD_H 30 | #include 31 | #endif 32 | 33 | #include "sndfile.h" 34 | #include "sfendian.h" 35 | #include "common.h" 36 | 37 | #if (ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_XIPH_LIBS) 38 | 39 | #include 40 | 41 | #include "ogg.h" 42 | 43 | typedef struct 44 | { int32_t serialno ; 45 | 46 | 47 | void * state ; 48 | } OPUS_PRIVATE ; 49 | 50 | static int ogg_opus_read_header (SF_PRIVATE * psf) ; 51 | static int ogg_opus_close (SF_PRIVATE *psf) ; 52 | 53 | int 54 | ogg_opus_open (SF_PRIVATE *psf) 55 | { OGG_PRIVATE* odata = psf->container_data ; 56 | OPUS_PRIVATE* oopus = calloc (1, sizeof (OPUS_PRIVATE)) ; 57 | int error = 0 ; 58 | 59 | if (odata == NULL) 60 | { psf_log_printf (psf, "%s : odata is NULL???\n", __func__) ; 61 | return SFE_INTERNAL ; 62 | } ; 63 | 64 | psf->codec_data = oopus ; 65 | if (oopus == NULL) 66 | return SFE_MALLOC_FAILED ; 67 | 68 | if (psf->file.mode == SFM_RDWR) 69 | return SFE_BAD_MODE_RW ; 70 | 71 | if (psf->file.mode == SFM_READ) 72 | { /* Call this here so it only gets called once, so no memory is leaked. */ 73 | ogg_sync_init (&odata->osync) ; 74 | 75 | if ((error = ogg_opus_read_header (psf))) 76 | return error ; 77 | 78 | #if 0 79 | psf->read_short = ogg_opus_read_s ; 80 | psf->read_int = ogg_opus_read_i ; 81 | psf->read_float = ogg_opus_read_f ; 82 | psf->read_double = ogg_opus_read_d ; 83 | psf->sf.frames = ogg_opus_length (psf) ; 84 | #endif 85 | } ; 86 | 87 | psf->codec_close = ogg_opus_close ; 88 | 89 | if (psf->file.mode == SFM_WRITE) 90 | { 91 | #if 0 92 | /* Set the default oopus quality here. */ 93 | vdata->quality = 0.4 ; 94 | 95 | psf->write_header = ogg_opus_write_header ; 96 | psf->write_short = ogg_opus_write_s ; 97 | psf->write_int = ogg_opus_write_i ; 98 | psf->write_float = ogg_opus_write_f ; 99 | psf->write_double = ogg_opus_write_d ; 100 | #endif 101 | 102 | psf->sf.frames = SF_COUNT_MAX ; /* Unknown really */ 103 | psf->strings.flags = SF_STR_ALLOW_START ; 104 | } ; 105 | 106 | psf->bytewidth = 1 ; 107 | psf->blockwidth = psf->bytewidth * psf->sf.channels ; 108 | 109 | #if 0 110 | psf->seek = ogg_opus_seek ; 111 | psf->command = ogg_opus_command ; 112 | #endif 113 | 114 | /* FIXME, FIXME, FIXME : Hack these here for now and correct later. */ 115 | psf->sf.format = SF_FORMAT_OGG | SF_FORMAT_SPEEX ; 116 | psf->sf.sections = 1 ; 117 | 118 | psf->datalength = 1 ; 119 | psf->dataoffset = 0 ; 120 | /* End FIXME. */ 121 | 122 | return error ; 123 | } /* ogg_opus_open */ 124 | 125 | static int 126 | ogg_opus_read_header (SF_PRIVATE * UNUSED (psf)) 127 | { 128 | return 0 ; 129 | } /* ogg_opus_read_header */ 130 | 131 | static int 132 | ogg_opus_close (SF_PRIVATE * UNUSED (psf)) 133 | { 134 | 135 | 136 | return 0 ; 137 | } /* ogg_opus_close */ 138 | 139 | 140 | #else /* ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_XIPH_LIBS */ 141 | 142 | int 143 | ogg_opus_open (SF_PRIVATE *psf) 144 | { 145 | psf_log_printf (psf, "This version of libsndfile was compiled without Ogg/Opus support.\n") ; 146 | return SFE_UNIMPLEMENTED ; 147 | } /* ogg_opus_open */ 148 | 149 | #endif 150 | -------------------------------------------------------------------------------- /src/ogg_pcm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2008-2016 Erik de Castro Lopo 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 | 20 | #include "sfconfig.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #if HAVE_UNISTD_H 30 | #include 31 | #endif 32 | 33 | #include "sndfile.h" 34 | #include "sfendian.h" 35 | #include "common.h" 36 | 37 | #if (ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_XIPH_LIBS) 38 | 39 | #include 40 | 41 | #include "ogg.h" 42 | 43 | typedef struct 44 | { int32_t serialno ; 45 | 46 | 47 | void * state ; 48 | } OPCM_PRIVATE ; 49 | 50 | static int opcm_read_header (SF_PRIVATE * psf) ; 51 | static int opcm_close (SF_PRIVATE *psf) ; 52 | 53 | int 54 | ogg_pcm_open (SF_PRIVATE *psf) 55 | { OGG_PRIVATE* odata = psf->container_data ; 56 | OPCM_PRIVATE* opcm = calloc (1, sizeof (OPCM_PRIVATE)) ; 57 | int error = 0 ; 58 | 59 | if (odata == NULL) 60 | { psf_log_printf (psf, "%s : odata is NULL???\n", __func__) ; 61 | return SFE_INTERNAL ; 62 | } ; 63 | 64 | psf->codec_data = opcm ; 65 | if (opcm == NULL) 66 | return SFE_MALLOC_FAILED ; 67 | 68 | if (psf->file.mode == SFM_RDWR) 69 | return SFE_BAD_MODE_RW ; 70 | 71 | if (psf->file.mode == SFM_READ) 72 | { /* Call this here so it only gets called once, so no memory is leaked. */ 73 | ogg_sync_init (&odata->osync) ; 74 | 75 | if ((error = opcm_read_header (psf))) 76 | return error ; 77 | 78 | #if 0 79 | psf->read_short = opcm_read_s ; 80 | psf->read_int = opcm_read_i ; 81 | psf->read_float = opcm_read_f ; 82 | psf->read_double = opcm_read_d ; 83 | psf->sf.frames = opcm_length (psf) ; 84 | #endif 85 | } ; 86 | 87 | psf->codec_close = opcm_close ; 88 | 89 | if (psf->file.mode == SFM_WRITE) 90 | { 91 | #if 0 92 | /* Set the default opcm quality here. */ 93 | vdata->quality = 0.4 ; 94 | 95 | psf->write_header = opcm_write_header ; 96 | psf->write_short = opcm_write_s ; 97 | psf->write_int = opcm_write_i ; 98 | psf->write_float = opcm_write_f ; 99 | psf->write_double = opcm_write_d ; 100 | #endif 101 | 102 | psf->sf.frames = SF_COUNT_MAX ; /* Unknown really */ 103 | psf->strings.flags = SF_STR_ALLOW_START ; 104 | } ; 105 | 106 | psf->bytewidth = 1 ; 107 | psf->blockwidth = psf->bytewidth * psf->sf.channels ; 108 | 109 | #if 0 110 | psf->seek = opcm_seek ; 111 | psf->command = opcm_command ; 112 | #endif 113 | 114 | /* FIXME, FIXME, FIXME : Hack these here for now and correct later. */ 115 | psf->sf.format = SF_FORMAT_OGG | SF_FORMAT_SPEEX ; 116 | psf->sf.sections = 1 ; 117 | 118 | psf->datalength = 1 ; 119 | psf->dataoffset = 0 ; 120 | /* End FIXME. */ 121 | 122 | return error ; 123 | } /* ogg_pcm_open */ 124 | 125 | static int 126 | opcm_read_header (SF_PRIVATE * UNUSED (psf)) 127 | { 128 | return 0 ; 129 | } /* opcm_read_header */ 130 | 131 | static int 132 | opcm_close (SF_PRIVATE * UNUSED (psf)) 133 | { 134 | 135 | 136 | return 0 ; 137 | } /* opcm_close */ 138 | 139 | 140 | 141 | /* 142 | encoded_speex_frames = (frames_per_packet * Packets) 143 | = 1 * 272 144 | = 272 145 | 146 | audio_samples = encoded_speex_frames * frame_size 147 | = 272 * 640 148 | = 174080 149 | 150 | duration = audio_samples / rate 151 | = 174080 / 44100 152 | = 3.947 153 | */ 154 | 155 | #else /* ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_XIPH_LIBS */ 156 | 157 | int 158 | ogg_pcm_open (SF_PRIVATE *psf) 159 | { 160 | psf_log_printf (psf, "This version of libsndfile was compiled without Ogg/Speex support.\n") ; 161 | return SFE_UNIMPLEMENTED ; 162 | } /* ogg_pcm_open */ 163 | 164 | #endif 165 | -------------------------------------------------------------------------------- /src/test_log_printf.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2003-2012 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "common.h" 28 | 29 | #include "test_main.h" 30 | 31 | #define CMP_0_ARGS(line, err, fmt) \ 32 | { psf->parselog.indx = 0 ; \ 33 | snprintf (buffer, sizeof (buffer), (fmt)) ; \ 34 | psf_log_printf (psf, (fmt)) ; \ 35 | err += compare_strings_or_die (line, fmt, buffer, psf->parselog.buf) ; \ 36 | } 37 | 38 | #define CMP_2_ARGS(line, err, fmt, a) \ 39 | { psf->parselog.indx = 0 ; \ 40 | snprintf (buffer, sizeof (buffer), (fmt), (a), (a)) ; \ 41 | psf_log_printf (psf, (fmt), (a), (a)) ; \ 42 | err += compare_strings_or_die (line, fmt, buffer, psf->parselog.buf) ; \ 43 | } 44 | 45 | #define CMP_4_ARGS(line, err, fmt, a) \ 46 | { psf->parselog.indx = 0 ; \ 47 | snprintf (buffer, sizeof (buffer), (fmt), (a), (a), (a), (a)) ; \ 48 | psf_log_printf (psf, (fmt), (a), (a), (a), (a)) ; \ 49 | err += compare_strings_or_die (line, fmt, buffer, psf->parselog.buf) ; \ 50 | } 51 | 52 | #define CMP_5_ARGS(line, err, fmt, a) \ 53 | { psf->parselog.indx = 0 ; \ 54 | snprintf (buffer, sizeof (buffer), (fmt), (a), (a), (a), (a), (a)) ; \ 55 | psf_log_printf (psf, (fmt), (a), (a), (a), (a), (a)) ; \ 56 | err += compare_strings_or_die (line, fmt, buffer, psf->parselog.buf) ; \ 57 | } 58 | 59 | #define CMP_6_ARGS(line, err, fmt, a) \ 60 | { psf->parselog.indx = 0 ; \ 61 | snprintf (buffer, sizeof (buffer), (fmt), (a), (a), (a), (a), (a), (a)) ; \ 62 | psf_log_printf (psf, (fmt), (a), (a), (a), (a), (a), (a)) ; \ 63 | err += compare_strings_or_die (line, fmt, buffer, psf->parselog.buf) ; \ 64 | } 65 | 66 | static int 67 | compare_strings_or_die (int linenum, const char *fmt, const char* s1, const char* s2) 68 | { int errors = 0 ; 69 | /*-puts (s1) ;puts (s2) ;-*/ 70 | 71 | if (strcmp (s1, s2) != 0) 72 | { printf ("\n\nLine %d: string compare mismatch:\n\t", linenum) ; 73 | printf ("\"%s\"\n", fmt) ; 74 | printf ("\t\"%s\"\n\t\"%s\"\n", s1, s2) ; 75 | errors ++ ; 76 | } ; 77 | 78 | return errors ; 79 | } /* compare_strings_or_die */ 80 | 81 | void 82 | test_log_printf (void) 83 | { static char buffer [2048] ; 84 | SF_PRIVATE sf_private, *psf ; 85 | int k, errors = 0 ; 86 | int int_values [] = { 0, 1, 12, 123, 1234, 123456, -1, -12, -123, -1234, -123456 } ; 87 | 88 | print_test_name ("Testing psf_log_printf") ; 89 | 90 | psf = &sf_private ; 91 | memset (psf, 0, sizeof (sf_private)) ; 92 | 93 | CMP_0_ARGS (__LINE__, errors, " ->%%<- ") ; 94 | 95 | /* Test printing of ints. */ 96 | for (k = 0 ; k < ARRAY_LEN (int_values) ; k++) 97 | CMP_6_ARGS (__LINE__, errors, "int A : %d, % d, %4d, % 4d, %04d, % 04d", int_values [k]) ; 98 | 99 | for (k = 0 ; k < ARRAY_LEN (int_values) ; k++) 100 | CMP_5_ARGS (__LINE__, errors, "int B : %+d, %+4d, %+04d, %-d, %-4d", int_values [k]) ; 101 | 102 | for (k = 0 ; k < ARRAY_LEN (int_values) ; k++) 103 | CMP_2_ARGS (__LINE__, errors, "int C : %- d, %- 4d", int_values [k]) ; 104 | 105 | /* Test printing of unsigned ints. */ 106 | for (k = 0 ; k < ARRAY_LEN (int_values) ; k++) 107 | CMP_4_ARGS (__LINE__, errors, "D : %u, %4u, %04u, %0u", int_values [k]) ; 108 | 109 | /* Test printing of hex ints. */ 110 | for (k = 0 ; k < ARRAY_LEN (int_values) ; k++) 111 | CMP_4_ARGS (__LINE__, errors, "E : %X, %4X, %04X, %0X", int_values [k]) ; 112 | 113 | /* Test printing of strings. */ 114 | CMP_4_ARGS (__LINE__, errors, "B %s, %3s, %8s, %-8s", "str") ; 115 | 116 | if (errors) 117 | { puts ("\nExiting due to errors.\n") ; 118 | exit (1) ; 119 | } ; 120 | 121 | puts ("ok") ; 122 | } /* test_log_printf */ 123 | 124 | -------------------------------------------------------------------------------- /src/G72x/g723_24.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This source code is a product of Sun Microsystems, Inc. and is provided 3 | * for unrestricted use. Users may copy or modify this source code without 4 | * charge. 5 | * 6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING 7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 9 | * 10 | * Sun source code is provided with no support and without any obligation on 11 | * the part of Sun Microsystems, Inc. to assist in its use, correction, 12 | * modification or enhancement. 13 | * 14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE 16 | * OR ANY PART THEREOF. 17 | * 18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 19 | * or profits or other special, indirect and consequential damages, even if 20 | * Sun has been advised of the possibility of such damages. 21 | * 22 | * Sun Microsystems, Inc. 23 | * 2550 Garcia Avenue 24 | * Mountain View, California 94043 25 | */ 26 | 27 | /* 28 | * g723_24.c 29 | * 30 | * Description: 31 | * 32 | * g723_24_encoder (), g723_24_decoder () 33 | * 34 | * These routines comprise an implementation of the CCITT G.723 24 Kbps 35 | * ADPCM coding algorithm. Essentially, this implementation is identical to 36 | * the bit level description except for a few deviations which take advantage 37 | * of workstation attributes, such as hardware 2's complement arithmetic. 38 | * 39 | */ 40 | 41 | #include "g72x.h" 42 | #include "g72x_priv.h" 43 | 44 | /* 45 | * Maps G.723_24 code word to reconstructed scale factor normalized log 46 | * magnitude values. 47 | */ 48 | static short _dqlntab [8] = { -2048, 135, 273, 373, 373, 273, 135, -2048 } ; 49 | 50 | /* Maps G.723_24 code word to log of scale factor multiplier. */ 51 | static short _witab [8] = { -128, 960, 4384, 18624, 18624, 4384, 960, -128 } ; 52 | 53 | /* 54 | * Maps G.723_24 code words to a set of values whose long and short 55 | * term averages are computed and then compared to give an indication 56 | * how stationary (steady state) the signal is. 57 | */ 58 | static short _fitab [8] = { 0, 0x200, 0x400, 0xE00, 0xE00, 0x400, 0x200, 0 } ; 59 | 60 | static short qtab_723_24 [3] = { 8, 218, 331 } ; 61 | 62 | /* 63 | * g723_24_encoder () 64 | * 65 | * Encodes a linear PCM, A-law or u-law input sample and returns its 3-bit code. 66 | * Returns -1 if invalid input coding value. 67 | */ 68 | int 69 | g723_24_encoder ( 70 | int sl, 71 | G72x_STATE *state_ptr) 72 | { 73 | short sei, sezi, se, sez ; /* ACCUM */ 74 | short d ; /* SUBTA */ 75 | short y ; /* MIX */ 76 | short sr ; /* ADDB */ 77 | short dqsez ; /* ADDC */ 78 | short dq, i ; 79 | 80 | /* linearize input sample to 14-bit PCM */ 81 | sl >>= 2 ; /* sl of 14-bit dynamic range */ 82 | 83 | sezi = predictor_zero (state_ptr) ; 84 | sez = sezi >> 1 ; 85 | sei = sezi + predictor_pole (state_ptr) ; 86 | se = sei >> 1 ; /* se = estimated signal */ 87 | 88 | d = sl - se ; /* d = estimation diff. */ 89 | 90 | /* quantize prediction difference d */ 91 | y = step_size (state_ptr) ; /* quantizer step size */ 92 | i = quantize (d, y, qtab_723_24, 3) ; /* i = ADPCM code */ 93 | dq = reconstruct (i & 4, _dqlntab [i], y) ; /* quantized diff. */ 94 | 95 | sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq ; /* reconstructed signal */ 96 | 97 | dqsez = sr + sez - se ; /* pole prediction diff. */ 98 | 99 | update (3, y, _witab [i], _fitab [i], dq, sr, dqsez, state_ptr) ; 100 | 101 | return i ; 102 | } 103 | 104 | /* 105 | * g723_24_decoder () 106 | * 107 | * Decodes a 3-bit CCITT G.723_24 ADPCM code and returns 108 | * the resulting 16-bit linear PCM, A-law or u-law sample value. 109 | * -1 is returned if the output coding is unknown. 110 | */ 111 | int 112 | g723_24_decoder ( 113 | int i, 114 | G72x_STATE *state_ptr) 115 | { 116 | short sezi, sei, sez, se ; /* ACCUM */ 117 | short y ; /* MIX */ 118 | short sr ; /* ADDB */ 119 | short dq ; 120 | short dqsez ; 121 | 122 | i &= 0x07 ; /* mask to get proper bits */ 123 | sezi = predictor_zero (state_ptr) ; 124 | sez = sezi >> 1 ; 125 | sei = sezi + predictor_pole (state_ptr) ; 126 | se = sei >> 1 ; /* se = estimated signal */ 127 | 128 | y = step_size (state_ptr) ; /* adaptive quantizer step size */ 129 | dq = reconstruct (i & 0x04, _dqlntab [i], y) ; /* unquantize pred diff */ 130 | 131 | sr = (dq < 0) ? (se - (dq & 0x3FFF)) : (se + dq) ; /* reconst. signal */ 132 | 133 | dqsez = sr - se + sez ; /* pole prediction diff. */ 134 | 135 | update (3, y, _witab [i], _fitab [i], dq, sr, dqsez, state_ptr) ; 136 | 137 | return arith_shift_left (sr, 2) ; /* sr was of 14-bit dynamic range */ 138 | } 139 | 140 | -------------------------------------------------------------------------------- /src/G72x/g72x_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This source code is a product of Sun Microsystems, Inc. and is provided 3 | * for unrestricted use. Users may copy or modify this source code without 4 | * charge. 5 | * 6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING 7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 9 | * 10 | * Sun source code is provided with no support and without any obligation on 11 | * the part of Sun Microsystems, Inc. to assist in its use, correction, 12 | * modification or enhancement. 13 | * 14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE 16 | * OR ANY PART THEREOF. 17 | * 18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 19 | * or profits or other special, indirect and consequential damages, even if 20 | * Sun has been advised of the possibility of such damages. 21 | * 22 | * Sun Microsystems, Inc. 23 | * 2550 Garcia Avenue 24 | * Mountain View, California 94043 25 | */ 26 | 27 | #ifndef G72X_PRIVATE_H 28 | #define G72X_PRIVATE_H 29 | 30 | #ifdef __cplusplus 31 | #error "This code is not designed to be compiled with a C++ compiler." 32 | #endif 33 | 34 | /* 35 | ** The following is the definition of the state structure used by the 36 | ** G.721/G.723 encoder and decoder to preserve their internal state 37 | ** between successive calls. The meanings of the majority of the state 38 | ** structure fields are explained in detail in the CCITT Recommendation 39 | ** G.721. The field names are essentially identical to variable names 40 | ** in the bit level description of the coding algorithm included in this 41 | ** Recommendation. 42 | */ 43 | 44 | struct g72x_state 45 | { long yl ; /* Locked or steady state step size multiplier. */ 46 | short yu ; /* Unlocked or non-steady state step size multiplier. */ 47 | short dms ; /* Short term energy estimate. */ 48 | short dml ; /* Long term energy estimate. */ 49 | short ap ; /* Linear weighting coefficient of 'yl' and 'yu'. */ 50 | 51 | short a [2] ; /* Coefficients of pole portion of prediction filter. */ 52 | short b [6] ; /* Coefficients of zero portion of prediction filter. */ 53 | short pk [2] ; /* 54 | ** Signs of previous two samples of a partially 55 | ** reconstructed signal. 56 | **/ 57 | short dq [6] ; /* 58 | ** Previous 6 samples of the quantized difference 59 | ** signal represented in an internal floating point 60 | ** format. 61 | **/ 62 | short sr [2] ; /* 63 | ** Previous 2 samples of the quantized difference 64 | ** signal represented in an internal floating point 65 | ** format. 66 | */ 67 | char td ; /* delayed tone detect, new in 1988 version */ 68 | 69 | /* The following struct members were added for libsndfile. The original 70 | ** code worked by calling a set of functions on a sample by sample basis 71 | ** which is slow on architectures like Intel x86. For libsndfile, this 72 | ** was changed so that the encoding and decoding routines could work on 73 | ** a block of samples at a time to reduce the function call overhead. 74 | */ 75 | int (*encoder) (int, struct g72x_state* state) ; 76 | int (*decoder) (int, struct g72x_state* state) ; 77 | 78 | int codec_bits, blocksize, samplesperblock ; 79 | } ; 80 | 81 | typedef struct g72x_state G72x_STATE ; 82 | 83 | int predictor_zero (G72x_STATE *state_ptr) ; 84 | 85 | int predictor_pole (G72x_STATE *state_ptr) ; 86 | 87 | int step_size (G72x_STATE *state_ptr) ; 88 | 89 | int quantize (int d, int y, short *table, int size) ; 90 | 91 | int reconstruct (int sign, int dqln, int y) ; 92 | 93 | void update (int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, G72x_STATE *state_ptr) ; 94 | 95 | int g721_encoder (int sample, G72x_STATE *state_ptr) ; 96 | int g721_decoder (int code, G72x_STATE *state_ptr) ; 97 | 98 | int g723_16_encoder (int sample, G72x_STATE *state_ptr) ; 99 | int g723_16_decoder (int code, G72x_STATE *state_ptr) ; 100 | 101 | int g723_24_encoder (int sample, G72x_STATE *state_ptr) ; 102 | int g723_24_decoder (int code, G72x_STATE *state_ptr) ; 103 | 104 | int g723_40_encoder (int sample, G72x_STATE *state_ptr) ; 105 | int g723_40_decoder (int code, G72x_STATE *state_ptr) ; 106 | 107 | void private_init_state (G72x_STATE *state_ptr) ; 108 | 109 | #if __GNUC__ 110 | #define ALWAYS_INLINE __attribute__ ((always_inline)) 111 | #else 112 | #define ALWAYS_INLINE 113 | #endif 114 | 115 | static inline int ALWAYS_INLINE 116 | arith_shift_left (int x, int shift) 117 | { return (int) (((unsigned int) x) << shift) ; 118 | } /* arith_shift_left */ 119 | 120 | static inline int ALWAYS_INLINE 121 | arith_shift_right (int x, int shift) 122 | { if (x >= 0) 123 | return x << shift ; 124 | return ~ ((~x) << shift) ; 125 | } /* arith_shift_right */ 126 | 127 | #endif /* G72X_PRIVATE_H */ 128 | -------------------------------------------------------------------------------- /doc/vorbis.README.txt: -------------------------------------------------------------------------------- 1 | ******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015 * 9 | * by the Xiph.org Foundation, http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | Vorbis is a general purpose audio and music encoding format 14 | contemporary to MPEG-4's AAC and TwinVQ, the next generation beyond 15 | MPEG audio layer 3. Unlike the MPEG sponsored formats (and other 16 | proprietary formats such as RealAudio G2 and Windows' flavor of the 17 | month), the Vorbis CODEC specification belongs to the public domain. 18 | All the technical details are published and documented, and any 19 | software entity may make full use of the format without license 20 | fee, royalty or patent concerns. 21 | 22 | This package contains: 23 | 24 | * libvorbis, a BSD-style license software implementation of 25 | the Vorbis specification by the Xiph.Org Foundation 26 | (http://www.xiph.org/) 27 | 28 | * libvorbisfile, a BSD-style license convenience library 29 | built on Vorbis designed to simplify common uses 30 | 31 | * libvorbisenc, a BSD-style license library that provides a simple, 32 | programmatic encoding setup interface 33 | 34 | * example code making use of libogg, libvorbis, libvorbisfile and 35 | libvorbisenc 36 | 37 | WHAT'S HERE: 38 | 39 | This source distribution includes libvorbis and an example 40 | encoder/player to demonstrate use of libvorbis as well as 41 | documentation on the Ogg Vorbis audio coding format. 42 | 43 | You'll need libogg (distributed separately) to compile this library. 44 | A more comprehensive set of utilities is available in the vorbis-tools 45 | package. 46 | 47 | Directory: 48 | 49 | ./lib The source for the libraries, a BSD-license implementation 50 | of the public domain Ogg Vorbis audio encoding format. 51 | 52 | ./include Library API headers 53 | 54 | ./debian Rules/spec files for building Debian .deb packages 55 | 56 | ./doc Vorbis documentation 57 | 58 | ./examples Example code illustrating programmatic use of libvorbis, 59 | libvorbisfile and libvorbisenc 60 | 61 | ./mac Codewarrior project files and build tweaks for MacOS. 62 | 63 | ./macosx Project files for MacOS X. 64 | 65 | ./win32 Win32 projects files and build automation 66 | 67 | ./vq Internal utilities for training/building new LSP/residue 68 | and auxiliary codebooks. 69 | 70 | CONTACT: 71 | 72 | The Ogg homepage is located at 'http://www.xiph.org/ogg/'. 73 | Vorbis's homepage is located at 'http://www.xiph.org/vorbis/'. 74 | Up to date technical documents, contact information, source code and 75 | pre-built utilities may be found there. 76 | 77 | The user website for Ogg Vorbis software and audio is http://vorbis.com/ 78 | 79 | BUILDING FROM TRUNK: 80 | 81 | Development source is under subversion revision control at 82 | https://svn.xiph.org/trunk/vorbis/. You will also need the 83 | newest versions of autoconf, automake, libtool and pkg-config in 84 | order to compile Vorbis from development source. A configure script 85 | is provided for you in the source tarball distributions. 86 | 87 | [update or checkout latest source] 88 | ./autogen.sh 89 | make 90 | 91 | and as root if desired: 92 | 93 | make install 94 | 95 | This will install the Vorbis libraries (static and shared) into 96 | /usr/local/lib, includes into /usr/local/include and API manpages 97 | (once we write some) into /usr/local/man. 98 | 99 | Documentation building requires xsltproc and pdfxmltex. 100 | 101 | BUILDING FROM TARBALL DISTRIBUTIONS: 102 | 103 | ./configure 104 | make 105 | 106 | and optionally (as root): 107 | make install 108 | 109 | BUILDING RPMS: 110 | 111 | after normal configuring: 112 | 113 | make dist 114 | rpm -ta libvorbis-.tar.gz 115 | 116 | BUILDING ON MACOS 9: 117 | 118 | Vorbis on MacOS 9 is built using Metroworks CodeWarrior. To build it, 119 | first verify that the Ogg libraries are already built following the 120 | instructions in the Ogg module README. Open vorbis/mac/libvorbis.mcp, 121 | switch to the "Targets" pane, select everything, and make the project. 122 | Do the same thing to build libvorbisenc.mcp, and libvorbisfile.mcp (in 123 | that order). In vorbis/mac/Output you will now have both debug and final 124 | versions of Vorbis shared libraries to link your projects against. 125 | 126 | To build a project using Ogg Vorbis, add access paths to your 127 | CodeWarrior project for the ogg/include, ogg/mac/Output, 128 | vorbis/include, and vorbis/mac/Output folders. Be sure that 129 | "interpret DOS and Unix paths" is turned on in your project; it can 130 | be found in the "access paths" pane in your project settings. Now 131 | simply add the shared libraries you need to your project (OggLib and 132 | VorbisLib at least) and #include "ogg/ogg.h" and "vorbis/codec.h" 133 | wherever you need to access Ogg and Vorbis functionality. 134 | 135 | -------------------------------------------------------------------------------- /src/test_audio_detect.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2007-2011 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | 24 | #if HAVE_UNISTD_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | 31 | #include "common.h" 32 | #include "sfendian.h" 33 | 34 | #include "test_main.h" 35 | 36 | static unsigned char float_le_mono [] = 37 | { 0x36, 0x86, 0x21, 0x44, 0xB5, 0xB4, 0x49, 0x44, 0xA2, 0xC0, 0x71, 0x44, 0x7B, 0xD1, 0x8C, 0x44, 38 | 0x54, 0xAA, 0xA0, 0x44, 0x60, 0x67, 0xB4, 0x44, 0x22, 0x05, 0xC8, 0x44, 0x29, 0x80, 0xDB, 0x44, 39 | 0x04, 0xD5, 0xEE, 0x44, 0x27, 0x00, 0x01, 0x45, 0x50, 0x7F, 0x0A, 0x45, 0x53, 0xE6, 0x13, 0x45, 40 | 0x85, 0x33, 0x1D, 0x45, 0x43, 0x65, 0x26, 0x45, 0xEC, 0x79, 0x2F, 0x45, 0xE3, 0x6F, 0x38, 0x45, 41 | 0x98, 0x45, 0x41, 0x45, 0x77, 0xF9, 0x49, 0x45, 0xF6, 0x89, 0x52, 0x45, 0x8F, 0xF5, 0x5A, 0x45, 42 | 0xC9, 0x3A, 0x63, 0x45, 0x28, 0x58, 0x6B, 0x45, 0x3C, 0x4C, 0x73, 0x45, 0x9F, 0x15, 0x7B, 0x45, 43 | 0x75, 0x59, 0x81, 0x45, 0x64, 0x11, 0x85, 0x45, 0xF1, 0xB1, 0x88, 0x45, 0x78, 0x3A, 0x8C, 0x45, 44 | 0x58, 0xAA, 0x8F, 0x45, 0xF2, 0x00, 0x93, 0x45, 0xB2, 0x3D, 0x96, 0x45, 0x01, 0x60, 0x99, 0x45, 45 | 0x50, 0x67, 0x9C, 0x45, 0x15, 0x53, 0x9F, 0x45, 0xCC, 0x22, 0xA2, 0x45, 0xF0, 0xD5, 0xA4, 0x45, 46 | 0x07, 0x6C, 0xA7, 0x45, 0x9C, 0xE4, 0xA9, 0x45, 0x3D, 0x3F, 0xAC, 0x45, 0x7A, 0x7B, 0xAE, 0x45, 47 | 0xF2, 0x98, 0xB0, 0x45, 0x3C, 0x97, 0xB2, 0x45, 0x02, 0x76, 0xB4, 0x45, 0xEC, 0x34, 0xB6, 0x45, 48 | 0xA8, 0xD3, 0xB7, 0x45, 0xEB, 0x51, 0xB9, 0x45, 0x6F, 0xAF, 0xBA, 0x45, 0xF5, 0xEB, 0xBB, 0x45, 49 | 0x41, 0x07, 0xBD, 0x45, 0x21, 0x01, 0xBE, 0x45, 0x64, 0xD9, 0xBE, 0x45, 0xE3, 0x8F, 0xBF, 0x45, 50 | 0x7E, 0x24, 0xC0, 0x45, 0x15, 0x97, 0xC0, 0x45, 0x92, 0xE7, 0xC0, 0x45, 0xE8, 0x15, 0xC1, 0x45, 51 | 0x7E, 0x24, 0xC0, 0x45, 0x15, 0x97, 0xC0, 0x45, 0x92, 0xE7, 0xC0, 0x45, 0xE8, 0x15, 0xC1, 0x45, 52 | 0x7E, 0x24, 0xC0, 0x45, 0x15, 0x97, 0xC0, 0x45, 0x92, 0xE7, 0xC0, 0x45, 0xE8, 0x15, 0xC1, 0x45, 53 | } ; 54 | 55 | static unsigned char int24_32_le_stereo [] = 56 | { 57 | 0x00, 0xE7, 0xFB, 0xFF, 0x00, 0x7C, 0xFD, 0xFF, 0x00, 0xA2, 0xFC, 0xFF, 0x00, 0x2B, 0xFC, 0xFF, 58 | 0x00, 0xF3, 0xFD, 0xFF, 0x00, 0x19, 0xFB, 0xFF, 0x00, 0xA5, 0xFE, 0xFF, 0x00, 0x8D, 0xFA, 0xFF, 59 | 0x00, 0x91, 0xFF, 0xFF, 0x00, 0xB5, 0xFA, 0xFF, 0x00, 0x91, 0x00, 0x00, 0x00, 0x5E, 0xFB, 0xFF, 60 | 0x00, 0xD9, 0x01, 0x00, 0x00, 0x82, 0xFB, 0xFF, 0x00, 0xDF, 0x03, 0x00, 0x00, 0x44, 0xFC, 0xFF, 61 | 0x00, 0x1C, 0x05, 0x00, 0x00, 0x77, 0xFC, 0xFF, 0x00, 0x8D, 0x06, 0x00, 0x00, 0x4F, 0xFC, 0xFF, 62 | 0x00, 0x84, 0x07, 0x00, 0x00, 0x74, 0xFC, 0xFF, 0x00, 0x98, 0x08, 0x00, 0x00, 0x33, 0xFD, 0xFF, 63 | 0x00, 0xB9, 0x09, 0x00, 0x00, 0x48, 0xFF, 0xFF, 0x00, 0xD1, 0x0A, 0x00, 0x00, 0x10, 0x02, 0x00, 64 | 0x00, 0x28, 0x0C, 0x00, 0x00, 0xA2, 0x05, 0x00, 0x00, 0xA7, 0x0C, 0x00, 0x00, 0x45, 0x08, 0x00, 65 | 0x00, 0x44, 0x0D, 0x00, 0x00, 0x1A, 0x0A, 0x00, 0x00, 0x65, 0x0D, 0x00, 0x00, 0x51, 0x0B, 0x00, 66 | 0x00, 0x8B, 0x0D, 0x00, 0x00, 0x18, 0x0B, 0x00, 0x00, 0x37, 0x0E, 0x00, 0x00, 0x24, 0x0B, 0x00, 67 | 0x00, 0x00, 0x0F, 0x00, 0x00, 0xDD, 0x0A, 0x00, 0x00, 0x83, 0x10, 0x00, 0x00, 0x31, 0x0A, 0x00, 68 | 0x00, 0x07, 0x12, 0x00, 0x00, 0xC0, 0x08, 0x00, 0x00, 0xF7, 0x12, 0x00, 0x00, 0x47, 0x06, 0x00, 69 | 0x00, 0xDD, 0x12, 0x00, 0x00, 0x6A, 0x03, 0x00, 0x00, 0xD5, 0x11, 0x00, 0x00, 0x99, 0x00, 0x00, 70 | 0x00, 0x01, 0x10, 0x00, 0x00, 0xC5, 0xFE, 0xFF, 0x00, 0xF4, 0x0D, 0x00, 0x00, 0x97, 0xFD, 0xFF, 71 | 0x00, 0x62, 0x0B, 0x00, 0x00, 0x75, 0xFC, 0xFF, 0x00, 0xE9, 0x08, 0x00, 0x00, 0xC0, 0xFB, 0xFF, 72 | 0x00, 0x80, 0x06, 0x00, 0x00, 0x3C, 0xFB, 0xFF, 0x00, 0xDA, 0x03, 0x00, 0x00, 0xE4, 0xFA, 0xFF, 73 | 0x00, 0xEB, 0x01, 0x00, 0x00, 0x21, 0xFB, 0xFF, 0x00, 0x20, 0x00, 0x00, 0x00, 0xE7, 0xFB, 0xFF, 74 | } ; 75 | 76 | 77 | void 78 | test_audio_detect (void) 79 | { 80 | SF_PRIVATE psf ; 81 | AUDIO_DETECT ad ; 82 | int errors = 0 ; 83 | 84 | print_test_name ("Testing audio detect") ; 85 | 86 | memset (&psf, 0, sizeof (psf)) ; 87 | 88 | ad.endianness = SF_ENDIAN_LITTLE ; 89 | ad.channels = 1 ; 90 | if (audio_detect (&psf, &ad, float_le_mono, sizeof (float_le_mono)) != SF_FORMAT_FLOAT) 91 | { puts (" float_le_mono") ; 92 | errors ++ ; 93 | } ; 94 | 95 | ad.endianness = SF_ENDIAN_LITTLE ; 96 | ad.channels = 2 ; 97 | if (audio_detect (&psf, &ad, int24_32_le_stereo, sizeof (int24_32_le_stereo)) != SF_FORMAT_PCM_32) 98 | { if (errors == 0) puts ("\nFailed tests :\n") ; 99 | puts (" int24_32_le_stereo") ; 100 | errors ++ ; 101 | } ; 102 | 103 | if (errors != 0) 104 | { printf ("\n Errors : %d\n\n", errors) ; 105 | exit (1) ; 106 | } ; 107 | 108 | puts ("ok") ; 109 | 110 | return ; 111 | } /* test_audio_detect */ 112 | -------------------------------------------------------------------------------- /src/G72x/g721.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This source code is a product of Sun Microsystems, Inc. and is provided 3 | * for unrestricted use. Users may copy or modify this source code without 4 | * charge. 5 | * 6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING 7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 9 | * 10 | * Sun source code is provided with no support and without any obligation on 11 | * the part of Sun Microsystems, Inc. to assist in its use, correction, 12 | * modification or enhancement. 13 | * 14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE 16 | * OR ANY PART THEREOF. 17 | * 18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 19 | * or profits or other special, indirect and consequential damages, even if 20 | * Sun has been advised of the possibility of such damages. 21 | * 22 | * Sun Microsystems, Inc. 23 | * 2550 Garcia Avenue 24 | * Mountain View, California 94043 25 | */ 26 | 27 | /* 28 | * g721.c 29 | * 30 | * Description: 31 | * 32 | * g721_encoder (), g721_decoder () 33 | * 34 | * These routines comprise an implementation of the CCITT G.721 ADPCM 35 | * coding algorithm. Essentially, this implementation is identical to 36 | * the bit level description except for a few deviations which 37 | * take advantage of work station attributes, such as hardware 2's 38 | * complement arithmetic and large memory. Specifically, certain time 39 | * consuming operations such as multiplications are replaced 40 | * with lookup tables and software 2's complement operations are 41 | * replaced with hardware 2's complement. 42 | * 43 | * The deviation from the bit level specification (lookup tables) 44 | * preserves the bit level performance specifications. 45 | * 46 | * As outlined in the G.721 Recommendation, the algorithm is broken 47 | * down into modules. Each section of code below is preceded by 48 | * the name of the module which it is implementing. 49 | * 50 | */ 51 | 52 | #include "g72x.h" 53 | #include "g72x_priv.h" 54 | 55 | static short qtab_721 [7] = { -124, 80, 178, 246, 300, 349, 400 } ; 56 | /* 57 | * Maps G.721 code word to reconstructed scale factor normalized log 58 | * magnitude values. 59 | */ 60 | static short _dqlntab [16] = { -2048, 4, 135, 213, 273, 323, 373, 425, 61 | 425, 373, 323, 273, 213, 135, 4, -2048 } ; 62 | 63 | /* Maps G.721 code word to log of scale factor multiplier. */ 64 | static short _witab [16] = { -12, 18, 41, 64, 112, 198, 355, 1122, 65 | 1122, 355, 198, 112, 64, 41, 18, -12 } ; 66 | /* 67 | * Maps G.721 code words to a set of values whose long and short 68 | * term averages are computed and then compared to give an indication 69 | * how stationary (steady state) the signal is. 70 | */ 71 | static short _fitab [16] = { 0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00, 72 | 0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0 } ; 73 | 74 | /* 75 | * g721_encoder () 76 | * 77 | * Encodes the input vale of linear PCM, A-law or u-law data sl and returns 78 | * the resulting code. -1 is returned for unknown input coding value. 79 | */ 80 | int 81 | g721_encoder ( 82 | int sl, 83 | G72x_STATE *state_ptr) 84 | { 85 | short sezi, se, sez ; /* ACCUM */ 86 | short d ; /* SUBTA */ 87 | short sr ; /* ADDB */ 88 | short y ; /* MIX */ 89 | short dqsez ; /* ADDC */ 90 | short dq, i ; 91 | 92 | /* linearize input sample to 14-bit PCM */ 93 | sl >>= 2 ; /* 14-bit dynamic range */ 94 | 95 | sezi = predictor_zero (state_ptr) ; 96 | sez = sezi >> 1 ; 97 | se = (sezi + predictor_pole (state_ptr)) >> 1 ; /* estimated signal */ 98 | 99 | d = sl - se ; /* estimation difference */ 100 | 101 | /* quantize the prediction difference */ 102 | y = step_size (state_ptr) ; /* quantizer step size */ 103 | i = quantize (d, y, qtab_721, 7) ; /* i = ADPCM code */ 104 | 105 | dq = reconstruct (i & 8, _dqlntab [i], y) ; /* quantized est diff */ 106 | 107 | sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq ; /* reconst. signal */ 108 | 109 | dqsez = sr + sez - se ; /* pole prediction diff. */ 110 | 111 | update (4, y, arith_shift_left (_witab [i], 5), _fitab [i], dq, sr, dqsez, state_ptr) ; 112 | 113 | return i ; 114 | } 115 | 116 | /* 117 | * g721_decoder () 118 | * 119 | * Description: 120 | * 121 | * Decodes a 4-bit code of G.721 encoded data of i and 122 | * returns the resulting linear PCM, A-law or u-law value. 123 | * return -1 for unknown out_coding value. 124 | */ 125 | int 126 | g721_decoder ( 127 | int i, 128 | G72x_STATE *state_ptr) 129 | { 130 | short sezi, sei, sez, se ; /* ACCUM */ 131 | short y ; /* MIX */ 132 | short sr ; /* ADDB */ 133 | short dq ; 134 | short dqsez ; 135 | 136 | i &= 0x0f ; /* mask to get proper bits */ 137 | sezi = predictor_zero (state_ptr) ; 138 | sez = sezi >> 1 ; 139 | sei = sezi + predictor_pole (state_ptr) ; 140 | se = sei >> 1 ; /* se = estimated signal */ 141 | 142 | y = step_size (state_ptr) ; /* dynamic quantizer step size */ 143 | 144 | dq = reconstruct (i & 0x08, _dqlntab [i], y) ; /* quantized diff. */ 145 | 146 | sr = (dq < 0) ? (se - (dq & 0x3FFF)) : se + dq ; /* reconst. signal */ 147 | 148 | dqsez = sr - se + sez ; /* pole prediction diff. */ 149 | 150 | update (4, y, arith_shift_left (_witab [i], 5), _fitab [i], dq, sr, dqsez, state_ptr) ; 151 | 152 | /* sr was 14-bit dynamic range */ 153 | return arith_shift_left (sr, 2) ; 154 | } 155 | 156 | -------------------------------------------------------------------------------- /src/G72x/g723_16.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This source code is a product of Sun Microsystems, Inc. and is provided 3 | * for unrestricted use. Users may copy or modify this source code without 4 | * charge. 5 | * 6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING 7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 9 | * 10 | * Sun source code is provided with no support and without any obligation on 11 | * the part of Sun Microsystems, Inc. to assist in its use, correction, 12 | * modification or enhancement. 13 | * 14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE 16 | * OR ANY PART THEREOF. 17 | * 18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 19 | * or profits or other special, indirect and consequential damages, even if 20 | * Sun has been advised of the possibility of such damages. 21 | * 22 | * Sun Microsystems, Inc. 23 | * 2550 Garcia Avenue 24 | * Mountain View, California 94043 25 | */ 26 | /* 16kbps version created, used 24kbps code and changing as little as possible. 27 | * G.726 specs are available from ITU's gopher or WWW site (http://www.itu.ch) 28 | * If any errors are found, please contact me at mrand@tamu.edu 29 | * -Marc Randolph 30 | */ 31 | 32 | /* 33 | * g723_16.c 34 | * 35 | * Description: 36 | * 37 | * g723_16_encoder (), g723_16_decoder () 38 | * 39 | * These routines comprise an implementation of the CCITT G.726 16 Kbps 40 | * ADPCM coding algorithm. Essentially, this implementation is identical to 41 | * the bit level description except for a few deviations which take advantage 42 | * of workstation attributes, such as hardware 2's complement arithmetic. 43 | * 44 | */ 45 | 46 | #include "g72x.h" 47 | #include "g72x_priv.h" 48 | 49 | /* 50 | * Maps G.723_16 code word to reconstructed scale factor normalized log 51 | * magnitude values. Comes from Table 11/G.726 52 | */ 53 | static short _dqlntab [4] = { 116, 365, 365, 116 } ; 54 | 55 | /* Maps G.723_16 code word to log of scale factor multiplier. 56 | * 57 | * _witab [4] is actually {-22 , 439, 439, -22}, but FILTD wants it 58 | * as WI << 5 (multiplied by 32), so we'll do that here 59 | */ 60 | static short _witab [4] = { -704, 14048, 14048, -704 } ; 61 | 62 | /* 63 | * Maps G.723_16 code words to a set of values whose long and short 64 | * term averages are computed and then compared to give an indication 65 | * how stationary (steady state) the signal is. 66 | */ 67 | 68 | /* Comes from FUNCTF */ 69 | static short _fitab [4] = { 0, 0xE00, 0xE00, 0 } ; 70 | 71 | /* Comes from quantizer decision level tables (Table 7/G.726) 72 | */ 73 | static short qtab_723_16 [1] = { 261 } ; 74 | 75 | 76 | /* 77 | * g723_16_encoder () 78 | * 79 | * Encodes a linear PCM, A-law or u-law input sample and returns its 2-bit code. 80 | * Returns -1 if invalid input coding value. 81 | */ 82 | int 83 | g723_16_encoder ( 84 | int sl, 85 | G72x_STATE *state_ptr) 86 | { 87 | short sei, sezi, se, sez ; /* ACCUM */ 88 | short d ; /* SUBTA */ 89 | short y ; /* MIX */ 90 | short sr ; /* ADDB */ 91 | short dqsez ; /* ADDC */ 92 | short dq, i ; 93 | 94 | /* linearize input sample to 14-bit PCM */ 95 | sl >>= 2 ; /* sl of 14-bit dynamic range */ 96 | 97 | sezi = predictor_zero (state_ptr) ; 98 | sez = sezi >> 1 ; 99 | sei = sezi + predictor_pole (state_ptr) ; 100 | se = sei >> 1 ; /* se = estimated signal */ 101 | 102 | d = sl - se ; /* d = estimation diff. */ 103 | 104 | /* quantize prediction difference d */ 105 | y = step_size (state_ptr) ; /* quantizer step size */ 106 | i = quantize (d, y, qtab_723_16, 1) ; /* i = ADPCM code */ 107 | 108 | /* Since quantize () only produces a three level output 109 | * (1, 2, or 3), we must create the fourth one on our own 110 | */ 111 | if (i == 3) /* i code for the zero region */ 112 | if ((d & 0x8000) == 0) /* If d > 0, i=3 isn't right... */ 113 | i = 0 ; 114 | 115 | dq = reconstruct (i & 2, _dqlntab [i], y) ; /* quantized diff. */ 116 | 117 | sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq ; /* reconstructed signal */ 118 | 119 | dqsez = sr + sez - se ; /* pole prediction diff. */ 120 | 121 | update (2, y, _witab [i], _fitab [i], dq, sr, dqsez, state_ptr) ; 122 | 123 | return i ; 124 | } 125 | 126 | /* 127 | * g723_16_decoder () 128 | * 129 | * Decodes a 2-bit CCITT G.723_16 ADPCM code and returns 130 | * the resulting 16-bit linear PCM, A-law or u-law sample value. 131 | * -1 is returned if the output coding is unknown. 132 | */ 133 | int 134 | g723_16_decoder ( 135 | int i, 136 | G72x_STATE *state_ptr) 137 | { 138 | short sezi, sei, sez, se ; /* ACCUM */ 139 | short y ; /* MIX */ 140 | short sr ; /* ADDB */ 141 | short dq ; 142 | short dqsez ; 143 | 144 | i &= 0x03 ; /* mask to get proper bits */ 145 | sezi = predictor_zero (state_ptr) ; 146 | sez = sezi >> 1 ; 147 | sei = sezi + predictor_pole (state_ptr) ; 148 | se = sei >> 1 ; /* se = estimated signal */ 149 | 150 | y = step_size (state_ptr) ; /* adaptive quantizer step size */ 151 | dq = reconstruct (i & 0x02, _dqlntab [i], y) ; /* unquantize pred diff */ 152 | 153 | sr = (dq < 0) ? (se - (dq & 0x3FFF)) : (se + dq) ; /* reconst. signal */ 154 | 155 | dqsez = sr - se + sez ; /* pole prediction diff. */ 156 | 157 | update (2, y, _witab [i], _fitab [i], dq, sr, dqsez, state_ptr) ; 158 | 159 | /* sr was of 14-bit dynamic range */ 160 | return (sr << 2) ; 161 | } 162 | 163 | -------------------------------------------------------------------------------- /src/G72x/g723_40.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This source code is a product of Sun Microsystems, Inc. and is provided 3 | * for unrestricted use. Users may copy or modify this source code without 4 | * charge. 5 | * 6 | * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING 7 | * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 8 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 9 | * 10 | * Sun source code is provided with no support and without any obligation on 11 | * the part of Sun Microsystems, Inc. to assist in its use, correction, 12 | * modification or enhancement. 13 | * 14 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 15 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE 16 | * OR ANY PART THEREOF. 17 | * 18 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 19 | * or profits or other special, indirect and consequential damages, even if 20 | * Sun has been advised of the possibility of such damages. 21 | * 22 | * Sun Microsystems, Inc. 23 | * 2550 Garcia Avenue 24 | * Mountain View, California 94043 25 | */ 26 | 27 | /* 28 | * g723_40.c 29 | * 30 | * Description: 31 | * 32 | * g723_40_encoder (), g723_40_decoder () 33 | * 34 | * These routines comprise an implementation of the CCITT G.723 40Kbps 35 | * ADPCM coding algorithm. Essentially, this implementation is identical to 36 | * the bit level description except for a few deviations which 37 | * take advantage of workstation attributes, such as hardware 2's 38 | * complement arithmetic. 39 | * 40 | * The deviation from the bit level specification (lookup tables), 41 | * preserves the bit level performance specifications. 42 | * 43 | * As outlined in the G.723 Recommendation, the algorithm is broken 44 | * down into modules. Each section of code below is preceded by 45 | * the name of the module which it is implementing. 46 | * 47 | */ 48 | 49 | #include "g72x.h" 50 | #include "g72x_priv.h" 51 | 52 | /* 53 | * Maps G.723_40 code word to ructeconstructed scale factor normalized log 54 | * magnitude values. 55 | */ 56 | static short _dqlntab [32] = { -2048, -66, 28, 104, 169, 224, 274, 318, 57 | 358, 395, 429, 459, 488, 514, 539, 566, 58 | 566, 539, 514, 488, 459, 429, 395, 358, 59 | 318, 274, 224, 169, 104, 28, -66, -2048 } ; 60 | 61 | /* Maps G.723_40 code word to log of scale factor multiplier. */ 62 | static short _witab [32] = { 448, 448, 768, 1248, 1280, 1312, 1856, 3200, 63 | 4512, 5728, 7008, 8960, 11456, 14080, 16928, 22272, 64 | 22272, 16928, 14080, 11456, 8960, 7008, 5728, 4512, 65 | 3200, 1856, 1312, 1280, 1248, 768, 448, 448 } ; 66 | 67 | /* 68 | * Maps G.723_40 code words to a set of values whose long and short 69 | * term averages are computed and then compared to give an indication 70 | * how stationary (steady state) the signal is. 71 | */ 72 | static short _fitab [32] = { 0, 0, 0, 0, 0, 0x200, 0x200, 0x200, 73 | 0x200, 0x200, 0x400, 0x600, 0x800, 0xA00, 0xC00, 0xC00, 74 | 0xC00, 0xC00, 0xA00, 0x800, 0x600, 0x400, 0x200, 0x200, 75 | 0x200, 0x200, 0x200, 0, 0, 0, 0, 0 } ; 76 | 77 | static short qtab_723_40 [15] = { -122, -16, 68, 139, 198, 250, 298, 339, 78 | 378, 413, 445, 475, 502, 528, 553 } ; 79 | 80 | /* 81 | * g723_40_encoder () 82 | * 83 | * Encodes a 16-bit linear PCM, A-law or u-law input sample and retuens 84 | * the resulting 5-bit CCITT G.723 40Kbps code. 85 | * Returns -1 if the input coding value is invalid. 86 | */ 87 | int g723_40_encoder (int sl, G72x_STATE *state_ptr) 88 | { 89 | short sei, sezi, se, sez ; /* ACCUM */ 90 | short d ; /* SUBTA */ 91 | short y ; /* MIX */ 92 | short sr ; /* ADDB */ 93 | short dqsez ; /* ADDC */ 94 | short dq, i ; 95 | 96 | /* linearize input sample to 14-bit PCM */ 97 | sl >>= 2 ; /* sl of 14-bit dynamic range */ 98 | 99 | sezi = predictor_zero (state_ptr) ; 100 | sez = sezi >> 1 ; 101 | sei = sezi + predictor_pole (state_ptr) ; 102 | se = sei >> 1 ; /* se = estimated signal */ 103 | 104 | d = sl - se ; /* d = estimation difference */ 105 | 106 | /* quantize prediction difference */ 107 | y = step_size (state_ptr) ; /* adaptive quantizer step size */ 108 | i = quantize (d, y, qtab_723_40, 15) ; /* i = ADPCM code */ 109 | 110 | dq = reconstruct (i & 0x10, _dqlntab [i], y) ; /* quantized diff */ 111 | 112 | sr = (dq < 0) ? se - (dq & 0x7FFF) : se + dq ; /* reconstructed signal */ 113 | 114 | dqsez = sr + sez - se ; /* dqsez = pole prediction diff. */ 115 | 116 | update (5, y, _witab [i], _fitab [i], dq, sr, dqsez, state_ptr) ; 117 | 118 | return i ; 119 | } 120 | 121 | /* 122 | * g723_40_decoder () 123 | * 124 | * Decodes a 5-bit CCITT G.723 40Kbps code and returns 125 | * the resulting 16-bit linear PCM, A-law or u-law sample value. 126 | * -1 is returned if the output coding is unknown. 127 | */ 128 | int g723_40_decoder (int i, G72x_STATE *state_ptr) 129 | { 130 | short sezi, sei, sez, se ; /* ACCUM */ 131 | short y ; /* MIX */ 132 | short sr ; /* ADDB */ 133 | short dq ; 134 | short dqsez ; 135 | 136 | i &= 0x1f ; /* mask to get proper bits */ 137 | sezi = predictor_zero (state_ptr) ; 138 | sez = sezi >> 1 ; 139 | sei = sezi + predictor_pole (state_ptr) ; 140 | se = sei >> 1 ; /* se = estimated signal */ 141 | 142 | y = step_size (state_ptr) ; /* adaptive quantizer step size */ 143 | dq = reconstruct (i & 0x10, _dqlntab [i], y) ; /* estimation diff. */ 144 | 145 | sr = (dq < 0) ? (se - (dq & 0x7FFF)) : (se + dq) ; /* reconst. signal */ 146 | 147 | dqsez = sr - se + sez ; /* pole prediction diff. */ 148 | 149 | update (5, y, _witab [i], _fitab [i], dq, sr, dqsez, state_ptr) ; 150 | 151 | return arith_shift_left (sr, 2) ; /* sr was of 14-bit dynamic range */ 152 | } 153 | 154 | -------------------------------------------------------------------------------- /src/pvf.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2002-2016 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "sndfile.h" 27 | #include "sfendian.h" 28 | #include "common.h" 29 | 30 | /*------------------------------------------------------------------------------ 31 | ** Macros to handle big/little endian issues. 32 | */ 33 | 34 | #define PVF1_MARKER (MAKE_MARKER ('P', 'V', 'F', '1')) 35 | 36 | /*------------------------------------------------------------------------------ 37 | ** Private static functions. 38 | */ 39 | 40 | static int pvf_close (SF_PRIVATE *psf) ; 41 | 42 | static int pvf_write_header (SF_PRIVATE *psf, int calc_length) ; 43 | static int pvf_read_header (SF_PRIVATE *psf) ; 44 | 45 | /*------------------------------------------------------------------------------ 46 | ** Public function. 47 | */ 48 | 49 | int 50 | pvf_open (SF_PRIVATE *psf) 51 | { int subformat ; 52 | int error = 0 ; 53 | 54 | if (psf->file.mode == SFM_READ || (psf->file.mode == SFM_RDWR && psf->filelength > 0)) 55 | { if ((error = pvf_read_header (psf))) 56 | return error ; 57 | } ; 58 | 59 | subformat = SF_CODEC (psf->sf.format) ; 60 | 61 | if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR) 62 | { if ((SF_CONTAINER (psf->sf.format)) != SF_FORMAT_PVF) 63 | return SFE_BAD_OPEN_FORMAT ; 64 | 65 | psf->endian = SF_ENDIAN_BIG ; 66 | 67 | if (pvf_write_header (psf, SF_FALSE)) 68 | return psf->error ; 69 | 70 | psf->write_header = pvf_write_header ; 71 | } ; 72 | 73 | psf->container_close = pvf_close ; 74 | 75 | psf->blockwidth = psf->bytewidth * psf->sf.channels ; 76 | 77 | switch (subformat) 78 | { case SF_FORMAT_PCM_S8 : /* 8-bit linear PCM. */ 79 | case SF_FORMAT_PCM_16 : /* 16-bit linear PCM. */ 80 | case SF_FORMAT_PCM_32 : /* 32-bit linear PCM. */ 81 | error = pcm_init (psf) ; 82 | break ; 83 | 84 | default : break ; 85 | } ; 86 | 87 | return error ; 88 | } /* pvf_open */ 89 | 90 | /*------------------------------------------------------------------------------ 91 | */ 92 | 93 | static int 94 | pvf_close (SF_PRIVATE * UNUSED (psf)) 95 | { 96 | return 0 ; 97 | } /* pvf_close */ 98 | 99 | static int 100 | pvf_write_header (SF_PRIVATE *psf, int UNUSED (calc_length)) 101 | { sf_count_t current ; 102 | 103 | if (psf->pipeoffset > 0) 104 | return 0 ; 105 | 106 | current = psf_ftell (psf) ; 107 | 108 | /* Reset the current header length to zero. */ 109 | psf->header.ptr [0] = 0 ; 110 | psf->header.indx = 0 ; 111 | 112 | if (psf->is_pipe == SF_FALSE) 113 | psf_fseek (psf, 0, SEEK_SET) ; 114 | 115 | snprintf ((char*) psf->header.ptr, psf->header.len, "PVF1\n%d %d %d\n", 116 | psf->sf.channels, psf->sf.samplerate, psf->bytewidth * 8) ; 117 | 118 | psf->header.indx = strlen ((char*) psf->header.ptr) ; 119 | 120 | /* Header construction complete so write it out. */ 121 | psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ; 122 | 123 | if (psf->error) 124 | return psf->error ; 125 | 126 | psf->dataoffset = psf->header.indx ; 127 | 128 | if (current > 0) 129 | psf_fseek (psf, current, SEEK_SET) ; 130 | 131 | return psf->error ; 132 | } /* pvf_write_header */ 133 | 134 | static int 135 | pvf_read_header (SF_PRIVATE *psf) 136 | { char buffer [32] ; 137 | int marker, channels, samplerate, bitwidth ; 138 | 139 | psf_binheader_readf (psf, "pmj", 0, &marker, 1) ; 140 | psf_log_printf (psf, "%M\n", marker) ; 141 | 142 | if (marker != PVF1_MARKER) 143 | return SFE_PVF_NO_PVF1 ; 144 | 145 | /* Grab characters up until a newline which is replaced by an EOS. */ 146 | psf_binheader_readf (psf, "G", buffer, sizeof (buffer)) ; 147 | 148 | if (sscanf (buffer, "%d %d %d", &channels, &samplerate, &bitwidth) != 3) 149 | return SFE_PVF_BAD_HEADER ; 150 | 151 | psf_log_printf (psf, " Channels : %d\n Sample rate : %d\n Bit width : %d\n", 152 | channels, samplerate, bitwidth) ; 153 | 154 | psf->sf.channels = channels ; 155 | psf->sf.samplerate = samplerate ; 156 | 157 | switch (bitwidth) 158 | { case 8 : 159 | psf->sf.format = SF_FORMAT_PVF | SF_FORMAT_PCM_S8 ; 160 | psf->bytewidth = 1 ; 161 | break ; 162 | 163 | case 16 : 164 | psf->sf.format = SF_FORMAT_PVF | SF_FORMAT_PCM_16 ; 165 | psf->bytewidth = 2 ; 166 | break ; 167 | case 32 : 168 | psf->sf.format = SF_FORMAT_PVF | SF_FORMAT_PCM_32 ; 169 | psf->bytewidth = 4 ; 170 | break ; 171 | 172 | default : 173 | return SFE_PVF_BAD_BITWIDTH ; 174 | } ; 175 | 176 | psf->dataoffset = psf_ftell (psf) ; 177 | psf_log_printf (psf, " Data Offset : %D\n", psf->dataoffset) ; 178 | 179 | psf->endian = SF_ENDIAN_BIG ; 180 | 181 | psf->datalength = psf->filelength - psf->dataoffset ; 182 | psf->blockwidth = psf->sf.channels * psf->bytewidth ; 183 | 184 | if (! psf->sf.frames && psf->blockwidth) 185 | psf->sf.frames = (psf->filelength - psf->dataoffset) / psf->blockwidth ; 186 | 187 | return 0 ; 188 | } /* pvf_read_header */ 189 | -------------------------------------------------------------------------------- /src/test_ima_oki_adpcm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2007-2011 Erik de Castro Lopo 3 | ** Copyright (c) 2007 4 | ** 5 | ** This library is free software; you can redistribute it and/or modify it 6 | ** under the terms of the GNU Lesser General Public License as published by 7 | ** the Free Software Foundation; either version 2 of the License, or (at 8 | ** your option) any later version. 9 | ** 10 | ** This library is distributed in the hope that it will be useful, but 11 | ** WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 13 | ** General Public License for more details. 14 | ** 15 | ** You should have received a copy of the GNU Lesser General Public License 16 | ** along with this library. If not, write to the Free Software Foundation, 17 | ** Fifth Floor, 51 Franklin Street, Boston, MA 02111-1301, USA. 18 | */ 19 | 20 | #include "sfconfig.h" 21 | 22 | #include 23 | 24 | #include "test_main.h" 25 | 26 | #include "ima_oki_adpcm.c" 27 | 28 | static const unsigned char test_codes [] = 29 | { 0x08, 0x08, 0x04, 0x7f, 0x72, 0xf7, 0x9f, 0x7c, 0xd7, 0xbc, 0x7a, 0xa7, 0xb8, 30 | 0x4b, 0x0b, 0x38, 0xf6, 0x9d, 0x7a, 0xd7, 0xbc, 0x7a, 0xd7, 0xa8, 0x6c, 0x81, 31 | 0x98, 0xe4, 0x0e, 0x7a, 0xd7, 0x9e, 0x7b, 0xc7, 0xab, 0x7a, 0x85, 0xc0, 0xb3, 32 | 0x8f, 0x58, 0xd7, 0xad, 0x7a, 0xd7, 0xad, 0x7a, 0x87, 0xd0, 0x2b, 0x0e, 0x48, 33 | 0xd7, 0xad, 0x78, 0xf7, 0xbc, 0x7a, 0xb7, 0xa8, 0x4b, 0x88, 0x18, 0xd5, 0x8d, 34 | 0x6a, 0xa4, 0x98, 0x08, 0x00, 0x80, 0x88, 35 | } ; 36 | 37 | static const short test_pcm [] = 38 | { 32, 0, 32, 0, 32, 320, 880, -336, 2304, 4192, -992, 10128, 5360, -16352, 39 | 30208, 2272, -31872, 14688, -7040, -32432, 14128, -1392, -15488, 22960, 40 | 1232, -1584, 21488, -240, 2576, -15360, 960, -1152, -30032, 10320, 1008, 41 | -30032, 16528, 1008, -30032, 16528, -5200, -30592, 15968, 448, -30592, 42 | 15968, 448, -2368, 30960, 3024, -80, 8384, 704, -1616, -29168, -1232, 1872, 43 | -32768, 13792, -1728, -32768, 13792, 4480, -32192, 14368, -7360, -32752, 44 | 13808, -1712, -21456, 16992, 1472, -1344, 26848, -1088, 2016, -17728, 208, 45 | -2112, -32768, 1376, -1728, -32768, 13792, -1728, -32768, 13792, -1728, 46 | -32768, 13792, -1728, -32768, 13792, -1728, -4544, 32767, -1377, 1727, 47 | 15823, -2113, 207, -27345, 591, -2513, -32768, 13792, -1728, -32768, 13792, 48 | 10688, -31632, 14928, -6800, -32192, 14368, -1152, -20896, 17552, 2032, 49 | -784, 22288, 560, -2256, -4816, 2176, 64, -21120, 9920, 6816, -24224, 16128, 50 | 608, -13488, 9584, 272, -2544, 16, -2304, -192, 1728, -16, 1568, 128, -1184, 51 | } ; 52 | 53 | 54 | static void 55 | test_oki_adpcm (void) 56 | { 57 | IMA_OKI_ADPCM adpcm ; 58 | unsigned char code ; 59 | int i, j ; 60 | 61 | print_test_name ("Testing ima/oki encoder") ; 62 | 63 | ima_oki_adpcm_init (&adpcm, IMA_OKI_ADPCM_TYPE_OKI) ; 64 | for (i = 0 ; i < ARRAY_LEN (test_codes) ; i++) 65 | for (j = 0, code = test_codes [i] ; j < 2 ; j++, code <<= 4) 66 | if (adpcm_decode (&adpcm, code >> 4) != test_pcm [2 * i + j]) 67 | { printf ("\n\nFail at i = %d, j = %d.\n\n", i, j) ; 68 | exit (1) ; 69 | } ; 70 | 71 | puts ("ok") ; 72 | 73 | print_test_name ("Testing ima/oki decoder") ; 74 | 75 | ima_oki_adpcm_init (&adpcm, IMA_OKI_ADPCM_TYPE_OKI) ; 76 | for (i = 0 ; i < ARRAY_LEN (test_pcm) - 1 ; i += 2) 77 | { code = adpcm_encode (&adpcm, test_pcm [i]) ; 78 | code = (code << 4) | adpcm_encode (&adpcm, test_pcm [i + 1]) ; 79 | if (code != test_codes [i / 2]) 80 | { printf ("\n\nFail at i = %d, %d should be %d\n\n", i, code, test_codes [i / 2]) ; 81 | exit (1) ; 82 | } ; 83 | } ; 84 | 85 | puts ("ok") ; 86 | } /* test_oki_adpcm */ 87 | 88 | static void 89 | test_oki_adpcm_block (void) 90 | { 91 | IMA_OKI_ADPCM adpcm ; 92 | int k ; 93 | 94 | if (ARRAY_LEN (adpcm.pcm) < ARRAY_LEN (test_pcm)) 95 | { printf ("\n\nLine %d : ARRAY_LEN (adpcm->pcm) > ARRAY_LEN (test_pcm) (%d > %d).\n\n", __LINE__, ARRAY_LEN (adpcm.pcm), ARRAY_LEN (test_pcm)) ; 96 | exit (1) ; 97 | } ; 98 | 99 | if (ARRAY_LEN (adpcm.codes) < ARRAY_LEN (test_codes)) 100 | { printf ("\n\nLine %d : ARRAY_LEN (adcodes->codes) > ARRAY_LEN (test_codes).n", __LINE__) ; 101 | exit (1) ; 102 | } ; 103 | 104 | print_test_name ("Testing ima/oki block encoder") ; 105 | 106 | ima_oki_adpcm_init (&adpcm, IMA_OKI_ADPCM_TYPE_OKI) ; 107 | 108 | memcpy (adpcm.pcm, test_pcm, sizeof (adpcm.pcm [0]) * ARRAY_LEN (test_pcm)) ; 109 | adpcm.pcm_count = ARRAY_LEN (test_pcm) ; 110 | adpcm.code_count = 13 ; 111 | 112 | ima_oki_adpcm_encode_block (&adpcm) ; 113 | 114 | if (adpcm.code_count * 2 != ARRAY_LEN (test_pcm)) 115 | { printf ("\n\nLine %d : %d * 2 != %d\n\n", __LINE__, adpcm.code_count * 2, ARRAY_LEN (test_pcm)) ; 116 | exit (1) ; 117 | } ; 118 | 119 | for (k = 0 ; k < ARRAY_LEN (test_codes) ; k++) 120 | if (adpcm.codes [k] != test_codes [k]) 121 | { printf ("\n\nLine %d : Fail at k = %d, %d should be %d\n\n", __LINE__, k, adpcm.codes [k], test_codes [k]) ; 122 | exit (1) ; 123 | } ; 124 | 125 | puts ("ok") ; 126 | 127 | print_test_name ("Testing ima/oki block decoder") ; 128 | 129 | ima_oki_adpcm_init (&adpcm, IMA_OKI_ADPCM_TYPE_OKI) ; 130 | 131 | memcpy (adpcm.codes, test_codes, sizeof (adpcm.codes [0]) * ARRAY_LEN (test_codes)) ; 132 | adpcm.code_count = ARRAY_LEN (test_codes) ; 133 | adpcm.pcm_count = 13 ; 134 | 135 | ima_oki_adpcm_decode_block (&adpcm) ; 136 | 137 | if (adpcm.pcm_count != 2 * ARRAY_LEN (test_codes)) 138 | { printf ("\n\nLine %d : %d * 2 != %d\n\n", __LINE__, adpcm.pcm_count, 2 * ARRAY_LEN (test_codes)) ; 139 | exit (1) ; 140 | } ; 141 | 142 | for (k = 0 ; k < ARRAY_LEN (test_pcm) ; k++) 143 | if (adpcm.pcm [k] != test_pcm [k]) 144 | { printf ("\n\nLine %d : Fail at i = %d, %d should be %d.\n\n", __LINE__, k, adpcm.pcm [k], test_pcm [k]) ; 145 | exit (1) ; 146 | } ; 147 | 148 | puts ("ok") ; 149 | } /* test_oki_adpcm_block */ 150 | 151 | void 152 | test_ima_oki_adpcm (void) 153 | { 154 | test_oki_adpcm () ; 155 | test_oki_adpcm_block () ; 156 | } /* main */ 157 | 158 | -------------------------------------------------------------------------------- /examples/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* Minimal example program that demonstrates how to use libsndfile-MSVC */ 2 | /* The code in this file (only in this file!) is dedicated to the public domain, by LoRd_MuldeR */ 3 | 4 | /*libsndfile*/ 5 | #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1 6 | #include 7 | 8 | /*CRT*/ 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /*Const*/ 15 | static const size_t BUFF_SIZE = 2048; 16 | 17 | /* Scan audio samples */ 18 | static void analyze_samples(double &max_sample, const double *const buffer, const long long count, const int channels) 19 | { 20 | for (long long i = 0; i < count; i++) 21 | { 22 | for (int c = 0; c < channels; c++) 23 | { 24 | const double current_sample = buffer[(i * channels) + c]; 25 | max_sample = std::max(max_sample, abs(current_sample)); 26 | } 27 | } 28 | } 29 | 30 | /* Process audio samples */ 31 | static void process_samples(const double max_sample, double *const buffer, const long long count, const int channels) 32 | { 33 | const double amplification_factor = 1.0 / max_sample; 34 | for (long long i = 0; i < count; i++) 35 | { 36 | for (int c = 0; c < channels; c++) 37 | { 38 | double ¤t_sample = buffer[(i * channels) + c]; 39 | current_sample *= amplification_factor; 40 | } 41 | } 42 | } 43 | 44 | /* Main function */ 45 | static int example_main(int argc, wchar_t *argv[]) 46 | { 47 | /* Print logo */ 48 | printf("libsndfile-MSVC example program [%s] [MSVC v%u]\n\n", __DATE__, _MSC_VER); 49 | printf("Powered by %s,\nCopyright (C) 1999-2017 Erik de Castro Lopo \n\n", sf_version_string()); 50 | 51 | /* Check for arguments */ 52 | if (argc < 3) 53 | { 54 | printf("Error: Command-line argument is missing!\n\n"); 55 | printf("Usage:\n example.exe \n\n"); 56 | return 1; 57 | } 58 | 59 | /* Initialize SF_INFO struct */ 60 | SF_INFO info_src; 61 | memset(&info_src, 0, sizeof(SF_INFO)); 62 | 63 | /* Open input file */ 64 | printf("Opening source audio file:\n%S\n\n", argv[1]); 65 | SNDFILE *handle_src = sf_wchar_open(argv[1], SFM_READ, &info_src); 66 | 67 | /* Check for success */ 68 | if (!handle_src) 69 | { 70 | printf("Failed to open source audio file for reading:\n%s\n\n", sf_error_number(sf_perror(NULL))); 71 | return 2; 72 | } 73 | 74 | /* Initialize SF_INFO struct */ 75 | SF_INFO info_out; 76 | memset(&info_out, 0, sizeof(SF_INFO)); 77 | 78 | /* Setuo outpout format */ 79 | info_out.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; 80 | info_out.channels = info_src.channels; 81 | info_out.samplerate = info_src.samplerate; 82 | 83 | /* Open output file */ 84 | printf("Opening output audio file:\n%S\n\n", argv[2]); 85 | SNDFILE *handle_out = sf_wchar_open(argv[2], SFM_WRITE, &info_out); 86 | 87 | /* Check for success */ 88 | if (!handle_out) 89 | { 90 | printf("Failed to open output audio file for writing:\n%s\n\n", sf_error_number(sf_perror(NULL))); 91 | sf_close(handle_src); 92 | return 3; 93 | } 94 | 95 | /* Print some info */ 96 | printf("[File Information]\n"); 97 | printf("File format identifier: 0x%X\n", info_src.format); 98 | printf("Number of channels: %d\n", info_src.channels); 99 | printf("Sampling rate: %d Hz\n", info_src.samplerate); 100 | printf("Duration, in frames: %lld\n", info_src.frames); 101 | printf("Is seekable: %s\n\n", info_src.seekable ? "YES" : "NO"); 102 | 103 | /* Allocate buffer */ 104 | double *buffer = new double[BUFF_SIZE * info_src.channels]; 105 | 106 | /* Simple 2-pass normalization algorithm */ 107 | static double max_sample = 0.0; 108 | for (int pass = 0; pass < 2; ++pass) 109 | { 110 | /* Loop over the entire file */ 111 | printf("Pass %d/2: %s audio samples, please wait...\n", pass + 1, pass ? "Process" : "Analyze"); 112 | long long count = BUFF_SIZE, total_samples = 0; 113 | while (count >= BUFF_SIZE) 114 | { 115 | /* Read next chunk auf data */ 116 | count = sf_readf_double(handle_src, &buffer[0], BUFF_SIZE); 117 | 118 | /* Process read audio data */ 119 | if (count > 0) 120 | { 121 | if (pass > 0) 122 | { 123 | /* Processing pass */ 124 | process_samples(max_sample, buffer, count, info_src.channels); 125 | 126 | /* Write out processed samples */ 127 | if (count != sf_writef_double(handle_out, &buffer[0], count)) 128 | { 129 | printf("Error: Failed to write data to audio file!\n\n"); 130 | delete[] buffer; 131 | sf_close(handle_out); 132 | sf_close(handle_src); 133 | return 4; 134 | } 135 | } 136 | else 137 | { 138 | /* Analysis pass */ 139 | analyze_samples(max_sample, buffer, count, info_src.channels); 140 | } 141 | 142 | /* Bookkeeping */ 143 | total_samples += count; 144 | } 145 | 146 | /* Update progress indicator */ 147 | if (info_src.frames > 0) 148 | { 149 | const double percentage = ((double)total_samples) / ((double)info_src.frames) * 100.0; 150 | printf("\r%lld/%lld [%.1f%%]", total_samples, info_src.frames, percentage); 151 | } 152 | else 153 | { 154 | printf("\r%lld", total_samples); 155 | } 156 | } 157 | printf("\n\n"); 158 | 159 | /*Rewind file after first pass*/ 160 | if (pass < 1) 161 | { 162 | if (sf_seek(handle_src, 0, SEEK_SET) != 0) 163 | { 164 | printf("Error: Failed to rewind audio file!\n\n"); 165 | delete[] buffer; 166 | sf_close(handle_out); 167 | sf_close(handle_src); 168 | return 5; 169 | } 170 | } 171 | } 172 | 173 | /* Completed */ 174 | printf("Everything completed succesfully.\n\n"); 175 | 176 | /* Clean up the mess */ 177 | delete[] buffer; 178 | sf_close(handle_out); 179 | sf_close(handle_src); 180 | 181 | /* Time to say goodbye */ 182 | return 0; 183 | } 184 | 185 | /* Entry point */ 186 | int wmain(int argc, wchar_t *argv[]) 187 | { 188 | #ifndef _DEBUG 189 | __try 190 | { 191 | return example_main(argc, argv); 192 | } 193 | __except (1) 194 | { 195 | fputs("\n\nFATAL ERROR: Unhandeled excaption error :-(\n\n", stderr); 196 | _exit(666); 197 | } 198 | #else 199 | return example_main(argc, argv); 200 | #endif 201 | } 202 | -------------------------------------------------------------------------------- /src/strings.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2001-2016 Erik de Castro Lopo 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 | #include "sfconfig.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "sndfile.h" 26 | #include "common.h" 27 | 28 | #define STRINGS_DEBUG 0 29 | 30 | int 31 | psf_store_string (SF_PRIVATE *psf, int str_type, const char *str) 32 | { char new_str [128] ; 33 | size_t str_len ; 34 | int k, str_flags ; 35 | 36 | if (str == NULL) 37 | return SFE_STR_BAD_STRING ; 38 | 39 | str_len = strlen (str) ; 40 | 41 | /* A few extra checks for write mode. */ 42 | if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR) 43 | { if ((psf->strings.flags & SF_STR_ALLOW_START) == 0) 44 | return SFE_STR_NO_SUPPORT ; 45 | if (psf->have_written && (psf->strings.flags & SF_STR_ALLOW_END) == 0) 46 | return SFE_STR_NO_SUPPORT ; 47 | /* Only allow zero length strings for software. */ 48 | if (str_type != SF_STR_SOFTWARE && str_len == 0) 49 | return SFE_STR_BAD_STRING ; 50 | } ; 51 | 52 | /* Find the next free slot in table. */ 53 | for (k = 0 ; k < SF_MAX_STRINGS ; k++) 54 | { /* If we find a matching entry clear it. */ 55 | if (psf->strings.data [k].type == str_type) 56 | psf->strings.data [k].type = -1 ; 57 | 58 | if (psf->strings.data [k].type == 0) 59 | break ; 60 | } ; 61 | 62 | /* Determine flags */ 63 | str_flags = SF_STR_LOCATE_START ; 64 | if (psf->file.mode == SFM_RDWR || psf->have_written) 65 | { if ((psf->strings.flags & SF_STR_ALLOW_END) == 0) 66 | return SFE_STR_NO_ADD_END ; 67 | str_flags = SF_STR_LOCATE_END ; 68 | } ; 69 | 70 | /* More sanity checking. */ 71 | if (k >= SF_MAX_STRINGS) 72 | return SFE_STR_MAX_COUNT ; 73 | 74 | if (k == 0 && psf->strings.storage_used != 0) 75 | { psf_log_printf (psf, "SFE_STR_WEIRD : k == 0 && psf->strings.storage_used != 0\n") ; 76 | return SFE_STR_WEIRD ; 77 | } ; 78 | 79 | if (k != 0 && psf->strings.storage_used == 0) 80 | { psf_log_printf (psf, "SFE_STR_WEIRD : k != 0 && psf->strings.storage_used == 0\n") ; 81 | return SFE_STR_WEIRD ; 82 | } ; 83 | 84 | /* Special case for the first string. */ 85 | if (k == 0) 86 | psf->strings.storage_used = 0 ; 87 | 88 | switch (str_type) 89 | { case SF_STR_SOFTWARE : 90 | /* In write mode, want to append libsndfile-version to string. */ 91 | if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR) 92 | { if (strstr (str, PACKAGE_NAME) == NULL) 93 | { /* 94 | ** If the supplied string does not already contain a 95 | ** libsndfile-X.Y.Z component, then add it. 96 | */ 97 | if (strlen (str) == 0) 98 | snprintf (new_str, sizeof (new_str), "%s-%s", PACKAGE_NAME, PACKAGE_VERSION) ; 99 | else 100 | snprintf (new_str, sizeof (new_str), "%s (%s-%s)", str, PACKAGE_NAME, PACKAGE_VERSION) ; 101 | } 102 | else 103 | snprintf (new_str, sizeof (new_str), "%s", str) ; 104 | 105 | str = new_str ; 106 | } ; 107 | break ; 108 | 109 | case SF_STR_TITLE : 110 | case SF_STR_COPYRIGHT : 111 | case SF_STR_ARTIST : 112 | case SF_STR_COMMENT : 113 | case SF_STR_DATE : 114 | case SF_STR_ALBUM : 115 | case SF_STR_LICENSE : 116 | case SF_STR_TRACKNUMBER : 117 | case SF_STR_GENRE : 118 | break ; 119 | 120 | default : 121 | psf_log_printf (psf, "%s : SFE_STR_BAD_TYPE\n", __func__) ; 122 | return SFE_STR_BAD_TYPE ; 123 | } ; 124 | 125 | /* Plus one to catch string terminator. */ 126 | str_len = strlen (str) + 1 ; 127 | 128 | if (psf->strings.storage_used + str_len + 1 > psf->strings.storage_len) 129 | { char * temp = psf->strings.storage ; 130 | size_t newlen = 2 * psf->strings.storage_len + str_len + 1 ; 131 | 132 | newlen = newlen < 256 ? 256 : newlen ; 133 | 134 | if ((psf->strings.storage = realloc (temp, newlen)) == NULL) 135 | { psf->strings.storage = temp ; 136 | return SFE_MALLOC_FAILED ; 137 | } ; 138 | 139 | psf->strings.storage_len = newlen ; 140 | } ; 141 | 142 | psf->strings.data [k].type = str_type ; 143 | psf->strings.data [k].offset = psf->strings.storage_used ; 144 | psf->strings.data [k].flags = str_flags ; 145 | 146 | memcpy (psf->strings.storage + psf->strings.storage_used, str, str_len) ; 147 | psf->strings.storage_used += str_len ; 148 | 149 | psf->strings.flags |= str_flags ; 150 | 151 | #if STRINGS_DEBUG 152 | printf ("storage_used : %zd / %zd\n", psf->strings.storage_used, psf->strings.storage_len) ; 153 | psf_hexdump (psf->strings.storage, psf->strings.storage_used) ; 154 | #endif 155 | 156 | return 0 ; 157 | } /* psf_store_string */ 158 | 159 | int 160 | psf_set_string (SF_PRIVATE *psf, int str_type, const char *str) 161 | { if (psf->file.mode == SFM_READ) 162 | return SFE_STR_NOT_WRITE ; 163 | 164 | return psf_store_string (psf, str_type, str) ; 165 | } /* psf_set_string */ 166 | 167 | const char* 168 | psf_get_string (SF_PRIVATE *psf, int str_type) 169 | { int k ; 170 | 171 | for (k = 0 ; k < SF_MAX_STRINGS ; k++) 172 | if (str_type == psf->strings.data [k].type) 173 | return psf->strings.storage + psf->strings.data [k].offset ; 174 | 175 | return NULL ; 176 | } /* psf_get_string */ 177 | 178 | int 179 | psf_location_string_count (const SF_PRIVATE * psf, int location) 180 | { int k, count = 0 ; 181 | 182 | for (k = 0 ; k < SF_MAX_STRINGS ; k++) 183 | if (psf->strings.data [k].type > 0 && psf->strings.data [k].flags & location) 184 | count ++ ; 185 | 186 | return count ; 187 | } /* psf_location_string_count */ 188 | -------------------------------------------------------------------------------- /examples/example_VS2013.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A} 18 | Win32Proj 19 | example_VS2015 20 | 8.1 21 | 22 | 23 | 24 | Application 25 | true 26 | v120_xp 27 | Unicode 28 | 29 | 30 | Application 31 | false 32 | v120_xp 33 | true 34 | Unicode 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | true 50 | $(ProjectDir)\bin\$(Platform)\$(Configuration)\ 51 | $(ProjectDir)\obj\$(Platform)\$(PlatformToolset)\$(Configuration)\ 52 | 53 | 54 | false 55 | $(ProjectDir)\bin\$(Platform)\$(Configuration)\ 56 | $(ProjectDir)\obj\$(Platform)\$(PlatformToolset)\$(Configuration)\ 57 | 58 | 59 | 60 | 61 | 62 | Level3 63 | Disabled 64 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 65 | $(SolutionDir)\include;%(AdditionalIncludeDirectories) 66 | 67 | 68 | Console 69 | true 70 | libsndfile_msvc.$(PlatformToolset).lib;libFLAC_static.$(PlatformToolset).lib;libogg_static.$(PlatformToolset).lib;libvorbis_static.$(PlatformToolset).lib;%(AdditionalDependencies) 71 | $(SolutionDir)\lib\$(Platform)\$(Configuration)\;$(SolutionDir)\..\Prerequisites\XiphAudioLibs\lib\Win32\static 72 | 73 | 74 | 75 | 76 | Level3 77 | NotUsing 78 | Full 79 | true 80 | true 81 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 82 | MultiThreaded 83 | false 84 | StreamingSIMDExtensions2 85 | Fast 86 | AnySuitable 87 | Speed 88 | true 89 | true 90 | $(SolutionDir)\include;%(AdditionalIncludeDirectories) 91 | false 92 | 93 | 94 | Console 95 | true 96 | true 97 | false 98 | libsndfile_msvc.$(PlatformToolset).lib;libFLAC_static.$(PlatformToolset).lib;libogg_static.$(PlatformToolset).lib;libvorbis_static.$(PlatformToolset).lib;%(AdditionalDependencies) 99 | $(SolutionDir)\lib\$(Platform)\$(Configuration)\;$(SolutionDir)\..\Prerequisites\XiphAudioLibs\lib\Win32\static 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /examples/example_VS2015.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A} 18 | Win32Proj 19 | example_VS2015 20 | 8.1 21 | 22 | 23 | 24 | Application 25 | true 26 | v140_xp 27 | Unicode 28 | 29 | 30 | Application 31 | false 32 | v140_xp 33 | true 34 | Unicode 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | true 50 | $(ProjectDir)\bin\$(Platform)\$(Configuration)\ 51 | $(ProjectDir)\obj\$(Platform)\$(PlatformToolset)\$(Configuration)\ 52 | 53 | 54 | false 55 | $(ProjectDir)\bin\$(Platform)\$(Configuration)\ 56 | $(ProjectDir)\obj\$(Platform)\$(PlatformToolset)\$(Configuration)\ 57 | 58 | 59 | 60 | 61 | 62 | Level3 63 | Disabled 64 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 65 | $(SolutionDir)\include;%(AdditionalIncludeDirectories) 66 | 67 | 68 | Console 69 | true 70 | libsndfile_msvc.$(PlatformToolset).lib;libFLAC_static.$(PlatformToolset).lib;libogg_static.$(PlatformToolset).lib;libvorbis_static.$(PlatformToolset).lib;%(AdditionalDependencies) 71 | $(SolutionDir)\lib\$(Platform)\$(Configuration)\;$(SolutionDir)\..\Prerequisites\XiphAudioLibs\lib\Win32\static 72 | 73 | 74 | 75 | 76 | Level3 77 | NotUsing 78 | Full 79 | true 80 | true 81 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 82 | MultiThreaded 83 | false 84 | StreamingSIMDExtensions2 85 | Fast 86 | AnySuitable 87 | Speed 88 | true 89 | true 90 | $(SolutionDir)\include;%(AdditionalIncludeDirectories) 91 | false 92 | 93 | 94 | Console 95 | true 96 | true 97 | false 98 | libsndfile_msvc.$(PlatformToolset).lib;libFLAC_static.$(PlatformToolset).lib;libogg_static.$(PlatformToolset).lib;libvorbis_static.$(PlatformToolset).lib;%(AdditionalDependencies) 99 | $(SolutionDir)\lib\$(Platform)\$(Configuration)\;$(SolutionDir)\..\Prerequisites\XiphAudioLibs\lib\Win32\static 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /src/G72x/g72x_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 1999-2014 Erik de Castro Lopo 3 | ** 4 | ** This program is free software; you can redistribute it and/or modify 5 | ** it under the terms of the GNU General Public License as published by 6 | ** the Free Software Foundation; either version 2 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 General Public License for more details. 13 | ** 14 | ** You should have received a copy of the GNU 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 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "g72x.h" 26 | #include "g72x_priv.h" 27 | 28 | #ifndef M_PI 29 | #define M_PI 3.14159265358979323846264338 30 | #endif 31 | 32 | #define BUFFER_SIZE (1 << 14) 33 | #define SAMPLE_RATE 11025 34 | 35 | 36 | static void g721_test (void) ; 37 | static void g723_test (double margin) ; 38 | 39 | static void gen_signal_double (double *data, double scale, int datalen) ; 40 | static int error_function (double data, double orig, double margin) ; 41 | 42 | static int oct_save_short (short *a, short *b, int len) ; 43 | 44 | int 45 | main (int argc, char *argv []) 46 | { int bDoAll = 0 ; 47 | int nTests = 0 ; 48 | 49 | if (argc != 2) 50 | { printf ("Usage : %s \n", argv [0]) ; 51 | printf (" Where is one of the following:\n") ; 52 | printf (" g721 - test G721 encoder and decoder\n") ; 53 | printf (" g723 - test G721 encoder and decoder\n") ; 54 | printf (" all - perform all tests\n") ; 55 | exit (1) ; 56 | } ; 57 | 58 | bDoAll = !strcmp (argv [1], "all") ; 59 | 60 | if (bDoAll || ! strcmp (argv [1], "g721")) 61 | { g721_test () ; 62 | nTests++ ; 63 | } ; 64 | 65 | if (bDoAll || ! strcmp (argv [1], "g723")) 66 | { g723_test (0.53) ; 67 | nTests++ ; 68 | } ; 69 | 70 | if (nTests == 0) 71 | { printf ("Mono : ************************************\n") ; 72 | printf ("Mono : * No '%s' test defined.\n", argv [1]) ; 73 | printf ("Mono : ************************************\n") ; 74 | return 1 ; 75 | } ; 76 | 77 | return 0 ; 78 | } /* main */ 79 | 80 | static void 81 | g721_test (void) 82 | { 83 | return ; 84 | } /* g721_test */ 85 | 86 | static void 87 | g723_test (double margin) 88 | { static double orig_buffer [BUFFER_SIZE] ; 89 | static short orig [BUFFER_SIZE] ; 90 | static short data [BUFFER_SIZE] ; 91 | 92 | G72x_STATE encoder_state, decoder_state ; 93 | 94 | long k ; 95 | int code, position, max_err ; 96 | 97 | private_init_state (&encoder_state) ; 98 | encoder_state.encoder = g723_24_encoder ; 99 | encoder_state.codec_bits = 3 ; 100 | 101 | private_init_state (&decoder_state) ; 102 | decoder_state.decoder = g723_24_decoder ; 103 | decoder_state.codec_bits = 3 ; 104 | 105 | memset (data, 0, BUFFER_SIZE * sizeof (short)) ; 106 | memset (orig, 0, BUFFER_SIZE * sizeof (short)) ; 107 | 108 | printf (" g723_test : ") ; 109 | fflush (stdout) ; 110 | 111 | gen_signal_double (orig_buffer, 32000.0, BUFFER_SIZE) ; 112 | for (k = 0 ; k < BUFFER_SIZE ; k++) 113 | orig [k] = (short) orig_buffer [k] ; 114 | 115 | /* Write and read data here. */ 116 | position = 0 ; 117 | max_err = 0 ; 118 | for (k = 0 ; k < BUFFER_SIZE ; k++) 119 | { code = encoder_state.encoder (orig [k], &encoder_state) ; 120 | data [k] = decoder_state.decoder (code, &decoder_state) ; 121 | if (abs (orig [k] - data [k]) > max_err) 122 | { position = k ; 123 | max_err = abs (orig [k] - data [k]) ; 124 | } ; 125 | } ; 126 | 127 | printf ("\n\nMax error of %d at postion %d.\n", max_err, position) ; 128 | 129 | for (k = 0 ; k < BUFFER_SIZE ; k++) 130 | { if (error_function (data [k], orig [k], margin)) 131 | { printf ("Line %d: Incorrect sample A (#%ld : %d should be %d).\n", __LINE__, k, data [k], orig [k]) ; 132 | oct_save_short (orig, data, BUFFER_SIZE) ; 133 | exit (1) ; 134 | } ; 135 | } ; 136 | 137 | 138 | printf ("ok\n") ; 139 | 140 | return ; 141 | } /* g723_test */ 142 | 143 | 144 | #define SIGNAL_MAXVAL 30000.0 145 | #define DECAY_COUNT 1000 146 | 147 | static void 148 | gen_signal_double (double *gendata, double scale, int gendatalen) 149 | { int k, ramplen ; 150 | double amp = 0.0 ; 151 | 152 | ramplen = DECAY_COUNT ; 153 | 154 | for (k = 0 ; k < gendatalen ; k++) 155 | { if (k <= ramplen) 156 | amp = scale * k / ((double) ramplen) ; 157 | else if (k > gendatalen - ramplen) 158 | amp = scale * (gendatalen - k) / ((double) ramplen) ; 159 | 160 | gendata [k] = amp * (0.4 * sin (33.3 * 2.0 * M_PI * ((double) (k+1)) / ((double) SAMPLE_RATE)) 161 | + 0.3 * cos (201.1 * 2.0 * M_PI * ((double) (k+1)) / ((double) SAMPLE_RATE))) ; 162 | } ; 163 | 164 | return ; 165 | } /* gen_signal_double */ 166 | 167 | static int 168 | error_function (double data, double orig, double margin) 169 | { double error ; 170 | 171 | if (fabs (orig) <= 500.0) 172 | error = fabs (fabs (data) - fabs (orig)) / 2000.0 ; 173 | else if (fabs (orig) <= 1000.0) 174 | error = fabs (data - orig) / 3000.0 ; 175 | else 176 | error = fabs (data - orig) / fabs (orig) ; 177 | 178 | if (error > margin) 179 | { printf ("\n\n*******************\nError : %f\n", error) ; 180 | return 1 ; 181 | } ; 182 | return 0 ; 183 | } /* error_function */ 184 | 185 | static int 186 | oct_save_short (short *a, short *b, int len) 187 | { FILE *file ; 188 | int k ; 189 | 190 | if (! (file = fopen ("error.dat", "w"))) 191 | return 1 ; 192 | 193 | fprintf (file, "# Not created by Octave\n") ; 194 | 195 | fprintf (file, "# name: a\n") ; 196 | fprintf (file, "# type: matrix\n") ; 197 | fprintf (file, "# rows: %d\n", len) ; 198 | fprintf (file, "# columns: 1\n") ; 199 | 200 | for (k = 0 ; k < len ; k++) 201 | fprintf (file, "% d\n", a [k]) ; 202 | 203 | fprintf (file, "# name: b\n") ; 204 | fprintf (file, "# type: matrix\n") ; 205 | fprintf (file, "# rows: %d\n", len) ; 206 | fprintf (file, "# columns: 1\n") ; 207 | 208 | for (k = 0 ; k < len ; k++) 209 | fprintf (file, "% d\n", b [k]) ; 210 | 211 | fclose (file) ; 212 | return 0 ; 213 | } /* oct_save_short */ 214 | 215 | -------------------------------------------------------------------------------- /examples/example_VS2017.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | {43BDEDA8-4089-44C2-B024-F9BCACFB2E3A} 18 | Win32Proj 19 | example_VS2017 20 | 8.1 21 | 22 | 23 | 24 | Application 25 | true 26 | v141_xp 27 | Unicode 28 | 29 | 30 | Application 31 | false 32 | v141_xp 33 | true 34 | Unicode 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | true 52 | $(ProjectDir)\bin\$(Platform)\$(Configuration)\ 53 | $(ProjectDir)\obj\$(Platform)\$(PlatformToolset)\$(Configuration)\ 54 | 55 | 56 | false 57 | $(ProjectDir)\bin\$(Platform)\$(Configuration)\ 58 | $(ProjectDir)\obj\$(Platform)\$(PlatformToolset)\$(Configuration)\ 59 | 60 | 61 | 62 | 63 | 64 | Level3 65 | Disabled 66 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 67 | $(SolutionDir)\include;%(AdditionalIncludeDirectories) 68 | 69 | 70 | Console 71 | true 72 | libsndfile_msvc.$(PlatformToolset).lib;libFLAC_static.$(PlatformToolset).lib;libogg_static.$(PlatformToolset).lib;libvorbis_static.$(PlatformToolset).lib;%(AdditionalDependencies) 73 | $(SolutionDir)\lib\$(Platform)\$(Configuration)\;$(SolutionDir)\..\Prerequisites\XiphAudioLibs\lib\Win32\static 74 | 75 | 76 | 77 | 78 | Level3 79 | NotUsing 80 | MaxSpeed 81 | true 82 | true 83 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 84 | MultiThreaded 85 | false 86 | StreamingSIMDExtensions2 87 | Fast 88 | AnySuitable 89 | Speed 90 | true 91 | true 92 | $(SolutionDir)\include;%(AdditionalIncludeDirectories) 93 | false 94 | 95 | 96 | Console 97 | true 98 | true 99 | false 100 | libsndfile_msvc.$(PlatformToolset).lib;libFLAC_static.$(PlatformToolset).lib;libogg_static.$(PlatformToolset).lib;libvorbis_static.$(PlatformToolset).lib;%(AdditionalDependencies) 101 | $(SolutionDir)\lib\$(Platform)\$(Configuration)\;$(SolutionDir)\..\Prerequisites\XiphAudioLibs\lib\Win32\static 102 | LinkVerboseLib 103 | 104 | 105 | 106 | 107 | 108 | --------------------------------------------------------------------------------