FS-1197 --resolve do make sndfile-reconf if your build breaks

This commit is contained in:
Anthony Minessale 2011-11-08 15:04:40 -06:00
parent ba14f95d81
commit 02a604f715
212 changed files with 5472 additions and 6793 deletions

View File

@ -1 +1 @@
Thu May 21 16:11:03 CDT 2009
Tue Nov 8 14:58:00 CST 2011

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,18 @@
dnl @synopsis AC_ADD_CFLAGS
dnl @synopsis MN_ADD_CFLAGS
dnl
dnl Add the given option to CFLAGS, if it doesn't break the compiler
AC_DEFUN([AC_ADD_CFLAGS],
AC_DEFUN([MN_ADD_CFLAGS],
[AC_MSG_CHECKING([if $CC accepts $1])
ac_add_cflags__old_cflags="$CFLAGS"
CFLAGS="$CFLAGS $1"
CFLAGS="$1"
AC_TRY_LINK([
#include <stdio.h>
],
[puts("Hello, World!"); return 0;],
AC_MSG_RESULT([yes]),
AC_MSG_RESULT([yes])
CFLAGS="$ac_add_cflags__old_cflags $1",
AC_MSG_RESULT([no])
CFLAGS="$ac_add_cflags__old_cflags"
CFLAGS="$ac_add_cflags__old_cflags"
)
])# AC_ADD_CFLAGS
])# MN_ADD_CFLAGS

View File

@ -1,17 +1,19 @@
dnl @synopsis AC_ADD_CXXFLAGS
dnl @synopsis MN_ADD_CXXFLAGS
dnl
dnl Add the given option to CXXFLAGS, if it doesn't break the compiler
AC_DEFUN([AC_ADD_CXXFLAGS],
AC_DEFUN([MN_ADD_CXXFLAGS],
[AC_MSG_CHECKING([if $CXX accepts $1])
AC_LANG_ASSERT([C++])
ac_add_cxxflags__old_cxxflags="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $1"
CXXFLAGS="$1"
AC_TRY_LINK([
#include <cstdio>
],
[puts("Hello, World!"); return 0;],
AC_MSG_RESULT([yes]),
AC_MSG_RESULT([yes])
CXXFLAGS="$ac_add_cxxflags__old_cxxflags $1",
AC_MSG_RESULT([no])
CXXFLAGS="$ac_add_cxxflags__old_cxxflags"
CXXFLAGS="$ac_add_cxxflags__old_cxxflags"
)
])# AC_ADD_CXXFLAGS
])# MN_ADD_CXXFLAGS

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C_CLIP_MODE
dnl @synopsis MN_C_CLIP_MODE
dnl
dnl Determine the clipping mode when converting float to int.
dnl @version 1.0 May 17 2003
@ -20,7 +20,7 @@ dnl Find the clipping mode in the following way:
dnl 1) If we are not cross compiling test it.
dnl 2) IF we are cross compiling, assume that clipping isn't done correctly.
AC_DEFUN([AC_C_CLIP_MODE],
AC_DEFUN([MN_C_CLIP_MODE],
[AC_CACHE_CHECK(processor clipping capabilities,
ac_cv_c_clip_type,
@ -119,6 +119,6 @@ case "$ac_cv_c_clip_positive$ac_cv_c_clip_negative" in
)
]
)# AC_C_CLIP_MODE
)# MN_C_CLIP_MODE

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C_FIND_ENDIAN
dnl @synopsis MN_C_FIND_ENDIAN
dnl
dnl Determine endian-ness of target processor.
dnl @version 1.1 Mar 03 2002
@ -20,7 +20,7 @@ dnl 2) If 1) fails, look in <sys/types.h> and <sys/param.h>.
dnl 3) If 1) and 2) fails and not cross compiling run a test program.
dnl 4) If 1) and 2) fails and cross compiling then guess based on target.
AC_DEFUN([AC_C_FIND_ENDIAN],
AC_DEFUN([MN_C_FIND_ENDIAN],
[AC_CACHE_CHECK(processor byte ordering,
ac_cv_c_byte_order,
@ -92,13 +92,11 @@ if test $ac_cv_c_byte_order = unknown ; then
[
case "$target_cpu" in
alpha* | i?86* | mipsel* | ia64*)
ac_cv_c_big_endian=0
ac_cv_c_little_endian=1
ac_cv_c_byte_order=little
;;
m68* | mips* | powerpc* | hppa* | sparc*)
ac_cv_c_big_endian=1
ac_cv_c_little_endian=0
ac_cv_c_byte_order=big
;;
esac
@ -116,7 +114,6 @@ if test $ac_cv_c_byte_order = unknown ; then
return (u.c [sizeof (long) - 1] == 1);
}
]], , ac_cv_c_byte_order=big,
ac_cv_c_byte_order=unknown
)
AC_TRY_RUN(
@ -129,7 +126,6 @@ if test $ac_cv_c_byte_order = unknown ; then
u.l = 1 ;
return (u.c [0] == 1);
}]], , ac_cv_c_byte_order=little,
ac_cv_c_byte_order=unknown
)
fi
fi
@ -154,6 +150,6 @@ else
fi
]
)# AC_C_FIND_ENDIAN
)# MN_C_FIND_ENDIAN

View File

@ -6,8 +6,8 @@ dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
dnl Written by Paul Eggert <eggert@twinsun.com>.
dnl Internal subroutine of AC_SYS_EXTRA_LARGEFILE.
dnl AC_SYS_EXTRA_LARGEFILE_FLAGS(FLAGSNAME)
AC_DEFUN([AC_SYS_EXTRA_LARGEFILE_FLAGS],
dnl MN_SYS_EXTRA_LARGEFILE_FLAGS(FLAGSNAME)
AC_DEFUN([MN_SYS_EXTRA_LARGEFILE_FLAGS],
[AC_CACHE_CHECK([for $1 value to request large file support],
ac_cv_sys_largefile_$1,
[ac_cv_sys_largefile_$1=`($GETCONF LFS_$1) 2>/dev/null` || {
@ -67,9 +67,9 @@ AC_DEFUN([AC_SYS_EXTRA_LARGEFILE],
[ --disable-largefile omit support for large files])
if test "$enable_largefile" != no; then
AC_CHECK_TOOL(GETCONF, getconf)
AC_SYS_EXTRA_LARGEFILE_FLAGS(CFLAGS)
AC_SYS_EXTRA_LARGEFILE_FLAGS(LDFLAGS)
AC_SYS_EXTRA_LARGEFILE_FLAGS(LIBS)
MN_SYS_EXTRA_LARGEFILE_FLAGS(CFLAGS)
MN_SYS_EXTRA_LARGEFILE_FLAGS(LDFLAGS)
MN_SYS_EXTRA_LARGEFILE_FLAGS(LIBS)
for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
case "$ac_flag" in

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C99_FLEXIBLE_ARRAY
dnl @synopsis MN_C99_FLEXIBLE_ARRAY
dnl
dnl Dose the compiler support the 1999 ISO C Standard "stuct hack".
dnl @version 1.1 Mar 15 2004
@ -10,7 +10,7 @@ dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
AC_DEFUN([AC_C99_FLEXIBLE_ARRAY],
AC_DEFUN([MN_C99_FLEXIBLE_ARRAY],
[AC_CACHE_CHECK(C99 struct flexible array support,
ac_cv_c99_flexible_array,
@ -28,5 +28,5 @@ AC_TRY_LINK([[
ac_cv_c99_flexible_array=yes,
ac_cv_c99_flexible_array=no
))]
) # AC_C99_FLEXIBLE_ARRAY
) # MN_C99_FLEXIBLE_ARRAY

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_GCC_VERSION
dnl @synopsis MN_GCC_VERSION
dnl
dnl Find the version of gcc.
dnl @version 1.0 Nov 05 2007
@ -11,7 +11,7 @@ dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_GCC_VERSION],
AC_DEFUN([MN_GCC_VERSION],
[
if test "x$ac_cv_c_compiler_gnu" = "xyes" ; then
@ -29,5 +29,5 @@ AC_SUBST(GCC_VERSION)
AC_SUBST(GCC_MAJOR_VERSION)
AC_SUBST(GCC_MINOR_VERSION)
])# AC_GCC_VERSION
])# MN_GCC_VERSION

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C99_FUNC_LLRINT
dnl @synopsis MN_C99_FUNC_LLRINT
dnl
dnl Check whether C99's llrint function is available.
dnl @version 1.1 Sep 30 2002
@ -10,7 +10,7 @@ dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_C99_FUNC_LLRINT],
AC_DEFUN([MN_C99_FUNC_LLRINT],
[AC_CACHE_CHECK(for llrint,
ac_cv_c99_llrint,
[
@ -34,5 +34,5 @@ if test "$ac_cv_c99_llrint" = yes; then
AC_DEFINE(HAVE_LLRINT, 1,
[Define if you have C99's llrint function.])
fi
])# AC_C99_FUNC_LLRINT
])# MN_C99_FUNC_LLRINT

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C99_FUNC_LRINT
dnl @synopsis MN_C99_FUNC_LRINT
dnl
dnl Check whether C99's lrint function is available.
dnl @version 1.3 Feb 12 2002
@ -10,7 +10,7 @@ dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_C99_FUNC_LRINT],
AC_DEFUN([MN_C99_FUNC_LRINT],
[AC_CACHE_CHECK(for lrint,
ac_cv_c99_lrint,
[
@ -33,5 +33,5 @@ if test "$ac_cv_c99_lrint" = yes; then
AC_DEFINE(HAVE_LRINT, 1,
[Define if you have C99's lrint function.])
fi
])# AC_C99_FUNC_LRINT
])# MN_C99_FUNC_LRINT

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C99_FUNC_LRINTF
dnl @synopsis MN_C99_FUNC_LRINTF
dnl
dnl Check whether C99's lrintf function is available.
dnl @version 1.3 Feb 12 2002
@ -10,7 +10,7 @@ dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_C99_FUNC_LRINTF],
AC_DEFUN([MN_C99_FUNC_LRINTF],
[AC_CACHE_CHECK(for lrintf,
ac_cv_c99_lrintf,
[
@ -33,5 +33,5 @@ if test "$ac_cv_c99_lrintf" = yes; then
AC_DEFINE(HAVE_LRINTF, 1,
[Define if you have C99's lrintf function.])
fi
])# AC_C99_FUNC_LRINTF
])# MN_C99_FUNC_LRINTF

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_MKOCTFILE_VERSION
dnl @synopsis OCTAVE_MKOCTFILE_VERSION
dnl
dnl Find the version of mkoctfile.
dnl @version 1.0 Aug 23 2007
@ -11,7 +11,7 @@ dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_MKOCTFILE_VERSION],
AC_DEFUN([OCTAVE_MKOCTFILE_VERSION],
[
@ -34,5 +34,5 @@ if test "x$ac_cv_prog_HAVE_MKOCTFILE" = "xyes" ; then
AC_SUBST(MKOCTFILE)
AC_SUBST(MKOCTFILE_VERSION)
])# AC_MKOCTFILE_VERSION
])# OCTAVE_MKOCTFILE_VERSION

View File

@ -102,7 +102,7 @@ dnl Default to no.
OCTAVE_BUILD=no
AC_OCTAVE_VERSION
AC_MKOCTFILE_VERSION
OCTAVE_MKOCTFILE_VERSION
AC_OCTAVE_CONFIG_VERSION
prog_concat="$ac_cv_prog_HAVE_OCTAVE$ac_cv_prog_HAVE_OCTAVE_CONFIG$ac_cv_prog_HAVE_MKOCTFILE"

View File

@ -1,29 +1,41 @@
## Process this file with automake to produce Makefile.in
DISTCHECK_CONFIGURE_FLAGS = --enable-gcc-werror
if BUILD_OCTAVE_MOD
octave_dir = Octave
endif
SUBDIRS = M4 Win32 src $(octave_dir)
#man doc examples regtest tests programs
DIST_SUBDIRS = M4 man doc Win32 src Octave examples regtest tests programs
EXTRA_DIST = libsndfile.spec.in sndfile.pc.in Mingw-make-dist.sh
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = sndfile.pc
m4datadir = $(datadir)/aclocal
test: check-recursive
# Target to make autogenerated files.
genfiles :
(cd src ; make genfiles)
(cd tests ; make genfiles)
## Process this file with automake to produce Makefile.in
DISTCHECK_CONFIGURE_FLAGS = --enable-gcc-werror
if BUILD_OCTAVE_MOD
octave_dir = Octave
endif
SUBDIRS = M4 man doc Win32 src $(octave_dir) examples regtest tests programs
DIST_SUBDIRS = M4 man doc Win32 src Octave examples regtest tests programs
EXTRA_DIST = libsndfile.spec.in sndfile.pc.in
CLEANFILES = *~
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = sndfile.pc
m4datadir = $(datadir)/aclocal
#===============================================================================
test: check-recursive
# Target to make autogenerated files.
genfiles :
(cd src ; make genfiles)
(cd tests ; make genfiles)
checkprograms :
(cd src ; make libsndfile.la checkprograms)
(cd tests ; make checkprograms)
testprogs :
(cd src ; make testprogs)
(cd tests ; make testprogs)
test-tarball : build-test-tarball.mk
make all
make -f build-test-tarball.mk

View File

@ -1,116 +0,0 @@
#!/bin/sh
# Copyright (C) 2006 Erik de Castro Lopo <erikd@mega-nerd.com>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the author nor the names of any contributors may be used
# to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -e
function unix_to_dos {
sed -e "s/\n/\r\n/" $1 > temp_file
mv -f temp_file $1
}
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo "Usage : Mingw-make-dist.sh <source tarball>."
exit 1
fi
TARGZ=$1
if [ ! -f $TARGZ ]; then
echo "Can't find source tarball."
fi
TARGZ=$1
if [ ! -f $TARGZ.asc ]; then
echo "Can't find source tarball signature."
fi
UNAME=`uname -s`
if [ x$UNAME != "xMINGW32_NT-5.1" ]; then
echo "Not able to build Win32 binaries on this platform."
fi
echo "Building MinGW binary/source zip file."
VERSION=`pwd | sed -e "s#.*/##" | sed -e s/libsndfile-//`
BUILD=`echo $VERSION | sed -e "s/\./_/g"`
INSTALL="libsndfile-$BUILD"
ZIPNAME="$INSTALL.zip"
if [ -z "$BUILD" ]; then
echo "Bad BUILD variable : '$BUILD'"
exit 1
fi
if [ ! -d $INSTALL/ ]; then
mkdir $INSTALL
fi
if [ ! -f config.status ]; then
./configure --prefix=`pwd`/$INSTALL/
else
teststr=`grep "with options" config.status | grep -- --prefix=`
if [ -z "$teststr" ]; then
# --disable-static doesn't work.
./configure --prefix=`pwd`/$INSTALL/
fi
fi
if [ ! -f src/.libs/libsndfile-1.dll ]; then
make all check
fi
if [ ! -f $INSTALL/bin/libsndfile-1.dll ]; then
make install
rm -f $INSTALL/bin/sndfile-regtest.exe
strip $INSTALL/bin/*.*
mv $INSTALL/bin/*.* $INSTALL/include/*.* $INSTALL/
rmdir $INSTALL/bin
rm -rf $INSTALL/lib
rmdir $INSTALL/include
cp src/libsndfile.def $INSTALL/libsndfile-1.def
cp Win32/README-precompiled-dll.txt Win32/testprog.c $INSTALL/
unix_to_dos $INSTALL/libsndfile-1.def
unix_to_dos $INSTALL/sndfile.h
unix_to_dos $INSTALL/README-precompiled-dll.txt
unix_to_dos $INSTALL/testprog.c
fi
if [ ! -f $INSTALL/libsndfile-$VERSION.tar.gz ]; then
cp $TARGZ $INSTALL/
if [ -f $TARGZ.asc ]; then
cp $TARGZ.asc $INSTALL/
fi
fi
if [ ! -f $ZIPNAME ]; then
zip -r $ZIPNAME $INSTALL/
fi

View File

@ -1,3 +1,37 @@
Version 1.0.25 (2011-07-13)
* Fix for Secunia Advisory SA45125, heap overflow in PAF file handler.
* Accept broken WAV files with blockalign == 0.
* Minor bug fixes and improvements.
Version 1.0.24 (2011-03-23)
* WAV files now have an 18 byte u-law and A-law fmt chunk.
* Document virtual I/O functionality.
* Two new methods rawHandle() and takeOwnership() in sndfile.hh.
* AIFF fix for non-zero offset value in SSND chunk.
* Minor bug fixes and improvements.
Version 1.0.23 (2010-10-10)
* Add version metadata to Windows DLL.
* Add a missing 'inline' to sndfile.hh.
* Update docs.
* Minor bug fixes and improvements.
Version 1.0.22 (2010-10-04)
* Couple of fixes for SDS file writer.
* Fixes arising from static analysis.
* Handle FLAC files with ID3 meta data at start of file.
* Handle FLAC files which report zero length.
* Other minor bug fixes and improvements.
Version 1.0.21 (2009-12-13)
* Add a couple of new binary programs to programs/ dir.
* Remove sndfile-jackplay (now in sndfile-tools package).
* Add windows only function sf_wchar_open().
* Bunch of minor bug fixes.
Version 1.0.20 (2009-05-14)
* Fix potential heap overflow in VOC file parser (Tobias Klein, http://www.trapkit.de/).
Version 1.0.19 (2009-03-02)
* Fix for CVE-2009-0186 (Alin Rad Pop, Secunia Research).
* Huge number of minor bug fixes as a result of static analysis.

View File

@ -30,13 +30,19 @@ oct_module_files = sndfile.oct PKG_ADD
noinst_DATA = $(oct_module_files)
# Used by shave which cleans up automake generated Makefile output.
V = @
Q = $(V:1=)
QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
# Use Octave's mkoctfile to do all the heavy lifting. Unfortunately, its
# a little dumb so we need to guide it carefully.
sndfile.oct : sndfile.o
$(MKOCTFILE) -v $(INCLUDES) $(top_builddir)/Octave/$+ -L$(SNDFILEDIR)/.libs -L$(SNDFILEDIR) -lsndfile -o $(top_builddir)/Octave/$@
$(QUIET_GEN) $(MKOCTFILE) -v $(INCLUDES) $(top_builddir)/Octave/$+ -L$(SNDFILEDIR)/.libs -L$(SNDFILEDIR) -lsndfile -o $(top_builddir)/Octave/$@ > /dev/null
sndfile.o : sndfile.cc
$(MKOCTFILE) -v $(INCLUDES) -c $+ -o $(top_builddir)/Octave/$@
$(QUIET_GEN) $(MKOCTFILE) -v $(INCLUDES) -c $+ -o $(top_builddir)/Octave/$@ > /dev/null
# Allow for the test being run in the build dir, but the test script
# being located in the source dir.

View File

@ -1,4 +1,4 @@
# Copyright (C) 2007 Erik de Castro Lopo <erikd@mega-nerd.com>
# Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
@ -16,9 +16,7 @@
# These tests are nowhere near comprehensive.
printf ("\n\n\n\n\n\n\n") ;
printf (" Running Octave tests : ") ;
printf (" Running Octave tests : ") ;
fflush (stdout) ;
filename = "whatever" ;
@ -51,6 +49,4 @@ if (err > 1e-7)
printf ("ok") ;
printf ("\n\n\n\n\n\n\n") ;
unlink (filename) ;

View File

@ -18,12 +18,10 @@ elif [ -f "../src/.libs/libsndfile.dylib" ]; then
elif [ -f "../src/libsndfile.dylib" ]; then
libsndfile_lib_location="../src/"
else
echo
echo
echo "Not able to find the libsndfile shared lib we've just built."
echo "This may cause the following test to fail."
echo
echo
fi
libsndfile_lib_location=`(cd $libsndfile_lib_location && pwd)`

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2007 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -367,7 +367,7 @@ string_of_minor_format (int format)
case SF_FORMAT_G723_40 : return "g723_40" ;
default : break ;
} ;
return "unknown" ;
} /* string_of_minor_format */

View File

@ -1,4 +1,4 @@
## Copyright (C) 2002 Erik de Castro Lopo
## Copyright (C) 2002-2011 Erik de Castro Lopo
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
@ -33,7 +33,7 @@ samplingrate = -1 ;
wavedata = -1 ;
eval (sprintf ('load -f %s', filename)) ;
eval (sprintf ('load -f %s', filename)) ;
if (samplerate > 0),
fs = samplerate ;
@ -42,7 +42,7 @@ elseif (samplingrate > 0),
else
error ("Not able to find sample rate.") ;
endif
if (max (size (wavedata)) > 1),
data = wavedata ;
else

View File

@ -1,4 +1,4 @@
## Copyright (C) 2002 Erik de Castro Lopo
## Copyright (C) 2002-2011 Erik de Castro Lopo
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by

View File

@ -1,4 +1,4 @@
## Copyright (C) 2002 Erik de Castro Lopo
## Copyright (C) 2002-2011 Erik de Castro Lopo
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by

View File

@ -1,4 +1,4 @@
This is libsndfile, 1.0.19
This is libsndfile, 1.0.25
libsndfile is a library of C routines for reading and writing
files containing sampled audio data.

View File

@ -1,42 +0,0 @@
Here's a list of what I (erikd AT mega-nerd DOT com) think needs to be
done. The list is by no means exhaustive and people are encouraged to
email me with suggestions.
o Add pipe in/out capabilities. libsndfile should be able to read
its input from a pipe and write its output to a pipe.
o Add checks of the error state after fseek???? Use ferror ().
o Modify tests/lossy_comp_test.c to add tests for stereo files.
o Testing compilation and correctness on more platforms.
o Improve testing routines. Must test all combinations of inputs
and outputs.
o Test sf_seek function on write???
o Add more sound file formats. People should contact me with their
requirements.
o Add support for accessing sound formats with multiple audio
data sections (ie samples within tracker files, Soundfont II and
multi-sample sampler formats).
o Add an interface to allow reading and writing of sample loop points
and other info within AIFF and other file formats. This must be a
general solution.
o Improve documentation. Is HTML documentation good enough?
o Look into the possibility of optional sample rate convert on file
read.
As I am the person who knows libsndfile best, I can probably implement
any new features faster than anybody else (and you can spend your time
writing applications with libsndfile). All I need is some
documentation and some sample files. Please contact me before emailing
me documentation and sample files. I would much rather pull them off
the web than have them clogging up my email inbox.

View File

@ -1,627 +0,0 @@
dnl By default, many hosts won't let programs access large files;
dnl one must use special compiler options to get large-file access to work.
dnl For more details about this brain damage please see:
dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
dnl Written by Paul Eggert <eggert@twinsun.com>.
m4_include([M4/gcc_version.m4])
m4_include([M4/octave.m4])
m4_include([M4/mkoctfile_version.m4])
dnl Internal subroutine of AC_SYS_EXTRA_LARGEFILE.
dnl AC_SYS_EXTRA_LARGEFILE_FLAGS(FLAGSNAME)
AC_DEFUN([AC_SYS_EXTRA_LARGEFILE_FLAGS],
[AC_CACHE_CHECK([for $1 value to request large file support],
ac_cv_sys_largefile_$1,
[ac_cv_sys_largefile_$1=`($GETCONF LFS_$1) 2>/dev/null` || {
ac_cv_sys_largefile_$1=no
ifelse($1, CFLAGS,
[case "$host_os" in
# IRIX 6.2 and later require cc -n32.
changequote(, )dnl
irix6.[2-9]* | irix6.1[0-9]* | irix[7-9].* | irix[1-9][0-9]*)
changequote([, ])dnl
if test "$GCC" != yes; then
ac_cv_sys_largefile_CFLAGS=-n32
fi
ac_save_CC="$CC"
CC="$CC $ac_cv_sys_largefile_CFLAGS"
AC_TRY_LINK(, , , ac_cv_sys_largefile_CFLAGS=no)
CC="$ac_save_CC"
esac])
}])])
dnl Internal subroutine of AC_SYS_EXTRA_LARGEFILE.
dnl AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND(VAR, VAL)
AC_DEFUN([AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND],
[case $2 in
no) ;;
?*)
case "[$]$1" in
'') $1=$2 ;;
*) $1=[$]$1' '$2 ;;
esac ;;
esac])
dnl Internal subroutine of AC_SYS_EXTRA_LARGEFILE.
dnl AC_SYS_EXTRA_LARGEFILE_MACRO_VALUE(C-MACRO, CACHE-VAR, COMMENT, CODE-TO-SET-DEFAULT)
AC_DEFUN([AC_SYS_EXTRA_LARGEFILE_MACRO_VALUE],
[AC_CACHE_CHECK([for $1], $2,
[$2=no
changequote(, )dnl
$4
for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
case "$ac_flag" in
-D$1)
$2=1 ;;
-D$1=*)
$2=`expr " $ac_flag" : '[^=]*=\(.*\)'` ;;
esac
done
changequote([, ])dnl
])
if test "[$]$2" != no; then
AC_DEFINE_UNQUOTED([$1], [$]$2, [$3])
fi])
AC_DEFUN([AC_SYS_EXTRA_LARGEFILE],
[AC_REQUIRE([AC_CANONICAL_HOST])
AC_ARG_ENABLE(largefile,
[ --disable-largefile omit support for large files])
if test "$enable_largefile" != no; then
AC_CHECK_TOOL(GETCONF, getconf)
AC_SYS_EXTRA_LARGEFILE_FLAGS(CFLAGS)
AC_SYS_EXTRA_LARGEFILE_FLAGS(LDFLAGS)
AC_SYS_EXTRA_LARGEFILE_FLAGS(LIBS)
for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
case "$ac_flag" in
no) ;;
-D_FILE_OFFSET_BITS=*) ;;
-D_LARGEFILE_SOURCE | -D_LARGEFILE_SOURCE=*) ;;
-D_LARGE_FILES | -D_LARGE_FILES=*) ;;
-D?* | -I?*)
AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND(CPPFLAGS, "$ac_flag") ;;
*)
AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND(CFLAGS, "$ac_flag") ;;
esac
done
AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND(LDFLAGS, "$ac_cv_sys_largefile_LDFLAGS")
AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND(LIBS, "$ac_cv_sys_largefile_LIBS")
AC_SYS_EXTRA_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS,
ac_cv_sys_file_offset_bits,
[Number of bits in a file offset, on hosts where this is settable.])
[case "$host_os" in
# HP-UX 10.20 and later
hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)
ac_cv_sys_file_offset_bits=64 ;;
esac]
AC_SYS_EXTRA_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE,
ac_cv_sys_largefile_source,
[Define to make fseeko etc. visible, on some hosts.],
[case "$host_os" in
# HP-UX 10.20 and later
hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)
ac_cv_sys_largefile_source=1 ;;
esac])
AC_SYS_EXTRA_LARGEFILE_MACRO_VALUE(_LARGE_FILES,
ac_cv_sys_large_files,
[Define for large files, on AIX-style hosts.],
[case "$host_os" in
# AIX 4.2 and later
aix4.[2-9]* | aix4.1[0-9]* | aix[5-9].* | aix[1-9][0-9]*)
ac_cv_sys_large_files=1 ;;
esac])
fi
])
dnl @synopsis AC_C_FIND_ENDIAN
dnl
dnl Determine endian-ness of target processor.
dnl @version 1.1 Mar 03 2002
dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
dnl
dnl Majority written from scratch to replace the standard autoconf macro
dnl AC_C_BIGENDIAN. Only part remaining from the original it the invocation
dnl of the AC_TRY_RUN macro.
dnl
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl Find endian-ness in the following way:
dnl 1) Look in <endian.h>.
dnl 2) If 1) fails, look in <sys/types.h> and <sys/param.h>.
dnl 3) If 1) and 2) fails and not cross compiling run a test program.
dnl 4) If 1) and 2) fails and cross compiling then guess based on target.
AC_DEFUN([AC_C_FIND_ENDIAN],
[AC_CACHE_CHECK(processor byte ordering,
ac_cv_c_byte_order,
# Initialize to unknown
ac_cv_c_byte_order=unknown
if test x$ac_cv_header_endian_h = xyes ; then
# First try <endian.h> which should set BYTE_ORDER.
[AC_TRY_LINK([
#include <endian.h>
#if BYTE_ORDER != LITTLE_ENDIAN
not big endian
#endif
], return 0 ;,
ac_cv_c_byte_order=little
)]
[AC_TRY_LINK([
#include <endian.h>
#if BYTE_ORDER != BIG_ENDIAN
not big endian
#endif
], return 0 ;,
ac_cv_c_byte_order=big
)]
fi
if test $ac_cv_c_byte_order = unknown ; then
[AC_TRY_LINK([
#include <sys/types.h>
#include <sys/param.h>
#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
bogus endian macros
#endif
], return 0 ;,
[AC_TRY_LINK([
#include <sys/types.h>
#include <sys/param.h>
#if BYTE_ORDER != LITTLE_ENDIAN
not big endian
#endif
], return 0 ;,
ac_cv_c_byte_order=little
)]
[AC_TRY_LINK([
#include <sys/types.h>
#include <sys/param.h>
#if BYTE_ORDER != LITTLE_ENDIAN
not big endian
#endif
], return 0 ;,
ac_cv_c_byte_order=little
)]
)]
fi
if test $ac_cv_c_byte_order = unknown ; then
if test $cross_compiling = yes ; then
# This is the last resort. Try to guess the target processor endian-ness
# by looking at the target CPU type.
[
case "$target_cpu" in
alpha* | i?86* | mipsel* | ia64*)
ac_cv_c_big_endian=0
ac_cv_c_little_endian=1
;;
m68* | mips* | powerpc* | hppa* | sparc*)
ac_cv_c_big_endian=1
ac_cv_c_little_endian=0
;;
esac
]
else
AC_TRY_RUN(
[[
int main (void)
{ /* Are we little or big endian? From Harbison&Steele. */
union
{ long l ;
char c [sizeof (long)] ;
} u ;
u.l = 1 ;
return (u.c [sizeof (long) - 1] == 1);
}
]], , ac_cv_c_byte_order=big,
ac_cv_c_byte_order=unknown
)
AC_TRY_RUN(
[[int main (void)
{ /* Are we little or big endian? From Harbison&Steele. */
union
{ long l ;
char c [sizeof (long)] ;
} u ;
u.l = 1 ;
return (u.c [0] == 1);
}]], , ac_cv_c_byte_order=little,
ac_cv_c_byte_order=unknown
)
fi
fi
)
]
if test $ac_cv_c_byte_order = big ; then
ac_cv_c_big_endian=1
ac_cv_c_little_endian=0
elif test $ac_cv_c_byte_order = little ; then
ac_cv_c_big_endian=0
ac_cv_c_little_endian=1
else
ac_cv_c_big_endian=0
ac_cv_c_little_endian=0
fi
)# AC_C_FIND_ENDIAN
dnl @synopsis AC_C99_FLEXIBLE_ARRAY
dnl
dnl Dose the compiler support the 1999 ISO C Standard "stuct hack".
dnl @version 1.1 Mar 15 2004
dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
dnl
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
AC_DEFUN([AC_C99_FLEXIBLE_ARRAY],
[AC_CACHE_CHECK(C99 struct flexible array support,
ac_cv_c99_flexible_array,
# Initialize to unknown
ac_cv_c99_flexible_array=no
AC_TRY_LINK([[
#include <stdlib.h>
typedef struct {
int k;
char buffer [] ;
} MY_STRUCT ;
]],
[ MY_STRUCT *p = calloc (1, sizeof (MY_STRUCT) + 42); ],
ac_cv_c99_flexible_array=yes,
ac_cv_c99_flexible_array=no
))]
) # AC_C99_FLEXIBLE_ARRAY
dnl @synopsis AC_C99_FUNC_LRINT
dnl
dnl Check whether C99's lrint function is available.
dnl @version 1.3 Feb 12 2002
dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
dnl
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_C99_FUNC_LRINT],
[AC_CACHE_CHECK(for lrint,
ac_cv_c99_lrint,
[
lrint_save_CFLAGS=$CFLAGS
CFLAGS="-lm"
AC_TRY_LINK([
#define _ISOC9X_SOURCE 1
#define _ISOC99_SOURCE 1
#define __USE_ISOC99 1
#define __USE_ISOC9X 1
#include <math.h>
], if (!lrint(3.14159)) lrint(2.7183);, ac_cv_c99_lrint=yes, ac_cv_c99_lrint=no)
CFLAGS=$lrint_save_CFLAGS
])
if test "$ac_cv_c99_lrint" = yes; then
AC_DEFINE(HAVE_LRINT, 1,
[Define if you have C99's lrint function.])
fi
])# AC_C99_FUNC_LRINT
dnl @synopsis AC_C99_FUNC_LRINTF
dnl
dnl Check whether C99's lrintf function is available.
dnl @version 1.3 Feb 12 2002
dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
dnl
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_C99_FUNC_LRINTF],
[AC_CACHE_CHECK(for lrintf,
ac_cv_c99_lrintf,
[
AC_TRY_LINK([
#define _ISOC9X_SOURCE 1
#define _ISOC99_SOURCE 1
#define __USE_ISOC99 1
#define __USE_ISOC9X 1
#include <math.h>
], if (!lrintf(3.14159)) lrintf(2.7183);, ac_cv_c99_lrintf=yes, ac_cv_c99_lrintf=no)
])
if test "$ac_cv_c99_lrintf" = yes; then
AC_DEFINE(HAVE_LRINTF, 1,
[Define if you have C99's lrintf function.])
fi
])# AC_C99_FUNC_LRINTF
dnl @synopsis AC_C99_FUNC_LLRINT
dnl
dnl Check whether C99's llrint function is available.
dnl @version 1.1 Sep 30 2002
dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
dnl
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_C99_FUNC_LLRINT],
[AC_CACHE_CHECK(for llrint,
ac_cv_c99_llrint,
[
AC_TRY_LINK([
#define _ISOC9X_SOURCE 1
#define _ISOC99_SOURCE 1
#define __USE_ISOC99 1
#define __USE_ISOC9X 1
#include <math.h>
#include <stdint.h>
], int64_t x ; x = llrint(3.14159) ;, ac_cv_c99_llrint=yes, ac_cv_c99_llrint=no)
])
if test "$ac_cv_c99_llrint" = yes; then
AC_DEFINE(HAVE_LLRINT, 1,
[Define if you have C99's llrint function.])
fi
])# AC_C99_FUNC_LLRINT
dnl @synopsis AC_C_CLIP_MODE
dnl
dnl Determine the clipping mode when converting float to int.
dnl @version 1.0 May 17 2003
dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
dnl
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl Find the clipping mode in the following way:
dnl 1) If we are not cross compiling test it.
dnl 2) IF we are cross compiling, assume that clipping isn't done correctly.
AC_DEFUN([AC_C_CLIP_MODE],
[AC_CACHE_CHECK(processor clipping capabilities,
ac_cv_c_clip_type,
# Initialize to unknown
ac_cv_c_clip_positive=unknown
ac_cv_c_clip_negative=unknown
if test $ac_cv_c_clip_positive = unknown ; then
AC_TRY_RUN(
[[
#define _ISOC9X_SOURCE 1
#define _ISOC99_SOURCE 1
#define __USE_ISOC99 1
#define __USE_ISOC9X 1
#include <math.h>
int main (void)
{ double fval ;
int k, ival ;
fval = 1.0 * 0x7FFFFFFF ;
for (k = 0 ; k < 100 ; k++)
{ ival = (lrint (fval)) >> 24 ;
if (ival != 127)
return 1 ;
fval *= 1.2499999 ;
} ;
return 0 ;
}
]],
ac_cv_c_clip_positive=yes,
ac_cv_c_clip_positive=no,
ac_cv_c_clip_positive=unknown
)
AC_TRY_RUN(
[[
#define _ISOC9X_SOURCE 1
#define _ISOC99_SOURCE 1
#define __USE_ISOC99 1
#define __USE_ISOC9X 1
#include <math.h>
int main (void)
{ double fval ;
int k, ival ;
fval = -8.0 * 0x10000000 ;
for (k = 0 ; k < 100 ; k++)
{ ival = (lrint (fval)) >> 24 ;
if (ival != -128)
return 1 ;
fval *= 1.2499999 ;
} ;
return 0 ;
}
]],
ac_cv_c_clip_negative=yes,
ac_cv_c_clip_negative=no,
ac_cv_c_clip_negative=unknown
)
fi
if test $ac_cv_c_clip_positive = yes ; then
ac_cv_c_clip_positive=1
else
ac_cv_c_clip_positive=0
fi
if test $ac_cv_c_clip_negative = yes ; then
ac_cv_c_clip_negative=1
else
ac_cv_c_clip_negative=0
fi
[[
case "$ac_cv_c_clip_positive$ac_cv_c_clip_negative" in
"00")
ac_cv_c_clip_type="none"
;;
"10")
ac_cv_c_clip_type="positive"
;;
"01")
ac_cv_c_clip_type="negative"
;;
"11")
ac_cv_c_clip_type="both"
;;
esac
]]
)
]
)# AC_C_CLIP_MODE
dnl @synopsis AC_ADD_CFLAGS
dnl
dnl Add the given option to CFLAGS, if it doesn't break the compiler
AC_DEFUN([AC_ADD_CFLAGS],
[AC_MSG_CHECKING([if $CC accepts $1])
ac_add_cflags__old_cflags="$CFLAGS"
CFLAGS="$CFLAGS $1"
AC_TRY_LINK([#include <stdio.h>],
[printf("Hello, World!\n"); return 0;],
AC_MSG_RESULT([yes]),
AC_MSG_RESULT([no])
CFLAGS="$ac_add_cflags__old_cflags")
])
dnl PKG_CHECK_MODULES(GSTUFF, gtk+-2.0 >= 1.3 glib = 1.3.4, action-if, action-not)
dnl defines GSTUFF_LIBS, GSTUFF_CFLAGS, see pkg-config man page
dnl also defines GSTUFF_PKG_ERRORS on error
AC_DEFUN([PKG_CHECK_MODULES], [
succeeded=no
if test -z "$PKG_CONFIG"; then
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
fi
if test "$PKG_CONFIG" = "no" ; then
echo "*** The pkg-config script could not be found. Make sure it is"
echo "*** in your path, or set the PKG_CONFIG environment variable"
echo "*** to the full path to pkg-config."
echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config."
else
PKG_CONFIG_MIN_VERSION=0.9.0
if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
AC_MSG_CHECKING(for $2)
if $PKG_CONFIG --exists "$2" ; then
AC_MSG_RESULT(yes)
succeeded=yes
AC_MSG_CHECKING($1_CFLAGS)
$1_CFLAGS=`$PKG_CONFIG --cflags "$2"`
AC_MSG_RESULT($$1_CFLAGS)
AC_MSG_CHECKING($1_LIBS)
$1_LIBS=`$PKG_CONFIG --libs "$2"`
AC_MSG_RESULT($$1_LIBS)
else
$1_CFLAGS=""
$1_LIBS=""
## If we have a custom action on failure, don't print errors, but
## do set a variable so people can do so.
$1_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
ifelse([$4], ,echo $$1_PKG_ERRORS,)
fi
AC_SUBST($1_CFLAGS)
AC_SUBST($1_LIBS)
else
echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
echo "*** See http://www.freedesktop.org/software/pkgconfig"
fi
fi
if test $succeeded = yes; then
ifelse([$3], , :, [$3])
else
ifelse([$4], , AC_MSG_ERROR([Library requirements ($2) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them.]), [$4])
fi
])
ifelse(dnl
Do not edit or modify anything in this comment block.
The arch-tag line is a file identity tag for the GNU Arch
revision control system.
arch-tag: bc38294d-bb5c-42ad-90b9-779def5eaab7
)dnl

View File

@ -1,30 +1,45 @@
# Copyright (C) 1999-2008 Erik de Castro Lopo (erikd AT mega-nerd DOT com).
# Copyright (C) 1999-2011 Erik de Castro Lopo (erikd AT mega-nerd DOT com).
dnl Require autoconf version
AC_PREREQ(2.57)
AC_INIT([libsndfile],[1.0.19],[erikd@mega-nerd.com])
AC_INIT([libsndfile],[1.0.25],[sndfile@mega-nerd.com],
[libsndfile],[http://www.mega-nerd.com/libsndfile/])
# Put config stuff in Cfg.
AC_CONFIG_AUX_DIR(Cfg)
CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
AC_CONFIG_SRCDIR([src/sndfile.c])
AC_CANONICAL_TARGET([])
AM_INIT_AUTOMAKE
AC_CONFIG_MACRO_DIR([M4])
AC_CONFIG_HEADERS([src/config.h])
AM_INIT_AUTOMAKE($PACKAGE_NAME,$PACKAGE_VERSION)
AM_SILENT_RULES([yes])
dnl Add parameters for aclocal
AC_SUBST(ACLOCAL_AMFLAGS, "-I M4")
AC_LANG([C])
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_SED
# Do not check for F77.
define([AC_LIBTOOL_LANG_F77_CONFIG], [:])dnl
AM_PROG_LIBTOOL
LT_PROG_RC
AC_CHECK_PROG(HAVE_AUTOGEN, autogen, yes, no)
AC_CHECK_PROG(HAVE_WINE, wine, yes, no)
AC_PROG_INSTALL
AC_PROG_LN_S
#------------------------------------------------------------------------------------
# Rules for library version information:
#
@ -41,22 +56,12 @@ AC_LANG([C])
# 6. If any interfaces have been removed since the last public release, then set age
# to 0.
SHARED_VERSION_INFO="1:19:0"
CLEAN_VERSION=`echo $PACKAGE_VERSION | $SED "s/p.*//"`
VERSION_MINOR=`echo $CLEAN_VERSION | $SED "s/.*\.//"`
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
SHARED_VERSION_INFO="1:$VERSION_MINOR:0"
# Do not check for F77.
define([AC_LIBTOOL_LANG_F77_CONFIG], [:])dnl
AM_PROG_LIBTOOL
AC_CHECK_PROG(HAVE_AUTOGEN, autogen, yes, no)
AC_CHECK_PROG(HAVE_WINE, wine, yes, no)
AC_PROG_INSTALL
AC_PROG_LN_S
#------------------------------------------------------------------------------------
AC_HEADER_STDC
@ -80,7 +85,7 @@ AM_CONDITIONAL([LINUX_MINGW_CROSS_TEST],
#====================================================================================
# Check for support of the struct hack.
AC_C99_FLEXIBLE_ARRAY
MN_C99_FLEXIBLE_ARRAY
if test x$ac_cv_c99_flexible_array = xyes ; then
AC_DEFINE([HAVE_FLEXIBLE_ARRAY],1, [Set to 1 if the compile supports the struct hack.])
@ -129,7 +134,7 @@ AC_ARG_ENABLE(alsa,
AC_HELP_STRING([--disable-alsa], [disable use of ALSA]))
AC_ARG_ENABLE(external-libs,
AC_HELP_STRING([--disable-external-libs], [disable use of FLAC, Ogg and Vorbis]))
AC_HELP_STRING([--disable-external-libs], [disable use of FLAC, Ogg and Vorbis [[default=no]]]))
AC_ARG_ENABLE(octave,
AC_HELP_STRING([--enable-octave], [disable building of GNU Octave module]))
@ -141,6 +146,7 @@ AM_CONDITIONAL([ENABLE_TEST_COVERAGE], [test "$enable_test_coverage" = yes])
#====================================================================================
# Check types and their sizes.
AC_CHECK_SIZEOF(wchar_t,4)
AC_CHECK_SIZEOF(short,2)
AC_CHECK_SIZEOF(int,4)
AC_CHECK_SIZEOF(long,4)
@ -162,15 +168,16 @@ unset ac_cv_sizeof_off_t
AC_CHECK_SIZEOF(off_t,1) # Fake default value.
case "$host_os" in
mingw*)
mingw32msvc | mingw32)
TYPEOF_SF_COUNT_T="__int64"
SF_COUNT_MAX="0x7FFFFFFFFFFFFFFFLL"
SIZEOF_SF_COUNT_T=8
AC_DEFINE([__USE_MINGW_ANSI_STDIO],1,[Set to 1 to use C99 printf/snprintf in MinGW.])
;;
*)
if test "x$ac_cv_sizeof_off_t" = "x8" ; then
# If sizeof (off_t) is 8, no further checking is needed.
TYPEOF_SF_COUNT_T="off_t"
TYPEOF_SF_COUNT_T="int64_t"
SF_COUNT_MAX="0x7FFFFFFFFFFFFFFFLL"
SIZEOF_SF_COUNT_T=8
else
@ -180,10 +187,10 @@ case "$host_os" in
TYPEOF_SF_COUNT_T="unknown"
if test "x$ac_cv_sizeof_loff_t" = "x8" ; then
TYPEOF_SF_COUNT_T="loff_t"
TYPEOF_SF_COUNT_T="int64_t"
SIZEOF_SF_COUNT_T=8
elif test "x$ac_cv_sizeof_off64_t" = "x8" ; then
TYPEOF_SF_COUNT_T="off64_t"
TYPEOF_SF_COUNT_T="int64_t"
SIZEOF_SF_COUNT_T=8
fi
@ -208,6 +215,7 @@ case "$host_os" in
AC_CHECK_SIZEOF(off_t,1) # Fake default value.
if test "x$ac_cv_sizeof_off_t" = "x8" ; then
TYPEOF_SF_COUNT_T="int64_t"
SF_COUNT_MAX="0x7FFFFFFFFFFFFFFFLL"
elif test "x$ac_cv_sizeof_off_t" = "x$pre_largefile_sizeof_off_t" ; then
AC_MSG_WARN([[This machine does not seem to support 64 bit file offsets.]])
@ -245,7 +253,7 @@ AC_CHECK_SIZEOF(ssize_t,4)
#====================================================================================
# Determine endian-ness of target processor.
AC_C_FIND_ENDIAN
MN_C_FIND_ENDIAN
AC_DEFINE_UNQUOTED(CPU_IS_BIG_ENDIAN, ${ac_cv_c_big_endian},
[Target processor is big endian.])
@ -264,12 +272,13 @@ AC_CHECK_FUNCS(snprintf vsnprintf)
AC_CHECK_FUNCS(gmtime gmtime_r localtime localtime_r gettimeofday)
AC_CHECK_FUNCS(mmap getpagesize)
AC_CHECK_FUNCS(setlocale)
AC_CHECK_FUNCS(pipe waitpid)
AC_CHECK_LIB([m],floor)
AC_CHECK_FUNCS(floor ceil fmod)
AC_C99_FUNC_LRINT
AC_C99_FUNC_LRINTF
MN_C99_FUNC_LRINT
MN_C99_FUNC_LRINTF
#====================================================================================
# Check for requirements for building plugins for other languages/enviroments.
@ -295,45 +304,60 @@ EXTERNAL_LIBS=""
# Check for pkg-config outside the if statement.
PKG_PROG_PKG_CONFIG
#if test x$enable_external_libs = xno ; then
AC_MSG_WARN([[*** External libs (FLAC, Ogg, Vorbis) disabled. ***]])
#else
# PKG_CHECK_MOD_VERSION(FLAC, flac >= 1.2.1, ac_cv_flac=yes, ac_cv_flac=no)
# PKG_CHECK_MOD_VERSION(OGG, ogg >= 1.1.3, ac_cv_ogg=yes, ac_cv_ogg=no)
if test -n "$PKG_CONFIG" ; then
if test x$enable_external_libs = xno ; then
AC_MSG_WARN([[*** External libs (FLAC, Ogg, Vorbis) disabled. ***]])
else
PKG_CHECK_MOD_VERSION(FLAC, flac >= 1.2.1, ac_cv_flac=yes, ac_cv_flac=no)
# Vorbis versions earlier than 1.2.1 are not const correct at the API level.
# Vorbis 1.2.2 adds vorbis_version_string.
# PKG_CHECK_MOD_VERSION(VORBIS, vorbis >= 1.2.0, ac_cv_vorbis=yes, ac_cv_vorbis=no)
# PKG_CHECK_MOD_VERSION(VORBISENC, vorbisenc >= 1.2.0, ac_cv_vorbisenc=yes, ac_cv_vorbisenc=no)
# fi
# Make sure the FLAC_CFLAGS value is sane.
FLAC_CFLAGS=`echo $FLAC_CLFAGS | $SED "s/FLAC$//"`
HAVE_VORBIS_VERSION_STRING=0
if test x$ac_cv_flac$ac_cv_ogg$ac_cv_vorbis$ac_cv_vorbisenc = "xyesyesyesyes" ; then
PKG_CHECK_MOD_VERSION(OGG, ogg >= 1.1.3, ac_cv_ogg=yes, ac_cv_ogg=no)
save_LIBS="$LIBS"
LIBS="$VORBIS_LIBS $LIBS"
AC_CHECK_LIB(vorbis, vorbis_version_string, HAVE_VORBIS_VERSION_STRING=1)
LIBS="$save_LIBS"
if test x$enable_experimental = xyes ; then
PKG_CHECK_MOD_VERSION(SPEEX, speex >= 1.2, ac_cv_speex=yes, ac_cv_speex=no)
else
SPEEX_CFLAGS=""
SPEEX_LIBS=""
fi
HAVE_EXTERNAL_LIBS=1
enable_external_libs=yes
# Vorbis versions earlier than 1.2.3 have bugs that cause the libsndfile
# test suite to fail on MIPS, PowerPC and others.
# See: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=549899
PKG_CHECK_MOD_VERSION(VORBIS, vorbis >= 1.2.3, ac_cv_vorbis=yes, ac_cv_vorbis=no)
PKG_CHECK_MOD_VERSION(VORBISENC, vorbisenc >= 1.2.3, ac_cv_vorbisenc=yes, ac_cv_vorbisenc=no)
enable_external_libs=yes
fi
EXTERNAL_CFLAGS="$FLAC_CFLAGS $OGG_CFLAGS $VORBISENC_CFLAGS"
EXTERNAL_LIBS="$FLAC_LIBS $VORBISENC_LIBS"
else
enable_external_libs=no
if test x$ac_cv_flac$ac_cv_ogg$ac_cv_vorbis$ac_cv_vorbisenc = "xyesyesyesyes" ; then
HAVE_EXTERNAL_LIBS=1
enable_external_libs=yes
EXTERNAL_CFLAGS="$FLAC_CFLAGS $OGG_CFLAGS $VORBISENC_CFLAGS $SPEEX_CFLAGS"
EXTERNAL_LIBS="$FLAC_LIBS $VORBISENC_LIBS $SPEEX_LIBS"
else
echo
AC_MSG_WARN([[*** One or more of the external libraries (ie libflac, libogg and]])
AC_MSG_WARN([[*** libvorbis) is either missing (possibly only the development]])
AC_MSG_WARN([[*** headers) or is of an unsupported version.]])
AC_MSG_WARN([[***]])
AC_MSG_WARN([[*** Unfortunately, for ease of maintenance, the external libs]])
AC_MSG_WARN([[*** are an all or nothing affair.]])
echo
enable_external_libs=no
fi
fi
AC_DEFINE_UNQUOTED([HAVE_EXTERNAL_LIBS], $HAVE_EXTERNAL_LIBS, [Will be set to 1 if flac, ogg and vorbis are available.])
AC_DEFINE_UNQUOTED([HAVE_VORBIS_VERSION_STRING], $HAVE_VORBIS_VERSION_STRING, [Set to 1 if we have vorbis_version_string.])
#====================================================================================
# Check for libsqlite3 (only used in regtest).
ac_cv_sqlite3=no
#if test x$enable_sqlite != xno ; then
# PKG_CHECK_MOD_VERSION(SQLITE3, sqlite3 >= 3.2, ac_cv_sqlite3=yes, ac_cv_sqlite3=no)
# fi
if test x$enable_sqlite != xno ; then
PKG_CHECK_MOD_VERSION(SQLITE3, sqlite3 >= 3.2, ac_cv_sqlite3=yes, ac_cv_sqlite3=no)
fi
if test x$ac_cv_sqlite3 = "xyes" ; then
HAVE_SQLITE3=1
@ -343,24 +367,11 @@ else
AC_DEFINE_UNQUOTED([HAVE_SQLITE3],$HAVE_SQLITE3,[Set to 1 if you have libsqlite3.])
#====================================================================================
# Check for JACK (only used for examples/sndfile-jackplay).
#PKG_CHECK_MOD_VERSION(JACK, jack >= 0.100, ac_cv_jack=yes, ac_cv_jack=no)
if test x$ac_cv_jack = "xyes" ; then
HAVE_JACK=1
else
HAVE_JACK=0
fi
AC_DEFINE_UNQUOTED([HAVE_JACK],$HAVE_JACK,[Set to 1 if you have JACK.])
#====================================================================================
# Determine if the processor can do clipping on float to int conversions.
if test x$enable_cpu_clip != "xno" ; then
AC_C_CLIP_MODE
MN_C_CLIP_MODE
else
echo "checking processor clipping capabilities... disabled"
ac_cv_c_clip_positive=0
@ -384,7 +395,7 @@ use_windows_api=0
case "$host_os" in
darwin* | rhapsody*)
os_is_macosx=1
OS_SPECIFIC_CFLAGS="-fpascal-strings -I/Developer/Headers/FlatCarbon"
OS_SPECIFIC_CFLAGS="-I/Developer/Headers/FlatCarbon"
OS_SPECIFIC_LINKS="-framework CoreAudio"
;;
mingw*)
@ -398,6 +409,8 @@ AC_DEFINE_UNQUOTED(OS_IS_WIN32, ${os_is_win32}, [Set to 1 if compiling for Win32
AC_DEFINE_UNQUOTED(OS_IS_MACOSX, ${os_is_macosx}, [Set to 1 if compiling for MacOSX])
AC_DEFINE_UNQUOTED(USE_WINDOWS_API, ${use_windows_api}, [Set to 1 to use the native windows API])
AM_CONDITIONAL(USE_WIN_VERSION_FILE, test ${use_windows_api} -eq 1)
#====================================================================================
# Check for ALSA.
@ -411,6 +424,15 @@ if test x$enable_alsa != xno ; then
fi
fi
#====================================================================================
# Check for OpenBSD's sndio.
SNDIO_LIBS=""
AC_CHECK_HEADERS(sndio.h)
if test x$ac_cv_header_sndio_h = xyes ; then
SNDIO_LIBS="-lsndio"
fi
#====================================================================================
# Test for sanity when cross-compiling.
@ -477,32 +499,32 @@ win32_target_dll=0
COMPILER_IS_GCC=0
if test x$ac_cv_c_compiler_gnu = xyes ; then
AC_ADD_CFLAGS(-std=gnu99)
MN_ADD_CFLAGS(-std=gnu99)
AC_GCC_VERSION
MN_GCC_VERSION
if test "x$GCC_MAJOR_VERSION$GCC_MINOR_VERSION" = "x42" ; then
# AC_MSG_WARN([****************************************************************])
# AC_MSG_WARN([** GCC version 4.2 warns about the inline keyword for no good **])
# AC_MSG_WARN([** reason but the maintainers do not see it as a bug. **])
# AC_MSG_WARN([** See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33995 **])
# AC_MSG_WARN([** Using -fgnu-inline to avoid this stupidity. **])
# AC_MSG_WARN([****************************************************************])
AC_ADD_CFLAGS([-fgnu89-inline])
AC_MSG_WARN([****************************************************************])
AC_MSG_WARN([** GCC version 4.2 warns about the inline keyword for no good **])
AC_MSG_WARN([** reason but the maintainers do not see it as a bug. **])
AC_MSG_WARN([** See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33995 **])
AC_MSG_WARN([** Using -fgnu-inline to avoid this stupidity. **])
AC_MSG_WARN([****************************************************************])
MN_ADD_CFLAGS([-fgnu89-inline])
fi
CFLAGS="$CFLAGS -Wall"
CXXFLAGS="$CXXFLAGS -Wall"
# AC_ADD_CFLAGS([-Wextra])
MN_ADD_CFLAGS([-Wextra])
AC_LANG_PUSH([C++])
# AC_ADD_CXXFLAGS([-Wextra])
MN_ADD_CXXFLAGS([-Wextra])
AC_LANG_POP([C++])
AC_ADD_CFLAGS([-Wdeclaration-after-statement])
AC_ADD_CFLAGS([-Wpointer-arith])
AC_ADD_CFLAGS([-funsigned-char])
MN_ADD_CFLAGS([-Wdeclaration-after-statement])
MN_ADD_CFLAGS([-Wpointer-arith])
MN_ADD_CFLAGS([-funsigned-char])
if test x$enable_gcc_werror = "xyes" ; then
CFLAGS="-Werror $CFLAGS"
@ -510,16 +532,16 @@ if test x$ac_cv_c_compiler_gnu = xyes ; then
fi
if test x$enable_test_coverage = "xyes" ; then
# AC_ADD_CFLAGS([-ftest-coverage])
AC_ADD_CFLAGS([-coverage])
# MN_ADD_CFLAGS([-ftest-coverage])
MN_ADD_CFLAGS([-coverage])
fi
CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Waggregate-return -Wcast-align -Wcast-qual -Wnested-externs -Wshadow -Wbad-function-cast -Wwrite-strings "
CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Waggregate-return -Wcast-align -Wcast-qual -Wnested-externs -Wshadow -Wbad-function-cast -Wwrite-strings -Wundef "
# -Wundef -Wmissing-declarations -Winline -Wconversion"
CXXFLAGS="$CXXFLAGS -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wreorder -Wsign-promo "
CXXFLAGS="$CXXFLAGS -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wreorder -Wsign-promo -Wundef "
if test "x$enable_gcc_opt" = "xno" ; then
temp_CFLAGS=`echo $CFLAGS | sed "s/O2/O0/"`
temp_CFLAGS=`echo $CFLAGS | $SED "s/O2/O0/"`
CFLAGS=$temp_CFLAGS
AC_MSG_WARN([[*** Compiler optimisations switched off. ***]])
fi
@ -529,12 +551,12 @@ if test x$ac_cv_c_compiler_gnu = xyes ; then
darwin* | rhapsody*)
# Disable -Wall, -pedantic and -Wshadow for Apple Darwin/Rhapsody.
# System headers on these systems are broken.
temp_CFLAGS=`echo $CFLAGS | sed "s/-Wall -pedantic//" | sed "s/-Wshadow//" | sed "s/-Waggregate-return//"`
temp_CFLAGS=`echo $CFLAGS | $SED "s/-Wall -pedantic//" | $SED "s/-Wshadow//" | $SED "s/-Waggregate-return//"`
CFLAGS=$temp_CFLAGS
SHLIB_VERSION_ARG="-Wl,-exported_symbols_list -Wl,\$(srcdir)/Symbols.darwin"
;;
linux*)
SHLIB_VERSION_ARG="-Wl,--version-script=\$(srcdir)/Symbols.linux"
linux*|kfreebsd*-gnu*|gnu*)
SHLIB_VERSION_ARG="-Wl,--version-script=\$(srcdir)/Symbols.gnu-binutils"
;;
mingw*)
# Linker flag '-Wl,--out-implib' does not work with mingw cross compiler
@ -560,34 +582,6 @@ if test x$ac_cv_c_compiler_gnu = xyes ; then
AC_DEFINE_UNQUOTED([WIN32_TARGET_DLL], ${win32_target_dll}, [Set to 1 if windows DLL is being built.])
AC_DEFINE_UNQUOTED([COMPILER_IS_GCC], ${COMPILER_IS_GCC}, [Set to 1 if the compile is GNU GCC.])
AC_DEFUN([AX_COMPILER_VENDOR],
[
AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor,
[ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=unknown
# note: don't check for gcc first since some other compilers define __GNUC__
for ventest in intel:__ICC,__ECC,__INTEL_COMPILER ibm:__xlc__,__xlC__,__IBMC__,__IBMCPP__ gnu:__GNUC__ sun:__SUNPRO_C,__SUNPRO_CC hp:__HP_cc,__HP_aCC dec:__DECC,__DECCXX,__DECC_VER,__DECCXX_VER borland:__BORLANDC__,__TURBOC__ comeau:__COMO__ cray:_CRAYC kai:__KCC lcc:__LCC__ metrowerks:__MWERKS__ sgi:__sgi,sgi microsoft:_MSC_VER watcom:__WATCOMC__ portland:__PGI; do
vencpp="defined("`echo $ventest | cut -d: -f2 | sed 's/,/) || defined(/g'`")"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[
#if !($vencpp)
thisisanerror;
#endif
])], [ax_cv_]_AC_LANG_ABBREV[_compiler_vendor=`echo $ventest | cut -d: -f1`; break])
done
])
])
AX_COMPILER_VENDOR
# Enable 64 bit build
AC_ARG_ENABLE(64,
[AC_HELP_STRING([--enable-64],[build with 64 bit support])],[enable_64="$enable_64"],[enable_64="no"])
if test "x${ax_cv_c_compiler_vendor}" = "xsun" ; then
if test "${enable_64}" = "yes"; then
CFLAGS="$CFLAGS -m64"
fi
fi
CFLAGS="$CFLAGS $OS_SPECIFIC_CFLAGS"
@ -596,43 +590,51 @@ if test x"$CFLAGS" = x ; then
exit
fi
HOST_TRIPLET="${host_cpu}-${host_vendor}-${host_os}"
if test "$HOST_TRIPLET" = "x86_64-w64-mingw32" ; then
OS_SPECIFIC_LINKS=" -static-libgcc $OS_SPECIFIC_LINKS"
fi
WIN_RC_VERSION=`echo $PACKAGE_VERSION | $SED -e "s/p.*//" -e "s/\./,/g"`
#-------------------------------------------------------------------------------
AC_SUBST(HOST_TRIPLET)
AC_SUBST(htmldocdir)
AC_SUBST(HTML_BGCOLOUR)
AC_SUBST(HTML_FGCOLOUR)
AC_SUBST(SHLIB_VERSION_ARG)
AC_SUBST(SHARED_VERSION_INFO)
AC_SUBST(CLEAN_VERSION)
AC_SUBST(WIN_RC_VERSION)
AC_SUBST(OS_SPECIFIC_CFLAGS)
AC_SUBST(OS_SPECIFIC_LINKS)
AC_SUBST(ALSA_LIBS)
AC_SUBST(ENABLE_EXPERIMENTAL_CODE)
AC_SUBST(SNDIO_LIBS)
AC_SUBST(EXTERNAL_CFLAGS)
AC_SUBST(EXTERNAL_LIBS)
AC_SUBST(COMPILER_IS_GCC)
AC_SUBST(GCC_MAJOR_VERSION)
AC_SUBST(HAVE_JACK)
dnl The following line causes the libtool distributed with the source
dnl to be replaced if the build system has a more recent version.
AC_SUBST(LIBTOOL_DEPS)
AC_CONFIG_FILES([ \
src/sndfile.h src/Makefile src/GSM610/Makefile src/G72x/Makefile \
man/Makefile examples/Makefile tests/Makefile regtest/Makefile \
M4/Makefile doc/Makefile Win32/Makefile Octave/Makefile \
programs/Makefile doc/libsndfile.css \
Makefile libsndfile.spec sndfile.pc \
tests/test_wrapper.sh \
src/Makefile man/Makefile examples/Makefile tests/Makefile regtest/Makefile \
M4/Makefile doc/Makefile Win32/Makefile Octave/Makefile programs/Makefile \
Makefile \
src/version-metadata.rc tests/test_wrapper.sh tests/pedantic-header-test.sh \
doc/libsndfile.css build-test-tarball.mk libsndfile.spec sndfile.pc \
src/sndfile.h \
])
AC_OUTPUT
# Make it executable.
chmod u+x tests/test_wrapper.sh
# Make sure these are executable.
chmod u+x tests/test_wrapper.sh build-test-tarball.mk
#====================================================================================
@ -641,19 +643,34 @@ AC_MSG_RESULT([
Configuration summary :
Version : ............................. ${VERSION}
libsndfile version : .................. ${VERSION}
Host CPU : ............................ ${host_cpu}
Host Vendor : ......................... ${host_vendor}
Host OS : ............................. ${host_os}
Experimental code : ................... ${enable_experimental:-no}
Using ALSA in example programs : ...... ${enable_alsa:-no}
External FLAC/Ogg/Vorbis : ............ ${enable_external_libs:-no}
])
if test -z "$PKG_CONFIG" ; then
echo " *****************************************************************"
echo " *** The pkg-config program is missing. ***"
echo " *** External FLAC/Ogg/Vorbis libs cannot be found without it. ***"
echo " *** http://pkg-config.freedesktop.org/wiki/ ***"
echo " *****************************************************************"
echo
fi
if test x$ac_cv_c_compiler_gnu = xyes ; then
echo -e " Tools :\n"
echo " Tools :"
echo
echo " Compiler is GCC : ..................... ${ac_cv_c_compiler_gnu}"
echo " GCC version : ......................... ${GCC_VERSION}"
if test $GCC_MAJOR_VERSION -lt 3 ; then
echo -e "\n ** This compiler version allows applications to write"
echo "\n"
echo " ** This compiler version allows applications to write"
echo " ** to static strings within the library."
echo " ** Compile with GCC version 3.X or above to avoid this problem."
fi
@ -678,8 +695,9 @@ AC_MSG_RESULT([[
if test x$prefix != "x/usr" ; then
echo "Compiling some other packages against libsndfile may require"
echo -e "the addition of \"$libdir/pkgconfig\" to the"
echo -e "PKG_CONFIG_PATH environment variable.\n"
echo "the addition of '$libdir/pkgconfig' to the"
echo "PKG_CONFIG_PATH environment variable."
echo
fi
(cd src && make genfiles)

View File

@ -8,65 +8,69 @@
<META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
<META NAME="Description" CONTENT="The libsndfile FAQ.">
<META NAME="Keywords" CONTENT="WAV AIFF AU libsndfile sound audio dsp Linux">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>
<H1><B>libsndfile : Frequently Asked Questions.</B></H1>
<P>
<A HREF="#Q001">Q1 : Do you plan to support XYZ codec in libsndfile?</A><BR>
<A HREF="#Q001">Q1 : Do you plan to support XYZ codec in libsndfile?</A><BR/>
<A HREF="#Q002">Q2 : In version 0 the SF_INFO struct had a pcmbitwidth field
but version 1 does not. Why?</A><BR>
<A HREF="#Q003">Q3 : Compiling is really slow on MacOSX. Why?</A><BR>
but version 1 does not. Why?</A><BR/>
<A HREF="#Q003">Q3 : Compiling is really slow on MacOS X. Why?</A><BR/>
<A HREF="#Q004">Q4 : When trying to compile libsndfile on Solaris I get a "bad
substitution" error during linking. What can I do to fix this?</A><BR>
<A HREF="#Q005">Q5 : Why doesn't libsndfile do interleaving/de-interleaving?</A><BR>
<A HREF="#Q006">Q6 : What's the best format for storing temporary files?</A><BR>
<A HREF="#Q007">Q7 : On Linux/Unix/MacOSX, what's the best way of detecting the
presence of libsndfile?</A><BR>
<A HREF="#Q008">Q8 : But I just want a simple Makefile! What do I do?</A><BR>
substitution" error during linking. What can I do to fix this?</A><BR/>
<A HREF="#Q005">Q5 : Why doesn't libsndfile do interleaving/de-interleaving?</A><BR/>
<A HREF="#Q006">Q6 : What's the best format for storing temporary files?</A><BR/>
<A HREF="#Q007">Q7 : On Linux/Unix/MacOS X, what's the best way of detecting the
presence of libsndfile?</A><BR/>
<A HREF="#Q008">Q8 : But I just want a simple Makefile! What do I do?</A><BR/>
<A HREF="#Q009">Q9 : How about adding the ability to write/read sound files to/from
memory buffers?</A><BR>
memory buffers?</A><BR/>
<A HREF="#Q010">Q10 : Reading a 16 bit PCM file as normalised floats and then
writing them back changes some sample values. Why?</A><BR>
writing them back changes some sample values. Why?</A><BR/>
<A HREF="#Q011">Q11 : I'm having problems with u-law encoded WAV files generated by
libsndfile in Winamp. Why?</A><BR>
<A HREF="#Q012">Q12 : I'm looking at sf_read*. What are items? What are frames?</A><BR>
libsndfile in Winamp. Why?</A><BR/>
<A HREF="#Q012">Q12 : I'm looking at sf_read*. What are items? What are frames?</A><BR/>
<A HREF="#Q013">Q13 : Why can't libsndfile open this Sound Designer II (SD2)
file?</A><BR>
file?</A><BR/>
<A HREF="#Q014">Q14 : I'd like to statically link libsndfile to my closed source
application. Can I buy a license so that this is possible?</A><BR>
application. Can I buy a license so that this is possible?</A><BR/>
<A HREF="#Q015">Q15 : My program is crashing during a call to a function in libsndfile.
Is this a bug in libsndfile?</A><BR>
Is this a bug in libsndfile?</A><BR/>
<A HREF="#Q016">Q16 : Will you accept a fix for compiling libsndfile with compiler X?
</A><BR>
</A><BR/>
<A HREF="#Q017">Q17 : Can libsndfile read/write files from/to UNIX pipes?
</A><BR>
<A HREF="#Q018">Q18 : Is it possible to build a Universal Binary on Mac OSX?
</A><BR>
</A><BR/>
<A HREF="#Q018">Q18 : Is it possible to build a Universal Binary on Mac OS X?
</A><BR/>
<A HREF="#Q019">Q19 : I have project files for Visual Studio / XCode / Whatever. Why
don't you distribute them with libsndfile?
</A><BR>
</A><BR/>
<A HREF="#Q020">Q20 : Why doesn't libsndfile support MP3? Lots of other Open Source
projects support it!
</A><BR>
</A><BR/>
<A HREF="#Q021">Q21 : How do I use libsndfile in a closed source or commercial program
and comply with the license?
</A><BR>
</A><BR/>
<A HREF="#Q022">Q22 : What versions of windows does libsndfile work on?
</A><BR>
</A><BR/>
<A HREF="#Q023">Q23 : I'm cross compiling libsndfile for another platform. How can I
run the test suite?
</A><BR/>
<HR>
<!-- ========================================================================= -->
<A NAME="Q001"></A>
<H2><BR><B>Q1 : Do you plan to support XYZ codec in libsnfile?</B></H2>
<H2><BR/><B>Q1 : Do you plan to support XYZ codec in libsndfile?</B></H2>
<P>
If source code for XYZ codec is available under a suitable license (LGPL, BSD,
MIT etc) then yes, I'd like to add it.
</P>
<P>
If suitable documentation is available on how to decode and enocde the format
If suitable documentation is available on how to decode and encode the format
then maybe, depending on how much work is involved.
</P>
<P>
@ -80,7 +84,7 @@ If you can't find either then the answer is no.
</P>
<!-- ========================================================================= -->
<A NAME="Q002"></A>
<H2><BR><B>Q2 : In version 0 the SF_INFO struct had a pcmbitwidth field
<H2><BR/><B>Q2 : In version 0 the SF_INFO struct had a pcmbitwidth field
but version 1 does not. Why?</B></H2>
<P>
This was dropped for a number of reasons:
@ -92,49 +96,49 @@ If you can't find either then the answer is no.
<P>
As documented
<A HREF="http://www.mega-nerd.com/libsndfile/api.html#note1">here</A>
there is now a well defined behavior which ensures that no matter what the
there is now a well defined behaviour which ensures that no matter what the
bit width of the source file, the scaling always does something sensible.
This makes it safe to read 8, 16, 24 and 32 bit PCM files using sf_read_short()
and always have the optimal behavior.
and always have the optimal behaviour.
</P>
<!-- ========================================================================= -->
<A NAME="Q003"></A>
<H2><BR><B>Q3 : Compiling is really slow on MacOSX. Why?</B></H2>
<H2><BR/><B>Q3 : Compiling is really slow on MacOS X. Why?</B></H2>
<P>
When you configure and compile libsndfile, it uses the /bin/sh shell for a number
of tasks (ie configure script and libtool).
Older versions of OSX (10.2?) shipped a a really crappy Bourne shell as /bin/sh
Older versions of OS X (10.2?) shipped a really crappy Bourne shell as /bin/sh
which resulted in <b>really</b> slow compiles.
New version of OSX ship GNU BASh as /bin/sh and this answer doesn't apply in that
Newer version of OS X ship GNU Bash as /bin/sh and this answer doesn't apply in that
case.
</P>
<P>
To fix this I suggest that you install the GNU Bash shell, rename /bin/sh to
/bin/sh.old and make a softlink from /bin/sh to the bash shell.
/bin/sh.old and make a symlink from /bin/sh to the bash shell.
Bash is designed to behave as a Bourne shell when is is called as /bin/sh.
</P>
<P>
When I did this on my iBook running MacOSX, compile times dropped from 13 minutes
When I did this on my iBook running MacOS X, compile times dropped from 13 minutes
to 3 minutes.
</P>
<!-- ========================================================================= -->
<A NAME="Q004"></A>
<H2><BR><B>Q4 : When trying to compile libsndfile on Solaris I get a "bad
<H2><BR/><B>Q4 : When trying to compile libsndfile on Solaris I get a "bad
substitution" error on linking. Why?</B></H2>
<P>
It seems that the Solaris Bourne shell disagrees with GNU libtool.
</P>
<P>
To fix this I suggest that you install the GNU Bash shell, rename /bin/sh to
/bin/sh.old and make a softlink from /bin/sh to the bash shell.
/bin/sh.old and make a symlink from /bin/sh to the bash shell.
Bash is designed to behave as a Bourne shell when is is called as /bin/sh.
</P>
<!-- ========================================================================= -->
<A NAME="Q005"></A>
<H2><BR><B>Q5 : Why doesn't libsndfile do interleaving/de-interleaving?</B></H2>
<H2><BR/><B>Q5 : Why doesn't libsndfile do interleaving/de-interleaving?</B></H2>
<P>
This problem is bigger than it may seem at first.
</P>
@ -143,7 +147,7 @@ For a stereo file, it is a pretty safe bet that a simple interleaving/de-interle
could satisfy most users.
However, for files with more than 2 channels this is unlikely to be the case.
If the user has a 4 channel file and want to play that file on a stereo output
sound card they either want the first two channels or they want some mixed combination
sound card they either want the first 2 channels or they want some mixed combination
of the 4 channels.
</P>
<P>
@ -156,7 +160,7 @@ This means that this feature will not be added any time soon.
<!-- ========================================================================= -->
<A NAME="Q006"></A>
<H2><BR><B>Q6 : What's the best format for storing temporary files?</B></H2>
<H2><BR/><B>Q6 : What's the best format for storing temporary files?</B></H2>
<P>
When you want to store temporary data there are a number of requirements;
@ -184,7 +188,7 @@ regardless of the host CPU.
<!-- ========================================================================= -->
<A NAME="Q007"></A>
<H2><BR><B>Q7 : On Linux/Unix/MaxOSX, what's the best way of detecting the presence
<H2><BR/><B>Q7 : On Linux/Unix/MaxOS X, what's the best way of detecting the presence
of libsndfile using autoconf?</B></H2>
<P>
@ -242,7 +246,7 @@ libsndfile configure process. For instance on my system I get this:
<!-- ========================================================================= -->
<A NAME="Q008"></A>
<H2><BR><B>Q8 : But I just want a simple Makefile! What do I do?</B></H2>
<H2><BR/><B>Q8 : But I just want a simple Makefile! What do I do?</B></H2>
<P>
The <B>pkg-config</B> program makes finding the correct compiler flag values and
@ -277,7 +281,7 @@ the command would be:
<!-- ========================================================================= -->
<A NAME="Q009"></A>
<H2><BR><B>Q9 : How about adding the ability to write/read sound files to/from
<H2><BR/><B>Q9 : How about adding the ability to write/read sound files to/from
memory buffers?</B></H2>
<P>
@ -287,7 +291,7 @@ This has been added for version 1.0.13.
<!-- ========================================================================= -->
<A NAME="Q010"></A>
<H2><BR><B>Q10 : Reading a 16 bit PCM file as normalised floats and then
<H2><BR/><B>Q10 : Reading a 16 bit PCM file as normalised floats and then
writing them back changes some sample values. Why?</B></H2>
<P>
@ -352,7 +356,7 @@ storage format (and which is also supported by most common file types).
<!-- ========================================================================= -->
<A NAME="Q011"></A>
<H2><BR><B>Q11 : I'm having problems with u-law encoded WAV files generated by
<H2><BR/><B>Q11 : I'm having problems with u-law encoded WAV files generated by
libsndfile in Winamp. Why?
</B></H2>
@ -381,21 +385,47 @@ is the risk of breaking something that currently works.
<!-- ========================================================================= -->
<A NAME="Q012"></A>
<H2><BR><B>Q12 : I'm looking at sf_read*. What are items? What are frames?
<H2><BR/><B>Q12 : I'm looking at sf_read*. What are items? What are frames?
</B></H2>
<P>
For a sound file with only one channel, a frame is the same as a item.
An <tt>item</tt>tt> is a single sample of the data type you are reading; ie a
single <tt>short</tt> value for <tt>sf_read_short</tt> or a single <tt>float</tt>
for <tt>sf_read_float</tt>.
</P>
For a sound file with only one channel, a frame is the same as a item (ie a
single sample) while for multi channel sound files, a single frame contains a
single item for each channel.
</P>
<P>
For multi channel sound files, a single frame contains a single item for
each channel.
Here are two simple, correct examples, both of which are assumed to be working
on a stereo file, first using items:
</P>
<PRE>
#define CHANNELS 2
short data [CHANNELS * 100] ;
sf_count items_read = sf_read_short (file, data, 200) ;
assert (items_read == 200) ;
</PRE>
<P>
and now readng the exact same amount of data using frames:
</P>
<PRE>
#define CHANNELS 2
short data [CHANNELS * 100] ;
sf_count frames_read = sf_readf_short (file, data, 100) ;
assert (frames_read == 100) ;
</PRE>
<!-- ========================================================================= -->
<A NAME="Q013"></A>
<H2><BR><B>Q13 : Why can't libsndfile open this Sound Designer II (SD2) file?
<H2><BR/><B>Q13 : Why can't libsndfile open this Sound Designer II (SD2) file?
</B></H2>
<P>
@ -407,7 +437,7 @@ First some background.
SD2 files are native to the Apple Macintosh platform and use features of
the Mac filesystem (file resource forks) to store the file's sample rate,
number of channels, sample width and more.
When you look at a file and its resource fork on Mac OSX it looks like
When you look at a file and its resource fork on Mac OS X it looks like
this:
</P>
@ -419,7 +449,7 @@ this:
<P>
Notice how the file itself looks like a directory containing a single file
named <B>rsrc</B>.
When libsndfile is compiled for MacOSX, it should open (for write and read)
When libsndfile is compiled for MacOS X, it should open (for write and read)
SD2 file with resource forks like this without any problems.
It will also handle files with the resource fork in a separate file as
described below.
@ -436,8 +466,8 @@ libsndfile to open the file.
<P>
However, it is possible to safely move an SD2 file to a Linux or Windows
machine.
For instance, when an SD2 file is copied from inside MacOSX to a windows
shared directory or a Samba share (ie Linux), MacOSX is clever enough to
For instance, when an SD2 file is copied from inside MacOS X to a windows
shared directory or a Samba share (ie Linux), MacOS X is clever enough to
store the resource fork of the file in a separate hidden file in the
same directory like this:
</P>
@ -475,7 +505,7 @@ files are.
<!-- ========================================================================= -->
<A NAME="Q014"></A>
<H2><BR><B>Q14 : I'd like to statically link libsndfile to my closed source
<H2><BR/><B>Q14 : I'd like to statically link libsndfile to my closed source
application. Can I buy a license so that this is possible?
</B></H2>
@ -494,7 +524,7 @@ library is if your application is released under the GNU GPL or LGPL.
<!-- ========================================================================= -->
<A NAME="Q015"></A>
<H2><BR><B>Q15 : My program is crashing during a call to a function in libsndfile.
<H2><BR/><B>Q15 : My program is crashing during a call to a function in libsndfile.
Is this a bug in libsndfile?
</B></H2>
@ -527,7 +557,7 @@ following:
<!-- ========================================================================= -->
<A NAME="Q016"></A>
<H2><BR><B>Q16 : Will you accept a fix for compiling libsndfile with compiler X?
<H2><BR/><B>Q16 : Will you accept a fix for compiling libsndfile with compiler X?
</B></H2>
<P>
@ -548,7 +578,7 @@ This can make compiling libsndfile with some older compilers difficult.
<!-- ========================================================================= -->
<A NAME="Q017"></A>
<H2><BR><B>Q17 : Can libsndfile read/write files from/to UNIX pipes?
<H2><BR/><B>Q17 : Can libsndfile read/write files from/to UNIX pipes?
</B></H2>
<P>
@ -583,7 +613,7 @@ See also <A HREF="#Q006">FAQ Q6</A>.
<!-- ========================================================================= -->
<A NAME="Q018"></A>
<H2><BR><B>Q18 : Is it possible to build a Universal Binary on Mac OSX?
<H2><BR/><B>Q18 : Is it possible to build a Universal Binary on Mac OS X?
</B></H2>
<P>
@ -644,7 +674,7 @@ libsndfile is currently working on.
<!-- ========================================================================= -->
<A NAME="Q019"></A>
<H2><BR><B>Q19 : I have project files for Visual Studio / XCode / Whatever. Why
<H2><BR/><B>Q19 : I have project files for Visual Studio / XCode / Whatever. Why
don't you distribute them with libsndfile?
</B></H2>
@ -674,7 +704,7 @@ fixing or even testing it.
<P>
I currently release sources that I personally test on Win32, Linux and
MacOSX (PowerPC) using the compiler I trust (GNU GCC).
MacOS X (PowerPC) using the compiler I trust (GNU GCC).
Supporting one compiler on three (actually much more because GCC is available
almost everywhere) platforms is doable without too much pain.
I also release binaries for Win32 with instructions on how to use those
@ -696,7 +726,7 @@ Hence, I'm not willing to enter into an arrangement like that again.
<!-- ========================================================================= -->
<A NAME="Q020"></A>
<H2><BR><B>Q20 : Why doesn't libsndfile support MP3? Lots of other Open Source
<H2><BR/><B>Q20 : Why doesn't libsndfile support MP3? Lots of other Open Source
projects support it!
</B></H2>
@ -734,7 +764,7 @@ John ffitch of the Csound project) in version 1.0.18.
<!-- ========================================================================= -->
<A NAME="Q021"></A>
<H2><BR><B>Q21 : How do I use libsndfile in a closed source or commercial program
<H2><BR/><B>Q21 : How do I use libsndfile in a closed source or commercial program
and comply with the license?
</B></H2>
@ -746,7 +776,7 @@ released under, the GNU Lesser General Public License (LGPL):
<ul>
<li>Make sure you are linking to libsndfile as a shared library (Linux and Unix
systems), Dynamic Link Library (Microsoft Windows) or dynlib (Mac OSX).
systems), Dynamic Link Library (Microsoft Windows) or dynlib (Mac OS X).
If you are using some other operating system that doesn't allow dynamically
linked libraries, you will not be able to use libsndfile unless you release
the source code to your program.
@ -762,28 +792,57 @@ released under, the GNU Lesser General Public License (LGPL):
<!-- ========================================================================= -->
<A NAME="Q022"></A>
<H2><BR><B>Q22 : What versions of windows does libsndfile work on?
<H2><BR/><B>Q22 : What versions of Windows does libsndfile work on?
</B></H2>
<p>
Currently the precompiled windows binaries are tested in Windows XP.
Currently the precompiled windows binaries are thoroughly tested on Windows XP.
As such, they should also work on Win2k and Windows Vista.
They may also work on earlier versions of windows.
They may also work on earlier versions of Windows.
</p>
<p>
libsndfile does not yet work on 64 bit versions of windows.
Support for 64 bit versions of WinXP and Vista is likely to be working some
time late in 2008.
Since version 0.1.18 I have also been releasing precompiled binaries for Win64,
the 64 bit version of Windows.
These binaries have received much less testing than the 32 bit versions, but
should work as expected.
I'd be very interested in receiving feedback on these binaries.
</p>
<!-- ========================================================================= -->
<A NAME="Q023"></A>
<H2><BR/><B>Q23 : I'm cross compiling libsndfile for another platform. How can I
run the test suite?
</B></H2>
<p>
</p>
<p>
Since version 1.0.21 the top level Makefile has an extra make target,
'test-tarball'.
Building this target creates a tarball called called:
</p>
<center><tt>
libsndfile-testsuite-${host_triplet}-${version}.tar.gz
</tt></center>
<p>
in the top level directory.
This tarball can then be copied to the target platform.
Once untarred and test script <tt>test_wrapper.sh</tt> can be run from
the top level of the extracted tarball.
</p>
<!-- ========================================================================= -->
<HR>
<P>
The libsndfile home page is here :
<A HREF="http://www.mega-nerd.com/libsndfile/">
http://www.mega-nerd.com/libsndfile/</A>.
<BR>
Version : 1.0.19
<BR/>
Version : 1.0.25
</P>
</BODY>

View File

@ -3,12 +3,13 @@
<HEAD>
<TITLE>
The libsndfile API.
The libsndfile API
</TITLE>
<META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
<META NAME="Description" CONTENT="The libsndfile API.">
<META NAME="Keywords" CONTENT="WAV AIFF AU libsndfile sound audio dsp Linux">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>
@ -34,9 +35,15 @@
unambiguous.
However, since maintaining the documentation is the least fun part of working
on libsndfile, these docs can and do fall behind the behaviour of library.
If any errors omissions or ambiguities are found, please notify
<A HREF="m&#97;ilt&#111;:&#101;rikd&#64;z&#105;p.&#99;om.au">
Erik de Castro Lopo</a>.
If any errors, omissions or ambiguities are found, please notify me (erikd)
at mega-nerd dot com.
</P>
<!-- pepper -->
<P>
To supplement this reference documentation, there are simple example programs
included in the source code tarball.
The test suite which is also part of the source code tarball is also a good
place to look for the correct usage of the library functions.
</P>
<!-- pepper -->
<P>
@ -46,7 +53,7 @@
</B>
</P>
<H2><B>SYNOPSIS</B></H2>
<H2><B>Synopsis</B></H2>
<P>
The functions of libsndfile are defined as follows:
</P>
@ -57,7 +64,7 @@ The functions of libsndfile are defined as follows:
SNDFILE* <A HREF="#open">sf_open</A> (const char *path, int mode, SF_INFO *sfinfo) ;
SNDFILE* <A HREF="#open_fd">sf_open_fd</A> (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
SNDFILE* <A HREF="#open_virtual">sf_open_virtual</A> (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data) ;
int <A HREF="#check">sf_format_check</A> (const SF_INFO *info) ;
sf_count_t <A HREF="#seek">sf_seek</A> (SNDFILE *sndfile, sf_count_t frames, int whence) ;
@ -186,6 +193,10 @@ Not all combinations of endian-ness and major and minor file types are valid.
SF_FORMAT_SD2 = 0x160000, /* Sound Designer 2 */
SF_FORMAT_FLAC = 0x170000, /* FLAC lossless file format */
SF_FORMAT_CAF = 0x180000, /* Core Audio File format */
SF_FORMAT_WVE = 0x190000, /* Psion WVE format */
SF_FORMAT_OGG = 0x200000, /* Xiph OGG container */
SF_FORMAT_MPC2K = 0x210000, /* Akai MPC 2000 sampler */
SF_FORMAT_RF64 = 0x220000, /* RF64 WAV file */
/* Subtypes from here on. */
@ -219,6 +230,8 @@ Not all combinations of endian-ness and major and minor file types are valid.
SF_FORMAT_DPCM_8 = 0x0050, /* 8 bit differential PCM (XI only) */
SF_FORMAT_DPCM_16 = 0x0051, /* 16 bit differential PCM (XI only) */
SF_FORMAT_VORBIS = 0x0060, /* Xiph Vorbis encoding. */
/* Endian-ness options. */
SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */
@ -238,10 +251,12 @@ memory allocated during the call to sf_open().
</P>
<!-- pepper -->
<P>
On success, the sf_open function returns a non NULL pointer which should be
On success, the sf_open function returns a non-NULL pointer which should be
passed as the first parameter to all subsequent libsndfile calls dealing with
that audio file.
On fail, the sf_open function returns a NULL pointer.
An explanation of the error can obtained by passing NULL to
<A HREF="#error">sf_strerror</A>.
</P>
<A NAME="open_fd"></A>
@ -251,6 +266,11 @@ On fail, the sf_open function returns a NULL pointer.
SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
</PRE>
<P>
<b>Note:</b> On Microsoft Windows, this function does not work if the
application and the libsndfile DLL are linked to different versions of the
Microsoft C runtime DLL.
</P>
<P>
The second open function takes a file descriptor of a file that has already been
opened.
@ -280,12 +300,92 @@ parameter was TRUE when the sf_open_fd() function was called.
</P>
<P>
On success, the sf_open_fd function returns a non NULL pointer which should be
On success, the sf_open_fd function returns a non-NULL pointer which should be
passed as the first parameter to all subsequent libsndfile calls dealing with
that audio file.
On fail, the sf_open_fd function returns a NULL pointer.
</P>
<A NAME="open_virtual"></A>
<h3><b>Virtual File Open Function</b></h3>
<pre>
SNDFILE* sf_open_virtual (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data) ;
</pre>
<p>
Opens a soundfile from a virtual file I/O context which is provided
by the caller. This is usually used to interface libsndfile to a stream or buffer
based system. Apart from the sfvirtual and the user_data parameters this function behaves
like <a href="#open">sf_open</a>.
</p>
<pre>
typedef struct
{ sf_vio_get_filelen get_filelen ;
sf_vio_seek seek ;
sf_vio_read read ;
sf_vio_write write ;
sf_vio_tell tell ;
} SF_VIRTUAL_IO ;
</pre>
<p>
Libsndfile calls the callbacks provided by the SF_VIRTUAL_IO structure when opening, reading
and writing to the virtual file context. The user_data pointer is a user defined context which
will be available in the callbacks.
</p>
<pre>
typedef sf_count_t (*sf_vio_get_filelen) (void *user_data) ;
typedef sf_count_t (*sf_vio_seek) (sf_count_t offset, int whence, void *user_data) ;
typedef sf_count_t (*sf_vio_read) (void *ptr, sf_count_t count, void *user_data) ;
typedef sf_count_t (*sf_vio_write) (const void *ptr, sf_count_t count, void *user_data) ;
typedef sf_count_t (*sf_vio_tell) (void *user_data) ;
</pre>
<h4>sf_vio_get_filelen</h4>
<pre>
typedef sf_count_t (*sf_vio_get_filelen) (void *user_data) ;
</pre>
<p>
The virtual file contex must return the length of the virtual file in bytes.<br>
</p>
<h4>sf_vio_seek</h4>
<pre>
typedef sf_count_t (*sf_vio_seek) (sf_count_t offset, int whence, void *user_data) ;
</pre>
<p>
The virtual file context must seek to offset using the seek mode provided by whence which is one of<br>
</p>
<pre>
SEEK_CUR
SEEK_SET
SEEK_END
</pre>
<p>
The return value must contain the new offset in the file.
</p>
<h4>sf_vio_read</h4>
<pre>
typedef sf_count_t (*sf_vio_read) (void *ptr, sf_count_t count, void *user_data) ;
</pre>
<p>
The virtual file context must copy ("read") "count" bytes into the
buffer provided by ptr and return the count of actually copied bytes.
</p>
<h4>sf_vio_write</h4>
<pre>
typedef sf_count_t (*sf_vio_write) (const void *ptr, sf_count_t count, void *user_data) ;
</pre>
<p>
The virtual file context must process "count" bytes stored in the
buffer passed with ptr and return the count of actually processed bytes.<br>
</p>
<h4>sf_vio_tell</h4>
<pre>
typedef sf_count_t (*sf_vio_tell) (void *user_data) ;
</pre>
<p>
Return the current position of the virtual file context.<br>
</p>
<A NAME="check"></A>
<BR><H2><B>Format Check Function</B></H2>
@ -541,6 +641,12 @@ same as the frames parameter).
sf_count_t sf_write_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
</PRE>
<P>
<b>Note:</b> Unless you are writing an external decoder/encode that uses
libsndfile to handle the file headers, you should not be using these
functions.
</P>
<P>
The raw read and write functions read raw audio data from the audio file (not to be
confused with reading RAW header-less PCM files). The number of bytes read or written
@ -586,12 +692,16 @@ The <B>str_type</B> parameter can be any one of the following string types:
SF_STR_SOFTWARE,
SF_STR_ARTIST,
SF_STR_COMMENT,
SF_STR_DATE
SF_STR_DATE,
SF_STR_ALBUM,
SF_STR_LICENSE,
SF_STR_TRACKNUMBER,
SF_STR_GENRE
} ;
</PRE>
<P>
The sf_get_string() function returns the specificed string if it exists and a
The sf_get_string() function returns the specified string if it exists and a
NULL pointer otherwise.
In addition to the string ids above, SF_STR_FIRST (== SF_STR_TITLE) and
SF_STR_LAST (always the same as the highest numbers string id) are also
@ -648,7 +758,7 @@ would mean that all sample values read from the file will be zero.
In order to read these files correctly using integer read methods, it is recommended
that you use the
<A HREF="command.html">sf_command</A>
interface a command of
interface, a command of
<A HREF="command.html#SFC_SET_SCALE_FLOAT_INT_READ">SFC_SET_SCALE_FLOAT_INT_READ</A>
and a parameter of SF_TRUE to force correct scaling.
</P>
@ -660,7 +770,7 @@ and a parameter of SF_TRUE to force correct scaling.
<A HREF="http://www.mega-nerd.com/libsndfile/">here</A>.
</P>
<P>
Version : 1.0.19
Version : 1.0.25
</P>
<!-- pepper -->
<!-- pepper -->

View File

@ -6,7 +6,8 @@
Bug Reporting
</TITLE>
<META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>
@ -45,7 +46,7 @@
<LI> Whether you are using a package provided by your distribution or you
compiled it youself.
<LI> If you compiled it yourself, the compiler you are using. (Also make
sure to run "make check".)
sure to run 'make check'.)
<LI> A description of the problem.
<LI> Information generated by the sndfile-info program (see next paragraph).
<LI> If you are having problems with sndfile-play and ALSA on Linux, I will

View File

@ -9,7 +9,8 @@
<!-- Another version at the bottom of the page. -->
<META NAME="Description" CONTENT="The libsndfile API.">
<META NAME="Keywords" CONTENT="WAV AIFF AU libsndfile sound audio dsp Linux">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>
@ -27,7 +28,7 @@
Most of these operations are performed on a per-file basis.
</P>
<P>
The cmd parameter is a integer identifier which is defined in &lt;sndfile.h&gt;.
The cmd parameter is an integer identifier which is defined in &lt;sndfile.h&gt;.
All of the valid command identifiers have names beginning with "SFC_".
Data is passed to and returned from the library by use of a void pointer.
The library will not read or write more than datasize bytes from the void pointer.
@ -167,12 +168,12 @@
<TR>
<TD><A HREF="#SFC_GET_CLIPPING">SFC_GET_CLIPPING</A></TD>
<TD>Retreive current clipping setting.</TD>
<TD>Retrieve current clipping setting.</TD>
</TR>
<TR>
<TD><A HREF="#SFC_GET_EMBED_FILE_INFO">SFC_GET_EMBED_FILE_INFO</A></TD>
<TD>Retreive information about audio files embedded inside other files.</TD>
<TD>Retrieve information about audio files embedded inside other files.</TD>
</TR>
<TR>
@ -205,6 +206,28 @@
<TD>Set the Broadcast Chunk info</TD>
</TR>
<TR>
<TD><A HREF="#SFC_GET_LOOP_INFO">SFC_GET_LOOP_INFO</A></TD>
<TD>Get loop info</TD>
</TR>
<TR>
<TD><A HREF="#SFC_GET_INSTRUMENT">SFC_GET_INSTRUMENT</A></TD>
<TD>Get instrument info</TD>
</TR>
<TR>
<TD><A HREF="#SFC_SET_INSTRUMENT">SFC_SET_INSTRUMENT</A></TD>
<TD>Set instrument info</TD>
</TR>
<TR>
<TD><A HREF="#SFC_SET_VBR_ENCODING_QUALITY">SFC_SET_VBR_ENCODING_QUALITY</A></TD>
<TD>Set variable bit rate encoding quality</TD>
</TR>
<!--
<TR>
<TD><A HREF="#add-dither">add dither</A></TD>
@ -891,7 +914,7 @@ Example:
<A NAME="SFC_GET_FORMAT_SUBTYPE"></A>
<H2><BR><B>SFC_GET_FORMAT_SUBTYPE</B></H2>
<P>
Enumerate the subtypes (this function does not translate a sub type into
Enumerate the subtypes (this function does not translate a subtype into
a string describing that subtype).
A typical use case might be retrieving a string description of all subtypes
so that a dialog box can be filled in.
@ -909,7 +932,7 @@ Parameters:
datasize : sizeof (SF_FORMAT_INFO)
</PRE>
<P>
Example 1: Retrieve all subytpes supported by the WAV format.
Example 1: Retrieve all sybtypes supported by the WAV format.
</P>
<PRE>
SF_FORMAT_INFO format_info ;
@ -1242,7 +1265,7 @@ Parameters:
</P>
<DL>
<DT>Return value: </DT>
<DD>SF_AMBISONIC_NONE or SF_AMBISONIC_B_FORMAT or zero if the file format
<DD>SF_AMBISONIC_NONE or SF_AMBISONIC_B_FORMAT or zero if the file format
does not support ambisonic formats.
</DL>
@ -1334,7 +1357,7 @@ Parameters:
<A NAME="SFC_GET_BROADCAST_INFO"></A>
<H2><BR><B>SFC_GET_BROADCAST_INFO</B></H2>
<P>
Retrieve the Broadcast Extention Chunk from WAV (and related) files.
Retrieve the Broadcast Extension Chunk from WAV (and related) files.
</P>
<p>
Parameters:
@ -1367,7 +1390,7 @@ The SF_BROADCAST_INFO struct is defined in &lt;sndfile.h&gt; as:
<DL>
<DT>Return value: </DT>
<DD>SF_TRUE if the file contained a Broadcast Extention chunk or SF_FALSE
<DD>SF_TRUE if the file contained a Broadcast Extension chunk or SF_FALSE
otherwise.
</DL>
@ -1375,7 +1398,7 @@ The SF_BROADCAST_INFO struct is defined in &lt;sndfile.h&gt; as:
<A NAME="SFC_SET_BROADCAST_INFO"></A>
<H2><BR><B>SFC_SET_BROADCAST_INFO</B></H2>
<P>
Set the Broadcast Extention Chunk for WAV (and related) files.
Set the Broadcast Extension Chunk for WAV (and related) files.
</P>
<p>
Parameters:
@ -1389,11 +1412,185 @@ Parameters:
<DL>
<DT>Return value: </DT>
<DD>SF_TRUE if setting the Broadcast Extention chunk was successful and SF_FALSE
<DD>SF_TRUE if setting the Broadcast Extension chunk was successful and SF_FALSE
otherwise.
</DL>
<!-- ========================================================================= -->
<A NAME="SFC_GET_LOOP_INFO"></A>
<H2><BR><B>SFC_GET_LOOP_INFO</B></H2>
<P>
Retrieve loop information for file including time signature, length in
beats and original MIDI base note
</P>
<p>
Parameters:
</p>
<PRE>
sndfile : A valid SNDFILE* pointer
cmd : SFC_GET_LOOP_INFO
data : a pointer to an SF_LOOP_INFO struct
datasize : sizeof (SF_LOOP_INFO)
</PRE>
<P>
The SF_BROADCAST_INFO struct is defined in &lt;sndfile.h&gt; as:
</P>
<PRE>
typedef struct
{ short time_sig_num ; /* any positive integer > 0 */
short time_sig_den ; /* any positive power of 2 > 0 */
int loop_mode ; /* see SF_LOOP enum */
int num_beats ; /* this is NOT the amount of quarter notes !!!*/
/* a full bar of 4/4 is 4 beats */
/* a full bar of 7/8 is 7 beats */
float bpm ; /* suggestion, as it can be calculated using other fields:*/
/* file's lenght, file's sampleRate and our time_sig_den*/
/* -> bpms are always the amount of _quarter notes_ per minute */
int root_key ; /* MIDI note, or -1 for None */
int future [6] ;
} SF_LOOP_INFO ;
</PRE>
<P>
Example:
</P>
<PRE>
SF_LOOP_INFO loop;
sf_command (sndfile, SFC_GET_LOOP_INFO, &amp;loop, sizeof (loop)) ;
</PRE>
<DL>
<DT>Return value:</DT>
<DD>SF_TRUE if the file header contains loop information for the file.
SF_FALSE otherwise.
</DL>
<!-- ========================================================================= -->
<A NAME="SFC_GET_INSTRUMENT"></A>
<H2><BR><B>SFC_GET_INSTRUMENT</B></H2>
<P>
Retrieve instrument information from file including MIDI base note,
keyboard mapping and looping informations(start/stop and mode).
</P>
<p>
Parameters:
</p>
<PRE>
sndfile : A valid SNDFILE* pointer
cmd : SFC_GET_INSTRUMENT
data : a pointer to an SF_INSTRUMENT struct
datasize : sizeof (SF_INSTRUMENT)
</PRE>
<P>
The SF_INSTRUMENT struct is defined in &lt;sndfile.h&gt; as:
</P>
<PRE>
enum
{ /*
** The loop mode field in SF_INSTRUMENT will be one of the following.
*/
SF_LOOP_NONE = 800,
SF_LOOP_FORWARD,
SF_LOOP_BACKWARD,
SF_LOOP_ALTERNATING
} ;
typedef struct
{ int gain ;
char basenote, detune ;
char velocity_lo, velocity_hi ;
char key_lo, key_hi ;
int loop_count ;
struct
{ int mode ;
unsigned int start ;
unsigned int end ;
unsigned int count ;
} loops [16] ; /* make variable in a sensible way */
} SF_INSTRUMENT ;
</PRE>
<P>
Example:
</P>
<PRE>
SF_INSTRUMENT inst ;
sf_command (sndfile, SFC_GET_INSTRUMENT, &amp;inst, sizeof (inst)) ;
</PRE>
<DL>
<DT>Return value:</DT>
<dd>SF_TRUE if the file header contains instrument information for the
file. SF_FALSE otherwise.
</DL>
<!-- ========================================================================= -->
<A NAME="SFC_SET_INSTRUMENT"></A>
<H2><BR><B>SFC_SET_INSTRUMENT</B></H2>
<P>
Set the instrument information for the file.
</P>
<p>
Parameters:
</p>
<PRE>
sndfile : A valid SNDFILE* pointer
cmd : SFC_GET_INSTRUMENT
data : a pointer to an SF_INSTRUMENT struct
datasize : sizeof (SF_INSTRUMENT)
</PRE>
<P>
Example:
</P>
<PRE>
SF_INSTRUMENT inst ;
sf_command (sndfile, SFC_SET_INSTRUMENT, &amp;inst, sizeof (inst)) ;
</PRE>
<DL>
<DT>Return value:</DT>
<dd>SF_TRUE if the file header contains instrument information for the
file. SF_FALSE otherwise.
</DL>
<!-- ========================================================================= -->
<A NAME="SFC_SET_VBR_ENCODING_QUALITY"></A>
<H2><BR><B>SFC_SET_VBR_ENCODING_QUALITY</B></H2>
<P>
Set the Variable Bite Rate encoding quality.
Currenly only implemented fro Ogg/Vorbis files.
</P>
<p>
Parameters:
</p>
<PRE>
sndfile : A valid SNDFILE* pointer
cmd : SFC_SET_VBR_ENCODING_QUALITY
data : a pointer to double specifing VBR quality
datasize : sizeof (double)
</PRE>
<P>
Example:
</P>
<PRE>
double quality = 0.5 ;
sf_command (sndfile, SFC_SET_VBR_ENCODING_QUALITY, &amp;quality, sizeof (double)) ;
</PRE>
<DL>
<DT>Return value:</DT>
<dd>SF_TRUE if VBR encoding quality was set.
SF_FALSE otherwise.
</DL>
<!-- ========================================================================= -->
<HR>
<P>
@ -1401,7 +1598,7 @@ Parameters:
<A HREF="http://www.mega-nerd.com/libsndfile/">
http://www.mega-nerd.com/libsndfile/</A>.
<BR>
Version : 1.0.19
Version : 1.0.25
</P>
</BODY>

View File

@ -9,7 +9,8 @@
<!-- Another version at the bottom of the page. -->
<META NAME="Description" CONTENT="The libsndfile API.">
<META NAME="Keywords" CONTENT="WAV AIFF AU libsndfile sound audio dsp Linux">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>
@ -1009,7 +1010,7 @@ Example:
<A HREF="http://www.mega-nerd.com/libsndfile/">
http://www.mega-nerd.com/libsndfile/</A>.
<BR>
Version : 1.0.19
Version : 1.0.25
</P>
</BODY>

View File

@ -8,7 +8,8 @@
<META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
<META NAME="Description" CONTENT="The libsndfile API.">
<META NAME="Keywords" CONTENT="WAV AIFF AU libsndfile sound audio dsp Linux">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<!-- pepper -->
<BODY>

View File

@ -6,11 +6,12 @@
libsndfile
</TITLE>
<META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
<META NAME="Version" CONTENT="libsndfile-1.0.19">
<META NAME="Version" CONTENT="libsndfile-1.0.25">
<META NAME="Description" CONTENT="The libsndfile Home Page">
<META NAME="Keywords" CONTENT="WAV AIFF AU SVX PAF NIST W64 libsndfile sound audio dsp Linux">
<META NAME="ROBOTS" CONTENT="NOFOLLOW">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>
@ -47,11 +48,8 @@
<!-- pepper -->
<P>
The library was written to compile and run on a Linux system but should compile
and run on just about any Unix (including MacOSX).
It can also be compiled and run on Win32 systems using the Microsoft compiler and
MacOS (OS9 and earlier) using the Metrowerks compiler.
There are directions for compiling libsndfile on these platforms in the Win32 and
MacOS directories of the source code distribution.
and run on just about any Unix (including MacOS X).
There are also pre-compiled binaries available for 32 and 64 bit windows.
</P>
<P>
It was designed to handle both little-endian (such as WAV) and big-endian
@ -67,18 +65,20 @@
</P>
<!-- pepper -->
<UL>
<LI>i586-pc-linux-gnu (Linux on PC hardware)
<LI>powerpc-unknown-linux-gnu (Linux on Apple Mac hardware)
<LI>powerpc-apple-darwin7.0 (Mac OS X 10.3)
<LI>sparc-sun-solaris2.8 (using gcc)
<LI>mips-sgi-irix5.3 (using gcc)
<LI>QNX 6.0
<LI>i386-unknown-openbsd2.9
<LI>Every platform supported by Debian GNU/Linux including x86_64-linux-gnu,
i486-linux-gnu, powerpc-linux-gnu, sparc-linux-gnu, alpha-linux-gnu,
mips-linux-gnu and armel-linux-gnu.</LI>
<LI>arm-linux-androideab (Android phones OS)</LI>
<LI>powerpc-apple-darwin7.0 (Mac OS X 10.3)</LI>
<LI>sparc-sun-solaris2.8 (using gcc)</LI>
<LI>mips-sgi-irix5.3 (using gcc)</LI>
<LI>QNX 6.0</LI>
<LI>i386-unknown-openbsd2.9</LI>
</UL>
<!-- pepper -->
<P>
At the moment, each new release is being tested on i386 Linux, PowerPC Linux,
MacOSX on PowerPC and Win32.
At the moment, each new release is being tested on i386 Linux, x86_64 Linux,
PowerPC Linux, Win32 and Win64.
</P>
<!-- pepper -->
@ -343,7 +343,7 @@ and
<LI>Version 1.0.5 (May 03 2003) One new file format and new functionality.
<LI>Version 1.0.6 (Feb 08 2004) Large file fix for Linux/Solaris, new functionality
and Win32 improvements.
<LI>Version 1.0.7 (Feb 24 2004) Fix build problems on MacOSX and fix ia64/MIPS etc
<LI>Version 1.0.7 (Feb 24 2004) Fix build problems on MacOS X and fix ia64/MIPS etc
clip mode detction.
<LI>Version 1.0.8 (Mar 14 2004) Minor bug fixes.
<LI>Version 1.0.9 (Mar 30 2004) Add AVR format. Improve handling of some WAV files.
@ -360,8 +360,15 @@ and
<LI>Version 1.0.17 (Aug 31 2006) Add C++ wrapper sndfile.hh. Minor bug fixes and cleanups.
<LI>Version 1.0.18 (Feb 07 2009) Add Ogg/Vorbis suppport, remove captive libraries, many
new features and bug fixes. Generate Win32 and Win64 pre-compiled binaries.
<LI>Version 1.0.19 (Mar 02 2009) Fix for CVE-2009-0186. Huge number of minor fixes as a
<LI>Version 1.0.19 (Mar 02 2009) Fix for CVE-2009-0186. Huge number of minor fixes as a
result of static analysis.
<LI>Version 1.0.20 (May 14 2009) Fix for potential heap overflow.
<LI>Version 1.0.21 (December 13 2009) Bunch of minor bug fixes.
<LI>Version 1.0.22 (October 04 2010) Bunch of minor bug fixes.
<LI>Version 1.0.23 (October 10 2010) Minor bug fixes.
<LI>Version 1.0.24 (March 23 2011) Minor bug fixes.
<LI>Version 1.0.25 (July 13 2011) Fix for Secunia Advisory SA45125. Minor bug fixes and
improvements.
</UL>
<A NAME="Similar"></A>
@ -389,7 +396,7 @@ and
<a href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">version 2.1</a>
and
<a href="http://www.gnu.org/copyleft/lesser.html">version 3</a>.
To mamximise the compatibility of libsndfile, the user may choose to use libsndfile
To maximise the compatibility of libsndfile, the user may choose to use libsndfile
under either of the above two licenses.
You can also read a simple explanation of the ideas behind the GPL and the LGPL
<A HREF="http://www.gnu.org/copyleft/copyleft.html">here</A>.
@ -410,24 +417,12 @@ and
<A HREF="http://www.gnu.org/">Free Software</A>
or
<A HREF="http://www.opensource.org/">Open Source</A>.
However, if you put in a great deal of effort building a huge application
However, if you put in a great deal of effort building a significant application
which simply uses libsndfile for file I/O, then I have no problem with you releasing
that as closed source and charging as much money as you want for it as long as you
abide by <A HREF="http://www.gnu.org/copyleft/lesser.html">the license</A>.
</P>
<P>
What I don't like to see is things like Steve Dekorte's <b>SoundConverter</b>
(no I won't link to his page) for Mac OSX.
Mr Dekorte has grabbed a number of Free Software packages and wrapped them in a
rather amateurish, buggy GUI and released the result as shareware.
He charges US$10 for the full version when his contribution to the whole is, by
his own
<A HREF="http://groups.google.com/groups?selm=3F9B8F8B.7853300B@mega-nerd.com">
admission</A>,
less than 10%.
</P>
<A NAME="Download"></A>
<H1><B>Download</B></H1>
<P>
@ -435,23 +430,22 @@ and
</P>
<UL>
<LI>Source code as a .tar.gz :
<A HREF="libsndfile-1.0.19.tar.gz">libsndfile-1.0.19.tar.gz</A>
<A HREF="files/libsndfile-1.0.25.tar.gz">libsndfile-1.0.25.tar.gz</A>
and
<A HREF="libsndfile-1.0.19.tar.gz.asc">(GPG signature)</A>.
<A HREF="files/libsndfile-1.0.25.tar.gz.asc">(GPG signature)</A>.
<LI>Win32 installer:
<A HREF="libsndfile-1.0.19-w32-setup.exe">
libsndfile-1.0.19-w32-setup.exe</A> (thoroughly tested under
<A HREF="files/libsndfile-1.0.25-w32-setup.exe">
libsndfile-1.0.25-w32-setup.exe</A> (thoroughly tested under
<a href="http://www.winehq.com/">Wine</a> and Windows XP).
<LI>Win64 installer:
<A HREF="libsndfile-1.0.19-w64-setup.exe">
libsndfile-1.0.19-w64-setup.exe</A> (alpha quality release).
<A HREF="files/libsndfile-1.0.25-w64-setup.exe">
libsndfile-1.0.25-w64-setup.exe</A>
(thoroughly tested on 64 bit Windows 7).
</UL>
<P>
The Win32 installer was compiled for Windows XP but should also work on Windows
2000 and Vista.
It may even work on earlier versions of Windows.
The Win64 is pretty much untested.
2000, Vista and Windows 7.
</p>
<P>

View File

@ -48,24 +48,32 @@ dl {
margin-left : 3% ;
margin-right : 3% ;
}
h1 {
font-size : xx-large ;
background : black ;
color : #5050FF ;
text-align : left ;
margin-left : 3% ;
margin-right : 3% ;
}
h2 {
font-size : x-large ;
h1 {
font-size : xx-large ;
background : black ;
color : #5050FF ;
text-align : left ;
margin-left : 3% ;
margin-right : 3% ;
}
h3 {
font-size : large ;
h2 {
font-size : x-large ;
background : black ;
color : #5050FF ;
text-align : left ;
margin-left : 3% ;
margin-right : 3% ;
}
h3 {
font-size : large ;
background : black ;
color : #5050FF ;
text-align : left ;
margin-left : 3% ;
margin-right : 3% ;
}
h4 {
font-size : medium ;
background : black ;
color : #5050FF ;
text-align : left ;

View File

@ -48,24 +48,32 @@ dl {
margin-left : 3% ;
margin-right : 3% ;
}
h1 {
font-size : xx-large ;
background : @HTML_BGCOLOUR@ ;
color : #5050FF ;
text-align : left ;
margin-left : 3% ;
margin-right : 3% ;
}
h2 {
font-size : x-large ;
h1 {
font-size : xx-large ;
background : @HTML_BGCOLOUR@ ;
color : #5050FF ;
text-align : left ;
margin-left : 3% ;
margin-right : 3% ;
}
h3 {
font-size : large ;
h2 {
font-size : x-large ;
background : @HTML_BGCOLOUR@ ;
color : #5050FF ;
text-align : left ;
margin-left : 3% ;
margin-right : 3% ;
}
h3 {
font-size : large ;
background : @HTML_BGCOLOUR@ ;
color : #5050FF ;
text-align : left ;
margin-left : 3% ;
margin-right : 3% ;
}
h4 {
font-size : medium ;
background : @HTML_BGCOLOUR@ ;
color : #5050FF ;
text-align : left ;

View File

@ -6,7 +6,8 @@
libsndfile Mailing Lists
</TITLE>
<META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>

View File

@ -6,7 +6,8 @@
libsndfile and GNU Octave
</TITLE>
<META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>
@ -85,7 +86,7 @@
to play the correct types of Octave files.
Using this command line player <B>sndfile-play</B> and a third Octave script
file allows Octave data to be played from within Octave on any of the platforms
which <B>sndfile-play</B> supports (at the moment: Linux, MacOSX, Solaris and
which <B>sndfile-play</B> supports (at the moment: Linux, MacOS X, Solaris and
Win32).
</P>
<PRE>

View File

@ -6,7 +6,8 @@
libsndfile : pkg-config
</TITLE>
<META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>
@ -18,7 +19,7 @@
From version 1.0.0 libsndfile has had the ability to read and write files of
greater than 2 Gig in size on most OSes even if sizeof (long) == 4.
OSes which support this feature include Linux (2.4 kernel, glibc6) on x86, PPC and
probably others, Win32, MacOSX, *BSD, Solaris and probably others.
probably others, Win32, MacOS X, *BSD, Solaris and probably others.
OSes on 64 bit processors where the default compile environment is LP64 (longs and
pointers are 64 bit ie Linux on DEC/Compaq/HP Alpha processors) automatically
support large file access.
@ -30,7 +31,7 @@
programs which link to the library.
</P>
<P>
Note : People using Win32, MacOS (both OSX and pre-OSX) or *BSD can disregard the
Note : People using Win32, MacOS (both OS X and pre-OS X) or *BSD can disregard the
rest of this document as it does not apply to either of these OSes.
</P>
<P>

View File

@ -6,7 +6,8 @@
sndfile-info
</TITLE>
<META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>

View File

@ -6,7 +6,8 @@
libsndfile Tutorial
</TITLE>
<META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>

View File

@ -6,7 +6,8 @@
Building libsndfile on Win32
</TITLE>
<META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
<LINK REL=StyleSheet HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
</HEAD>
<BODY>

View File

@ -1,231 +0,0 @@
/*
** Copyright (C) 2002-2005 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/stat.h>
#include <sndfile.h>
#define BUFFER_LEN 1024
static void usage_exit (char *progname) ;
static int is_data_really_float (SNDFILE *sndfile) ;
static void fix_file (char *filename) ;
static off_t file_size (char *filename) ;
static union
{ int i [BUFFER_LEN] ;
float f [BUFFER_LEN] ;
} buffer ;
int
main (int argc, char *argv [])
{ SNDFILE *sndfile ;
SF_INFO sfinfo ;
int k, data_is_float, converted = 0 ;
puts ("\nCooledit Fixer.\n---------------") ;
if (argc < 2)
usage_exit (argv [0]) ;
for (k = 1 ; k < argc ; k++)
{ if ((sndfile = sf_open (argv [k], SFM_READ, &sfinfo)) == NULL)
{ /*-printf ("Failed to open : %s\n", argv [k]) ;-*/
continue ;
} ;
if (sfinfo.format != (SF_FORMAT_WAV | SF_FORMAT_PCM_32))
{ /*-printf ("%-50s : not a 32 bit PCM WAV file.\n", argv [k]) ;-*/
sf_close (sndfile) ;
continue ;
} ;
data_is_float = is_data_really_float (sndfile) ;
sf_close (sndfile) ;
if (data_is_float == SF_FALSE)
{ /*-printf ("%-50s : not a Cooledit abomination.\n", argv [k]) ;-*/
continue ;
} ;
fix_file (argv [k]) ;
converted ++ ;
} ;
if (converted == 0)
puts ("\nNo files converted.") ;
puts ("") ;
return 0 ;
} /* main */
static void
usage_exit (char *progname)
{ char *cptr ;
if ((cptr = strrchr (progname, '/')))
progname = cptr + 1 ;
if ((cptr = strrchr (progname, '\\')))
progname = cptr + 1 ;
printf ("\n Usage : %s <filename>\n", progname) ;
puts ("\n"
"Fix broken files created by Syntrillium's Cooledit. These files are \n"
"marked as containing PCM data but actually contain floating point \n"
"data. Only the broken files created by Cooledit are processed. All \n"
"other files remain untouched.\n"
"\n"
"More than one file may be included on the command line. \n"
) ;
exit (1) ;
} /* usage_exit */
static int
is_data_really_float (SNDFILE *sndfile)
{ int k, readcount ;
while ((readcount = sf_read_int (sndfile, buffer.i, BUFFER_LEN)) > 0)
{ for (k = 0 ; k < readcount ; k++)
{ if (buffer.i [k] == 0)
continue ;
if (fabs (buffer.f [k]) > 32768.0)
return SF_FALSE ;
} ;
} ;
return SF_TRUE ;
} /* is_data_really_float */
static void
fix_file (char *filename)
{ static char newfilename [512] ;
SNDFILE *infile, *outfile ;
SF_INFO sfinfo ;
int readcount, k ;
float normfactor ;
char *cptr ;
printf ("\nFixing : %s\n", filename) ;
if ((infile = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Not able to open input file %s\n", filename) ;
exit (1) ;
} ;
if (strlen (filename) >= sizeof (newfilename) - 1)
{ puts ("Error : Path name too long.\n") ;
exit (1) ;
} ;
strncpy (newfilename, filename, sizeof (newfilename)) ;
newfilename [sizeof (newfilename) - 1] = 0 ;
if ((cptr = strrchr (newfilename, '/')) == NULL)
cptr = strrchr (newfilename, '\\') ;
if (cptr)
{ cptr [1] = 0 ;
strncat (newfilename, "fixed.wav", sizeof (newfilename) - strlen (newfilename) - 1) ;
}
else
strncpy (newfilename, "fixed.wav", sizeof (newfilename) - 1) ;
newfilename [sizeof (newfilename) - 1] = 0 ;
printf (" Output : %s\n", newfilename) ;
sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT ;
if ((outfile = sf_open (newfilename, SFM_WRITE, &sfinfo)) == NULL)
{ printf ("Not able to output open file %s\n", filename) ;
exit (1) ;
} ;
/* Find the file peak. sf-command (SFC_CALC_SIGNAL_MAX) cannot be used. */
normfactor = 0.0 ;
while ((readcount = sf_read_int (infile, buffer.i, BUFFER_LEN)) > 0)
{ for (k = 0 ; k < readcount ; k++)
if (fabs (buffer.f [k]) > normfactor)
normfactor = fabs (buffer.f [k]) ;
} ;
printf (" Peak : %g\n", normfactor) ;
normfactor = 1.0 / normfactor ;
sf_seek (infile, 0, SEEK_SET) ;
while ((readcount = sf_read_int (infile, buffer.i, BUFFER_LEN)) > 0)
{ for (k = 0 ; k < readcount ; k++)
buffer.f [k] *= normfactor ;
sf_write_float (outfile, buffer.f, readcount) ;
} ;
sf_close (infile) ;
sf_close (outfile) ;
if (abs (file_size (filename) - file_size (newfilename)) > 50)
{ puts ("Error : file size mismatch.\n") ;
exit (1) ;
} ;
printf (" Renaming : %s\n", filename) ;
if (remove (filename) != 0)
{ perror ("rename") ;
exit (1) ;
} ;
if (rename (newfilename, filename) != 0)
{ perror ("rename") ;
exit (1) ;
} ;
return ;
} /* fix_file */
static off_t
file_size (char *filename)
{ struct stat buf ;
if (stat (filename, &buf) != 0)
{ perror ("stat") ;
exit (1) ;
} ;
return buf.st_size ;
} /* file_size */
/*
** Do not edit or modify anything in this comment block.
** The arch-tag line is a file identity tag for the GNU Arch
** revision control system.
**
** arch-tag: 5475655e-3898-40ff-969b-c8ab2351b0e4
*/

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2002-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** All rights reserved.
**
@ -119,7 +119,7 @@ encode_file (const char *infilename, const char *outfilename, int filetype)
} ;
while ((readcount = sf_read_float (infile, buffer, BUFFER_LEN)) > 0)
sf_write_float (outfile, buffer, BUFFER_LEN) ;
sf_write_float (outfile, buffer, readcount) ;
sf_close (infile) ;
sf_close (outfile) ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2001-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2001-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** All rights reserved.
**

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** All rights reserved.
**

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2001-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2001-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** All rights reserved.
**

View File

@ -1,376 +0,0 @@
/*
** Copyright (C) 1999-2005 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sndfile.h>
#define BUFFER_LEN 1024
typedef struct
{ char *infilename, *outfilename ;
SF_INFO infileinfo, outfileinfo ;
} OptionData ;
typedef struct
{ const char *ext ;
int len ;
int format ;
} OUTPUT_FORMAT_MAP ;
static void copy_metadata (SNDFILE *outfile, SNDFILE *infile) ;
static void copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels) ;
static void copy_data_int (SNDFILE *outfile, SNDFILE *infile, int channels) ;
static OUTPUT_FORMAT_MAP format_map [] =
{
{ "aif", 3, SF_FORMAT_AIFF },
{ "wav", 0, SF_FORMAT_WAV },
{ "au", 0, SF_FORMAT_AU },
{ "caf", 0, SF_FORMAT_CAF },
{ "flac", 0, SF_FORMAT_FLAC },
{ "snd", 0, SF_FORMAT_AU },
{ "svx", 0, SF_FORMAT_SVX },
{ "paf", 0, SF_ENDIAN_BIG | SF_FORMAT_PAF },
{ "fap", 0, SF_ENDIAN_LITTLE | SF_FORMAT_PAF },
{ "gsm", 0, SF_FORMAT_RAW },
{ "nist", 0, SF_FORMAT_NIST },
{ "ircam", 0, SF_FORMAT_IRCAM },
{ "sf", 0, SF_FORMAT_IRCAM },
{ "voc", 0, SF_FORMAT_VOC },
{ "w64", 0, SF_FORMAT_W64 },
{ "raw", 0, SF_FORMAT_RAW },
{ "mat4", 0, SF_FORMAT_MAT4 },
{ "mat5", 0, SF_FORMAT_MAT5 },
{ "mat", 0, SF_FORMAT_MAT4 },
{ "pvf", 0, SF_FORMAT_PVF },
{ "sds", 0, SF_FORMAT_SDS },
{ "sd2", 0, SF_FORMAT_SD2 },
{ "vox", 0, SF_FORMAT_RAW },
{ "xi", 0, SF_FORMAT_XI }
} ; /* format_map */
static int
guess_output_file_type (char *str, int format)
{ char buffer [16], *cptr ;
int k ;
format &= SF_FORMAT_SUBMASK ;
if ((cptr = strrchr (str, '.')) == NULL)
return 0 ;
strncpy (buffer, cptr + 1, 15) ;
buffer [15] = 0 ;
for (k = 0 ; buffer [k] ; k++)
buffer [k] = tolower ((buffer [k])) ;
if (strcmp (buffer, "gsm") == 0)
return SF_FORMAT_RAW | SF_FORMAT_GSM610 ;
if (strcmp (buffer, "vox") == 0)
return SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM ;
for (k = 0 ; k < (int) (sizeof (format_map) / sizeof (format_map [0])) ; k++)
{ if (format_map [k].len > 0 && strncmp (buffer, format_map [k].ext, format_map [k].len) == 0)
return format_map [k].format | format ;
else if (strcmp (buffer, format_map [k].ext) == 0)
return format_map [k].format | format ;
} ;
return 0 ;
} /* guess_output_file_type */
static void
print_usage (char *progname)
{ SF_FORMAT_INFO info ;
int k ;
printf ("\nUsage : %s [encoding] <input file> <output file>\n", progname) ;
puts ("\n"
" where [encoding] may be one of the following:\n\n"
" -pcms8 : force the output to signed 8 bit pcm\n"
" -pcmu8 : force the output to unsigned 8 bit pcm\n"
" -pcm16 : force the output to 16 bit pcm\n"
" -pcm24 : force the output to 24 bit pcm\n"
" -pcm32 : force the output to 32 bit pcm\n"
" -float32 : force the output to 32 bit floating point"
) ;
puts (
" -ulaw : force the output ULAW\n"
" -alaw : force the output ALAW\n"
" -ima-adpcm : force the output to IMA ADPCM (WAV only)\n"
" -ms-adpcm : force the output to MS ADPCM (WAV only)\n"
" -gsm610 : force the GSM6.10 (WAV only)\n"
" -dwvw12 : force the output to 12 bit DWVW (AIFF only)\n"
" -dwvw16 : force the output to 16 bit DWVW (AIFF only)\n"
" -dwvw24 : force the output to 24 bit DWVW (AIFF only)\n"
) ;
puts (
" The format of the output file is determined by the file extension of the\n"
" output file name. The following extensions are currently understood:\n"
) ;
for (k = 0 ; k < (int) (sizeof (format_map) / sizeof (format_map [0])) ; k++)
{ info.format = format_map [k].format ;
sf_command (NULL, SFC_GET_FORMAT_INFO, &info, sizeof (info)) ;
printf (" %-10s : %s\n", format_map [k].ext, info.name) ;
} ;
puts ("") ;
} /* print_usage */
int
main (int argc, char * argv [])
{ char *progname, *infilename, *outfilename ;
SNDFILE *infile = NULL, *outfile = NULL ;
SF_INFO sfinfo ;
int k, outfilemajor, outfileminor = 0, infileminor ;
progname = strrchr (argv [0], '/') ;
progname = progname ? progname + 1 : argv [0] ;
if (argc < 3 || argc > 5)
{ print_usage (progname) ;
return 1 ;
} ;
infilename = argv [argc-2] ;
outfilename = argv [argc-1] ;
if (strcmp (infilename, outfilename) == 0)
{ printf ("Error : Input and output filenames are the same.\n\n") ;
print_usage (progname) ;
return 1 ;
} ;
if (infilename [0] == '-')
{ printf ("Error : Input filename (%s) looks like an option.\n\n", infilename) ;
print_usage (progname) ;
return 1 ;
} ;
if (outfilename [0] == '-')
{ printf ("Error : Output filename (%s) looks like an option.\n\n", outfilename) ;
print_usage (progname) ;
return 1 ;
} ;
for (k = 1 ; k < argc - 2 ; k++)
{ if (! strcmp (argv [k], "-pcms8"))
{ outfileminor = SF_FORMAT_PCM_S8 ;
continue ;
} ;
if (! strcmp (argv [k], "-pcmu8"))
{ outfileminor = SF_FORMAT_PCM_U8 ;
continue ;
} ;
if (! strcmp (argv [k], "-pcm16"))
{ outfileminor = SF_FORMAT_PCM_16 ;
continue ;
} ;
if (! strcmp (argv [k], "-pcm24"))
{ outfileminor = SF_FORMAT_PCM_24 ;
continue ;
} ;
if (! strcmp (argv [k], "-pcm32"))
{ outfileminor = SF_FORMAT_PCM_32 ;
continue ;
} ;
if (! strcmp (argv [k], "-float32"))
{ outfileminor = SF_FORMAT_FLOAT ;
continue ;
} ;
if (! strcmp (argv [k], "-ulaw"))
{ outfileminor = SF_FORMAT_ULAW ;
continue ;
} ;
if (! strcmp (argv [k], "-alaw"))
{ outfileminor = SF_FORMAT_ALAW ;
continue ;
} ;
if (! strcmp (argv [k], "-ima-adpcm"))
{ outfileminor = SF_FORMAT_IMA_ADPCM ;
continue ;
} ;
if (! strcmp (argv [k], "-ms-adpcm"))
{ outfileminor = SF_FORMAT_MS_ADPCM ;
continue ;
} ;
if (! strcmp (argv [k], "-gsm610"))
{ outfileminor = SF_FORMAT_GSM610 ;
continue ;
} ;
if (! strcmp (argv [k], "-dwvw12"))
{ outfileminor = SF_FORMAT_DWVW_12 ;
continue ;
} ;
if (! strcmp (argv [k], "-dwvw16"))
{ outfileminor = SF_FORMAT_DWVW_16 ;
continue ;
} ;
if (! strcmp (argv [k], "-dwvw24"))
{ outfileminor = SF_FORMAT_DWVW_24 ;
continue ;
} ;
printf ("Error : Not able to decode argunment '%s'.\n", argv [k]) ;
exit (1) ;
} ;
if ((infile = sf_open (infilename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Not able to open input file %s.\n", infilename) ;
puts (sf_strerror (NULL)) ;
return 1 ;
} ;
infileminor = sfinfo.format & SF_FORMAT_SUBMASK ;
if ((sfinfo.format = guess_output_file_type (outfilename, sfinfo.format)) == 0)
{ printf ("Error : Not able to determine output file type for %s.\n", outfilename) ;
return 1 ;
} ;
outfilemajor = sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_ENDMASK) ;
if (outfileminor == 0)
outfileminor = sfinfo.format & SF_FORMAT_SUBMASK ;
if (outfileminor != 0)
sfinfo.format = outfilemajor | outfileminor ;
else
sfinfo.format = outfilemajor | (sfinfo.format & SF_FORMAT_SUBMASK) ;
if ((sfinfo.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_XI)
switch (sfinfo.format & SF_FORMAT_SUBMASK)
{ case SF_FORMAT_PCM_16 :
sfinfo.format = outfilemajor | SF_FORMAT_DPCM_16 ;
break ;
case SF_FORMAT_PCM_S8 :
case SF_FORMAT_PCM_U8 :
sfinfo.format = outfilemajor | SF_FORMAT_DPCM_8 ;
break ;
} ;
if (sf_format_check (&sfinfo) == 0)
{ printf ("Error : output file format is invalid (0x%08X).\n", sfinfo.format) ;
return 1 ;
} ;
/* Open the output file. */
if ((outfile = sf_open (outfilename, SFM_WRITE, &sfinfo)) == NULL)
{ printf ("Not able to open output file %s : %s\n", outfilename, sf_strerror (NULL)) ;
return 1 ;
} ;
/* Copy the metadata */
copy_metadata (outfile, infile) ;
if ((outfileminor == SF_FORMAT_DOUBLE) || (outfileminor == SF_FORMAT_FLOAT) ||
(infileminor == SF_FORMAT_DOUBLE) || (infileminor == SF_FORMAT_FLOAT))
copy_data_fp (outfile, infile, sfinfo.channels) ;
else
copy_data_int (outfile, infile, sfinfo.channels) ;
sf_close (infile) ;
sf_close (outfile) ;
return 0 ;
} /* main */
static void
copy_metadata (SNDFILE *outfile, SNDFILE *infile)
{ SF_INSTRUMENT inst ;
const char *str ;
int k, err = 0 ;
for (k = SF_STR_FIRST ; k <= SF_STR_LAST ; k++)
{ str = sf_get_string (infile, k) ;
if (str != NULL)
err = sf_set_string (outfile, k, str) ;
} ;
memset (&inst, 0, sizeof (inst)) ;
if (sf_command (infile, SFC_GET_INSTRUMENT, &inst, sizeof (inst)) == SF_TRUE)
sf_command (outfile, SFC_SET_INSTRUMENT, &inst, sizeof (inst)) ;
} /* copy_metadata */
static void
copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels)
{ static double data [BUFFER_LEN], max ;
int frames, readcount, k ;
frames = BUFFER_LEN / channels ;
readcount = frames ;
sf_command (infile, SFC_CALC_SIGNAL_MAX, &max, sizeof (max)) ;
if (max < 1.0)
{ while (readcount > 0)
{ readcount = sf_readf_double (infile, data, frames) ;
sf_writef_double (outfile, data, readcount) ;
} ;
}
else
{ sf_command (infile, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
while (readcount > 0)
{ readcount = sf_readf_double (infile, data, frames) ;
for (k = 0 ; k < readcount * channels ; k++)
data [k] /= max ;
sf_writef_double (outfile, data, readcount) ;
} ;
} ;
return ;
} /* copy_data_fp */
static void
copy_data_int (SNDFILE *outfile, SNDFILE *infile, int channels)
{ static int data [BUFFER_LEN] ;
int frames, readcount ;
frames = BUFFER_LEN / channels ;
readcount = frames ;
while (readcount > 0)
{ readcount = sf_readf_int (infile, data, frames) ;
sf_writef_int (outfile, data, readcount) ;
} ;
return ;
} /* copy_data_int */
/*
** Do not edit or modify anything in this comment block.
** The arch-tag line is a file identity tag for the GNU Arch
** revision control system.
**
** arch-tag: 259682b3-2887-48a6-b5bb-3cde00521ba3
*/

View File

@ -1,354 +0,0 @@
/*
** Copyright (C) 1999-2006 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <sndfile.h>
#define BUFFER_LEN (1 << 16)
#if (defined (WIN32) || defined (_WIN32))
#define snprintf _snprintf
#endif
static void print_version (void) ;
static void print_usage (const char *progname) ;
static void info_dump (const char *filename) ;
static void instrument_dump (const char *filename) ;
static void broadcast_dump (const char *filename) ;
int
main (int argc, char *argv [])
{ int k ;
print_version () ;
if (argc < 2 || strcmp (argv [1], "--help") == 0 || strcmp (argv [1], "-h") == 0)
{ char *progname ;
progname = strrchr (argv [0], '/') ;
progname = progname ? progname + 1 : argv [0] ;
print_usage (progname) ;
return 1 ;
} ;
if (strcmp (argv [1], "-i") == 0)
{ instrument_dump (argv [2]) ;
return 0 ;
} ;
if (strcmp (argv [1], "-b") == 0)
{ broadcast_dump (argv [2]) ;
return 0 ;
} ;
for (k = 1 ; k < argc ; k++)
info_dump (argv [k]) ;
return 0 ;
} /* main */
/*==============================================================================
** Print version and usage.
*/
static double data [BUFFER_LEN] ;
static void
print_version (void)
{ char buffer [256] ;
sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
printf ("\nVersion : %s\n\n", buffer) ;
} /* print_version */
static void
print_usage (const char *progname)
{ printf ("Usage :\n %s <file> ...\n", progname) ;
printf (" Prints out information about one or more sound files.\n\n") ;
printf (" %s -i <file>\n", progname) ;
printf (" Prints out the instrument data for the given file.\n\n") ;
printf (" %s -b <file>\n", progname) ;
printf (" Prints out the broadcast WAV info for the given file.\n\n") ;
#if (defined (_WIN32) || defined (WIN32))
printf ("This is a Unix style command line application which\n"
"should be run in a MSDOS box or Command Shell window.\n\n") ;
printf ("Sleeping for 5 seconds before exiting.\n\n") ;
fflush (stdout) ;
/* This is the officially blessed by microsoft way but I can't get
** it to link.
** Sleep (15) ;
** Instead, use this:
*/
_sleep (5 * 1000) ;
#endif
} /* print_usage */
/*==============================================================================
** Dumping of sndfile info.
*/
static double data [BUFFER_LEN] ;
static double
get_signal_max (SNDFILE *file)
{ double max, temp ;
int readcount, k, save_state ;
save_state = sf_command (file, SFC_GET_NORM_DOUBLE, NULL, 0) ;
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
max = 0.0 ;
while ((readcount = sf_read_double (file, data, BUFFER_LEN)))
{ for (k = 0 ; k < readcount ; k++)
{ temp = fabs (data [k]) ;
if (temp > max)
max = temp ;
} ;
} ;
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, save_state) ;
return max ;
} /* get_signal_max */
static double
calc_decibels (SF_INFO * sfinfo, double max)
{ double decibels ;
switch (sfinfo->format & SF_FORMAT_SUBMASK)
{ case SF_FORMAT_PCM_U8 :
case SF_FORMAT_PCM_S8 :
decibels = max / 0x80 ;
break ;
case SF_FORMAT_PCM_16 :
decibels = max / 0x8000 ;
break ;
case SF_FORMAT_PCM_24 :
decibels = max / 0x800000 ;
break ;
case SF_FORMAT_PCM_32 :
decibels = max / 0x80000000 ;
break ;
case SF_FORMAT_FLOAT :
case SF_FORMAT_DOUBLE :
decibels = max / 1.0 ;
break ;
default :
decibels = max / 0x8000 ;
break ;
} ;
return 20.0 * log10 (decibels) ;
} /* calc_decibels */
static const char *
generate_duration_str (SF_INFO *sfinfo)
{ static char str [128] ;
int seconds ;
memset (str, 0, sizeof (str)) ;
if (sfinfo->samplerate < 1)
return NULL ;
if (sfinfo->frames / sfinfo->samplerate > 0x7FFFFFFF)
return "unknown" ;
seconds = sfinfo->frames / sfinfo->samplerate ;
snprintf (str, sizeof (str) - 1, "%02d:", seconds / 60 / 60) ;
seconds = seconds % (60 * 60) ;
snprintf (str + strlen (str), sizeof (str) - strlen (str) - 1, "%02d:", seconds / 60) ;
seconds = seconds % 60 ;
snprintf (str + strlen (str), sizeof (str) - strlen (str) - 1, "%02d.", seconds) ;
seconds = ((1000 * sfinfo->frames) / sfinfo->samplerate) % 1000 ;
snprintf (str + strlen (str), sizeof (str) - strlen (str) - 1, "%03d", seconds) ;
return str ;
} /* generate_duration_str */
static void
info_dump (const char *filename)
{ static char strbuffer [BUFFER_LEN] ;
SNDFILE *file ;
SF_INFO sfinfo ;
double signal_max, decibels ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Error : Not able to open input file %s.\n", filename) ;
fflush (stdout) ;
memset (data, 0, sizeof (data)) ;
sf_command (file, SFC_GET_LOG_INFO, strbuffer, BUFFER_LEN) ;
puts (strbuffer) ;
puts (sf_strerror (NULL)) ;
return ;
} ;
printf ("========================================\n") ;
sf_command (file, SFC_GET_LOG_INFO, strbuffer, BUFFER_LEN) ;
puts (strbuffer) ;
printf ("----------------------------------------\n") ;
if (file == NULL)
{ printf ("Error : Not able to open input file %s.\n", filename) ;
fflush (stdout) ;
memset (data, 0, sizeof (data)) ;
puts (sf_strerror (NULL)) ;
}
else
{ printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
if (sfinfo.frames > 0x7FFFFFFF)
printf ("Frames : unknown\n") ;
else
printf ("Frames : %ld\n", (long) sfinfo.frames) ;
printf ("Channels : %d\n", sfinfo.channels) ;
printf ("Format : 0x%08X\n", sfinfo.format) ;
printf ("Sections : %d\n", sfinfo.sections) ;
printf ("Seekable : %s\n", (sfinfo.seekable ? "TRUE" : "FALSE")) ;
printf ("Duration : %s\n", generate_duration_str (&sfinfo)) ;
/* Do not use sf_signal_max because it doesn work for non-seekable files . */
signal_max = get_signal_max (file) ;
decibels = calc_decibels (&sfinfo, signal_max) ;
printf ("Signal Max : %g (%4.2f dB)\n\n", signal_max, decibels) ;
} ;
sf_close (file) ;
} /* info_dump */
/*==============================================================================
** Dumping of SF_INSTRUMENT data.
*/
static const char *
str_of_type (int mode)
{ switch (mode)
{ case SF_LOOP_NONE : return "none" ;
case SF_LOOP_FORWARD : return "fwd " ;
case SF_LOOP_BACKWARD : return "back" ;
case SF_LOOP_ALTERNATING : return "alt " ;
default : break ;
} ;
return "????" ;
} /* str_of_mode */
static void
instrument_dump (const char *filename)
{ SNDFILE *file ;
SF_INFO sfinfo ;
SF_INSTRUMENT inst ;
int got_inst, k ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Error : Not able to open input file %s.\n", filename) ;
fflush (stdout) ;
memset (data, 0, sizeof (data)) ;
puts (sf_strerror (NULL)) ;
return ;
} ;
got_inst = sf_command (file, SFC_GET_INSTRUMENT, &inst, sizeof (inst)) ;
sf_close (file) ;
if (got_inst == SF_FALSE)
{ printf ("Error : File '%s' does not contain instrument data.\n\n", filename) ;
return ;
} ;
printf ("Instrument : %s\n\n", filename) ;
printf (" Gain : %d\n", inst.gain) ;
printf (" Base note : %d\n", inst.basenote) ;
printf (" Velocity : %d - %d\n", (int) inst.velocity_lo, (int) inst.velocity_hi) ;
printf (" Key : %d - %d\n", (int) inst.key_lo, (int) inst.key_hi) ;
printf (" Loop points : %d\n", inst.loop_count) ;
for (k = 0 ; k < inst.loop_count ; k++)
printf (" %-2d Mode : %s Start : %6d End : %6d Count : %6d\n", k, str_of_type (inst.loops [k].mode), inst.loops [k].start, inst.loops [k].end, inst.loops [k].count) ;
putchar ('\n') ;
} /* instrument_dump */
static void
broadcast_dump (const char *filename)
{ SNDFILE *file ;
SF_INFO sfinfo ;
SF_BROADCAST_INFO bext ;
int got_bext ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Error : Not able to open input file %s.\n", filename) ;
fflush (stdout) ;
memset (data, 0, sizeof (data)) ;
puts (sf_strerror (NULL)) ;
return ;
} ;
memset (&bext, 0, sizeof (SF_BROADCAST_INFO)) ;
got_bext = sf_command (file, SFC_GET_BROADCAST_INFO, &bext, sizeof (bext)) ;
sf_close (file) ;
if (got_bext == SF_FALSE)
{ printf ("Error : File '%s' does not contain broadcast information.\n\n", filename) ;
return ;
} ;
printf ("Description : %.*s\n", (int) sizeof (bext.description), bext.description) ;
printf ("Originator : %.*s\n", (int) sizeof (bext.originator), bext.originator) ;
printf ("Origination ref : %.*s\n", (int) sizeof (bext.originator_reference), bext.originator_reference) ;
printf ("Origination date : %.*s\n", (int) sizeof (bext.origination_date), bext.origination_date) ;
printf ("Origination time : %.*s\n", (int) sizeof (bext.origination_time), bext.origination_time) ;
printf ("BWF version : %d\n", bext.version) ;
printf ("UMID : %.*s\n", (int) sizeof (bext.umid), bext.umid) ;
printf ("Coding history : %.*s\n", bext.coding_history_size, bext.coding_history) ;
} /* broadcast_dump */
/*
** Do not edit or modify anything in this comment block.
** The arch-tag line is a file identity tag for the GNU Arch
** revision control system.
**
** arch-tag: f59a05db-a182-41de-aedd-d717ce2bb099
*/

View File

@ -1,153 +0,0 @@
/*
** Copyright (C) 2001 Marcus Overhagen <marcus@overhagen.de>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <Application.h>
#include <SoundPlayer.h>
#include <string.h>
#include <sndfile.h>
#define BUFFER_LEN 1024
/*------------------------------------------------------------------------------
** BeOS functions for playing a sound.
*/
#if defined (__BEOS__)
struct shared_data
{
BSoundPlayer *player;
SNDFILE *sndfile;
SF_INFO sfinfo;
sem_id finished;
};
static void
buffer_callback(void *theCookie, void *buf, size_t size, const media_raw_audio_format &format)
{
shared_data *data = (shared_data *)theCookie;
short *buffer = (short *)buf;
int count = size / sizeof(short);
int m, readcount;
if (!data->player->HasData())
return;
readcount = sf_read_short(data->sndfile, buffer, count);
if (readcount == 0)
{ data->player->SetHasData(false);
release_sem(data->finished);
}
if (readcount < count)
{ for (m = readcount ; m < count ; m++)
buffer [m] = 0 ;
}
if (data->sfinfo.pcmbitwidth < 16)
{ for (m = 0 ; m < count ; m++)
buffer [m] *= 256 ;
}
}
static void
beos_play (int argc, char *argv [])
{
shared_data data;
status_t status;
int k;
/* BSoundPlayer requires a BApplication object */
BApplication app("application/x-vnd.MarcusOverhagen-sfplay");
for (k = 1 ; k < argc ; k++)
{ printf ("Playing %s\n", argv [k]) ;
if (! (data.sndfile = sf_open_read (argv [k], &data.sfinfo)))
{ sf_perror (NULL) ;
continue ;
} ;
if (data.sfinfo.channels < 1 || data.sfinfo.channels > 2)
{ printf ("Error : channels = %d.\n", data.sfinfo.channels) ;
sf_close (data.sndfile) ;
continue ;
} ;
data.finished = create_sem(0,"finished");
media_raw_audio_format format =
{ data.sfinfo.samplerate,
data.sfinfo.channels,
media_raw_audio_format::B_AUDIO_SHORT,
B_HOST_IS_LENDIAN ? B_MEDIA_LITTLE_ENDIAN : B_MEDIA_BIG_ENDIAN,
BUFFER_LEN * sizeof(short)
};
BSoundPlayer player(&format,"player",buffer_callback,NULL,&data);
data.player = &player;
if ((status = player.InitCheck()) != B_OK)
{
printf ("Error : BSoundPlayer init failed, %s.\n", strerror(status)) ;
delete_sem(data.finished);
sf_close (data.sndfile) ;
continue ;
}
player.SetVolume(1.0);
player.Start();
player.SetHasData(true);
acquire_sem(data.finished);
player.Stop();
delete_sem(data.finished);
sf_close (data.sndfile) ;
} ;
} /* beos_play */
#endif
/*==============================================================================
** Main function.
*/
int
main (int argc, char *argv [])
{
if (argc < 2)
{ printf ("Usage : %s <input sound file>\n\n", argv [0]) ;
return 1 ;
} ;
beos_play (argc, argv) ;
return 0 ;
} /* main */
/*
** Do not edit or modify anything in this comment block.
** The arch-tag line is a file identity tag for the GNU Arch
** revision control system.
**
** arch-tag: 5407a79d-88de-41c7-8d8e-9acf2cf13cc1
*/

View File

@ -1,960 +0,0 @@
/*
** Copyright (C) 1999-2005 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "sfconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_ALSA_ASOUNDLIB_H
#define ALSA_PCM_NEW_HW_PARAMS_API
#define ALSA_PCM_NEW_SW_PARAMS_API
#include <alsa/asoundlib.h>
#include <sys/time.h>
#endif
#if defined (__linux__)
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#elif (defined (__MACH__) && defined (__APPLE__))
#include <Carbon.h>
#include <CoreAudio/AudioHardware.h>
#elif (defined (sun) && defined (unix))
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/audioio.h>
#elif (OS_IS_WIN32 == 1)
#include <windows.h>
#include <mmsystem.h>
#endif
#include <sndfile.h>
#define SIGNED_SIZEOF(x) ((int) sizeof (x))
#define BUFFER_LEN (2048)
/*------------------------------------------------------------------------------
** Linux/OSS functions for playing a sound.
*/
#if HAVE_ALSA_ASOUNDLIB_H
static snd_pcm_t * alsa_open (int channels, unsigned srate, int realtime) ;
static int alsa_write_float (snd_pcm_t *alsa_dev, float *data, int frames, int channels) ;
static void
alsa_play (int argc, char *argv [])
{ static float buffer [BUFFER_LEN] ;
SNDFILE *sndfile ;
SF_INFO sfinfo ;
snd_pcm_t * alsa_dev ;
int k, readcount, subformat ;
for (k = 1 ; k < argc ; k++)
{ memset (&sfinfo, 0, sizeof (sfinfo)) ;
printf ("Playing %s\n", argv [k]) ;
if (! (sndfile = sf_open (argv [k], SFM_READ, &sfinfo)))
{ puts (sf_strerror (NULL)) ;
continue ;
} ;
if (sfinfo.channels < 1 || sfinfo.channels > 2)
{ printf ("Error : channels = %d.\n", sfinfo.channels) ;
continue ;
} ;
if ((alsa_dev = alsa_open (sfinfo.channels, (unsigned) sfinfo.samplerate, SF_FALSE)) == NULL)
continue ;
subformat = sfinfo.format & SF_FORMAT_SUBMASK ;
if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE)
{ double scale ;
int m ;
sf_command (sndfile, SFC_CALC_SIGNAL_MAX, &scale, sizeof (scale)) ;
if (scale < 1e-10)
scale = 1.0 ;
else
scale = 32700.0 / scale ;
while ((readcount = sf_read_float (sndfile, buffer, BUFFER_LEN)))
{ for (m = 0 ; m < readcount ; m++)
buffer [m] *= scale ;
alsa_write_float (alsa_dev, buffer, BUFFER_LEN / sfinfo.channels, sfinfo.channels) ;
} ;
}
else
{ while ((readcount = sf_read_float (sndfile, buffer, BUFFER_LEN)))
alsa_write_float (alsa_dev, buffer, BUFFER_LEN / sfinfo.channels, sfinfo.channels) ;
} ;
snd_pcm_drain (alsa_dev) ;
snd_pcm_close (alsa_dev) ;
sf_close (sndfile) ;
} ;
return ;
} /* alsa_play */
static snd_pcm_t *
alsa_open (int channels, unsigned samplerate, int realtime)
{ const char * device = "plughw:0" ;
snd_pcm_t *alsa_dev = NULL ;
snd_pcm_hw_params_t *hw_params ;
snd_pcm_uframes_t buffer_size, xfer_align, start_threshold ;
snd_pcm_uframes_t alsa_period_size, alsa_buffer_frames ;
snd_pcm_sw_params_t *sw_params ;
int err ;
if (realtime)
{ alsa_period_size = 256 ;
alsa_buffer_frames = 3 * alsa_period_size ;
}
else
{ alsa_period_size = 1024 ;
alsa_buffer_frames = 4 * alsa_period_size ;
} ;
if ((err = snd_pcm_open (&alsa_dev, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
{ fprintf (stderr, "cannot open audio device \"%s\" (%s)\n", device, snd_strerror (err)) ;
goto catch_error ;
} ;
snd_pcm_nonblock (alsa_dev, 0) ;
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0)
{ fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n", snd_strerror (err)) ;
goto catch_error ;
} ;
if ((err = snd_pcm_hw_params_any (alsa_dev, hw_params)) < 0)
{ fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n", snd_strerror (err)) ;
goto catch_error ;
} ;
if ((err = snd_pcm_hw_params_set_access (alsa_dev, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
{ fprintf (stderr, "cannot set access type (%s)\n", snd_strerror (err)) ;
goto catch_error ;
} ;
if ((err = snd_pcm_hw_params_set_format (alsa_dev, hw_params, SND_PCM_FORMAT_FLOAT)) < 0)
{ fprintf (stderr, "cannot set sample format (%s)\n", snd_strerror (err)) ;
goto catch_error ;
} ;
if ((err = snd_pcm_hw_params_set_rate_near (alsa_dev, hw_params, &samplerate, 0)) < 0)
{ fprintf (stderr, "cannot set sample rate (%s)\n", snd_strerror (err)) ;
goto catch_error ;
} ;
if ((err = snd_pcm_hw_params_set_channels (alsa_dev, hw_params, channels)) < 0)
{ fprintf (stderr, "cannot set channel count (%s)\n", snd_strerror (err)) ;
goto catch_error ;
} ;
if ((err = snd_pcm_hw_params_set_buffer_size_near (alsa_dev, hw_params, &alsa_buffer_frames)) < 0)
{ fprintf (stderr, "cannot set buffer size (%s)\n", snd_strerror (err)) ;
goto catch_error ;
} ;
if ((err = snd_pcm_hw_params_set_period_size_near (alsa_dev, hw_params, &alsa_period_size, 0)) < 0)
{ fprintf (stderr, "cannot set period size (%s)\n", snd_strerror (err)) ;
goto catch_error ;
} ;
if ((err = snd_pcm_hw_params (alsa_dev, hw_params)) < 0)
{ fprintf (stderr, "cannot set parameters (%s)\n", snd_strerror (err)) ;
goto catch_error ;
} ;
/* extra check: if we have only one period, this code won't work */
snd_pcm_hw_params_get_period_size (hw_params, &alsa_period_size, 0) ;
snd_pcm_hw_params_get_buffer_size (hw_params, &buffer_size) ;
if (alsa_period_size == buffer_size)
{ fprintf (stderr, "Can't use period equal to buffer size (%lu == %lu)", alsa_period_size, buffer_size) ;
goto catch_error ;
} ;
snd_pcm_hw_params_free (hw_params) ;
if ((err = snd_pcm_sw_params_malloc (&sw_params)) != 0)
{ fprintf (stderr, "%s: snd_pcm_sw_params_malloc: %s", __func__, snd_strerror (err)) ;
goto catch_error ;
} ;
if ((err = snd_pcm_sw_params_current (alsa_dev, sw_params)) != 0)
{ fprintf (stderr, "%s: snd_pcm_sw_params_current: %s", __func__, snd_strerror (err)) ;
goto catch_error ;
} ;
/* note: set start threshold to delay start until the ring buffer is full */
snd_pcm_sw_params_current (alsa_dev, sw_params) ;
if ((err = snd_pcm_sw_params_get_xfer_align (sw_params, &xfer_align)) < 0)
{ fprintf (stderr, "cannot get xfer align (%s)\n", snd_strerror (err)) ;
goto catch_error ;
} ;
/* round up to closest transfer boundary */
start_threshold = (buffer_size / xfer_align) * xfer_align ;
if (start_threshold < 1)
start_threshold = 1 ;
if ((err = snd_pcm_sw_params_set_start_threshold (alsa_dev, sw_params, start_threshold)) < 0)
{ fprintf (stderr, "cannot set start threshold (%s)\n", snd_strerror (err)) ;
goto catch_error ;
} ;
if ((err = snd_pcm_sw_params (alsa_dev, sw_params)) != 0)
{ fprintf (stderr, "%s: snd_pcm_sw_params: %s", __func__, snd_strerror (err)) ;
goto catch_error ;
} ;
snd_pcm_sw_params_free (sw_params) ;
snd_pcm_reset (alsa_dev) ;
catch_error :
if (err < 0 && alsa_dev != NULL)
{ snd_pcm_close (alsa_dev) ;
return NULL ;
} ;
return alsa_dev ;
} /* alsa_open */
static int
alsa_write_float (snd_pcm_t *alsa_dev, float *data, int frames, int channels)
{ static int epipe_count = 0 ;
snd_pcm_status_t *status ;
int total = 0 ;
int retval ;
if (epipe_count > 0)
epipe_count -- ;
while (total < frames)
{ retval = snd_pcm_writei (alsa_dev, data + total * channels, frames - total) ;
if (retval >= 0)
{ total += retval ;
if (total == frames)
return total ;
continue ;
} ;
switch (retval)
{ case -EAGAIN :
puts ("alsa_write_float: EAGAIN") ;
continue ;
break ;
case -EPIPE :
if (epipe_count > 0)
{ printf ("alsa_write_float: EPIPE %d\n", epipe_count) ;
if (epipe_count > 140)
return retval ;
} ;
epipe_count += 100 ;
if (0)
{ snd_pcm_status_alloca (&status) ;
if ((retval = snd_pcm_status (alsa_dev, status)) < 0)
fprintf (stderr, "alsa_out: xrun. can't determine length\n") ;
else if (snd_pcm_status_get_state (status) == SND_PCM_STATE_XRUN)
{ struct timeval now, diff, tstamp ;
gettimeofday (&now, 0) ;
snd_pcm_status_get_trigger_tstamp (status, &tstamp) ;
timersub (&now, &tstamp, &diff) ;
fprintf (stderr, "alsa_write_float xrun: of at least %.3f msecs. resetting stream\n",
diff.tv_sec * 1000 + diff.tv_usec / 1000.0) ;
}
else
fprintf (stderr, "alsa_write_float: xrun. can't determine length\n") ;
} ;
snd_pcm_prepare (alsa_dev) ;
break ;
case -EBADFD :
fprintf (stderr, "alsa_write_float: Bad PCM state.n") ;
return 0 ;
break ;
case -ESTRPIPE :
fprintf (stderr, "alsa_write_float: Suspend event.n") ;
return 0 ;
break ;
case -EIO :
puts ("alsa_write_float: EIO") ;
return 0 ;
default :
fprintf (stderr, "alsa_write_float: retval = %d\n", retval) ;
return 0 ;
break ;
} ; /* switch */
} ; /* while */
return total ;
} /* alsa_write_float */
#endif /* HAVE_ALSA_ASOUNDLIB_H */
/*------------------------------------------------------------------------------
** Linux/OSS functions for playing a sound.
*/
#if defined (__linux__)
static int linux_open_dsp_device (int channels, int srate) ;
static void
linux_play (int argc, char *argv [])
{ static short buffer [BUFFER_LEN] ;
SNDFILE *sndfile ;
SF_INFO sfinfo ;
int k, audio_device, readcount, subformat ;
for (k = 1 ; k < argc ; k++)
{ memset (&sfinfo, 0, sizeof (sfinfo)) ;
printf ("Playing %s\n", argv [k]) ;
if (! (sndfile = sf_open (argv [k], SFM_READ, &sfinfo)))
{ puts (sf_strerror (NULL)) ;
continue ;
} ;
if (sfinfo.channels < 1 || sfinfo.channels > 2)
{ printf ("Error : channels = %d.\n", sfinfo.channels) ;
continue ;
} ;
audio_device = linux_open_dsp_device (sfinfo.channels, sfinfo.samplerate) ;
subformat = sfinfo.format & SF_FORMAT_SUBMASK ;
if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE)
{ static float float_buffer [BUFFER_LEN] ;
double scale ;
int m ;
sf_command (sndfile, SFC_CALC_SIGNAL_MAX, &scale, sizeof (scale)) ;
if (scale < 1e-10)
scale = 1.0 ;
else
scale = 32700.0 / scale ;
while ((readcount = sf_read_float (sndfile, float_buffer, BUFFER_LEN)))
{ for (m = 0 ; m < readcount ; m++)
buffer [m] = scale * float_buffer [m] ;
write (audio_device, buffer, readcount * sizeof (short)) ;
} ;
}
else
{ while ((readcount = sf_read_short (sndfile, buffer, BUFFER_LEN)))
write (audio_device, buffer, readcount * sizeof (short)) ;
} ;
if (ioctl (audio_device, SNDCTL_DSP_POST, 0) == -1)
perror ("ioctl (SNDCTL_DSP_POST) ") ;
if (ioctl (audio_device, SNDCTL_DSP_SYNC, 0) == -1)
perror ("ioctl (SNDCTL_DSP_SYNC) ") ;
close (audio_device) ;
sf_close (sndfile) ;
} ;
return ;
} /* linux_play */
static int
linux_open_dsp_device (int channels, int srate)
{ int fd, stereo, fmt ;
if ((fd = open ("/dev/dsp", O_WRONLY, 0)) == -1 &&
(fd = open ("/dev/sound/dsp", O_WRONLY, 0)) == -1)
{ perror ("linux_open_dsp_device : open ") ;
exit (1) ;
} ;
stereo = 0 ;
if (ioctl (fd, SNDCTL_DSP_STEREO, &stereo) == -1)
{ /* Fatal error */
perror ("linux_open_dsp_device : stereo ") ;
exit (1) ;
} ;
if (ioctl (fd, SNDCTL_DSP_RESET, 0))
{ perror ("linux_open_dsp_device : reset ") ;
exit (1) ;
} ;
fmt = CPU_IS_BIG_ENDIAN ? AFMT_S16_BE : AFMT_S16_LE ;
if (ioctl (fd, SOUND_PCM_SETFMT, &fmt) != 0)
{ perror ("linux_open_dsp_device : set format ") ;
exit (1) ;
} ;
if (ioctl (fd, SOUND_PCM_WRITE_CHANNELS, &channels) != 0)
{ perror ("linux_open_dsp_device : channels ") ;
exit (1) ;
} ;
if (ioctl (fd, SOUND_PCM_WRITE_RATE, &srate) != 0)
{ perror ("linux_open_dsp_device : sample rate ") ;
exit (1) ;
} ;
if (ioctl (fd, SNDCTL_DSP_SYNC, 0) != 0)
{ perror ("linux_open_dsp_device : sync ") ;
exit (1) ;
} ;
return fd ;
} /* linux_open_dsp_device */
#endif /* __linux__ */
/*------------------------------------------------------------------------------
** Mac OS X functions for playing a sound.
*/
#if (defined (__MACH__) && defined (__APPLE__)) /* MacOSX */
typedef struct
{ AudioStreamBasicDescription format ;
UInt32 buf_size ;
AudioDeviceID device ;
SNDFILE *sndfile ;
SF_INFO sfinfo ;
int fake_stereo ;
int done_playing ;
} MacOSXAudioData ;
#include <math.h>
static OSStatus
macosx_audio_out_callback (AudioDeviceID device, const AudioTimeStamp* current_time,
const AudioBufferList* data_in, const AudioTimeStamp* time_in,
AudioBufferList* data_out, const AudioTimeStamp* time_out,
void* client_data)
{ MacOSXAudioData *audio_data ;
int size, sample_count, read_count, k ;
float *buffer ;
/* Prevent compiler warnings. */
device = device ;
current_time = current_time ;
data_in = data_in ;
time_in = time_in ;
time_out = time_out ;
audio_data = (MacOSXAudioData*) client_data ;
size = data_out->mBuffers [0].mDataByteSize ;
sample_count = size / sizeof (float) ;
buffer = (float*) data_out->mBuffers [0].mData ;
if (audio_data->fake_stereo != 0)
{ read_count = sf_read_float (audio_data->sndfile, buffer, sample_count / 2) ;
for (k = read_count - 1 ; k >= 0 ; k--)
{ buffer [2 * k ] = buffer [k] ;
buffer [2 * k + 1] = buffer [k] ;
} ;
read_count *= 2 ;
}
else
read_count = sf_read_float (audio_data->sndfile, buffer, sample_count) ;
/* Fill the remainder with zeroes. */
if (read_count < sample_count)
{ if (audio_data->fake_stereo == 0)
memset (&(buffer [read_count]), 0, (sample_count - read_count) * sizeof (float)) ;
/* Tell the main application to terminate. */
audio_data->done_playing = SF_TRUE ;
} ;
return noErr ;
} /* macosx_audio_out_callback */
static void
macosx_play (int argc, char *argv [])
{ MacOSXAudioData audio_data ;
OSStatus err ;
UInt32 count, buffer_size ;
int k ;
audio_data.fake_stereo = 0 ;
audio_data.device = kAudioDeviceUnknown ;
/* get the default output device for the HAL */
count = sizeof (AudioDeviceID) ;
if ((err = AudioHardwareGetProperty (kAudioHardwarePropertyDefaultOutputDevice,
&count, (void *) &(audio_data.device))) != noErr)
{ printf ("AudioHardwareGetProperty (kAudioDevicePropertyDefaultOutputDevice) failed.\n") ;
return ;
} ;
/* get the buffersize that the default device uses for IO */
count = sizeof (UInt32) ;
if ((err = AudioDeviceGetProperty (audio_data.device, 0, false, kAudioDevicePropertyBufferSize,
&count, &buffer_size)) != noErr)
{ printf ("AudioDeviceGetProperty (kAudioDevicePropertyBufferSize) failed.\n") ;
return ;
} ;
/* get a description of the data format used by the default device */
count = sizeof (AudioStreamBasicDescription) ;
if ((err = AudioDeviceGetProperty (audio_data.device, 0, false, kAudioDevicePropertyStreamFormat,
&count, &(audio_data.format))) != noErr)
{ printf ("AudioDeviceGetProperty (kAudioDevicePropertyStreamFormat) failed.\n") ;
return ;
} ;
/* Base setup completed. Now play files. */
for (k = 1 ; k < argc ; k++)
{ printf ("Playing %s\n", argv [k]) ;
if (! (audio_data.sndfile = sf_open (argv [k], SFM_READ, &(audio_data.sfinfo))))
{ puts (sf_strerror (NULL)) ;
continue ;
} ;
if (audio_data.sfinfo.channels < 1 || audio_data.sfinfo.channels > 2)
{ printf ("Error : channels = %d.\n", audio_data.sfinfo.channels) ;
continue ;
} ;
audio_data.format.mSampleRate = audio_data.sfinfo.samplerate ;
if (audio_data.sfinfo.channels == 1)
{ audio_data.format.mChannelsPerFrame = 2 ;
audio_data.fake_stereo = 1 ;
}
else
audio_data.format.mChannelsPerFrame = audio_data.sfinfo.channels ;
if ((err = AudioDeviceSetProperty (audio_data.device, NULL, 0, false, kAudioDevicePropertyStreamFormat,
sizeof (AudioStreamBasicDescription), &(audio_data.format))) != noErr)
{ printf ("AudioDeviceSetProperty (kAudioDevicePropertyStreamFormat) failed.\n") ;
return ;
} ;
/* we want linear pcm */
if (audio_data.format.mFormatID != kAudioFormatLinearPCM)
return ;
/* Fire off the device. */
if ((err = AudioDeviceAddIOProc (audio_data.device, macosx_audio_out_callback,
(void *) &audio_data)) != noErr)
{ printf ("AudioDeviceAddIOProc failed.\n") ;
return ;
} ;
err = AudioDeviceStart (audio_data.device, macosx_audio_out_callback) ;
if (err != noErr)
return ;
audio_data.done_playing = SF_FALSE ;
while (audio_data.done_playing == SF_FALSE)
usleep (10 * 1000) ; /* 10 000 milliseconds. */
if ((err = AudioDeviceStop (audio_data.device, macosx_audio_out_callback)) != noErr)
{ printf ("AudioDeviceStop failed.\n") ;
return ;
} ;
err = AudioDeviceRemoveIOProc (audio_data.device, macosx_audio_out_callback) ;
if (err != noErr)
{ printf ("AudioDeviceRemoveIOProc failed.\n") ;
return ;
} ;
sf_close (audio_data.sndfile) ;
} ;
return ;
} /* macosx_play */
#endif /* MacOSX */
/*------------------------------------------------------------------------------
** Win32 functions for playing a sound.
**
** This API sucks. Its needlessly complicated and is *WAY* too loose with
** passing pointers arounf in integers and and using char* pointers to
** point to data instead of short*. It plain sucks!
*/
#if (OS_IS_WIN32 == 1)
#define WIN32_BUFFER_LEN (1<<15)
typedef struct
{ HWAVEOUT hwave ;
WAVEHDR whdr [2] ;
CRITICAL_SECTION mutex ; /* to control access to BuffersInUSe */
HANDLE Event ; /* signal that a buffer is free */
short buffer [WIN32_BUFFER_LEN / sizeof (short)] ;
int current, bufferlen ;
int BuffersInUse ;
SNDFILE *sndfile ;
SF_INFO sfinfo ;
sf_count_t remaining ;
} Win32_Audio_Data ;
static void
win32_play_data (Win32_Audio_Data *audio_data)
{ int thisread, readcount ;
/* fill a buffer if there is more data and we can read it sucessfully */
readcount = (audio_data->remaining > audio_data->bufferlen) ? audio_data->bufferlen : (int) audio_data->remaining ;
thisread = (int) sf_read_short (audio_data->sndfile, (short *) (audio_data->whdr [audio_data->current].lpData), readcount) ;
audio_data->remaining -= thisread ;
if (thisread > 0)
{ /* Fix buffer length if this is only a partial block. */
if (thisread < audio_data->bufferlen)
audio_data->whdr [audio_data->current].dwBufferLength = thisread * sizeof (short) ;
/* Queue the WAVEHDR */
waveOutWrite (audio_data->hwave, (LPWAVEHDR) &(audio_data->whdr [audio_data->current]), sizeof (WAVEHDR)) ;
/* count another buffer in use */
EnterCriticalSection (&audio_data->mutex) ;
audio_data->BuffersInUse ++ ;
LeaveCriticalSection (&audio_data->mutex) ;
/* use the other buffer next time */
audio_data->current = (audio_data->current + 1) % 2 ;
} ;
return ;
} /* win32_play_data */
static void CALLBACK
win32_audio_out_callback (HWAVEOUT hwave, UINT msg, DWORD data, DWORD param1, DWORD param2)
{ Win32_Audio_Data *audio_data ;
/* Prevent compiler warnings. */
hwave = hwave ;
param1 = param2 ;
if (data == 0)
return ;
/*
** I consider this technique of passing a pointer via an integer as
** fundamentally broken but thats the way microsoft has defined the
** interface.
*/
audio_data = (Win32_Audio_Data*) data ;
/* let main loop know a buffer is free */
if (msg == MM_WOM_DONE)
{ EnterCriticalSection (&audio_data->mutex) ;
audio_data->BuffersInUse -- ;
LeaveCriticalSection (&audio_data->mutex) ;
SetEvent (audio_data->Event) ;
} ;
return ;
} /* win32_audio_out_callback */
/* This is needed for earlier versions of the M$ development tools. */
#ifndef DWORD_PTR
#define DWORD_PTR DWORD
#endif
static void
win32_play (int argc, char *argv [])
{ Win32_Audio_Data audio_data ;
WAVEFORMATEX wf ;
int k, error ;
audio_data.sndfile = NULL ;
audio_data.hwave = 0 ;
for (k = 1 ; k < argc ; k++)
{ printf ("Playing %s\n", argv [k]) ;
if (! (audio_data.sndfile = sf_open (argv [k], SFM_READ, &(audio_data.sfinfo))))
{ puts (sf_strerror (NULL)) ;
continue ;
} ;
audio_data.remaining = audio_data.sfinfo.frames * audio_data.sfinfo.channels ;
audio_data.current = 0 ;
InitializeCriticalSection (&audio_data.mutex) ;
audio_data.Event = CreateEvent (0, FALSE, FALSE, 0) ;
wf.nChannels = audio_data.sfinfo.channels ;
wf.wFormatTag = WAVE_FORMAT_PCM ;
wf.cbSize = 0 ;
wf.wBitsPerSample = 16 ;
wf.nSamplesPerSec = audio_data.sfinfo.samplerate ;
wf.nBlockAlign = audio_data.sfinfo.channels * sizeof (short) ;
wf.nAvgBytesPerSec = wf.nBlockAlign * wf.nSamplesPerSec ;
error = waveOutOpen (&(audio_data.hwave), WAVE_MAPPER, &wf, (DWORD_PTR) win32_audio_out_callback,
(DWORD_PTR) &audio_data, CALLBACK_FUNCTION) ;
if (error)
{ puts ("waveOutOpen failed.") ;
audio_data.hwave = 0 ;
continue ;
} ;
audio_data.whdr [0].lpData = (char*) audio_data.buffer ;
audio_data.whdr [1].lpData = ((char*) audio_data.buffer) + sizeof (audio_data.buffer) / 2 ;
audio_data.whdr [0].dwBufferLength = sizeof (audio_data.buffer) / 2 ;
audio_data.whdr [1].dwBufferLength = sizeof (audio_data.buffer) / 2 ;
audio_data.whdr [0].dwFlags = 0 ;
audio_data.whdr [1].dwFlags = 0 ;
/* length of each audio buffer in samples */
audio_data.bufferlen = sizeof (audio_data.buffer) / 2 / sizeof (short) ;
/* Prepare the WAVEHDRs */
if ((error = waveOutPrepareHeader (audio_data.hwave, &(audio_data.whdr [0]), sizeof (WAVEHDR))))
{ printf ("waveOutPrepareHeader [0] failed : %08X\n", error) ;
waveOutClose (audio_data.hwave) ;
continue ;
} ;
if ((error = waveOutPrepareHeader (audio_data.hwave, &(audio_data.whdr [1]), sizeof (WAVEHDR))))
{ printf ("waveOutPrepareHeader [1] failed : %08X\n", error) ;
waveOutUnprepareHeader (audio_data.hwave, &(audio_data.whdr [0]), sizeof (WAVEHDR)) ;
waveOutClose (audio_data.hwave) ;
continue ;
} ;
/* Fill up both buffers with audio data */
audio_data.BuffersInUse = 0 ;
win32_play_data (&audio_data) ;
win32_play_data (&audio_data) ;
/* loop until both buffers are released */
while (audio_data.BuffersInUse > 0)
{
/* wait for buffer to be released */
WaitForSingleObject (audio_data.Event, INFINITE) ;
/* refill the buffer if there is more data to play */
win32_play_data (&audio_data) ;
} ;
waveOutUnprepareHeader (audio_data.hwave, &(audio_data.whdr [0]), sizeof (WAVEHDR)) ;
waveOutUnprepareHeader (audio_data.hwave, &(audio_data.whdr [1]), sizeof (WAVEHDR)) ;
waveOutClose (audio_data.hwave) ;
audio_data.hwave = 0 ;
DeleteCriticalSection (&audio_data.mutex) ;
sf_close (audio_data.sndfile) ;
} ;
} /* win32_play */
#endif /* Win32 */
/*------------------------------------------------------------------------------
** Solaris.
*/
#if (defined (sun) && defined (unix)) /* ie Solaris */
static void
solaris_play (int argc, char *argv [])
{ static short buffer [BUFFER_LEN] ;
audio_info_t audio_info ;
SNDFILE *sndfile ;
SF_INFO sfinfo ;
unsigned long delay_time ;
long k, start_count, output_count, write_count, read_count ;
int audio_fd, error, done ;
for (k = 1 ; k < argc ; k++)
{ printf ("Playing %s\n", argv [k]) ;
if (! (sndfile = sf_open (argv [k], SFM_READ, &sfinfo)))
{ puts (sf_strerror (NULL)) ;
continue ;
} ;
if (sfinfo.channels < 1 || sfinfo.channels > 2)
{ printf ("Error : channels = %d.\n", sfinfo.channels) ;
continue ;
} ;
/* open the audio device - write only, non-blocking */
if ((audio_fd = open ("/dev/audio", O_WRONLY | O_NONBLOCK)) < 0)
{ perror ("open (/dev/audio) failed") ;
return ;
} ;
/* Retrive standard values. */
AUDIO_INITINFO (&audio_info) ;
audio_info.play.sample_rate = sfinfo.samplerate ;
audio_info.play.channels = sfinfo.channels ;
audio_info.play.precision = 16 ;
audio_info.play.encoding = AUDIO_ENCODING_LINEAR ;
audio_info.play.gain = AUDIO_MAX_GAIN ;
audio_info.play.balance = AUDIO_MID_BALANCE ;
if ((error = ioctl (audio_fd, AUDIO_SETINFO, &audio_info)))
{ perror ("ioctl (AUDIO_SETINFO) failed") ;
return ;
} ;
/* Delay time equal to 1/4 of a buffer in microseconds. */
delay_time = (BUFFER_LEN * 1000000) / (audio_info.play.sample_rate * 4) ;
done = 0 ;
while (! done)
{ read_count = sf_read_short (sndfile, buffer, BUFFER_LEN) ;
if (read_count < BUFFER_LEN)
{ memset (&(buffer [read_count]), 0, (BUFFER_LEN - read_count) * sizeof (short)) ;
/* Tell the main application to terminate. */
done = SF_TRUE ;
} ;
start_count = 0 ;
output_count = BUFFER_LEN * sizeof (short) ;
while (output_count > 0)
{ /* write as much data as possible */
write_count = write (audio_fd, &(buffer [start_count]), output_count) ;
if (write_count > 0)
{ output_count -= write_count ;
start_count += write_count ;
}
else
{ /* Give the audio output time to catch up. */
usleep (delay_time) ;
} ;
} ; /* while (outpur_count > 0) */
} ; /* while (! done) */
close (audio_fd) ;
} ;
return ;
} /* solaris_play */
#endif /* Solaris */
/*==============================================================================
** Main function.
*/
int
main (int argc, char *argv [])
{
if (argc < 2)
{
printf ("\nUsage : %s <input sound file>\n\n", argv [0]) ;
#if (OS_IS_WIN32 == 1)
printf ("This is a Unix style command line application which\n"
"should be run in a MSDOS box or Command Shell window.\n\n") ;
printf ("Sleeping for 5 seconds before exiting.\n\n") ;
/* This is the officially blessed by microsoft way but I can't get
** it to link.
** Sleep (15) ;
** Instead, use this:
*/
_sleep (5 * 1000) ;
#endif
return 1 ;
} ;
#if defined (__linux__)
#if HAVE_ALSA_ASOUNDLIB_H
if (access ("/proc/asound/cards", R_OK) == 0)
alsa_play (argc, argv) ;
else
#endif
linux_play (argc, argv) ;
#elif (defined (__MACH__) && defined (__APPLE__))
macosx_play (argc, argv) ;
#elif (defined (sun) && defined (unix))
solaris_play (argc, argv) ;
#elif (OS_IS_WIN32 == 1)
win32_play (argc, argv) ;
#elif defined (__BEOS__)
printf ("This program cannot be compiled on BeOS.\n") ;
printf ("Instead, compile the file sfplay_beos.cpp.\n") ;
return 1 ;
#else
puts ("*** Playing sound not yet supported on this platform.") ;
puts ("*** Please feel free to submit a patch.") ;
return 1 ;
#endif
return 0 ;
} /* main */
/*
** Do not edit or modify anything in this comment block.
** The arch-tag line is a file identity tag for the GNU Arch
** revision control system.
**
** arch-tag: 8fc4110d-6cec-4e03-91df-0f384cabedac
*/

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** All rights reserved.
**

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2007 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,15 @@
## Process this file with automake to produce Makefile.in
man_MANS = sndfile-info.1 sndfile-play.1 sndfile-convert.1
man_MANS = sndfile-info.1 sndfile-play.1 sndfile-convert.1 sndfile-cmp.1 \
sndfile-metadata-get.1 sndfile-metadata-set.1 sndfile-concat.1 \
sndfile-interleave.1 sndfile-deinterleave.1
EXTRA_DIST = sndfile-info.1 sndfile-play.1 sndfile-convert.1
EXTRA_DIST = sndfile-info.1 sndfile-play.1 sndfile-convert.1 sndfile-cmp.1 \
sndfile-metadata-get.1 sndfile-concat.1 sndfile-interleave.1
# Same manpage for both programs.
sndfile-metadata-set.1 : sndfile-metadata-get.1
$(LN_S) $(srcdir)/sndfile-metadata-get.1 $@
sndfile-deinterleave.1 : sndfile-interleave.1
$(LN_S) $(srcdir)/sndfile-interleave.1 $@

View File

@ -16,7 +16,7 @@ The format of the output file is determined by the filename extension
of the output file.
.LP
The optional encoding parameter allows setting of the data encoding for
the output file. Run "sndfile-convert --help" for more information.
the output file. Run "sndfile\-convert \-\-help" for more information.
.SH AUTHOR
This manual page was written by Erik de Castro Lopo <erikd@mega-nerd.com>.

View File

@ -1,36 +1,47 @@
## Process this file with automake to produce Makefile.in
bin_PROGRAMS = sndfile-info sndfile-play sndfile-convert sndfile-jackplay sndfile-cmp \
sndfile-metadata-set sndfile-metadata-get
bin_PROGRAMS = sndfile-info sndfile-play sndfile-convert sndfile-cmp \
sndfile-metadata-set sndfile-metadata-get sndfile-interleave \
sndfile-deinterleave sndfile-concat sndfile-salvage
OS_SPECIFIC_CFLAGS = @OS_SPECIFIC_CFLAGS@
OS_SPECIFIC_LINKS = @OS_SPECIFIC_LINKS@
INCLUDES = -I$(top_srcdir)/src $(OS_SPECIFIC_CFLAGS)
CLEANFILES = *~
# This is the BeOS version of sndfile-play. It needs to be compiled with the C++
# compiler.
EXTRA_DIST = sndfile-play-beos.cpp test-sndfile-metadata-set.py
sndfile_info_SOURCES = sndfile-info.c
sndfile_info_SOURCES = sndfile-info.c common.c common.h
sndfile_info_LDADD = $(top_builddir)/src/libsndfile.la
sndfile_play_SOURCES = sndfile-play.c
sndfile_play_LDADD = $(top_builddir)/src/libsndfile.la $(OS_SPECIFIC_LINKS) $(ALSA_LIBS)
sndfile_jackplay_SOURCES = sndfile-jackplay.c
sndfile_jackplay_CFLAGS = $(JACK_CFLAGS)
sndfile_jackplay_LDADD = $(top_builddir)/src/libsndfile.la $(JACK_LIBS)
sndfile_play_SOURCES = sndfile-play.c common.c common.h
sndfile_play_LDADD = $(top_builddir)/src/libsndfile.la $(OS_SPECIFIC_LINKS) $(ALSA_LIBS) $(SNDIO_LIBS)
sndfile_convert_SOURCES = sndfile-convert.c common.c common.h
sndfile_convert_LDADD = $(top_builddir)/src/libsndfile.la
sndfile_cmp_SOURCES = sndfile-cmp.c
sndfile_cmp_SOURCES = sndfile-cmp.c common.c common.h
sndfile_cmp_LDADD = $(top_builddir)/src/libsndfile.la
sndfile_metadata_set_SOURCES = sndfile-metadata-set.c common.c common.h
sndfile_metadata_set_LDADD = $(top_builddir)/src/libsndfile.la
sndfile_metadata_get_SOURCES = sndfile-metadata-get.c
sndfile_metadata_get_SOURCES = sndfile-metadata-get.c common.c common.h
sndfile_metadata_get_LDADD = $(top_builddir)/src/libsndfile.la
sndfile_interleave_SOURCES = sndfile-interleave.c common.c common.h
sndfile_interleave_LDADD = $(top_builddir)/src/libsndfile.la
sndfile_deinterleave_SOURCES = sndfile-deinterleave.c common.c common.h
sndfile_deinterleave_LDADD = $(top_builddir)/src/libsndfile.la
sndfile_concat_SOURCES = sndfile-concat.c common.c common.h
sndfile_concat_LDADD = $(top_builddir)/src/libsndfile.la
sndfile_salvage_SOURCES = sndfile-salvage.c common.c common.h
sndfile_salvage_LDADD = $(top_builddir)/src/libsndfile.la

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2008 George Blood Audio
**
** All rights reserved.
@ -35,6 +35,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdint.h>
#include <sndfile.h>
@ -146,6 +147,14 @@ merge_broadcast_info (SNDFILE * infile, SNDFILE * outfile, int format, const MET
REPLACE_IF_NEW (origination_time) ;
REPLACE_IF_NEW (umid) ;
/* Special case for Time Ref. */
if (info->time_ref != NULL)
{ uint64_t ts = atoll (info->time_ref) ;
binfo.time_reference_high = (ts >> 32) ;
binfo.time_reference_low = (ts & 0xffffffff) ;
} ;
/* Special case for coding_history because we may want to append. */
if (info->coding_history != NULL)
{ if (info->coding_hist_append)
@ -180,22 +189,22 @@ update_strings (SNDFILE * outfile, const METADATA_INFO * info)
sf_set_string (outfile, SF_STR_TITLE, info->title) ;
if (info->copyright != NULL)
sf_set_string (outfile, SF_STR_TITLE, info->copyright) ;
sf_set_string (outfile, SF_STR_COPYRIGHT, info->copyright) ;
if (info->artist != NULL)
sf_set_string (outfile, SF_STR_ARTIST, info->artist) ;
if (info->comment != NULL)
sf_set_string (outfile, SF_STR_TITLE, info->comment) ;
sf_set_string (outfile, SF_STR_COMMENT, info->comment) ;
if (info->date != NULL)
sf_set_string (outfile, SF_STR_DATE, info->date) ;
if (info->album != NULL)
sf_set_string (outfile, SF_STR_TITLE, info->album) ;
sf_set_string (outfile, SF_STR_ALBUM, info->album) ;
if (info->license != NULL)
sf_set_string (outfile, SF_STR_TITLE, info->license) ;
sf_set_string (outfile, SF_STR_LICENSE, info->license) ;
} /* update_strings */
@ -238,8 +247,6 @@ sfe_apply_metadata_changes (const char * filenames [2], const METADATA_INFO * in
goto cleanup_exit ;
} ;
update_strings (outfile, info) ;
if (infile != outfile)
{ int infileminor = SF_FORMAT_SUBMASK & sfinfo.format ;
@ -250,6 +257,8 @@ sfe_apply_metadata_changes (const char * filenames [2], const METADATA_INFO * in
sfe_copy_data_int (outfile, infile, sfinfo.channels) ;
} ;
update_strings (outfile, info) ;
cleanup_exit :
if (outfile != NULL && outfile != infile)
@ -264,3 +273,107 @@ cleanup_exit :
return ;
} /* sfe_apply_metadata_changes */
/*==============================================================================
*/
typedef struct
{ const char *ext ;
int len ;
int format ;
} OUTPUT_FORMAT_MAP ;
static OUTPUT_FORMAT_MAP format_map [] =
{
{ "aif", 3, SF_FORMAT_AIFF },
{ "wav", 0, SF_FORMAT_WAV },
{ "au", 0, SF_FORMAT_AU },
{ "caf", 0, SF_FORMAT_CAF },
{ "flac", 0, SF_FORMAT_FLAC },
{ "snd", 0, SF_FORMAT_AU },
{ "svx", 0, SF_FORMAT_SVX },
{ "paf", 0, SF_ENDIAN_BIG | SF_FORMAT_PAF },
{ "fap", 0, SF_ENDIAN_LITTLE | SF_FORMAT_PAF },
{ "gsm", 0, SF_FORMAT_RAW },
{ "nist", 0, SF_FORMAT_NIST },
{ "htk", 0, SF_FORMAT_HTK },
{ "ircam", 0, SF_FORMAT_IRCAM },
{ "sf", 0, SF_FORMAT_IRCAM },
{ "voc", 0, SF_FORMAT_VOC },
{ "w64", 0, SF_FORMAT_W64 },
{ "raw", 0, SF_FORMAT_RAW },
{ "mat4", 0, SF_FORMAT_MAT4 },
{ "mat5", 0, SF_FORMAT_MAT5 },
{ "mat", 0, SF_FORMAT_MAT4 },
{ "pvf", 0, SF_FORMAT_PVF },
{ "sds", 0, SF_FORMAT_SDS },
{ "sd2", 0, SF_FORMAT_SD2 },
{ "vox", 0, SF_FORMAT_RAW },
{ "xi", 0, SF_FORMAT_XI },
{ "wve", 0, SF_FORMAT_WVE },
{ "oga", 0, SF_FORMAT_OGG },
{ "mpc", 0, SF_FORMAT_MPC2K },
{ "rf64", 0, SF_FORMAT_RF64 },
} ; /* format_map */
int
sfe_file_type_of_ext (const char *str, int format)
{ char buffer [16], *cptr ;
int k ;
format &= SF_FORMAT_SUBMASK ;
if ((cptr = strrchr (str, '.')) == NULL)
return 0 ;
strncpy (buffer, cptr + 1, 15) ;
buffer [15] = 0 ;
for (k = 0 ; buffer [k] ; k++)
buffer [k] = tolower ((buffer [k])) ;
if (strcmp (buffer, "gsm") == 0)
return SF_FORMAT_RAW | SF_FORMAT_GSM610 ;
if (strcmp (buffer, "vox") == 0)
return SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM ;
for (k = 0 ; k < (int) (sizeof (format_map) / sizeof (format_map [0])) ; k++)
{ if (format_map [k].len > 0 && strncmp (buffer, format_map [k].ext, format_map [k].len) == 0)
return format_map [k].format | format ;
else if (strcmp (buffer, format_map [k].ext) == 0)
return format_map [k].format | format ;
} ;
/* Default if all the above fails. */
return (SF_FORMAT_WAV | SF_FORMAT_PCM_24) ;
} /* sfe_file_type_of_ext */
void
sfe_dump_format_map (void)
{ SF_FORMAT_INFO info ;
int k ;
for (k = 0 ; k < ARRAY_LEN (format_map) ; k++)
{ info.format = format_map [k].format ;
sf_command (NULL, SFC_GET_FORMAT_INFO, &info, sizeof (info)) ;
printf (" %-10s : %s\n", format_map [k].ext, info.name == NULL ? "????" : info.name) ;
} ;
} /* sfe_dump_format_map */
const char *
program_name (const char * argv0)
{ const char * tmp ;
tmp = strrchr (argv0, '/') ;
argv0 = tmp ? tmp + 1 : argv0 ;
tmp = strrchr (argv0, '/') ;
argv0 = tmp ? tmp + 1 : argv0 ;
/* Remove leading libtool name mangling. */
if (strstr (argv0, "lt-") == argv0)
return argv0 + 3 ;
return argv0 ;
} /* program_name */

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** All rights reserved.
**
@ -30,7 +30,9 @@
** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sndfile.h>
#define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof (x [0])))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
typedef struct
{ const char * title ;
@ -53,6 +55,7 @@ typedef struct
const char * origination_time ;
const char * umid ;
const char * coding_history ;
const char * time_ref ;
} METADATA_INFO ;
typedef SF_BROADCAST_INFO_VAR (2048) SF_BROADCAST_INFO_2K ;
@ -62,3 +65,9 @@ void sfe_apply_metadata_changes (const char * filenames [2], const METADATA_INFO
void sfe_copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels) ;
void sfe_copy_data_int (SNDFILE *outfile, SNDFILE *infile, int channels) ;
int sfe_file_type_of_ext (const char *filename, int format) ;
void sfe_dump_format_map (void) ;
const char * program_name (const char * argv0) ;

View File

@ -1,5 +1,6 @@
/*
** Copyright (C) 2008-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2008 Conrad Parker <conrad@metadecks.org>
**
** All rights reserved.
**
@ -30,27 +31,31 @@
** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* sndfile-cmp.c
* Conrad Parker 2008
*/
#include "sfconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <sndfile.h>
#include "common.h"
/* Length of comparison data buffers in units of items */
#define BUFLEN 65536
static char * progname ;
static char * filename1, * filename2 ;
static const char * progname = NULL ;
static char * filename1 = NULL, * filename2 = NULL ;
static int
comparison_error (const char * what)
{ printf ("%s: %s of files %s and %s differ\n", progname, what, filename1, filename2) ;
comparison_error (const char * what, sf_count_t frame_offset)
{ char buffer [128] = "" ;
if (frame_offset >= 0)
snprintf (buffer, sizeof (buffer), " (at frame offset %" PRId64 ")", frame_offset) ;
printf ("%s: %s of files %s and %s differ%s.\n", progname, what, filename1, filename2, buffer) ;
return 1 ;
} /* comparison_error */
@ -60,7 +65,7 @@ compare (void)
double buf1 [BUFLEN], buf2 [BUFLEN] ;
SF_INFO sfinfo1, sfinfo2 ;
SNDFILE * sf1 = NULL, * sf2 = NULL ;
sf_count_t len, i, nread1, nread2 ;
sf_count_t items, i, nread1, nread2, offset = 0 ;
int retval = 0 ;
memset (&sfinfo1, 0, sizeof (SF_INFO)) ;
@ -80,34 +85,35 @@ compare (void)
} ;
if (sfinfo1.samplerate != sfinfo2.samplerate)
{ retval = comparison_error ("Samplerates") ;
{ retval = comparison_error ("Samplerates", -1) ;
goto out ;
} ;
if (sfinfo1.channels != sfinfo2.channels)
{ retval = comparison_error ("Number of channels") ;
{ retval = comparison_error ("Number of channels", -1) ;
goto out ;
} ;
/* Calculate the framecount that will fit in our data buffers */
len = BUFLEN / sfinfo1.channels ;
items = BUFLEN / sfinfo1.channels ;
while ( (nread1 = sf_readf_double (sf1, buf1, len)) > 0)
while ( (nread1 = sf_readf_double (sf1, buf1, items)) > 0)
{ nread2 = sf_readf_double (sf2, buf2, nread1) ;
if (nread2 != nread1)
{ retval = comparison_error ("PCM data lengths") ;
{ retval = comparison_error ("PCM data lengths", -1) ;
goto out ;
} ;
for (i = 0 ; i < nread1 ; i++)
for (i = 0 ; i < nread1 * sfinfo1.channels ; i++)
{ if (buf1 [i] != buf2 [i])
{ retval = comparison_error ("PCM data") ;
{ retval = comparison_error ("PCM data", offset + i / sfinfo1.channels) ;
goto out ;
} ;
} ;
offset += nread1 ;
} ;
if ( (nread2 = sf_readf_double (sf2, buf2, nread1)) != 0)
{ retval = comparison_error ("PCM data lengths") ;
{ retval = comparison_error ("PCM data lengths", -1) ;
goto out ;
} ;
@ -127,22 +133,22 @@ print_version (void)
} /* print_version */
static void
print_usage (void)
usage_exit (void)
{
print_version () ;
printf ("Usage : %s <filename> <filename>\n", progname) ;
printf (" Compare the PCM data of two sound files.\n\n") ;
} /* print_usage */
exit (0) ;
} /* usage_exit */
int
main (int argc, char *argv [])
{
progname = strrchr (argv [0], '/') ;
progname = progname ? progname + 1 : argv [0] ;
progname = program_name (argv [0]) ;
if (argc != 3)
{ print_usage () ;
{ usage_exit () ;
return 1 ;
} ;
@ -151,7 +157,7 @@ main (int argc, char *argv [])
if (strcmp (filename1, filename2) == 0)
{ printf ("Error : Input filenames are the same.\n\n") ;
print_usage () ;
usage_exit () ;
return 1 ;
} ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** All rights reserved.
**
@ -45,93 +45,18 @@ typedef struct
SF_INFO infileinfo, outfileinfo ;
} OptionData ;
typedef struct
{ const char *ext ;
int len ;
int format ;
} OUTPUT_FORMAT_MAP ;
static void copy_metadata (SNDFILE *outfile, SNDFILE *infile) ;
static OUTPUT_FORMAT_MAP format_map [] =
{
{ "aif", 3, SF_FORMAT_AIFF },
{ "wav", 0, SF_FORMAT_WAV },
{ "au", 0, SF_FORMAT_AU },
{ "caf", 0, SF_FORMAT_CAF },
{ "flac", 0, SF_FORMAT_FLAC },
{ "snd", 0, SF_FORMAT_AU },
{ "svx", 0, SF_FORMAT_SVX },
{ "paf", 0, SF_ENDIAN_BIG | SF_FORMAT_PAF },
{ "fap", 0, SF_ENDIAN_LITTLE | SF_FORMAT_PAF },
{ "gsm", 0, SF_FORMAT_RAW },
{ "nist", 0, SF_FORMAT_NIST },
{ "htk", 0, SF_FORMAT_HTK },
{ "ircam", 0, SF_FORMAT_IRCAM },
{ "sf", 0, SF_FORMAT_IRCAM },
{ "voc", 0, SF_FORMAT_VOC },
{ "w64", 0, SF_FORMAT_W64 },
{ "raw", 0, SF_FORMAT_RAW },
{ "mat4", 0, SF_FORMAT_MAT4 },
{ "mat5", 0, SF_FORMAT_MAT5 },
{ "mat", 0, SF_FORMAT_MAT4 },
{ "pvf", 0, SF_FORMAT_PVF },
{ "sds", 0, SF_FORMAT_SDS },
{ "sd2", 0, SF_FORMAT_SD2 },
{ "vox", 0, SF_FORMAT_RAW },
{ "xi", 0, SF_FORMAT_XI },
{ "wve", 0, SF_FORMAT_WVE },
{ "oga", 0, SF_FORMAT_OGG },
{ "mpc", 0, SF_FORMAT_MPC2K },
{ "rf64", 0, SF_FORMAT_RF64 },
} ; /* format_map */
static int
guess_output_file_type (char *str, int format)
{ char buffer [16], *cptr ;
int k ;
format &= SF_FORMAT_SUBMASK ;
if ((cptr = strrchr (str, '.')) == NULL)
return 0 ;
strncpy (buffer, cptr + 1, 15) ;
buffer [15] = 0 ;
for (k = 0 ; buffer [k] ; k++)
buffer [k] = tolower ((buffer [k])) ;
if (strcmp (buffer, "gsm") == 0)
return SF_FORMAT_RAW | SF_FORMAT_GSM610 ;
if (strcmp (buffer, "vox") == 0)
return SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM ;
for (k = 0 ; k < (int) (sizeof (format_map) / sizeof (format_map [0])) ; k++)
{ if (format_map [k].len > 0 && strncmp (buffer, format_map [k].ext, format_map [k].len) == 0)
return format_map [k].format | format ;
else if (strcmp (buffer, format_map [k].ext) == 0)
return format_map [k].format | format ;
} ;
return 0 ;
} /* guess_output_file_type */
static void copy_metadata (SNDFILE *outfile, SNDFILE *infile, int channels) ;
static void
print_usage (char *progname)
{ SF_FORMAT_INFO info ;
int k ;
usage_exit (const char *progname)
{
printf ("\nUsage : %s [options] [encoding] <input file> <output file>\n", progname) ;
puts ("\n"
" where [option] may be:\n\n"
" -override-sample-rate=X : force sample rate of input to X\n\n"
" -override-sample-rate=X : force sample rate of input to X\n"
) ;
puts ("\n"
puts (
" where [encoding] may be one of the following:\n\n"
" -pcms8 : force the output to signed 8 bit pcm\n"
" -pcmu8 : force the output to unsigned 8 bit pcm\n"
@ -157,28 +82,24 @@ print_usage (char *progname)
" output file name. The following extensions are currently understood:\n"
) ;
for (k = 0 ; k < (int) (sizeof (format_map) / sizeof (format_map [0])) ; k++)
{ info.format = format_map [k].format ;
sf_command (NULL, SFC_GET_FORMAT_INFO, &info, sizeof (info)) ;
printf (" %-10s : %s\n", format_map [k].ext, info.name) ;
} ;
sfe_dump_format_map () ;
puts ("") ;
} /* print_usage */
exit (0) ;
} /* usage_exit */
int
main (int argc, char * argv [])
{ char *progname, *infilename, *outfilename ;
{ const char *progname, *infilename, *outfilename ;
SNDFILE *infile = NULL, *outfile = NULL ;
SF_INFO sfinfo ;
int k, outfilemajor, outfileminor = 0, infileminor ;
int override_sample_rate = 0 ; /* assume no sample rate override. */
progname = strrchr (argv [0], '/') ;
progname = progname ? progname + 1 : argv [0] ;
progname = program_name (argv [0]) ;
if (argc < 3 || argc > 5)
{ print_usage (progname) ;
{ usage_exit (progname) ;
return 1 ;
} ;
@ -187,19 +108,19 @@ main (int argc, char * argv [])
if (strcmp (infilename, outfilename) == 0)
{ printf ("Error : Input and output filenames are the same.\n\n") ;
print_usage (progname) ;
usage_exit (progname) ;
return 1 ;
} ;
if (infilename [0] == '-')
if (strlen (infilename) > 1 && infilename [0] == '-')
{ printf ("Error : Input filename (%s) looks like an option.\n\n", infilename) ;
print_usage (progname) ;
usage_exit (progname) ;
return 1 ;
} ;
if (outfilename [0] == '-')
{ printf ("Error : Output filename (%s) looks like an option.\n\n", outfilename) ;
print_usage (progname) ;
usage_exit (progname) ;
return 1 ;
} ;
@ -277,6 +198,8 @@ main (int argc, char * argv [])
exit (1) ;
} ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
if ((infile = sf_open (infilename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Not able to open input file %s.\n", infilename) ;
puts (sf_strerror (NULL)) ;
@ -289,7 +212,7 @@ main (int argc, char * argv [])
infileminor = sfinfo.format & SF_FORMAT_SUBMASK ;
if ((sfinfo.format = guess_output_file_type (outfilename, sfinfo.format)) == 0)
if ((sfinfo.format = sfe_file_type_of_ext (outfilename, sfinfo.format)) == 0)
{ printf ("Error : Not able to determine output file type for %s.\n", outfilename) ;
return 1 ;
} ;
@ -328,7 +251,7 @@ main (int argc, char * argv [])
} ;
/* Copy the metadata */
copy_metadata (outfile, infile) ;
copy_metadata (outfile, infile, sfinfo.channels) ;
if ((outfileminor == SF_FORMAT_DOUBLE) || (outfileminor == SF_FORMAT_FLOAT)
|| (infileminor == SF_FORMAT_DOUBLE) || (infileminor == SF_FORMAT_FLOAT)
@ -344,21 +267,28 @@ main (int argc, char * argv [])
} /* main */
static void
copy_metadata (SNDFILE *outfile, SNDFILE *infile)
copy_metadata (SNDFILE *outfile, SNDFILE *infile, int channels)
{ SF_INSTRUMENT inst ;
SF_BROADCAST_INFO_2K binfo ;
const char *str ;
int k, err = 0 ;
int k, chanmap [256] ;
for (k = SF_STR_FIRST ; k <= SF_STR_LAST ; k++)
{ str = sf_get_string (infile, k) ;
if (str != NULL)
err = sf_set_string (outfile, k, str) ;
sf_set_string (outfile, k, str) ;
} ;
memset (&inst, 0, sizeof (inst)) ;
memset (&binfo, 0, sizeof (binfo)) ;
if (channels < ARRAY_LEN (chanmap))
{ size_t size = channels * sizeof (chanmap [0]) ;
if (sf_command (infile, SFC_GET_CHANNEL_MAP_INFO, chanmap, size) == SF_TRUE)
sf_command (outfile, SFC_SET_CHANNEL_MAP_INFO, chanmap, size) ;
} ;
if (sf_command (infile, SFC_GET_INSTRUMENT, &inst, sizeof (inst)) == SF_TRUE)
sf_command (outfile, SFC_SET_INSTRUMENT, &inst, sizeof (inst)) ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** All rights reserved.
**
@ -45,15 +45,15 @@
#if (defined (WIN32) || defined (_WIN32))
#include <windows.h>
#define snprintf _snprintf
#endif
static void print_version (void) ;
static void print_usage (const char *progname) ;
static void usage_exit (const char *progname) ;
static void info_dump (const char *filename) ;
static int instrument_dump (const char *filename) ;
static int broadcast_dump (const char *filename) ;
static int chanmap_dump (const char *filename) ;
static void total_dump (void) ;
static double total_seconds = 0.0 ;
@ -65,12 +65,7 @@ main (int argc, char *argv [])
print_version () ;
if (argc < 2 || strcmp (argv [1], "--help") == 0 || strcmp (argv [1], "-h") == 0)
{ char *progname ;
progname = strrchr (argv [0], '/') ;
progname = progname ? progname + 1 : argv [0] ;
print_usage (progname) ;
{ usage_exit (program_name (argv [0])) ;
return 1 ;
} ;
@ -90,6 +85,14 @@ main (int argc, char *argv [])
return error ;
} ;
if (strcmp (argv [1], "-c") == 0)
{ int error = 0 ;
for (k = 2 ; k < argc ; k++)
error += chanmap_dump (argv [k]) ;
return error ;
} ;
for (k = 1 ; k < argc ; k++)
info_dump (argv [k]) ;
@ -115,7 +118,7 @@ print_version (void)
static void
print_usage (const char *progname)
usage_exit (const char *progname)
{ printf ("Usage :\n %s <file> ...\n", progname) ;
printf (" Prints out information about one or more sound files.\n\n") ;
printf (" %s -i <file>\n", progname) ;
@ -135,7 +138,9 @@ print_usage (const char *progname)
*/
Sleep (5 * 1000) ;
#endif
} /* print_usage */
printf ("Using %s.\n\n", sf_version_string ()) ;
exit (0) ;
} /* usage_exit */
/*==============================================================================
** Dumping of sndfile info.
@ -248,7 +253,12 @@ info_dump (const char *filename)
printf ("----------------------------------------\n") ;
printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
printf ("Frames : %" PRId64 "\n", sfinfo.frames) ;
if (sfinfo.frames == SF_COUNT_MAX)
printf ("Frames : unknown\n") ;
else
printf ("Frames : %" PRId64 "\n", sfinfo.frames) ;
printf ("Channels : %d\n", sfinfo.channels) ;
printf ("Format : 0x%08X\n", sfinfo.format) ;
printf ("Sections : %d\n", sfinfo.sections) ;
@ -379,6 +389,82 @@ broadcast_dump (const char *filename)
return 0 ;
} /* broadcast_dump */
static int
chanmap_dump (const char *filename)
{ SNDFILE *file ;
SF_INFO sfinfo ;
int * channel_map ;
int got_chanmap, k ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Error : Not able to open input file %s.\n", filename) ;
fflush (stdout) ;
memset (data, 0, sizeof (data)) ;
puts (sf_strerror (NULL)) ;
return 1 ;
} ;
if ((channel_map = calloc (sfinfo.channels, sizeof (int))) == NULL)
{ printf ("Error : malloc failed.\n\n") ;
return 1 ;
} ;
got_chanmap = sf_command (file, SFC_GET_CHANNEL_MAP_INFO, channel_map, sfinfo.channels * sizeof (int)) ;
sf_close (file) ;
if (got_chanmap == SF_FALSE)
{ printf ("Error : File '%s' does not contain channel map information.\n\n", filename) ;
free (channel_map) ;
return 1 ;
} ;
printf ("File : %s\n\n", filename) ;
puts (" Chan Position") ;
for (k = 0 ; k < sfinfo.channels ; k ++)
{ const char * name ;
#define CASE_NAME(x) case x : name = #x ; break ;
switch (channel_map [k])
{ CASE_NAME (SF_CHANNEL_MAP_INVALID) ;
CASE_NAME (SF_CHANNEL_MAP_MONO) ;
CASE_NAME (SF_CHANNEL_MAP_LEFT) ;
CASE_NAME (SF_CHANNEL_MAP_RIGHT) ;
CASE_NAME (SF_CHANNEL_MAP_CENTER) ;
CASE_NAME (SF_CHANNEL_MAP_FRONT_LEFT) ;
CASE_NAME (SF_CHANNEL_MAP_FRONT_RIGHT) ;
CASE_NAME (SF_CHANNEL_MAP_FRONT_CENTER) ;
CASE_NAME (SF_CHANNEL_MAP_REAR_CENTER) ;
CASE_NAME (SF_CHANNEL_MAP_REAR_LEFT) ;
CASE_NAME (SF_CHANNEL_MAP_REAR_RIGHT) ;
CASE_NAME (SF_CHANNEL_MAP_LFE) ;
CASE_NAME (SF_CHANNEL_MAP_FRONT_LEFT_OF_CENTER) ;
CASE_NAME (SF_CHANNEL_MAP_FRONT_RIGHT_OF_CENTER) ;
CASE_NAME (SF_CHANNEL_MAP_SIDE_LEFT) ;
CASE_NAME (SF_CHANNEL_MAP_SIDE_RIGHT) ;
CASE_NAME (SF_CHANNEL_MAP_TOP_CENTER) ;
CASE_NAME (SF_CHANNEL_MAP_TOP_FRONT_LEFT) ;
CASE_NAME (SF_CHANNEL_MAP_TOP_FRONT_RIGHT) ;
CASE_NAME (SF_CHANNEL_MAP_TOP_FRONT_CENTER) ;
CASE_NAME (SF_CHANNEL_MAP_TOP_REAR_LEFT) ;
CASE_NAME (SF_CHANNEL_MAP_TOP_REAR_RIGHT) ;
CASE_NAME (SF_CHANNEL_MAP_TOP_REAR_CENTER) ;
CASE_NAME (SF_CHANNEL_MAP_MAX) ;
default : name = "default" ;
break ;
} ;
printf (" %3d %s\n", k, name) ;
} ;
putchar ('\n') ;
free (channel_map) ;
return 0 ;
} /* chanmap_dump */
static void
total_dump (void)
{ printf ("========================================\n") ;

View File

@ -1,277 +0,0 @@
/*
** Copyright (c) 2007-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2007 Jonatan Liljedahl <lijon@kymatica.com>
**
** This program is free software ; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation ; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY ; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program ; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "sfconfig.h"
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_JACK
#include <math.h>
#include <pthread.h>
#include <jack/jack.h>
#include <jack/ringbuffer.h>
#include <sndfile.h>
#define RB_SIZE (1 << 16)
typedef struct _thread_info
{ pthread_t thread_id ;
SNDFILE *sndfile ;
jack_nframes_t pos ;
jack_client_t *client ;
unsigned int channels ;
volatile int can_process ;
volatile int read_done ;
volatile int play_done ;
} thread_info_t ;
pthread_mutex_t disk_thread_lock = PTHREAD_MUTEX_INITIALIZER ;
pthread_cond_t data_ready = PTHREAD_COND_INITIALIZER ;
static jack_ringbuffer_t *ringbuf ;
static jack_port_t **output_port ;
static jack_default_audio_sample_t ** outs ;
const size_t sample_size = sizeof (jack_default_audio_sample_t) ;
static int
process (jack_nframes_t nframes, void * arg)
{
thread_info_t *info = (thread_info_t *) arg ;
jack_default_audio_sample_t buf [info->channels] ;
unsigned i, n ;
if (! info->can_process)
return 0 ;
for (n = 0 ; n < info->channels ; n++)
outs [n] = jack_port_get_buffer (output_port [n], nframes) ;
for (i = 0 ; i < nframes ; i++)
{ size_t read_cnt ;
/* Read one frame of audio. */
read_cnt = jack_ringbuffer_read (ringbuf, (void*) buf, sample_size*info->channels) ;
if (read_cnt == 0 && info->read_done)
{ /* File is done, so stop the main loop. */
info->play_done = 1 ;
return 0 ;
} ;
/* Update play-position counter. */
info->pos += read_cnt / (sample_size*info->channels) ;
/* Output each channel of the frame. */
for (n = 0 ; n < info->channels ; n++)
outs [n][i] = buf [n] ;
} ;
/* Wake up the disk thread to read more data. */
if (pthread_mutex_trylock (&disk_thread_lock) == 0)
{ pthread_cond_signal (&data_ready) ;
pthread_mutex_unlock (&disk_thread_lock) ;
} ;
return 0 ;
} /* process */
static void *
disk_thread (void *arg)
{ thread_info_t *info = (thread_info_t *) arg ;
sf_count_t buf_avail, read_frames ;
jack_ringbuffer_data_t vec [2] ;
size_t bytes_per_frame = sample_size*info->channels ;
pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL) ;
pthread_mutex_lock (&disk_thread_lock) ;
while (1)
{ jack_ringbuffer_get_write_vector (ringbuf, vec) ;
read_frames = 0 ;
if (vec [0].len)
{ /* Fill the first part of the ringbuffer. */
buf_avail = vec [0].len / bytes_per_frame ;
read_frames = sf_readf_float (info->sndfile, (float *) vec [0].buf, buf_avail) ;
if (vec [1].len)
{ /* Fill the second part of the ringbuffer? */
buf_avail = vec [1].len / bytes_per_frame ;
read_frames += sf_readf_float (info->sndfile, (float *) vec [1].buf, buf_avail) ;
} ;
} ;
if (read_frames == 0)
break ; /* end of file? */
jack_ringbuffer_write_advance (ringbuf, read_frames * bytes_per_frame) ;
/* Tell process that we've filled the ringbuffer. */
info->can_process = 1 ;
/* Wait for the process thread to wake us up. */
pthread_cond_wait (&data_ready, &disk_thread_lock) ;
} ;
/* Tell that we're done reading the file. */
info->read_done = 1 ;
pthread_mutex_unlock (&disk_thread_lock) ;
return 0 ;
} /* disk_thread */
static void
jack_shutdown (void *arg)
{ (void) arg ;
exit (1) ;
} /* jack_shutdown */
static void
print_time (jack_nframes_t pos, int jack_sr)
{ float sec = pos / (1.0 * jack_sr) ;
int min = sec / 60.0 ;
fprintf (stderr, "%02d:%05.2f", min, fmod (sec, 60.0)) ;
} /* print_time */
int
main (int narg, char * args [])
{
SNDFILE *sndfile ;
SF_INFO sndfileinfo ;
jack_client_t *client ;
thread_info_t info ;
int i, jack_sr ;
if (narg < 2)
{ fprintf (stderr, "no soundfile given\n") ;
return 1 ;
} ;
// create jack client
if ((client = jack_client_new ("jackplay")) == 0)
{
fprintf (stderr, "Jack server not running?\n") ;
return 1 ;
} ;
jack_sr = jack_get_sample_rate (client) ;
/* Open the soundfile. */
sndfileinfo.format = 0 ;
sndfile = sf_open (args [1], SFM_READ, &sndfileinfo) ;
if (sndfile == NULL)
{ fprintf (stderr, "Could not open soundfile '%s'\n", args [1]) ;
return 1 ;
} ;
fprintf (stderr, "Channels : %d\nSample rate : %d Hz\nDuration : ", sndfileinfo.channels, sndfileinfo.samplerate) ;
print_time (sndfileinfo.frames, sndfileinfo.samplerate) ;
fprintf (stderr, "\n") ;
if (sndfileinfo.samplerate != jack_sr)
fprintf (stderr, "Warning: samplerate of soundfile (%d Hz) does not match jack server (%d Hz).\n", sndfileinfo.samplerate, jack_sr) ;
/* Init the thread info struct. */
memset (&info, 0, sizeof (info)) ;
info.can_process = 0 ;
info.read_done = 0 ;
info.play_done = 0 ;
info.sndfile = sndfile ;
info.channels = sndfileinfo.channels ;
info.client = client ;
info.pos = 0 ;
/* Set up callbacks. */
jack_set_process_callback (client, process, &info) ;
jack_on_shutdown (client, jack_shutdown, 0) ;
/* Allocate output ports. */
output_port = calloc (sndfileinfo.channels, sizeof (jack_port_t *)) ;
outs = calloc (sndfileinfo.channels, sizeof (jack_default_audio_sample_t *)) ;
for (i = 0 ; i < sndfileinfo.channels ; i++)
{ char name [16] ;
snprintf (name, sizeof (name), "out_%d", i + 1) ;
output_port [i] = jack_port_register (client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0) ;
} ;
/* Allocate and clear ringbuffer. */
ringbuf = jack_ringbuffer_create (sizeof (jack_default_audio_sample_t) * RB_SIZE) ;
memset (ringbuf->buf, 0, ringbuf->size) ;
/* Activate client. */
if (jack_activate (client))
{ fprintf (stderr, "Cannot activate client.\n") ;
return 1 ;
} ;
/* Auto connect all channels. */
for (i = 0 ; i < sndfileinfo.channels ; i++)
{ char name [64] ;
snprintf (name, sizeof (name), "alsa_pcm:playback_%d", i + 1) ;
if (jack_connect (client, jack_port_name (output_port [i]), name))
fprintf (stderr, "Cannot connect output port %d (%s).\n", i, name) ;
} ;
/* Start the disk thread. */
pthread_create (&info.thread_id, NULL, disk_thread, &info) ;
/* Sit in a loop, displaying the current play position. */
while (! info.play_done)
{ fprintf (stderr, "\r-> ") ;
print_time (info.pos, jack_sr) ;
fflush (stdout) ;
usleep (50000) ;
} ;
/* Clean up. */
jack_client_close (client) ;
jack_ringbuffer_free (ringbuf) ;
sf_close (sndfile) ;
free (outs) ;
free (output_port) ;
puts ("") ;
return 0 ;
} /* main */
#else
int
main (void)
{
puts (
"Sorry this program was compiled without libjack (which probably\n"
"only exists on Linux and Mac OSX) and hence doesn't work."
) ;
return 0 ;
} /* main */
#endif

View File

@ -1,6 +1,6 @@
/*
** Copyright (C) 2008 George Blood Audio
** Written by Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2008-2010 George Blood Audio
**
** All rights reserved.
**
@ -58,8 +58,7 @@ main (int argc, char *argv [])
int start ;
/* Store the program name. */
progname = strrchr (argv [0], '/') ;
progname = progname ? progname + 1 : argv [0] ;
progname = program_name (argv [0]) ;
/* Check if we've been asked for help. */
if (argc <= 2 || strcmp (argv [1], "--help") == 0 || strcmp (argv [1], "-h") == 0)
@ -123,6 +122,7 @@ usage_exit (const char *progname, int exit_code)
" --str-license Print the license metadata.\n"
) ;
printf ("Using %s.\n\n", sf_version_string ()) ;
exit (exit_code) ;
} /* usage_exit */

View File

@ -1,6 +1,6 @@
/*
** Copyright (C) 2008 George Blood Audio
** Written by Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2008-2010 George Blood Audio
**
** All rights reserved.
**
@ -60,8 +60,7 @@ main (int argc, char *argv [])
int k ;
/* Store the program name. */
progname = strrchr (argv [0], '/') ;
progname = progname ? progname + 1 : argv [0] ;
progname = program_name (argv [0]) ;
/* Check if we've been asked for help. */
if (argc < 3 || strcmp (argv [1], "--help") == 0 || strcmp (argv [1], "-h") == 0)
@ -103,6 +102,7 @@ main (int argc, char *argv [])
HANDLE_BEXT_ARG ("--bext-orig-date", origination_date) ;
HANDLE_BEXT_ARG ("--bext-orig-time", origination_time) ;
HANDLE_BEXT_ARG ("--bext-coding-hist", coding_history) ;
HANDLE_BEXT_ARG ("--bext-time-ref", time_ref) ;
#define HANDLE_STR_ARG(cmd,field) \
if (strcmp (argv [k], cmd) == 0) \
@ -112,6 +112,7 @@ main (int argc, char *argv [])
continue ; \
} ;
HANDLE_STR_ARG ("--str-comment", comment) ;
HANDLE_STR_ARG ("--str-title", title) ;
HANDLE_STR_ARG ("--str-copyright", copyright) ;
HANDLE_STR_ARG ("--str-artist", artist) ;
@ -206,8 +207,10 @@ usage_exit (const char *progname, int exit_code)
" --bext-umid Set the 'bext' UMID.\n"
" --bext-orig-date Set the 'bext' origination date.\n"
" --bext-orig-time Set the 'bext' origination time.\n"
" --bext-coding-hist Set the 'bext' coding history\n"
" --bext-coding-hist Set the 'bext' coding history.\n"
" --bext-time-raf Set the 'bext' Time ref.\n"
"\n"
" --str-comment Set the metadata comment.\n"
" --str-title Set the metadata title.\n"
" --str-copyright Set the metadata copyright.\n"
" --str-artist Set the metadata artist.\n"
@ -231,6 +234,7 @@ usage_exit (const char *progname, int exit_code)
"exit with an appropriate error message.\n"
) ;
printf ("Using %s.\n\n", sf_version_string ()) ;
exit (exit_code) ;
} /* usage_exit */
@ -250,7 +254,7 @@ has_bext_fields_set (const METADATA_INFO * info)
if (info->description || info->originator || info->originator_reference)
return 1 ;
if (info->origination_date || info->origination_time || info->umid || info->coding_history)
if (info->origination_date || info->origination_time || info->umid || info->coding_history || info->time_ref)
return 1 ;
return 0 ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** All rights reserved.
**
@ -41,6 +41,10 @@
#include <unistd.h>
#endif
#include <sndfile.h>
#include "common.h"
#if HAVE_ALSA_ASOUNDLIB_H
#define ALSA_PCM_NEW_HW_PARAMS_API
#define ALSA_PCM_NEW_SW_PARAMS_API
@ -48,7 +52,7 @@
#include <sys/time.h>
#endif
#if defined (__linux__)
#if defined (__linux__) || defined (__FreeBSD_kernel__) || defined (__FreeBSD__)
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
@ -57,6 +61,9 @@
#include <Carbon.h>
#include <CoreAudio/AudioHardware.h>
#elif defined (HAVE_SNDIO_H)
#include <sndio.h>
#elif (defined (sun) && defined (unix))
#include <fcntl.h>
#include <sys/ioctl.h>
@ -68,8 +75,6 @@
#endif
#include <sndfile.h>
#define SIGNED_SIZEOF(x) ((int) sizeof (x))
#define BUFFER_LEN (2048)
@ -348,12 +353,12 @@ alsa_write_float (snd_pcm_t *alsa_dev, float *data, int frames, int channels)
** Linux/OSS functions for playing a sound.
*/
#if defined (__linux__)
#if defined (__linux__) || defined (__FreeBSD_kernel__) || defined (__FreeBSD__)
static int linux_open_dsp_device (int channels, int srate) ;
static int opensoundsys_open_device (int channels, int srate) ;
static void
linux_play (int argc, char *argv [])
static int
opensoundsys_play (int argc, char *argv [])
{ static short buffer [BUFFER_LEN] ;
SNDFILE *sndfile ;
SF_INFO sfinfo ;
@ -373,7 +378,7 @@ linux_play (int argc, char *argv [])
continue ;
} ;
audio_device = linux_open_dsp_device (sfinfo.channels, sfinfo.samplerate) ;
audio_device = opensoundsys_open_device (sfinfo.channels, sfinfo.samplerate) ;
subformat = sfinfo.format & SF_FORMAT_SUBMASK ;
@ -410,54 +415,54 @@ linux_play (int argc, char *argv [])
sf_close (sndfile) ;
} ;
return ;
} /* linux_play */
return writecount ;
} /* opensoundsys_play */
static int
linux_open_dsp_device (int channels, int srate)
opensoundsys_open_device (int channels, int srate)
{ int fd, stereo, fmt ;
if ((fd = open ("/dev/dsp", O_WRONLY, 0)) == -1 &&
(fd = open ("/dev/sound/dsp", O_WRONLY, 0)) == -1)
{ perror ("linux_open_dsp_device : open ") ;
{ perror ("opensoundsys_open_device : open ") ;
exit (1) ;
} ;
stereo = 0 ;
if (ioctl (fd, SNDCTL_DSP_STEREO, &stereo) == -1)
{ /* Fatal error */
perror ("linux_open_dsp_device : stereo ") ;
perror ("opensoundsys_open_device : stereo ") ;
exit (1) ;
} ;
if (ioctl (fd, SNDCTL_DSP_RESET, 0))
{ perror ("linux_open_dsp_device : reset ") ;
{ perror ("opensoundsys_open_device : reset ") ;
exit (1) ;
} ;
fmt = CPU_IS_BIG_ENDIAN ? AFMT_S16_BE : AFMT_S16_LE ;
if (ioctl (fd, SNDCTL_DSP_SETFMT, &fmt) != 0)
{ perror ("linux_open_dsp_device : set format ") ;
{ perror ("opensoundsys_open_device : set format ") ;
exit (1) ;
} ;
if (ioctl (fd, SNDCTL_DSP_CHANNELS, &channels) != 0)
{ perror ("linux_open_dsp_device : channels ") ;
{ perror ("opensoundsys_open_device : channels ") ;
exit (1) ;
} ;
if (ioctl (fd, SNDCTL_DSP_SPEED, &srate) != 0)
{ perror ("linux_open_dsp_device : sample rate ") ;
{ perror ("opensoundsys_open_device : sample rate ") ;
exit (1) ;
} ;
if (ioctl (fd, SNDCTL_DSP_SYNC, 0) != 0)
{ perror ("linux_open_dsp_device : sync ") ;
{ perror ("opensoundsys_open_device : sync ") ;
exit (1) ;
} ;
return fd ;
} /* linux_open_dsp_device */
} /* opensoundsys_open_device */
#endif /* __linux__ */
@ -819,6 +824,66 @@ win32_play (int argc, char *argv [])
#endif /* Win32 */
/*------------------------------------------------------------------------------
** OpenBDS's sndio.
*/
#if defined (HAVE_SNDIO_H)
static void
sndio_play (int argc, char *argv [])
{ struct sio_hdl *hdl ;
struct sio_par par ;
short buffer [BUFFER_LEN] ;
SNDFILE *sndfile ;
SF_INFO sfinfo ;
int k, readcount ;
for (k = 1 ; k < argc ; k++)
{ printf ("Playing %s\n", argv [k]) ;
if (! (sndfile = sf_open (argv [k], SFM_READ, &sfinfo)))
{ puts (sf_strerror (NULL)) ;
continue ;
} ;
if (sfinfo.channels < 1 || sfinfo.channels > 2)
{ printf ("Error : channels = %d.\n", sfinfo.channels) ;
continue ;
} ;
if ((hdl = sio_open (NULL, SIO_PLAY, 0)) == NULL)
{ fprintf (stderr, "open sndio device failed") ;
return ;
} ;
sio_initpar (&par) ;
par.rate = sfinfo.samplerate ;
par.pchan = sfinfo.channels ;
par.bits = 16 ;
par.sig = 1 ;
par.le = SIO_LE_NATIVE ;
if (! sio_setpar (hdl, &par) || ! sio_getpar (hdl, &par))
{ fprintf (stderr, "set sndio params failed") ;
return ;
} ;
if (! sio_start (hdl))
{ fprintf (stderr, "sndio start failed") ;
return ;
} ;
while ((readcount = sf_read_short (sndfile, buffer, BUFFER_LEN)))
sio_write (hdl, buffer, readcount * sizeof (short)) ;
sio_close (hdl) ;
} ;
return ;
} /* sndio_play */
#endif /* sndio */
/*------------------------------------------------------------------------------
** Solaris.
*/
@ -914,17 +979,13 @@ main (int argc, char *argv [])
{
if (argc < 2)
{
printf ("\nUsage : %s <input sound file>\n\n", argv [0]) ;
printf ("\nUsage : %s <input sound file>\n\n", program_name (argv [0])) ;
printf (" Using %s.\n\n", sf_version_string ()) ;
#if (OS_IS_WIN32 == 1)
printf ("This is a Unix style command line application which\n"
"should be run in a MSDOS box or Command Shell window.\n\n") ;
printf ("Sleeping for 5 seconds before exiting.\n\n") ;
/* This is the officially blessed by microsoft way but I can't get
** it to link.
** Sleep (15) ;
** Instead, use this:
*/
Sleep (5 * 1000) ;
#endif
return 1 ;
@ -936,9 +997,13 @@ main (int argc, char *argv [])
alsa_play (argc, argv) ;
else
#endif
linux_play (argc, argv) ;
opensoundsys_play (argc, argv) ;
#elif defined (__FreeBSD_kernel__) || defined (__FreeBSD__)
opensoundsys_play (argc, argv) ;
#elif (defined (__MACH__) && defined (__APPLE__))
macosx_play (argc, argv) ;
#elif defined HAVE_SNDIO_H
sndio_play (argc, argv) ;
#elif (defined (sun) && defined (unix))
solaris_play (argc, argv) ;
#elif (OS_IS_WIN32 == 1)

5
libs/libsndfile/programs/test-sndfile-metadata-set.py Normal file → Executable file
View File

@ -1,6 +1,6 @@
#!/usr/bin/python
# Copyright (C) 2008 Erik de Castro Lopo <erikd@mega-nerd.com>
# Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
#
# All rights reserved.
#
@ -176,7 +176,8 @@ test_post_mod (tests)
test_update ([ ("--str-artist", "Fox") ])
test_coding_history ()
# This never worked.
# test_coding_history ()
test_rewrite ()

View File

@ -1,63 +0,0 @@
#!/usr/bin/make -f
# The auto tools MUST be run in the following order:
#
# 1. aclocal
# 2. libtoolize (if you use libtool)
# 3. autoconf
# 4. autoheader (if you use autoheader)
# 5. automake (if you use automake)
#
# The following makefile runs these in the correct order according to their
# dependancies. It also makes up for Mac OSX's fucked-upped-ness.
ACLOCAL = aclocal
ifneq ($(shell uname -s), Darwin)
LIBTOOLIZE = libtoolize
else
# Fuck Apple! Why the hell did they rename libtoolize????
LIBTOOLIZE = glibtoolize
# Fink sucks as well, but this seems necessary.
ACLOCAL_INC = -I /sw/share/aclocal
endif
genfiles : config.status
(cd src && make genfiles)
(cd tests && make genfiles)
config.status: configure src/config.h.in Makefile.in src/Makefile.in tests/Makefile.in
./configure --enable-gcc-werror
configure: ltmain.sh
autoconf
Makefile.in: Makefile.am
automake --copy --add-missing
src/Makefile.in: src/Makefile.am
automake --copy --add-missing
tests/Makefile.in: tests/Makefile.am
automake --copy --add-missing
src/config.h.in: configure
autoheader
libtool ltmain.sh: aclocal.m4
$(LIBTOOLIZE) --copy --force
# Need to re-run aclocal whenever acinclude.m4 is modified.
aclocal.m4: acinclude.m4
$(ACLOCAL) $(ACLOCAL_INC)
clean:
rm -f libtool ltmain.sh aclocal.m4 Makefile.in src/config.h.in config.cache config.status
find . -name .deps -type d -exec rm -rf {} \;
# Do not edit or modify anything in this comment block.
# The arch-tag line is a file identity tag for the GNU Arch
# revision control system.
#
# arch-tag: 2b02bfd0-d5ed-489b-a554-2bf36903cca9

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2005-2009 Erik de Castro Lopo
** Copyright (C) 2005-2011 Erik de Castro Lopo
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2005-2009 Erik de Castro Lopo
** Copyright (C) 2005-2011 Erik de Castro Lopo
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -146,7 +146,7 @@ db_file_exists (REG_DB * db_handle, const char * filename)
db->count = 0 ;
err = sqlite3_exec (db->sql, db->cmdbuf, (sqlite3_callback) count_callback, db, &errmsg) ;
if (db->count == 1)
if (err == 0 && db->count == 1)
return 1 ;
return 0 ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2005 Erik de Castro Lopo
** Copyright (C) 2005-2011 Erik de Castro Lopo
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2005-2009 Erik de Castro Lopo
** Copyright (C) 2005-2011 Erik de Castro Lopo
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by

View File

@ -8,4 +8,5 @@ Description: A library for reading and writing audio files
Requires:
Version: @VERSION@
Libs: -L${libdir} -lsndfile
Libs.private: @EXTERNAL_LIBS@
Cflags: -I${includedir}

View File

@ -1,22 +0,0 @@
## Process this file with automake to produce Makefile.in
EXTRA_DIST = README README.original ChangeLog
noinst_HEADERS = g72x.h g72x_priv.h
noinst_LTLIBRARIES = libg72x.la
noinst_PROGRAMS = g72x_test
CFILES = g72x.c g721.c g723_16.c g723_24.c g723_40.c
libg72x_la_SOURCES = $(CFILES) $(noinst_HEADERS)
g72x_test_SOURCES = g72x_test.c
g72x_test_LDADD = ./libg72x.la -lm
check: g72x_test$(EXEEXT)
./g72x_test$(EXEEXT) all
# Disable autoheader.
AUTOHEADER=echo

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by

View File

@ -1,21 +1,21 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
@ -77,20 +77,20 @@ main (int argc, char *argv [])
return 0 ;
} /* main */
static void
static void
g721_test (void)
{
return ;
} /* g721_test */
static void
static void
g723_test (double margin)
{ static double orig_buffer [BUFFER_SIZE] ;
static short orig [BUFFER_SIZE] ;
static short data [BUFFER_SIZE] ;
G72x_STATE encoder_state, decoder_state ;
long k ;
int code, position, max_err ;
@ -104,10 +104,10 @@ g723_test (double margin)
memset (data, 0, BUFFER_SIZE * sizeof (short)) ;
memset (orig, 0, BUFFER_SIZE * sizeof (short)) ;
printf (" g723_test : ") ;
fflush (stdout) ;
gen_signal_double (orig_buffer, 32000.0, BUFFER_SIZE) ;
for (k = 0 ; k < BUFFER_SIZE ; k++)
orig [k] = (short) orig_buffer [k] ;
@ -144,13 +144,13 @@ g723_test (double margin)
#define SIGNAL_MAXVAL 30000.0
#define DECAY_COUNT 1000
static void
static void
gen_signal_double (double *gendata, double scale, int gendatalen)
{ int k, ramplen ;
double amp = 0.0 ;
ramplen = DECAY_COUNT ;
for (k = 0 ; k < gendatalen ; k++)
{ if (k <= ramplen)
amp = scale * k / ((double) ramplen) ;
@ -160,11 +160,11 @@ gen_signal_double (double *gendata, double scale, int gendatalen)
gendata [k] = amp * (0.4 * sin (33.3 * 2.0 * M_PI * ((double) (k+1)) / ((double) SAMPLE_RATE))
+ 0.3 * cos (201.1 * 2.0 * M_PI * ((double) (k+1)) / ((double) SAMPLE_RATE))) ;
} ;
return ;
} /* gen_signal_double */
static int
static int
error_function (double data, double orig, double margin)
{ double error ;
@ -174,7 +174,7 @@ error_function (double data, double orig, double margin)
error = fabs (data - orig) / 3000.0 ;
else
error = fabs (data - orig) / fabs (orig) ;
if (error > margin)
{ printf ("\n\n*******************\nError : %f\n", error) ;
return 1 ;
@ -182,21 +182,21 @@ error_function (double data, double orig, double margin)
return 0 ;
} /* error_function */
static int
static int
oct_save_short (short *a, short *b, int len)
{ FILE *file ;
int k ;
if (! (file = fopen ("error.dat", "w")))
return 1 ;
fprintf (file, "# Not created by Octave\n") ;
fprintf (file, "# name: a\n") ;
fprintf (file, "# type: matrix\n") ;
fprintf (file, "# rows: %d\n", len) ;
fprintf (file, "# columns: 1\n") ;
for (k = 0 ; k < len ; k++)
fprintf (file, "% d\n", a [k]) ;
@ -204,7 +204,7 @@ oct_save_short (short *a, short *b, int len)
fprintf (file, "# type: matrix\n") ;
fprintf (file, "# rows: %d\n", len) ;
fprintf (file, "# columns: 1\n") ;
for (k = 0 ; k < len ; k++)
fprintf (file, "% d\n", b [k]) ;

View File

@ -1,16 +0,0 @@
## Process this file with automake to produce Makefile.in
EXTRA_DIST = README COPYRIGHT ChangeLog
noinst_HEADERS = gsm.h config.h gsm610_priv.h
noinst_LTLIBRARIES = libgsm.la
CFILES = add.c decode.c gsm_decode.c gsm_encode.c long_term.c preprocess.c \
short_term.c code.c gsm_create.c gsm_destroy.c gsm_option.c lpc.c rpe.c table.c
libgsm_la_SOURCES = $(CFILES) $(noinst_HEADERS)
# Disable autoheader.
AUTOHEADER=echo

View File

@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = GSM610 G72x
AUTOMAKE_OPTIONS = subdir-objects
INCLUDES = @EXTERNAL_CFLAGS@
@ -8,29 +8,43 @@ lib_LTLIBRARIES = libsndfile.la
include_HEADERS = sndfile.hh
nodist_include_HEADERS = sndfile.h
noinst_LTLIBRARIES = libcommon.la
noinst_LTLIBRARIES = GSM610/libgsm.la G72x/libg72x.la libcommon.la
OS_SPECIFIC_CFLAGS = @OS_SPECIFIC_CFLAGS@
OS_SPECIFIC_LINKS = @OS_SPECIFIC_LINKS@
SYMBOL_FILES = Symbols.linux Symbols.darwin libsndfile-1.def Symbols.os2
SYMBOL_FILES = Symbols.gnu-binutils Symbols.darwin libsndfile-1.def Symbols.os2 Symbols.static
EXTRA_DIST = sndfile.h.in config.h.in test_endswap.tpl test_endswap.def \
$(SYMBOL_FILES) create_symbols_file.py binheader_writef_check.py
$(SYMBOL_FILES) create_symbols_file.py binheader_writef_check.py \
GSM610/README GSM610/COPYRIGHT GSM610/ChangeLog \
G72x/README G72x/README.original G72x/ChangeLog \
make-static-lib-hidden-privates.sh
noinst_HEADERS = common.h sfconfig.h sfendian.h wav_w64.h sf_unistd.h
noinst_HEADERS = common.h sfconfig.h sfendian.h wav_w64.h sf_unistd.h ogg.h chanmap.h
noinst_PROGRAMS =
check_PROGRAMS = test_main G72x/g72x_test
COMMON = common.c file_io.c command.c pcm.c ulaw.c alaw.c float32.c \
double64.c ima_adpcm.c ms_adpcm.c gsm610.c dwvw.c vox_adpcm.c \
interleave.c strings.c dither.c broadcast.c audio_detect.c \
ima_oki_adpcm.c ima_oki_adpcm.h chunk.c
ima_oki_adpcm.c ima_oki_adpcm.h chunk.c ogg.c chanmap.c \
windows.c id3.c $(WIN_VERSION_FILE)
FILESPECIFIC = sndfile.c aiff.c au.c avr.c caf.c dwd.c flac.c g72x.c htk.c ircam.c \
macbinary3.c macos.c mat4.c mat5.c nist.c ogg.c paf.c pvf.c raw.c rx2.c sd2.c \
sds.c svx.c txw.c voc.c wve.c w64.c wav_w64.c wav.c xi.c mpc2k.c rf64.c
macbinary3.c macos.c mat4.c mat5.c nist.c paf.c pvf.c raw.c rx2.c sd2.c \
sds.c svx.c txw.c voc.c wve.c w64.c wav_w64.c wav.c xi.c mpc2k.c rf64.c \
ogg_vorbis.c ogg_speex.c ogg_pcm.c
CLEANFILES = *~
if USE_WIN_VERSION_FILE
WIN_VERSION_FILE = version-metadata.rc
else
WIN_VERSION_FILE =
endif
#===============================================================================
# MinGW requires -no-undefined if a DLL is to be built.
libsndfile_la_LDFLAGS = -no-undefined -version-info @SHARED_VERSION_INFO@ @SHLIB_VERSION_ARG@
libsndfile_la_SOURCES = $(FILESPECIFIC) $(noinst_HEADERS)
@ -40,38 +54,48 @@ libsndfile_la_LIBADD = libcommon.la GSM610/libgsm.la G72x/libg72x.la \
libcommon_la_SOURCES = $(COMMON)
#test_main_SOURCES = test_main.c test_main.h test_conversions.c test_float.c test_endswap.c \
# test_audio_detect.c test_log_printf.c test_file_io.c test_ima_oki_adpcm.c
#test_main_LDADD = libcommon.la
#
#
#test_endswap.c: test_endswap.def test_endswap.tpl
# autogen --writable test_endswap.def
#======================================================================
# Subdir libraries.
genfiles : $(SYMBOL_FILES)
GSM610_libgsm_la_SOURCES = GSM610/config.h GSM610/gsm.h GSM610/gsm610_priv.h \
GSM610/add.c GSM610/code.c GSM610/decode.c GSM610/gsm_create.c \
GSM610/gsm_decode.c GSM610/gsm_destroy.c GSM610/gsm_encode.c \
GSM610/gsm_option.c GSM610/long_term.c GSM610/lpc.c GSM610/preprocess.c \
GSM610/rpe.c GSM610/short_term.c GSM610/table.c
# A single test programs.
# It is not possible to place these in the tests/ directory because they
# need access to the internals of the SF_PRIVATE struct.
G72x_libg72x_la_SOURCES = $(COMMON)G72x/g72x.h G72x/g72x_priv.h \
G72x/g721.c G72x/g723_16.c G72x/g723_24.c G72x/g723_40.c G72x/g72x.c
check: $(noinst_PROGRAMS)
@echo
@echo
@echo
@echo "============================================================"
@if [ -x /usr/bin/python2.5 ]; then $(srcdir)/binheader_writef_check.py $(srcdir)/*.c ; fi
#======================================================================
# Test programs.
test_main_SOURCES = test_main.c test_main.h test_conversions.c test_float.c test_endswap.c \
test_audio_detect.c test_log_printf.c test_file_io.c test_ima_oki_adpcm.c \
test_strncpy_crlf.c test_broadcast_var.c
test_main_LDADD = libcommon.la
G72x_g72x_test_SOURCES = G72x/g72x_test.c
G72x_g72x_test_LDADD = G72x/libg72x.la
test_endswap.c: test_endswap.def test_endswap.tpl
autogen --writable test_endswap.def
genfiles : test_endswap.c $(SYMBOL_FILES)
check :
@if [ -x /usr/bin/python ]; then $(srcdir)/binheader_writef_check.py $(srcdir)/*.c ; fi
G72x/g72x_test$(EXEEXT) all
./test_main$(EXEEXT)
@echo "============================================================"
@echo
@echo
@echo
# Need this target to force building of test programs.
checkprograms : $(check_PROGRAMS)
#======================================================================
# Generate an OS specific Symbols files. This is done when the author
# builds the distribution tarball. There should be not need for the
# end user to create these files.
Symbols.linux: create_symbols_file.py
Symbols.gnu-binutils: create_symbols_file.py
./create_symbols_file.py linux $(VERSION) > $@
Symbols.darwin: create_symbols_file.py
@ -83,18 +107,21 @@ libsndfile-1.def: create_symbols_file.py
Symbols.os2: create_symbols_file.py
./create_symbols_file.py os2 $(VERSION) > $@
Symbols.static: create_symbols_file.py
./create_symbols_file.py static $(VERSION) > $@
# Fake dependancy to force the creation of these files.
sndfile.o : $(SYMBOL_FILES)
#======================================================================
# Building windows resource files (if needed).
.rc.lo:
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --tag=RC --mode=compile $(RC) $(RCFLAGS) $< -o $@
#======================================================================
# Disable autoheader.
AUTOHEADER=echo
# Dependancies.
aiff.c au.c g72x.c ircam.c mat4.c mat5.c nist.c paf.c pvf.c : sndfile.h common.h
raw.c svx.c voc.c w64.c wav.c wav_w64.c htk.c sd2.c rx2.c txw.c : sndfile.h common.h
sds.c wve.c dwd.c ogg.c xi.c sndfile.c common.c file_io.c : sndfile.h common.h
command.c pcm.c ulaw.c alaw.c float32.c double64.c ima_adpcm.c : sndfile.h common.h
ms_adpcm.c gsm610.c dwvw.c vox_adpcm.c interleave.c strings.c : sndfile.h common.h
dither.c : sndfile.h common.h

View File

@ -30,6 +30,7 @@ _sf_write_double
_sf_strerror
_sf_get_string
_sf_set_string
_sf_version_string
_sf_open_fd
_sf_open_virtual
_sf_write_sync

View File

@ -1,42 +0,0 @@
# Auto-generated by create_symbols_file.py
libsndfile.so.1.0
{
global:
sf_command ;
sf_open ;
sf_close ;
sf_seek ;
sf_error ;
sf_perror ;
sf_error_str ;
sf_error_number ;
sf_format_check ;
sf_read_raw ;
sf_readf_short ;
sf_readf_int ;
sf_readf_float ;
sf_readf_double ;
sf_read_short ;
sf_read_int ;
sf_read_float ;
sf_read_double ;
sf_write_raw ;
sf_writef_short ;
sf_writef_int ;
sf_writef_float ;
sf_writef_double ;
sf_write_short ;
sf_write_int ;
sf_write_float ;
sf_write_double ;
sf_strerror ;
sf_get_string ;
sf_set_string ;
sf_open_fd ;
sf_open_virtual ;
sf_write_sync ;
local:
* ;
} ;

View File

@ -1,6 +1,6 @@
; Auto-generated by create_symbols_file.py
LIBRARY sndfile1.dll
LIBRARY sndfile1
INITINSTANCE TERMINSTANCE
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE NONSHARED
@ -36,6 +36,7 @@ _sf_write_double @40
_sf_strerror @50
_sf_get_string @60
_sf_set_string @61
_sf_version_string @68
_sf_open_fd @70
_sf_open_virtual @80
_sf_write_sync @90

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2005 David Viens <davidv@plogue.com>
**
** This program is free software; you can redistribute it and/or modify
@ -24,10 +24,12 @@
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <inttypes.h>
#include "sndfile.h"
#include "sfendian.h"
#include "common.h"
#include "chanmap.h"
/*------------------------------------------------------------------------------
* Macros to handle big/little endian issues.
@ -41,6 +43,7 @@
#define MARK_MARKER (MAKE_MARKER ('M', 'A', 'R', 'K'))
#define INST_MARKER (MAKE_MARKER ('I', 'N', 'S', 'T'))
#define APPL_MARKER (MAKE_MARKER ('A', 'P', 'P', 'L'))
#define CHAN_MARKER (MAKE_MARKER ('C', 'H', 'A', 'N'))
#define c_MARKER (MAKE_MARKER ('(', 'c', ')', ' '))
#define NAME_MARKER (MAKE_MARKER ('N', 'A', 'M', 'E'))
@ -187,6 +190,8 @@ typedef struct
sf_count_t comm_offset ;
sf_count_t ssnd_offset ;
int chanmap_tag ;
MARK_ID_POS *markstr ;
} AIFF_PRIVATE ;
@ -215,6 +220,8 @@ static short get_loop_mode (short mode) ;
static int aiff_read_basc_chunk (SF_PRIVATE * psf, int) ;
static int aiff_read_chanmap (SF_PRIVATE * psf, unsigned dword) ;
static unsigned int marker_to_position (const MARK_ID_POS *m, unsigned short n, int marksize) ;
/*------------------------------------------------------------------------------
@ -233,26 +240,26 @@ aiff_open (SF_PRIVATE *psf)
if ((psf->container_data = calloc (1, sizeof (AIFF_PRIVATE))) == NULL)
return SFE_MALLOC_FAILED ;
if (psf->mode == SFM_READ || (psf->mode == SFM_RDWR && psf->filelength > 0))
if (psf->file.mode == SFM_READ || (psf->file.mode == SFM_RDWR && psf->filelength > 0))
{ if ((error = aiff_read_header (psf, &comm_fmt)))
return error ;
psf_fseek (psf, psf->dataoffset, SEEK_SET) ;
} ;
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
{ if (psf->is_pipe)
return SFE_NO_PIPE_WRITE ;
if ((SF_CONTAINER (psf->sf.format)) != SF_FORMAT_AIFF)
return SFE_BAD_OPEN_FORMAT ;
if (psf->mode == SFM_WRITE && (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE))
if (psf->file.mode == SFM_WRITE && (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE))
{ if ((psf->peak_info = peak_info_calloc (psf->sf.channels)) == NULL)
return SFE_MALLOC_FAILED ;
psf->peak_info->peak_loc = SF_PEAK_START ;
} ;
if (psf->mode != SFM_RDWR || psf->filelength < 40)
if (psf->file.mode != SFM_RDWR || psf->filelength < 40)
{ psf->filelength = 0 ;
psf->datalength = 0 ;
psf->dataoffset = 0 ;
@ -315,7 +322,7 @@ aiff_open (SF_PRIVATE *psf)
break ;
case SF_FORMAT_DWVW_N :
if (psf->mode != SFM_READ)
if (psf->file.mode != SFM_READ)
{ error = SFE_DWVW_BAD_BITWIDTH ;
break ;
} ;
@ -369,7 +376,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
AIFF_PRIVATE *paiff ;
unsigned marker, dword, FORMsize, SSNDsize, bytesread ;
int k, found_chunk = 0, done = 0, error = 0 ;
char *cptr, byte ;
char *cptr ;
int instr_found = 0, mark_found = 0, mark_count = 0 ;
if (psf->filelength > SF_PLATFORM_S64 (0xffffffff))
@ -396,7 +403,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
while (! done)
{ psf_binheader_readf (psf, "m", &marker) ;
if (psf->mode == SFM_RDWR && (found_chunk & HAVE_SSND))
if (psf->file.mode == SFM_RDWR && (found_chunk & HAVE_SSND))
return SFE_AIFF_RW_SSND_NOT_LAST ;
switch (marker)
@ -405,7 +412,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
return SFE_AIFF_NO_FORM ;
psf_binheader_readf (psf, "E4", &FORMsize) ;
pchk4_store (&(paiff->chunk4), marker, psf->headindex - 8, FORMsize) ;
pchk4_store (&paiff->chunk4, marker, psf->headindex - 8, FORMsize) ;
if (psf->fileoffset > 0 && psf->filelength > FORMsize + 8)
{ /* Set file length. */
@ -485,10 +492,10 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
psf->peak_info->peaks [dword].value = value ;
psf->peak_info->peaks [dword].position = position ;
snprintf (cptr, sizeof (psf->u.scbuf), " %2d %-12ld %g\n",
dword, (long) psf->peak_info->peaks [dword].position, psf->peak_info->peaks [dword].value) ;
snprintf (cptr, sizeof (psf->u.scbuf), " %2d %-12" PRId64 " %g\n",
dword, psf->peak_info->peaks [dword].position, psf->peak_info->peaks [dword].value) ;
cptr [sizeof (psf->u.scbuf) - 1] = 0 ;
psf_log_printf (psf, cptr) ;
psf_log_printf (psf, "%s", cptr) ;
} ;
psf->peak_info->peak_loc = ((found_chunk & HAVE_SSND) == 0) ? SF_PEAK_START : SF_PEAK_END ;
@ -520,8 +527,10 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
psf->datalength -= ssnd_fmt.offset ;
}
else
{ psf_log_printf (psf, " Offset : %u (Should be zero)\n", ssnd_fmt.offset) ;
{ psf_log_printf (psf, " Offset : %u\n", ssnd_fmt.offset) ;
psf_log_printf (psf, " Block Size : %u ???\n", ssnd_fmt.blocksize) ;
psf->dataoffset += ssnd_fmt.offset ;
psf->datalength -= ssnd_fmt.offset ;
} ;
/* Only set dataend if there really is data at the end. */
@ -630,7 +639,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
cptr [dword] = 0 ;
for (k = 0 ; k < (int) dword ; k++)
if (! isprint (cptr [k]))
if (! psf_isprint (cptr [k]))
{ cptr [k] = 0 ;
break ;
} ;
@ -756,7 +765,6 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
pchk4_store (&paiff->chunk4, marker, psf_ftell (psf) - 8, dword) ;
psf_log_printf (psf, " %M : %d\n", marker, dword) ;
{ unsigned short mark_id, n = 0 ;
unsigned char pstr_len ;
unsigned int position ;
bytesread = psf_binheader_readf (psf, "E2", &n) ;
@ -771,13 +779,24 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
return SFE_MALLOC_FAILED ;
for (n = 0 ; n < mark_count && bytesread < dword ; n++)
{ bytesread += psf_binheader_readf (psf, "E241", &mark_id, &position, &pstr_len) ;
{ unsigned int pstr_len ;
unsigned char ch ;
bytesread += psf_binheader_readf (psf, "E241", &mark_id, &position, &ch) ;
psf_log_printf (psf, " Mark ID : %u\n Position : %u\n", mark_id, position) ;
pstr_len += (pstr_len & 1) ? 0 : 1 ;
pstr_len = (ch & 1) ? ch : ch + 1 ;
if (pstr_len < sizeof (psf->u.scbuf) - 1)
{ bytesread += psf_binheader_readf (psf, "b", psf->u.scbuf, pstr_len) ;
psf->u.scbuf [pstr_len] = 0 ;
}
else
{ unsigned int read_len = pstr_len - (sizeof (psf->u.scbuf) - 1) ;
bytesread += psf_binheader_readf (psf, "bj", psf->u.scbuf, read_len, pstr_len - read_len) ;
psf->u.scbuf [sizeof (psf->u.scbuf) - 1] = 0 ;
}
bytesread += psf_binheader_readf (psf, "b", psf->u.scbuf, pstr_len) ;
psf->u.scbuf [pstr_len] = 0 ;
psf_log_printf (psf, " Name : %s\n", psf->u.scbuf) ;
paiff->markstr [n].markerID = mark_id ;
@ -808,14 +827,32 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
case NONE_MARKER :
/* Fix for broken AIFC files with incorrect COMM chunk length. */
psf_binheader_readf (psf, "1", &byte) ;
dword = byte ;
psf_binheader_readf (psf, "j", dword) ;
{ unsigned char byte ;
psf_binheader_readf (psf, "1", &byte) ;
dword = byte ;
psf_binheader_readf (psf, "j", dword) ;
}
break ;
case CHAN_MARKER :
psf_binheader_readf (psf, "E4", &dword) ;
pchk4_store (&paiff->chunk4, marker, psf_ftell (psf) - 8, dword) ;
if (dword < 12)
{ psf_log_printf (psf, " %M : %d (should be >= 12)\n", marker, dword) ;
psf_binheader_readf (psf, "j", dword) ;
break ;
}
psf_log_printf (psf, " %M : %d\n", marker, dword) ;
if ((error = aiff_read_chanmap (psf, dword)))
return error ;
break ;
default :
if (isprint ((marker >> 24) & 0xFF) && isprint ((marker >> 16) & 0xFF)
&& isprint ((marker >> 8) & 0xFF) && isprint (marker & 0xFF))
if (psf_isprint ((marker >> 24) & 0xFF) && psf_isprint ((marker >> 16) & 0xFF)
&& psf_isprint ((marker >> 8) & 0xFF) && psf_isprint (marker & 0xFF))
{ psf_binheader_readf (psf, "E4", &dword) ;
psf_log_printf (psf, " %M : %d (unknown marker)\n", marker, dword) ;
@ -876,7 +913,7 @@ aiff_close (SF_PRIVATE *psf)
paiff->markstr = NULL ;
} ;
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
{ aiff_write_tailer (psf) ;
aiff_write_header (psf, SF_TRUE) ;
} ;
@ -1119,7 +1156,7 @@ aiff_write_header (SF_PRIVATE *psf, int calc_length)
psf->sf.frames = psf->datalength / (psf->bytewidth * psf->sf.channels) ;
} ;
if (psf->mode == SFM_RDWR && psf->dataoffset > 0 && paiff->chunk4.count > 0)
if (psf->file.mode == SFM_RDWR && psf->dataoffset > 0 && paiff->chunk4.count > 0)
{ int err = aiff_rewrite_header (psf, paiff) ;
if (current > 0)
psf_fseek (psf, current, SEEK_SET) ;
@ -1134,34 +1171,72 @@ aiff_write_header (SF_PRIVATE *psf, int calc_length)
bit_width = psf->bytewidth * 8 ;
comm_frames = (psf->sf.frames > 0xFFFFFFFF) ? 0xFFFFFFFF : psf->sf.frames ;
switch (SF_CODEC (psf->sf.format))
{ case SF_FORMAT_PCM_S8 :
switch (SF_CODEC (psf->sf.format) | endian)
{ case SF_FORMAT_PCM_S8 | SF_ENDIAN_BIG :
psf->endian = SF_ENDIAN_BIG ;
comm_type = AIFC_MARKER ;
comm_size = SIZEOF_AIFC_COMM ;
comm_encoding = twos_MARKER ;
break ;
case SF_FORMAT_PCM_S8 | SF_ENDIAN_LITTLE :
psf->endian = SF_ENDIAN_LITTLE ;
comm_type = AIFC_MARKER ;
comm_size = SIZEOF_AIFC_COMM ;
comm_encoding = sowt_MARKER ;
break ;
case SF_FORMAT_PCM_16 | SF_ENDIAN_BIG :
psf->endian = SF_ENDIAN_BIG ;
comm_type = AIFC_MARKER ;
comm_size = SIZEOF_AIFC_COMM ;
comm_encoding = twos_MARKER ;
break ;
case SF_FORMAT_PCM_16 | SF_ENDIAN_LITTLE :
psf->endian = SF_ENDIAN_LITTLE ;
comm_type = AIFC_MARKER ;
comm_size = SIZEOF_AIFC_COMM ;
comm_encoding = sowt_MARKER ;
break ;
case SF_FORMAT_PCM_24 | SF_ENDIAN_BIG :
psf->endian = SF_ENDIAN_BIG ;
comm_type = AIFC_MARKER ;
comm_size = SIZEOF_AIFC_COMM ;
comm_encoding = in24_MARKER ;
break ;
case SF_FORMAT_PCM_24 | SF_ENDIAN_LITTLE :
psf->endian = SF_ENDIAN_LITTLE ;
comm_type = AIFC_MARKER ;
comm_size = SIZEOF_AIFC_COMM ;
comm_encoding = ni24_MARKER ;
break ;
case SF_FORMAT_PCM_32 | SF_ENDIAN_BIG :
psf->endian = SF_ENDIAN_BIG ;
comm_type = AIFC_MARKER ;
comm_size = SIZEOF_AIFC_COMM ;
comm_encoding = in32_MARKER ;
break ;
case SF_FORMAT_PCM_32 | SF_ENDIAN_LITTLE :
psf->endian = SF_ENDIAN_LITTLE ;
comm_type = AIFC_MARKER ;
comm_size = SIZEOF_AIFC_COMM ;
comm_encoding = ni32_MARKER ;
break ;
case SF_FORMAT_PCM_S8 : /* SF_ENDIAN_FILE */
case SF_FORMAT_PCM_16 :
case SF_FORMAT_PCM_24 :
case SF_FORMAT_PCM_32 :
switch (endian)
{ case SF_ENDIAN_BIG :
psf->endian = SF_ENDIAN_BIG ;
comm_type = AIFC_MARKER ;
comm_size = SIZEOF_AIFC_COMM ;
comm_encoding = twos_MARKER ;
break ;
case SF_ENDIAN_LITTLE :
psf->endian = SF_ENDIAN_LITTLE ;
comm_type = AIFC_MARKER ;
comm_size = SIZEOF_AIFC_COMM ;
comm_encoding = sowt_MARKER ;
break ;
default : /* SF_ENDIAN_FILE */
psf->endian = SF_ENDIAN_BIG ;
comm_type = AIFF_MARKER ;
comm_size = SIZEOF_AIFF_COMM ;
comm_encoding = 0 ;
break ;
} ;
break ;
psf->endian = SF_ENDIAN_BIG ;
comm_type = AIFF_MARKER ;
comm_size = SIZEOF_AIFF_COMM ;
comm_encoding = 0 ;
break ;
case SF_FORMAT_FLOAT : /* Big endian floating point. */
psf->endian = SF_ENDIAN_BIG ;
@ -1278,6 +1353,9 @@ aiff_write_header (SF_PRIVATE *psf, int calc_length)
if (comm_type == AIFC_MARKER)
psf_binheader_writef (psf, "mb", comm_encoding, comm_zero_bytes, sizeof (comm_zero_bytes)) ;
if (psf->channel_map && paiff->chanmap_tag)
psf_binheader_writef (psf, "Em4444", CHAN_MARKER, 12, paiff->chanmap_tag, 0, 0) ;
if (psf->instrument != NULL)
{ MARK_ID_POS m [4] ;
INST_CHUNK ch ;
@ -1448,8 +1526,23 @@ aiff_write_strings (SF_PRIVATE *psf, int location)
} /* aiff_write_strings */
static int
aiff_command (SF_PRIVATE * UNUSED (psf), int UNUSED (command), void * UNUSED (data), int UNUSED (datasize))
{
aiff_command (SF_PRIVATE * psf, int command, void * UNUSED (data), int UNUSED (datasize))
{ AIFF_PRIVATE *paiff ;
if ((paiff = psf->container_data) == NULL)
return SFE_INTERNAL ;
switch (command)
{ case SFC_SET_CHANNEL_MAP_INFO :
paiff->chanmap_tag = aiff_caf_find_channel_layout_tag (psf->channel_map, psf->sf.channels) ;
return (paiff->chanmap_tag != 0) ;
default :
break ;
} ;
return 0 ;
} /* aiff_command */
@ -1610,3 +1703,36 @@ aiff_read_basc_chunk (SF_PRIVATE * psf, int datasize)
return 0 ;
} /* aiff_read_basc_chunk */
static int
aiff_read_chanmap (SF_PRIVATE * psf, unsigned dword)
{ const AIFF_CAF_CHANNEL_MAP * map_info ;
unsigned channel_bitmap, channel_decriptions, bytesread ;
int layout_tag ;
bytesread = psf_binheader_readf (psf, "444", &layout_tag, &channel_bitmap, &channel_decriptions) ;
if ((map_info = aiff_caf_of_channel_layout_tag (layout_tag)) == NULL)
return 0 ;
psf_log_printf (psf, " Tag : %x\n", layout_tag) ;
if (map_info)
psf_log_printf (psf, " Layout : %s\n", map_info->name) ;
if (bytesread < dword)
psf_binheader_readf (psf, "j", dword - bytesread) ;
if (map_info->channel_map != NULL)
{ size_t chanmap_size = psf->sf.channels * sizeof (psf->channel_map [0]) ;
free (psf->channel_map) ;
if ((psf->channel_map = malloc (chanmap_size)) == NULL)
return SFE_MALLOC_FAILED ;
memcpy (psf->channel_map, map_info->channel_map, chanmap_size) ;
} ;
return 0 ;
} /* aiff_read_chanmap */

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -47,14 +47,14 @@ static void d2alaw_array (const double *buffer, int count, unsigned char *ptr, d
int
alaw_init (SF_PRIVATE *psf)
{
if (psf->mode == SFM_READ || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_READ || psf->file.mode == SFM_RDWR)
{ psf->read_short = alaw_read_alaw2s ;
psf->read_int = alaw_read_alaw2i ;
psf->read_float = alaw_read_alaw2f ;
psf->read_double = alaw_read_alaw2d ;
} ;
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
{ psf->write_short = alaw_write_s2alaw ;
psf->write_int = alaw_write_i2alaw ;
psf->write_float = alaw_write_f2alaw ;
@ -69,7 +69,7 @@ alaw_init (SF_PRIVATE *psf)
else
psf->datalength = 0 ;
psf->sf.frames = psf->datalength / psf->blockwidth ;
psf->sf.frames = psf->blockwidth > 0 ? psf->datalength / psf->blockwidth : 0 ;
return 0 ;
} /* alaw_init */

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -106,7 +106,7 @@ au_open (SF_PRIVATE *psf)
{ int subformat ;
int error = 0 ;
if (psf->mode == SFM_READ || (psf->mode == SFM_RDWR && psf->filelength > 0))
if (psf->file.mode == SFM_READ || (psf->file.mode == SFM_RDWR && psf->filelength > 0))
{ if ((error = au_read_header (psf)))
return error ;
} ;
@ -116,7 +116,7 @@ au_open (SF_PRIVATE *psf)
subformat = SF_CODEC (psf->sf.format) ;
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
{ psf->endian = SF_ENDIAN (psf->sf.format) ;
if (CPU_IS_LITTLE_ENDIAN && psf->endian == SF_ENDIAN_CPU)
psf->endian = SF_ENDIAN_LITTLE ;
@ -189,7 +189,7 @@ au_open (SF_PRIVATE *psf)
static int
au_close (SF_PRIVATE *psf)
{
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
au_write_header (psf, SF_TRUE) ;
return 0 ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2004-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2004-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -80,7 +80,7 @@ int
avr_open (SF_PRIVATE *psf)
{ int error = 0 ;
if (psf->mode == SFM_READ || (psf->mode == SFM_RDWR && psf->filelength > 0))
if (psf->file.mode == SFM_READ || (psf->file.mode == SFM_RDWR && psf->filelength > 0))
{ if ((error = avr_read_header (psf)))
return error ;
} ;
@ -88,7 +88,7 @@ avr_open (SF_PRIVATE *psf)
if ((SF_CONTAINER (psf->sf.format)) != SF_FORMAT_AVR)
return SFE_BAD_OPEN_FORMAT ;
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
{ psf->endian = SF_ENDIAN (psf->sf.format) ;
psf->endian = SF_ENDIAN_BIG ;
@ -239,7 +239,7 @@ avr_write_header (SF_PRIVATE *psf, int calc_length)
static int
avr_close (SF_PRIVATE *psf)
{
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
avr_write_header (psf, SF_TRUE) ;
return 0 ;

10
libs/libsndfile/src/binheader_writef_check.py Normal file → Executable file
View File

@ -1,6 +1,6 @@
#!/usr/bin/python2.5
#!/usr/bin/python
# Copyright (C) 2006 Erik de Castro Lopo <erikd@mega-nerd.com>
# Copyright (C) 2006-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
#
# All rights reserved.
#
@ -97,13 +97,13 @@ def handle_file (fname):
print " %s" % item
errors += 1
param_index += 2
return errors
#===============================================================================
if len (sys.argv) > 1:
print "%s\n binheader_writef_check :" % sys.argv [0],
print "\n binheader_writef_check :",
sys.stdout.flush ()
errors = 0
for fname in sys.argv [1:]:
@ -112,5 +112,5 @@ if len (sys.argv) > 1:
print "\nErrors : %d\n" % errors
sys.exit (1)
print "ok"
print "ok\n"

View File

@ -1,6 +1,6 @@
/*
** Copyright (C) 2006-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2006 Paul Davis <paul@linuxaudiosystems.com>
** Copyright (C) 2006-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -17,13 +17,15 @@
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "sfconfig.h"
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include "common.h"
static void strncpy_crlf (char *dest, const char *src, size_t destmax, size_t srcmax) ;
static int gen_coding_history (char * added_history, int added_history_max, const SF_INFO * psfinfo) ;
static inline size_t
@ -32,29 +34,16 @@ bc_min_size (const SF_BROADCAST_INFO* info)
return 0 ;
return offsetof (SF_BROADCAST_INFO, coding_history) + info->coding_history_size ;
} /* broadcast_size */
} /* bc_min_size */
static inline size_t
bc_var_coding_hist_size (const SF_BROADCAST_VAR* var)
{ return var->size - offsetof (SF_BROADCAST_VAR, binfo.coding_history) ;
} /* broadcast_size */
SF_BROADCAST_VAR*
broadcast_var_alloc (size_t datasize)
{ SF_BROADCAST_VAR * data ;
if ((data = calloc (1, datasize)) != NULL)
data->size = datasize ;
return data ;
SF_BROADCAST_INFO_16K*
broadcast_var_alloc (void)
{ return calloc (1, sizeof (SF_BROADCAST_INFO_16K)) ;
} /* broadcast_var_alloc */
int
broadcast_var_set (SF_PRIVATE *psf, const SF_BROADCAST_INFO * info, size_t datasize)
{ char added_history [256] ;
int added_history_len, len ;
{ size_t len ;
if (info == NULL)
return SF_FALSE ;
@ -64,42 +53,40 @@ broadcast_var_set (SF_PRIVATE *psf, const SF_BROADCAST_INFO * info, size_t datas
return SF_FALSE ;
} ;
added_history_len = gen_coding_history (added_history, sizeof (added_history), &(psf->sf)) ;
if (datasize >= sizeof (SF_BROADCAST_INFO_16K))
{ psf->error = SFE_BAD_BROADCAST_INFO_TOO_BIG ;
return SF_FALSE ;
} ;
if (psf->broadcast_var != NULL)
{ size_t coding_hist_offset = offsetof (SF_BROADCAST_INFO, coding_history) ;
if (psf->broadcast_var->binfo.coding_history_size + added_history_len < datasize - coding_hist_offset)
{ free (psf->broadcast_var) ;
psf->broadcast_var = NULL ;
if (psf->broadcast_16k == NULL)
{ if ((psf->broadcast_16k = broadcast_var_alloc ()) == NULL)
{ psf->error = SFE_MALLOC_FAILED ;
return SF_FALSE ;
} ;
} ;
if (psf->broadcast_var == NULL)
{ int size = datasize + added_history_len + 512 ;
memcpy (psf->broadcast_16k, info, offsetof (SF_BROADCAST_INFO, coding_history)) ;
psf->broadcast_var = calloc (1, size) ;
psf->broadcast_var->size = size ;
psf_strlcpy_crlf (psf->broadcast_16k->coding_history, info->coding_history, sizeof (psf->broadcast_16k->coding_history), datasize - offsetof (SF_BROADCAST_INFO, coding_history)) ;
len = strlen (psf->broadcast_16k->coding_history) ;
if (len > 0 && psf->broadcast_16k->coding_history [len - 1] != '\n')
psf_strlcat (psf->broadcast_16k->coding_history, sizeof (psf->broadcast_16k->coding_history), "\r\n") ;
if (psf->file.mode == SFM_WRITE)
{ char added_history [256] ;
gen_coding_history (added_history, sizeof (added_history), &(psf->sf)) ;
psf_strlcat (psf->broadcast_16k->coding_history, sizeof (psf->broadcast_16k->coding_history), added_history) ;
} ;
memcpy (&(psf->broadcast_var->binfo), info, offsetof (SF_BROADCAST_INFO, coding_history)) ;
strncpy_crlf (psf->broadcast_var->binfo.coding_history, info->coding_history, bc_var_coding_hist_size (psf->broadcast_var), info->coding_history_size) ;
len = strlen (psf->broadcast_var->binfo.coding_history) ;
if (len > 0 && psf->broadcast_var->binfo.coding_history [len] != '\n')
strncat (psf->broadcast_var->binfo.coding_history, "\r\n", 2) ;
if (psf->mode == SFM_WRITE)
strncat (psf->broadcast_var->binfo.coding_history, added_history, strlen (added_history)) ;
psf->broadcast_var->binfo.coding_history_size = strlen (psf->broadcast_var->binfo.coding_history) ;
/* Fore coding_history_size to be even. */
psf->broadcast_var->binfo.coding_history_size += (psf->broadcast_var->binfo.coding_history_size & 1) ? 1 : 0 ;
/* Force coding_history_size to be even. */
len = strlen (psf->broadcast_16k->coding_history) ;
len += (len & 1) ? 1 : 2 ;
psf->broadcast_16k->coding_history_size = len ;
/* Currently writing this version. */
psf->broadcast_var->binfo.version = 1 ;
psf->broadcast_16k->version = 1 ;
return SF_TRUE ;
} /* broadcast_var_set */
@ -109,54 +96,19 @@ int
broadcast_var_get (SF_PRIVATE *psf, SF_BROADCAST_INFO * data, size_t datasize)
{ size_t size ;
if (psf->broadcast_var == NULL)
if (psf->broadcast_16k == NULL)
return SF_FALSE ;
size = SF_MIN (datasize, bc_min_size (&(psf->broadcast_var->binfo))) ;
size = SF_MIN (datasize, bc_min_size ((const SF_BROADCAST_INFO *) psf->broadcast_16k)) ;
memcpy (data, &(psf->broadcast_var->binfo), size) ;
memcpy (data, psf->broadcast_16k, size) ;
return SF_TRUE ;
} /* broadcast_var_set */
} /* broadcast_var_get */
/*------------------------------------------------------------------------------
** Strncpy which converts all line endings to CR/LF.
*/
static void
strncpy_crlf (char *dest, const char *src, size_t destmax, size_t srcmax)
{ char * destend = dest + destmax - 1 ;
const char * srcend = src + srcmax ;
while (dest < destend && src < srcend)
{ if ((src [0] == '\r' && src [1] == '\n') || (src [0] == '\n' && src [1] == '\r'))
{ *dest++ = '\r' ;
*dest++ = '\n' ;
src += 2 ;
continue ;
} ;
if (src [0] == '\r')
{ *dest++ = '\r' ;
*dest++ = '\n' ;
src += 1 ;
continue ;
} ;
if (src [0] == '\n')
{ *dest++ = '\r' ;
*dest++ = '\n' ;
src += 1 ;
continue ;
} ;
*dest++ = *src++ ;
} ;
/* Make sure dest is terminated. */
*dest = 0 ;
} /* strncpy_crlf */
static int
gen_coding_history (char * added_history, int added_history_max, const SF_INFO * psfinfo)
{ char chnstr [16] ;
@ -185,11 +137,11 @@ gen_coding_history (char * added_history, int added_history_max, const SF_INFO *
return SF_FALSE ;
case 1 :
strncpy (chnstr, "mono", sizeof (chnstr)) ;
psf_strlcpy (chnstr, sizeof (chnstr), "mono") ;
break ;
case 2 :
strncpy (chnstr, "stereo", sizeof (chnstr)) ;
psf_strlcpy (chnstr, sizeof (chnstr), "stereo") ;
break ;
default :

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2005-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2005-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -23,10 +23,12 @@
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <inttypes.h>
#include "sndfile.h"
#include "sfendian.h"
#include "common.h"
#include "chanmap.h"
/*------------------------------------------------------------------------------
** Macros to handle big/little endian issues.
@ -82,6 +84,10 @@ typedef struct
unsigned int bits_per_chan ;
} DESC_CHUNK ;
typedef struct
{ int chanmap_tag ;
} CAF_PRIVATE ;
/*------------------------------------------------------------------------------
** Private static functions.
*/
@ -89,6 +95,8 @@ typedef struct
static int caf_close (SF_PRIVATE *psf) ;
static int caf_read_header (SF_PRIVATE *psf) ;
static int caf_write_header (SF_PRIVATE *psf, int calc_length) ;
static int caf_command (SF_PRIVATE *psf, int command, void *data, int datasize) ;
static int caf_read_chanmap (SF_PRIVATE * psf, sf_count_t chunk_size) ;
/*------------------------------------------------------------------------------
** Public function.
@ -98,14 +106,17 @@ int
caf_open (SF_PRIVATE *psf)
{ int subformat, format, error = 0 ;
if (psf->mode == SFM_READ || (psf->mode == SFM_RDWR && psf->filelength > 0))
if (psf->file.mode == SFM_READ || (psf->file.mode == SFM_RDWR && psf->filelength > 0))
{ if ((error = caf_read_header (psf)))
return error ;
} ;
subformat = SF_CODEC (psf->sf.format) ;
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
if ((psf->container_data = calloc (1, sizeof (CAF_PRIVATE))) == NULL)
return SFE_MALLOC_FAILED ;
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
{ if (psf->is_pipe)
return SFE_NO_PIPE_WRITE ;
@ -115,7 +126,7 @@ caf_open (SF_PRIVATE *psf)
psf->blockwidth = psf->bytewidth * psf->sf.channels ;
if (psf->mode != SFM_RDWR || psf->filelength < 44)
if (psf->file.mode != SFM_RDWR || psf->filelength < 44)
{ psf->filelength = 0 ;
psf->datalength = 0 ;
psf->dataoffset = 0 ;
@ -128,7 +139,7 @@ caf_open (SF_PRIVATE *psf)
** By default, add the peak chunk to floating point files. Default behaviour
** can be switched off using sf_command (SFC_SET_PEAK_CHUNK, SF_FALSE).
*/
if (psf->mode == SFM_WRITE && (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE))
if (psf->file.mode == SFM_WRITE && (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE))
{ if ((psf->peak_info = peak_info_calloc (psf->sf.channels)) == NULL)
return SFE_MALLOC_FAILED ;
psf->peak_info->peak_loc = SF_PEAK_START ;
@ -141,7 +152,7 @@ caf_open (SF_PRIVATE *psf)
} ;
psf->container_close = caf_close ;
/*psf->command = caf_command ;*/
psf->command = caf_command ;
switch (subformat)
{ case SF_FORMAT_PCM_S8 :
@ -179,12 +190,31 @@ caf_open (SF_PRIVATE *psf)
static int
caf_close (SF_PRIVATE *psf)
{
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
caf_write_header (psf, SF_TRUE) ;
return 0 ;
} /* caf_close */
static int
caf_command (SF_PRIVATE * psf, int command, void * UNUSED (data), int UNUSED (datasize))
{ CAF_PRIVATE *pcaf ;
if ((pcaf = psf->container_data) == NULL)
return SFE_INTERNAL ;
switch (command)
{ case SFC_SET_CHANNEL_MAP_INFO :
pcaf->chanmap_tag = aiff_caf_find_channel_layout_tag (psf->channel_map, psf->sf.channels) ;
return (pcaf->chanmap_tag != 0) ;
default :
break ;
} ;
return 0 ;
} /* caf_command */
/*------------------------------------------------------------------------------
*/
@ -252,7 +282,7 @@ caf_read_header (SF_PRIVATE *psf)
sf_count_t chunk_size ;
double srate ;
short version, flags ;
int marker, k, have_data = 0 ;
int marker, k, have_data = 0, error ;
memset (&desc, 0, sizeof (desc)) ;
@ -282,7 +312,7 @@ caf_read_header (SF_PRIVATE *psf)
" Frames / packet : %u\n Channels / frame : %u\n Bits / channel : %u\n",
desc.fmt_id, desc.fmt_flags, desc.pkt_bytes, desc.pkt_frames, desc.channels_per_frame, desc.bits_per_chan) ;
if (desc.channels_per_frame > 200)
if (desc.channels_per_frame > SF_MAX_CHANNELS)
{ psf_log_printf (psf, "**** Bad channels per frame value %u.\n", desc.channels_per_frame) ;
return SFE_MALFORMED_FILE ;
} ;
@ -311,7 +341,7 @@ caf_read_header (SF_PRIVATE *psf)
psf_binheader_readf (psf, "E4", & (psf->peak_info->edit_number)) ;
psf_log_printf (psf, " edit count : %d\n", psf->peak_info->edit_number) ;
psf_log_printf (psf, " Ch Position Value\n") ;
psf_log_printf (psf, " Ch Position Value\n") ;
for (k = 0 ; k < psf->sf.channels ; k++)
{ sf_count_t position ;
float value ;
@ -320,20 +350,36 @@ caf_read_header (SF_PRIVATE *psf)
psf->peak_info->peaks [k].value = value ;
psf->peak_info->peaks [k].position = position ;
snprintf (psf->u.cbuf, sizeof (psf->u.cbuf), " %2d %-12ld %g\n", k, (long) position, value) ;
snprintf (psf->u.cbuf, sizeof (psf->u.cbuf), " %2d %-12" PRId64 " %g\n", k, position, value) ;
psf_log_printf (psf, psf->u.cbuf) ;
} ;
psf->peak_info->peak_loc = SF_PEAK_START ;
break ;
case chan_MARKER :
if (chunk_size < 12)
{ psf_log_printf (psf, "%M : %D (should be >= 12)\n", marker, chunk_size) ;
psf_binheader_readf (psf, "j", (int) chunk_size) ;
break ;
}
psf_log_printf (psf, "%M : %D\n", marker, chunk_size) ;
if ((error = caf_read_chanmap (psf, chunk_size)))
return error ;
break ;
case free_MARKER :
psf_log_printf (psf, "%M : %D\n", marker, chunk_size) ;
psf_binheader_readf (psf, "j", (int) chunk_size) ;
break ;
case data_MARKER :
psf_log_printf (psf, "%M : %D\n", marker, chunk_size) ;
if (psf->filelength > 0 && chunk_size + psf->headindex != psf->filelength)
psf_log_printf (psf, "%M : %D (should be %D)\n", marker, chunk_size, chunk_size + 4) ;
else
psf_log_printf (psf, "%M : %D\n", marker, chunk_size) ;
psf_binheader_readf (psf, "E4", &k) ;
psf_log_printf (psf, " edit : %u\n", k) ;
have_data = 1 ;
@ -371,10 +417,14 @@ caf_read_header (SF_PRIVATE *psf)
static int
caf_write_header (SF_PRIVATE *psf, int calc_length)
{ DESC_CHUNK desc ;
{ CAF_PRIVATE *pcaf ;
DESC_CHUNK desc ;
sf_count_t current, free_len ;
int subformat ;
if ((pcaf = psf->container_data) == NULL)
return SFE_INTERNAL ;
memset (&desc, 0, sizeof (desc)) ;
current = psf_ftell (psf) ;
@ -513,13 +563,16 @@ caf_write_header (SF_PRIVATE *psf, int calc_length)
psf_binheader_writef (psf, "Ef8", (float) psf->peak_info->peaks [k].value, psf->peak_info->peaks [k].position) ;
} ;
if (psf->channel_map && pcaf->chanmap_tag)
psf_binheader_writef (psf, "Em8444", chan_MARKER, (sf_count_t) 12, pcaf->chanmap_tag, 0, 0) ;
/* Add free chunk so that the actual audio data starts at a multiple 0x1000. */
free_len = 0x1000 - psf->headindex - 16 - 12 ;
while (free_len < 0)
free_len += 0x1000 ;
psf_binheader_writef (psf, "Em8z", free_MARKER, free_len, (int) free_len) ;
psf_binheader_writef (psf, "Em84", data_MARKER, psf->datalength, 0) ;
psf_binheader_writef (psf, "Em84", data_MARKER, psf->datalength + 4, 0) ;
psf_fwrite (psf->header, psf->headindex, 1, psf) ;
if (psf->error)
@ -534,3 +587,34 @@ caf_write_header (SF_PRIVATE *psf, int calc_length)
return psf->error ;
} /* caf_write_header */
static int
caf_read_chanmap (SF_PRIVATE * psf, sf_count_t chunk_size)
{ const AIFF_CAF_CHANNEL_MAP * map_info ;
unsigned channel_bitmap, channel_decriptions, bytesread ;
int layout_tag ;
bytesread = psf_binheader_readf (psf, "E444", &layout_tag, &channel_bitmap, &channel_decriptions) ;
map_info = aiff_caf_of_channel_layout_tag (layout_tag) ;
psf_log_printf (psf, " Tag : %x\n", layout_tag) ;
if (map_info)
psf_log_printf (psf, " Layout : %s\n", map_info->name) ;
if (bytesread < chunk_size)
psf_binheader_readf (psf, "j", chunk_size - bytesread) ;
if (map_info->channel_map != NULL)
{ size_t chanmap_size = psf->sf.channels * sizeof (psf->channel_map [0]) ;
free (psf->channel_map) ;
if ((psf->channel_map = malloc (chanmap_size)) == NULL)
return SFE_MALLOC_FAILED ;
memcpy (psf->channel_map, map_info->channel_map, chanmap_size) ;
} ;
return 0 ;
} /* caf_read_chanmap */

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2001-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2001-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -124,12 +124,14 @@ static SF_FORMAT_INFO const major_formats [] =
{ SF_FORMAT_SVX, "IFF (Amiga IFF/SVX8/SV16)", "iff" },
{ SF_FORMAT_MAT4, "MAT4 (GNU Octave 2.0 / Matlab 4.2)", "mat" },
{ SF_FORMAT_MAT5, "MAT5 (GNU Octave 2.1 / Matlab 5.0)", "mat" },
{ SF_FORMAT_MPC2K, "MPC (Akai MPC 2k)", "mpc" },
#if HAVE_EXTERNAL_LIBS
{ SF_FORMAT_OGG, "OGG (OGG Container format)", "oga" },
#endif
{ SF_FORMAT_PAF, "PAF (Ensoniq PARIS)", "paf" },
{ SF_FORMAT_PVF, "PVF (Portable Voice Format)", "pvf" },
{ SF_FORMAT_RAW, "RAW (header-less)", "raw" },
{ SF_FORMAT_RF64, "RF64 (RIFF 64)", "rf64" },
{ SF_FORMAT_SD2, "SD2 (Sound Designer II)", "sd2" },
{ SF_FORMAT_SDS, "SDS (Midi Sample Dump Standard)", "sds" },
{ SF_FORMAT_IRCAM, "SF (Berkeley/IRCAM/CARL)", "sf" },

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -23,9 +23,8 @@
#include <ctype.h>
#include <math.h>
#include <time.h>
#ifndef _MSC_VER
#include <sys/time.h>
#endif
#include "sndfile.h"
#include "sfendian.h"
#include "common.h"
@ -1035,14 +1034,14 @@ psf_binheader_readf (SF_PRIVATE *psf, char const *format, ...)
case 'b' :
charptr = va_arg (argptr, char*) ;
count = va_arg (argptr, int) ;
count = va_arg (argptr, size_t) ;
if (count > 0)
byte_count += header_read (psf, charptr, count) ;
break ;
case 'G' :
charptr = va_arg (argptr, char*) ;
count = va_arg (argptr, int) ;
count = va_arg (argptr, size_t) ;
if (count > 0)
byte_count += header_gets (psf, charptr, count) ;
break ;
@ -1061,14 +1060,14 @@ psf_binheader_readf (SF_PRIVATE *psf, char const *format, ...)
case 'p' :
/* Get the seek position first. */
count = va_arg (argptr, int) ;
count = va_arg (argptr, size_t) ;
header_seek (psf, count, SEEK_SET) ;
byte_count = count ;
break ;
case 'j' :
/* Get the seek position first. */
count = va_arg (argptr, int) ;
count = va_arg (argptr, size_t) ;
header_seek (psf, count, SEEK_CUR) ;
byte_count += count ;
break ;
@ -1133,7 +1132,7 @@ psf_hexdump (const void *ptr, int len)
printf ("%08X: ", k) ;
for (m = 0 ; m < 16 && k + m < len ; m++)
{ printf (m == 8 ? " %02X " : "%02X ", data [k + m] & 0xFF) ;
ascii [m] = isprint (data [k + m]) ? data [k + m] : '.' ;
ascii [m] = psf_isprint (data [k + m]) ? data [k + m] : '.' ;
} ;
if (m <= 8) printf (" ") ;
@ -1208,7 +1207,7 @@ psf_sanitize_string (char * cptr, int len)
do
{
len -- ;
cptr [len] = isprint (cptr [len]) ? cptr [len] : '.' ;
cptr [len] = psf_isprint (cptr [len]) ? cptr [len] : '.' ;
}
while (len > 0) ;
} /* psf_sanitize_string */
@ -1315,6 +1314,57 @@ psf_rand_int32 (void)
return value ;
} /* psf_rand_int32 */
void
append_snprintf (char * dest, size_t maxlen, const char * fmt, ...)
{ size_t len = strlen (dest) ;
if (len < maxlen)
{ va_list ap ;
va_start (ap, fmt) ;
vsnprintf (dest + len, maxlen - len, fmt, ap) ;
va_end (ap) ;
} ;
return ;
} /* append_snprintf */
void
psf_strlcpy_crlf (char *dest, const char *src, size_t destmax, size_t srcmax)
{ /* Must be minus 2 so it can still expand a single trailing '\n' or '\r'. */
char * destend = dest + destmax - 2 ;
const char * srcend = src + srcmax ;
while (dest < destend && src < srcend)
{ if ((src [0] == '\r' && src [1] == '\n') || (src [0] == '\n' && src [1] == '\r'))
{ *dest++ = '\r' ;
*dest++ = '\n' ;
src += 2 ;
continue ;
} ;
if (src [0] == '\r')
{ *dest++ = '\r' ;
*dest++ = '\n' ;
src += 1 ;
continue ;
} ;
if (src [0] == '\n')
{ *dest++ = '\r' ;
*dest++ = '\n' ;
src += 1 ;
continue ;
} ;
*dest++ = *src++ ;
} ;
/* Make sure dest is terminated. */
*dest = 0 ;
} /* psf_strlcpy_crlf */
/*==============================================================================
*/

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -22,15 +22,16 @@
#include "sfconfig.h"
#include <stdlib.h>
#include <string.h>
#if HAVE_STDINT_H
#include <stdint.h>
#elif HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifndef SNDFILE_H
#include "sndfile.h"
#elif HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef __cplusplus
@ -39,7 +40,9 @@
#if (SIZEOF_LONG == 8)
# define SF_PLATFORM_S64(x) x##l
#elif COMPILER_IS_GCC || __SUNPRO_C
#elif (SIZEOF_LONG_LONG == 8)
# define SF_PLATFORM_S64(x) x##ll
#elif COMPILER_IS_GCC
# define SF_PLATFORM_S64(x) x##ll
#elif OS_IS_WIN32
# define SF_PLATFORM_S64(x) x##I64
@ -87,6 +90,8 @@
#define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
#define NOT(x) (! (x))
#if (COMPILER_IS_GCC == 1)
#define SF_MAX(x,y) ({ \
typeof (x) sf_max_x1 = (x) ; \
@ -104,6 +109,10 @@
#define SF_MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#define SF_MAX_CHANNELS 256
/*
* Macros for spliting the format file of SF_INFI into contrainer type,
** codec type and endian-ness.
@ -112,7 +121,6 @@
#define SF_CODEC(x) ((x) & SF_FORMAT_SUBMASK)
#define SF_ENDIAN(x) ((x) & SF_FORMAT_ENDMASK)
enum
{ /* PEAK chunk location. */
SF_PEAK_START = 42,
@ -143,6 +151,8 @@ enum
enum
{ /* Work in progress. */
SF_FORMAT_SPEEX = 0x5000000,
SF_FORMAT_OGGFLAC = 0x5000001,
/* Formats supported read only. */
SF_FORMAT_TXW = 0x4030000, /* Yamaha TX16 sampler file */
@ -214,22 +224,72 @@ make_size_t (int x)
{ return (size_t) x ;
} /* size_t_of_int */
typedef SF_BROADCAST_INFO_VAR (16 * 1024) SF_BROADCAST_INFO_16K ;
#if SIZEOF_WCHAR_T == 2
typedef wchar_t sfwchar_t ;
#else
typedef int16_t sfwchar_t ;
#endif
/*
** This version of isprint specifically ignores any locale info. Its used for
** determining which characters can be printed in things like hexdumps.
*/
static inline int
psf_isprint (int ch)
{ return (ch >= ' ' && ch <= '~') ;
} /* psf_isprint */
/*=======================================================================================
** SF_PRIVATE stuct - a pointer to this struct is passed back to the caller of the
** sf_open_XXXX functions. The caller however has no knowledge of the struct's
** contents.
*/
typedef struct
{ int size ;
SF_BROADCAST_INFO binfo ;
} SF_BROADCAST_VAR ;
{
union
{ char c [SF_FILENAME_LEN] ;
sfwchar_t wc [SF_FILENAME_LEN] ;
} path ;
union
{ char c [SF_FILENAME_LEN] ;
sfwchar_t wc [SF_FILENAME_LEN] ;
} dir ;
union
{ char c [SF_FILENAME_LEN / 4] ;
sfwchar_t wc [SF_FILENAME_LEN / 4] ;
} name ;
#if USE_WINDOWS_API
/*
** These fields can only be used in src/file_io.c.
** They are basically the same as a windows file HANDLE.
*/
void *handle, *hsaved ;
int use_wchar ;
#else
/* These fields can only be used in src/file_io.c. */
int filedes, savedes ;
#endif
int do_not_close_descriptor ;
int mode ; /* Open mode : SFM_READ, SFM_WRITE or SFM_RDWR. */
} PSF_FILE ;
typedef struct sf_private_tag
{
/* Canary in a coal mine. */
char canary [64] ;
union
{ /* Place a double here to encourage double alignment. */
double d [2] ;
char c [16] ;
} canary ;
/* Force the compiler to double align the start of buffer. */
union
@ -247,10 +307,8 @@ typedef struct sf_private_tag
unsigned char ucbuf [SF_BUFFER_LEN / sizeof (signed char)] ;
} u ;
char filepath [SF_FILENAME_LEN] ;
char rsrcpath [SF_FILENAME_LEN] ;
char directory [SF_FILENAME_LEN] ;
char filename [SF_FILENAME_LEN / 4] ;
PSF_FILE file, rsrc ;
char syserr [SF_SYSERR_LEN] ;
@ -278,22 +336,9 @@ typedef struct sf_private_tag
int logindex ;
int headindex, headend ;
int has_text ;
int do_not_close_descriptor ;
#if USE_WINDOWS_API
/*
** These fields can only be used in src/file_io.c.
** They are basically the same as a windows file HANDLE.
*/
void *hfile, *hrsrc, *hsaved ;
#else
/* These fields can only be used in src/file_io.c. */
int filedes, rsrcdes, savedes ;
#endif
int error ;
int mode ; /* Open mode : SFM_READ, SFM_WRITE or SFM_RDWR. */
int endian ; /* File endianness : SF_ENDIAN_LITTLE or SF_ENDIAN_BIG. */
int data_endswap ; /* Need to endswap data? */
@ -323,7 +368,7 @@ typedef struct sf_private_tag
SF_INSTRUMENT *instrument ;
/* Broadcast (EBU) Info */
SF_BROADCAST_VAR *broadcast_var ;
SF_BROADCAST_INFO_16K *broadcast_16k ;
/* Channel map data (if present) : an array of ints. */
int *channel_map ;
@ -453,6 +498,7 @@ enum
SFE_RDWR_BAD_HEADER,
SFE_CMD_HAS_DATA,
SFE_BAD_BROADCAST_INFO_SIZE,
SFE_BAD_BROADCAST_INFO_TOO_BIG,
SFE_STR_NO_SUPPORT,
SFE_STR_NOT_WRITE,
@ -506,6 +552,7 @@ enum
SFE_PAF_VERSION,
SFE_PAF_UNKNOWN_FORMAT,
SFE_PAF_SHORT_HEADER,
SFE_PAF_BAD_CHANNELS,
SFE_SVX_NO_FORM,
SFE_SVX_NO_BODY,
@ -612,6 +659,9 @@ void psf_log_SF_INFO (SF_PRIVATE *psf) ;
int32_t psf_rand_int32 (void) ;
void append_snprintf (char * dest, size_t maxlen, const char * fmt, ...) ;
void psf_strlcpy_crlf (char *dest, const char *src, size_t destmax, size_t srcmax) ;
/* Functions used when writing file headers. */
int psf_binheader_writef (SF_PRIVATE *psf, const char *format, ...) ;
@ -665,13 +715,15 @@ int macos_guess_file_type (SF_PRIVATE *psf, const char *filename) ;
** some 32 bit OSes. Implementation in file_io.c.
*/
int psf_fopen (SF_PRIVATE *psf, const char *pathname, int flags) ;
int psf_set_stdio (SF_PRIVATE *psf, int mode) ;
int psf_fopen (SF_PRIVATE *psf) ;
int psf_set_stdio (SF_PRIVATE *psf) ;
int psf_file_valid (SF_PRIVATE *psf) ;
void psf_set_file (SF_PRIVATE *psf, int fd) ;
void psf_init_files (SF_PRIVATE *psf) ;
void psf_use_rsrc (SF_PRIVATE *psf, int on_off) ;
SNDFILE * psf_open_file (SF_PRIVATE *psf, SF_INFO *sfinfo) ;
sf_count_t psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence) ;
sf_count_t psf_fread (void *ptr, sf_count_t bytes, sf_count_t count, SF_PRIVATE *psf) ;
sf_count_t psf_fwrite (const void *ptr, sf_count_t bytes, sf_count_t count, SF_PRIVATE *psf) ;
@ -687,7 +739,7 @@ int psf_ftruncate (SF_PRIVATE *psf, sf_count_t len) ;
int psf_fclose (SF_PRIVATE *psf) ;
/* Open and close the resource fork of a file. */
int psf_open_rsrc (SF_PRIVATE *psf, int mode) ;
int psf_open_rsrc (SF_PRIVATE *psf) ;
int psf_close_rsrc (SF_PRIVATE *psf) ;
/*
@ -724,6 +776,11 @@ int rf64_open (SF_PRIVATE *psf) ;
/* In progress. Do not currently work. */
int ogg_vorbis_open (SF_PRIVATE *psf) ;
int ogg_speex_open (SF_PRIVATE *psf) ;
int ogg_pcm_open (SF_PRIVATE *psf) ;
int mpeg_open (SF_PRIVATE *psf) ;
int ogg_open (SF_PRIVATE *psf) ;
int rx2_open (SF_PRIVATE *psf) ;
@ -774,6 +831,30 @@ typedef struct
void pchk4_store (PRIV_CHUNK4 * pchk, int marker, sf_count_t offset, sf_count_t len) ;
int pchk4_find (PRIV_CHUNK4 * pchk, int marker) ;
/*------------------------------------------------------------------------------------
** Functions that work like OpenBSD's strlcpy/strlcat to replace strncpy/strncat.
**
** See : http://www.gratisoft.us/todd/papers/strlcpy.html
**
** These functions are available on *BSD, but are not avaialble everywhere so we
** implement them here.
**
** The argument order has been changed to that of strncpy/strncat to cause
** compiler errors if code is carelessly converted from one to the other.
*/
static inline void
psf_strlcat (char *dest, size_t n, const char *src)
{ strncat (dest, src, n - strlen (dest) - 1) ;
dest [n - 1] = 0 ;
} /* psf_strlcat */
static inline void
psf_strlcpy (char *dest, size_t n, const char *src)
{ strncpy (dest, src, n - 1) ;
dest [n - 1] = 0 ;
} /* psf_strlcpy */
/*------------------------------------------------------------------------------------
** Other helper functions.
*/
@ -787,7 +868,7 @@ void psf_sanitize_string (char * cptr, int len) ;
/* Generate the current date as a string. */
void psf_get_date_str (char *str, int maxlen) ;
SF_BROADCAST_VAR* broadcast_var_alloc (size_t datasize) ;
SF_BROADCAST_INFO_16K * broadcast_var_alloc (void) ;
int broadcast_var_set (SF_PRIVATE *psf, const SF_BROADCAST_INFO * data, size_t datasize) ;
int broadcast_var_get (SF_PRIVATE *psf, SF_BROADCAST_INFO * data, size_t datasize) ;
@ -798,7 +879,7 @@ typedef struct
} AUDIO_DETECT ;
int audio_detect (SF_PRIVATE * psf, AUDIO_DETECT *ad, const unsigned char * data, int datalen) ;
int id3_skip (SF_PRIVATE * psf) ;
/*------------------------------------------------------------------------------------
** Helper/debug functions.

View File

@ -1,6 +1,6 @@
#!/usr/bin/python
# Copyright (C) 2003-2007 Erik de Castro Lopo <erikd@mega-nerd.com>
# Copyright (C) 2003-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
#
# All rights reserved.
#
@ -69,7 +69,9 @@ ALL_SYMBOLS = (
( "sf_strerror", 50 ),
( "sf_get_string", 60 ),
( "sf_set_string", 61 ),
( "sf_version_string",68 ),
( "sf_open_fd", 70 ),
( "sf_wchar_open", 71 ),
( "sf_open_virtual", 80 ),
( "sf_write_sync", 90 )
)
@ -82,6 +84,8 @@ def linux_symbols (progname, version):
print "{"
print " global:"
for name, ordinal in ALL_SYMBOLS:
if name == "sf_wchar_open":
continue
print " %s ;" % name
print " local:"
print " * ;"
@ -92,6 +96,8 @@ def linux_symbols (progname, version):
def darwin_symbols (progname, version):
print "# Auto-generated by %s\n" %progname
for name, ordinal in ALL_SYMBOLS:
if name == "sf_wchar_open":
continue
print "_%s" % name
print
return
@ -107,16 +113,22 @@ def win32_symbols (progname, version, name):
def os2_symbols (progname, version, name):
print "; Auto-generated by %s\n" %progname
print "LIBRARY %s%s.dll" % (name, re.sub ("\..*", "", version))
print "LIBRARY %s%s" % (name, re.sub ("\..*", "", version))
print "INITINSTANCE TERMINSTANCE"
print "CODE PRELOAD MOVEABLE DISCARDABLE"
print "DATA PRELOAD MOVEABLE MULTIPLE NONSHARED"
print "EXPORTS\n"
for name, ordinal in ALL_SYMBOLS:
print "_%-20s @%s" % (name, ordinal)
if name == "sf_wchar_open":
continue
print "_%-20s @%s" % (name, ordinal)
print
return
def plain_symbols (progname, version, name):
for name, ordinal in ALL_SYMBOLS:
print name
def no_symbols (os_name):
print
print "No known way of restricting exported symbols on '%s'." % os_name
@ -138,13 +150,14 @@ if len (sys.argv) != 3:
print " win32 (ie wintendo)"
print " cygwin (Cygwin on wintendo)"
print " os2 (OS/2)"
print " plain (plain list of symbols)"
print
sys.exit (1)
os_name = sys.argv [1]
version = re.sub ("\.[a-z0-9]+$", "", sys.argv [2])
if os_name == "linux":
if os_name == "linux" or os_name == "gnu" or os_name == "binutils":
linux_symbols (progname, version)
elif os_name == "darwin":
darwin_symbols (progname, version)
@ -154,6 +167,8 @@ elif os_name == "cygwin":
win32_symbols (progname, version, "cygsndfile")
elif os_name == "os2":
os2_symbols (progname, version, "sndfile")
elif os_name == "static":
plain_symbols (progname, version, "")
else:
no_symbols (os_name)

View File

@ -1,39 +0,0 @@
; Auto-generated by create_symbols_file.py
LIBRARY cygsndfile-1.dll
EXPORTS
sf_command @1
sf_open @2
sf_close @3
sf_seek @4
sf_error @7
sf_perror @8
sf_error_str @9
sf_error_number @10
sf_format_check @11
sf_read_raw @16
sf_readf_short @17
sf_readf_int @18
sf_readf_float @19
sf_readf_double @20
sf_read_short @21
sf_read_int @22
sf_read_float @23
sf_read_double @24
sf_write_raw @32
sf_writef_short @33
sf_writef_int @34
sf_writef_float @35
sf_writef_double @36
sf_write_short @37
sf_write_int @38
sf_write_float @39
sf_write_double @40
sf_strerror @50
sf_get_string @60
sf_set_string @61
sf_open_fd @70
sf_open_virtual @80
sf_write_sync @90

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2003-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2003-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -95,7 +95,7 @@ double64_init (SF_PRIVATE *psf)
psf->blockwidth = sizeof (double) * psf->sf.channels ;
if (psf->mode == SFM_READ || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_READ || psf->file.mode == SFM_RDWR)
{ switch (psf->endian + double64_caps)
{ case (SF_ENDIAN_BIG + DOUBLE_CAN_RW_BE) :
psf->data_endswap = SF_FALSE ;
@ -166,7 +166,7 @@ double64_init (SF_PRIVATE *psf)
} ;
} ;
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
{ switch (psf->endian + double64_caps)
{ case (SF_ENDIAN_LITTLE + DOUBLE_CAN_RW_LE) :
psf->data_endswap = SF_FALSE ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2002-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -69,9 +69,9 @@ static int dwd_close (SF_PRIVATE *psf) ;
int
dwd_open (SF_PRIVATE *psf)
{ int subformat, error = 0 ;
{ int error = 0 ;
if (psf->mode == SFM_READ || (psf->mode == SFM_RDWR && psf->filelength > 0))
if (psf->file.mode == SFM_READ || (psf->file.mode == SFM_RDWR && psf->filelength > 0))
{ if ((error = dwd_read_header (psf)))
return error ;
} ;
@ -79,9 +79,7 @@ dwd_open (SF_PRIVATE *psf)
if ((SF_CONTAINER (psf->sf.format)) != SF_FORMAT_DWD)
return SFE_BAD_OPEN_FORMAT ;
subformat = SF_CODEC (psf->sf.format) ;
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
{
/*-psf->endian = SF_ENDIAN (psf->sf.format) ;
if (CPU_IS_LITTLE_ENDIAN && psf->endian == SF_ENDIAN_CPU)

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2002-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -86,7 +86,7 @@ dwvw_init (SF_PRIVATE *psf, int bitwidth)
if (bitwidth > 24)
return SFE_DWVW_BAD_BITWIDTH ;
if (psf->mode == SFM_RDWR)
if (psf->file.mode == SFM_RDWR)
return SFE_BAD_MODE_RW ;
if ((pdwvw = calloc (1, sizeof (DWVW_PRIVATE))) == NULL)
@ -101,14 +101,14 @@ dwvw_init (SF_PRIVATE *psf, int bitwidth)
dwvw_read_reset (pdwvw) ;
if (psf->mode == SFM_READ)
if (psf->file.mode == SFM_READ)
{ psf->read_short = dwvw_read_s ;
psf->read_int = dwvw_read_i ;
psf->read_float = dwvw_read_f ;
psf->read_double = dwvw_read_d ;
} ;
if (psf->mode == SFM_WRITE)
if (psf->file.mode == SFM_WRITE)
{ psf->write_short = dwvw_write_s ;
psf->write_int = dwvw_write_i ;
psf->write_float = dwvw_write_f ;
@ -137,7 +137,7 @@ dwvw_close (SF_PRIVATE *psf)
return 0 ;
pdwvw = (DWVW_PRIVATE*) psf->codec_data ;
if (psf->mode == SFM_WRITE)
if (psf->file.mode == SFM_WRITE)
{ static int last_values [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } ;
/* Write 8 zero samples to fully flush output. */

Some files were not shown because too many files have changed in this diff Show More