add libsndifle 1.0.17 to in tree libs

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3761 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris
2006-12-20 19:08:07 +00:00
parent 2506451f8a
commit f210c27f43
233 changed files with 141616 additions and 1 deletions

View File

@@ -0,0 +1,46 @@
## Process this file with automake to produce Makefile.in
bin_PROGRAMS = sndfile-info sndfile-play sndfile-convert
noinst_PROGRAMS = make_sine sfprocess list_formats cooledit-fixer generate
# This is the BeOS version of sndfile-play. It needs to be compiled with the C++
# compiler.
EXTRA_DIST = sndfile-play-beos.cpp
OS_SPECIFIC_CFLAGS = @OS_SPECIFIC_CFLAGS@
OS_SPECIFIC_LINKS = @OS_SPECIFIC_LINKS@
SNDFILEDIR =../src
INCLUDES = -I$(srcdir)/$(SNDFILEDIR) $(OS_SPECIFIC_CFLAGS)
sndfile_info_SOURCES = sndfile-info.c
sndfile_info_LDADD = $(SNDFILEDIR)/libsndfile.la
sndfile_play_SOURCES = sndfile-play.c
sndfile_play_LDADD = $(SNDFILEDIR)/libsndfile.la $(OS_SPECIFIC_LINKS) $(ALSA_LIBS)
sndfile_convert_SOURCES = sndfile-convert.c
sndfile_convert_LDADD = $(SNDFILEDIR)/libsndfile.la
make_sine_SOURCES = make_sine.c
make_sine_LDADD = $(SNDFILEDIR)/libsndfile.la
sfprocess_SOURCES = sfprocess.c
sfprocess_LDADD = $(SNDFILEDIR)/libsndfile.la
list_formats_SOURCES = list_formats.c
list_formats_LDADD = $(SNDFILEDIR)/libsndfile.la
cooledit_fixer_SOURCES = cooledit-fixer.c
cooledit_fixer_LDADD = $(SNDFILEDIR)/libsndfile.la
generate_SOURCES = generate.c
generate_LDADD = $(SNDFILEDIR)/libsndfile.la
## 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: faeb8674-e417-4162-9ac9-05f2b8369b57

View File

@@ -0,0 +1,565 @@
# Makefile.in generated by automake 1.9.6 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
bin_PROGRAMS = sndfile-info$(EXEEXT) sndfile-play$(EXEEXT) \
sndfile-convert$(EXEEXT)
noinst_PROGRAMS = make_sine$(EXEEXT) sfprocess$(EXEEXT) \
list_formats$(EXEEXT) cooledit-fixer$(EXEEXT) \
generate$(EXEEXT)
subdir = examples
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
am__installdirs = "$(DESTDIR)$(bindir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS)
am_cooledit_fixer_OBJECTS = cooledit-fixer.$(OBJEXT)
cooledit_fixer_OBJECTS = $(am_cooledit_fixer_OBJECTS)
cooledit_fixer_DEPENDENCIES = $(SNDFILEDIR)/libsndfile.la
am_generate_OBJECTS = generate.$(OBJEXT)
generate_OBJECTS = $(am_generate_OBJECTS)
generate_DEPENDENCIES = $(SNDFILEDIR)/libsndfile.la
am_list_formats_OBJECTS = list_formats.$(OBJEXT)
list_formats_OBJECTS = $(am_list_formats_OBJECTS)
list_formats_DEPENDENCIES = $(SNDFILEDIR)/libsndfile.la
am_make_sine_OBJECTS = make_sine.$(OBJEXT)
make_sine_OBJECTS = $(am_make_sine_OBJECTS)
make_sine_DEPENDENCIES = $(SNDFILEDIR)/libsndfile.la
am_sfprocess_OBJECTS = sfprocess.$(OBJEXT)
sfprocess_OBJECTS = $(am_sfprocess_OBJECTS)
sfprocess_DEPENDENCIES = $(SNDFILEDIR)/libsndfile.la
am_sndfile_convert_OBJECTS = sndfile-convert.$(OBJEXT)
sndfile_convert_OBJECTS = $(am_sndfile_convert_OBJECTS)
sndfile_convert_DEPENDENCIES = $(SNDFILEDIR)/libsndfile.la
am_sndfile_info_OBJECTS = sndfile-info.$(OBJEXT)
sndfile_info_OBJECTS = $(am_sndfile_info_OBJECTS)
sndfile_info_DEPENDENCIES = $(SNDFILEDIR)/libsndfile.la
am_sndfile_play_OBJECTS = sndfile-play.$(OBJEXT)
sndfile_play_OBJECTS = $(am_sndfile_play_OBJECTS)
am__DEPENDENCIES_1 =
sndfile_play_DEPENDENCIES = $(SNDFILEDIR)/libsndfile.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(cooledit_fixer_SOURCES) $(generate_SOURCES) \
$(list_formats_SOURCES) $(make_sine_SOURCES) \
$(sfprocess_SOURCES) $(sndfile_convert_SOURCES) \
$(sndfile_info_SOURCES) $(sndfile_play_SOURCES)
DIST_SOURCES = $(cooledit_fixer_SOURCES) $(generate_SOURCES) \
$(list_formats_SOURCES) $(make_sine_SOURCES) \
$(sfprocess_SOURCES) $(sndfile_convert_SOURCES) \
$(sndfile_info_SOURCES) $(sndfile_play_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ALSA_LIBS = @ALSA_LIBS@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
COMPILER_IS_GCC = @COMPILER_IS_GCC@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
ENABLE_EXPERIMENTAL_CODE = @ENABLE_EXPERIMENTAL_CODE@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
FLAC_LIBS = @FLAC_LIBS@
GCC_MAJOR_VERSION = @GCC_MAJOR_VERSION@
GETCONF = @GETCONF@
GREP = @GREP@
HTML_BGCOLOUR = @HTML_BGCOLOUR@
HTML_FGCOLOUR = @HTML_FGCOLOUR@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LIBTOOL_DEPS = @LIBTOOL_DEPS@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
OBJEXT = @OBJEXT@
OS_SPECIFIC_CFLAGS = @OS_SPECIFIC_CFLAGS@
OS_SPECIFIC_LINKS = @OS_SPECIFIC_LINKS@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
RANLIB = @RANLIB@
SET_MAKE = @SET_MAKE@
SF_COUNT_MAX = @SF_COUNT_MAX@
SHARED_VERSION_INFO = @SHARED_VERSION_INFO@
SHELL = @SHELL@
SHLIB_VERSION_ARG = @SHLIB_VERSION_ARG@
SIZEOF_SF_COUNT_T = @SIZEOF_SF_COUNT_T@
SQLITE3_CFLAGS = @SQLITE3_CFLAGS@
SQLITE3_LIBS = @SQLITE3_LIBS@
STRIP = @STRIP@
TYPEOF_SF_COUNT_T = @TYPEOF_SF_COUNT_T@
VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
autogen = @autogen@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
htmldocdir = @htmldocdir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
# This is the BeOS version of sndfile-play. It needs to be compiled with the C++
# compiler.
EXTRA_DIST = sndfile-play-beos.cpp
SNDFILEDIR = ../src
INCLUDES = -I$(srcdir)/$(SNDFILEDIR) $(OS_SPECIFIC_CFLAGS)
sndfile_info_SOURCES = sndfile-info.c
sndfile_info_LDADD = $(SNDFILEDIR)/libsndfile.la
sndfile_play_SOURCES = sndfile-play.c
sndfile_play_LDADD = $(SNDFILEDIR)/libsndfile.la $(OS_SPECIFIC_LINKS) $(ALSA_LIBS)
sndfile_convert_SOURCES = sndfile-convert.c
sndfile_convert_LDADD = $(SNDFILEDIR)/libsndfile.la
make_sine_SOURCES = make_sine.c
make_sine_LDADD = $(SNDFILEDIR)/libsndfile.la
sfprocess_SOURCES = sfprocess.c
sfprocess_LDADD = $(SNDFILEDIR)/libsndfile.la
list_formats_SOURCES = list_formats.c
list_formats_LDADD = $(SNDFILEDIR)/libsndfile.la
cooledit_fixer_SOURCES = cooledit-fixer.c
cooledit_fixer_LDADD = $(SNDFILEDIR)/libsndfile.la
generate_SOURCES = generate.c
generate_LDADD = $(SNDFILEDIR)/libsndfile.la
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu examples/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
@list='$(bin_PROGRAMS)'; for p in $$list; do \
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
if test -f $$p \
|| test -f $$p1 \
; then \
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
$(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
clean-binPROGRAMS:
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
clean-noinstPROGRAMS:
@list='$(noinst_PROGRAMS)'; for p in $$list; do \
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
cooledit-fixer$(EXEEXT): $(cooledit_fixer_OBJECTS) $(cooledit_fixer_DEPENDENCIES)
@rm -f cooledit-fixer$(EXEEXT)
$(LINK) $(cooledit_fixer_LDFLAGS) $(cooledit_fixer_OBJECTS) $(cooledit_fixer_LDADD) $(LIBS)
generate$(EXEEXT): $(generate_OBJECTS) $(generate_DEPENDENCIES)
@rm -f generate$(EXEEXT)
$(LINK) $(generate_LDFLAGS) $(generate_OBJECTS) $(generate_LDADD) $(LIBS)
list_formats$(EXEEXT): $(list_formats_OBJECTS) $(list_formats_DEPENDENCIES)
@rm -f list_formats$(EXEEXT)
$(LINK) $(list_formats_LDFLAGS) $(list_formats_OBJECTS) $(list_formats_LDADD) $(LIBS)
make_sine$(EXEEXT): $(make_sine_OBJECTS) $(make_sine_DEPENDENCIES)
@rm -f make_sine$(EXEEXT)
$(LINK) $(make_sine_LDFLAGS) $(make_sine_OBJECTS) $(make_sine_LDADD) $(LIBS)
sfprocess$(EXEEXT): $(sfprocess_OBJECTS) $(sfprocess_DEPENDENCIES)
@rm -f sfprocess$(EXEEXT)
$(LINK) $(sfprocess_LDFLAGS) $(sfprocess_OBJECTS) $(sfprocess_LDADD) $(LIBS)
sndfile-convert$(EXEEXT): $(sndfile_convert_OBJECTS) $(sndfile_convert_DEPENDENCIES)
@rm -f sndfile-convert$(EXEEXT)
$(LINK) $(sndfile_convert_LDFLAGS) $(sndfile_convert_OBJECTS) $(sndfile_convert_LDADD) $(LIBS)
sndfile-info$(EXEEXT): $(sndfile_info_OBJECTS) $(sndfile_info_DEPENDENCIES)
@rm -f sndfile-info$(EXEEXT)
$(LINK) $(sndfile_info_LDFLAGS) $(sndfile_info_OBJECTS) $(sndfile_info_LDADD) $(LIBS)
sndfile-play$(EXEEXT): $(sndfile_play_OBJECTS) $(sndfile_play_DEPENDENCIES)
@rm -f sndfile-play$(EXEEXT)
$(LINK) $(sndfile_play_LDFLAGS) $(sndfile_play_OBJECTS) $(sndfile_play_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cooledit-fixer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generate.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list_formats.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/make_sine.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sfprocess.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sndfile-convert.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sndfile-info.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sndfile-play.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(PROGRAMS)
installdirs:
for dir in "$(DESTDIR)$(bindir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-binPROGRAMS clean-generic clean-libtool \
clean-noinstPROGRAMS mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-libtool distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am:
install-exec-am: install-binPROGRAMS
install-info: install-info-am
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-binPROGRAMS uninstall-info-am
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
clean-generic clean-libtool clean-noinstPROGRAMS ctags \
distclean distclean-compile distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-binPROGRAMS \
install-data install-data-am install-exec install-exec-am \
install-info install-info-am install-man install-strip \
installcheck installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-binPROGRAMS \
uninstall-info-am
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,231 @@
/*
** 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

@@ -0,0 +1,125 @@
/*
** 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 "sfconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sndfile.h>
#define BUFFER_LEN 4096
static void encode_file (const char *infilename, const char *outfilename, int filetype) ;
int
main (int argc, char **argv)
{
if (argc != 2)
{ puts ("\nEncode a single input file into a number of different output ") ;
puts ("encodings. These output encodings can then be moved to another ") ;
puts ("OS for testing.\n") ;
puts (" Usage : generate <filename>\n") ;
exit (1) ;
} ;
/* A couple of standard WAV files. Make sure Win32 plays these. */
encode_file (argv [1], "pcmu8.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_U8) ;
encode_file (argv [1], "pcm16.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
encode_file (argv [1], "imaadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM) ;
encode_file (argv [1], "msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM) ;
encode_file (argv [1], "gsm610.wav" , SF_FORMAT_WAV | SF_FORMAT_GSM610) ;
/* Soundforge W64. */
encode_file (argv [1], "pcmu8.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_U8) ;
encode_file (argv [1], "pcm16.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_16) ;
encode_file (argv [1], "imaadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM) ;
encode_file (argv [1], "msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM) ;
encode_file (argv [1], "gsm610.w64" , SF_FORMAT_W64 | SF_FORMAT_GSM610) ;
return 0 ;
} /* main */
/*============================================================================================
** Helper functions and macros.
*/
#define PUT_DOTS(k) \
{ while (k--) \
putchar ('.') ; \
putchar (' ') ; \
}
/*========================================================================================
*/
static void
encode_file (const char *infilename, const char *outfilename, int filetype)
{ static float buffer [BUFFER_LEN] ;
SNDFILE *infile, *outfile ;
SF_INFO sfinfo ;
int k, readcount ;
printf (" %s -> %s ", infilename, outfilename) ;
fflush (stdout) ;
k = 16 - strlen (outfilename) ;
PUT_DOTS (k) ;
if (! (infile = sf_open (infilename, SFM_READ, &sfinfo)))
{ printf ("Error : could not open file : %s\n", infilename) ;
puts (sf_strerror (NULL)) ;
exit (1) ;
}
sfinfo.format = filetype ;
if (! sf_format_check (&sfinfo))
{ sf_close (infile) ;
printf ("Invalid encoding\n") ;
return ;
} ;
if (! (outfile = sf_open (outfilename, SFM_WRITE, &sfinfo)))
{ printf ("Error : could not open file : %s\n", outfilename) ;
puts (sf_strerror (NULL)) ;
exit (1) ;
} ;
while ((readcount = sf_read_float (infile, buffer, BUFFER_LEN)) > 0)
sf_write_float (outfile, buffer, BUFFER_LEN) ;
sf_close (infile) ;
sf_close (outfile) ;
printf ("ok\n") ;
return ;
} /* encode_file */
/*
** 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: fe28ef37-ae89-4f61-966b-0b1f68e37425
*/

View File

@@ -0,0 +1,76 @@
/*
** Copyright (C) 2001-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 <sndfile.h>
int
main (void)
{ SF_FORMAT_INFO info ;
SF_INFO sfinfo ;
char buffer [128] ;
int format, major_count, subtype_count, m, s ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
buffer [0] = 0 ;
sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
if (strlen (buffer) < 1)
{ printf ("Line %d: could not retrieve lib version.\n", __LINE__) ;
exit (1) ;
} ;
printf ("Version : %s\n\n", buffer) ;
sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof (int)) ;
sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof (int)) ;
sfinfo.channels = 1 ;
for (m = 0 ; m < major_count ; m++)
{ info.format = m ;
sf_command (NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof (info)) ;
printf ("%s (extension \"%s\")\n", info.name, info.extension) ;
format = info.format ;
for (s = 0 ; s < subtype_count ; s++)
{ info.format = s ;
sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof (info)) ;
format = (format & SF_FORMAT_TYPEMASK) | info.format ;
sfinfo.format = format ;
if (sf_format_check (&sfinfo))
printf (" %s\n", info.name) ;
} ;
puts ("") ;
} ;
puts ("") ;
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: 58127a0c-93a2-46cf-b615-fcb9adacf3f1
*/

View File

@@ -0,0 +1,89 @@
/*
** 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 <math.h>
#include <sndfile.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338
#endif
#define SAMPLE_RATE 44100
#define SAMPLE_COUNT (SAMPLE_RATE * 4) /* 4 seconds */
#define AMPLITUDE (1.0 * 0x7F000000)
#define LEFT_FREQ (344.0 / SAMPLE_RATE)
#define RIGHT_FREQ (466.0 / SAMPLE_RATE)
int
main (void)
{ SNDFILE *file ;
SF_INFO sfinfo ;
int k ;
int *buffer ;
if (! (buffer = malloc (2 * SAMPLE_COUNT * sizeof (int))))
{ printf ("Malloc failed.\n") ;
exit (0) ;
} ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = SAMPLE_COUNT ;
sfinfo.channels = 2 ;
sfinfo.format = (SF_FORMAT_WAV | SF_FORMAT_PCM_24) ;
if (! (file = sf_open ("sine.wav", SFM_WRITE, &sfinfo)))
{ printf ("Error : Not able to open output file.\n") ;
return 1 ;
} ;
if (sfinfo.channels == 1)
{ for (k = 0 ; k < SAMPLE_COUNT ; k++)
buffer [k] = AMPLITUDE * sin (LEFT_FREQ * 2 * k * M_PI) ;
}
else if (sfinfo.channels == 2)
{ for (k = 0 ; k < SAMPLE_COUNT ; k++)
{ buffer [2 * k] = AMPLITUDE * sin (LEFT_FREQ * 2 * k * M_PI) ;
buffer [2 * k + 1] = AMPLITUDE * sin (RIGHT_FREQ * 2 * k * M_PI) ;
} ;
}
else
{ printf ("makesine can only generate mono or stereo files.\n") ;
exit (1) ;
} ;
if (sf_write_int (file, buffer, sfinfo.channels * SAMPLE_COUNT) !=
sfinfo.channels * SAMPLE_COUNT)
puts (sf_strerror (file)) ;
sf_close (file) ;
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: fd945a2c-a306-49ef-a262-6336ced15246
*/

View File

@@ -0,0 +1,131 @@
/*
** Copyright (C) 2001-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 this header file to use functions from libsndfile. */
#include <sndfile.h>
/* This will be the length of the buffer used to hold.frames while
** we process them.
*/
#define BUFFER_LEN 1024
/* libsndfile can handle more than 6 channels but we'll restrict it to 6. */
#define MAX_CHANNELS 6
/* Function prototype. */
static void process_data (double *data, int count, int channels) ;
int
main (void)
{ /* This is a buffer of double precision floating point values
** which will hold our data while we process it.
*/
static double data [BUFFER_LEN] ;
/* A SNDFILE is very much like a FILE in the Standard C library. The
** sf_open function return an SNDFILE* pointer when they sucessfully
** open the specified file.
*/
SNDFILE *infile, *outfile ;
/* A pointer to an SF_INFO stutct is passed to sf_open.
** On read, the library fills this struct with information about the file.
** On write, the struct must be filled in before calling sf_open.
*/
SF_INFO sfinfo ;
int readcount ;
const char *infilename = "input.wav" ;
const char *outfilename = "output.wav" ;
/* Here's where we open the input file. We pass sf_open the file name and
** a pointer to an SF_INFO struct.
** On successful open, sf_open returns a SNDFILE* pointer which is used
** for all subsequent operations on that file.
** If an error occurs during sf_open, the function returns a NULL pointer.
**
** If you are trying to open a raw headerless file you will need to set the
** format and channels fields of sfinfo before calling sf_open(). For
** instance to open a raw 16 bit stereo PCM file you would need the following
** two lines:
**
** sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16 ;
** sfinfo.channels = 2 ;
*/
if (! (infile = sf_open (infilename, SFM_READ, &sfinfo)))
{ /* Open failed so print an error message. */
printf ("Not able to open input file %s.\n", infilename) ;
/* Print the error message from libsndfile. */
puts (sf_strerror (NULL)) ;
return 1 ;
} ;
if (sfinfo.channels > MAX_CHANNELS)
{ printf ("Not able to process more than %d channels\n", MAX_CHANNELS) ;
return 1 ;
} ;
/* Open the output file. */
if (! (outfile = sf_open (outfilename, SFM_WRITE, &sfinfo)))
{ printf ("Not able to open output file %s.\n", outfilename) ;
puts (sf_strerror (NULL)) ;
return 1 ;
} ;
/* While there are.frames in the input file, read them, process
** them and write them to the output file.
*/
while ((readcount = sf_read_double (infile, data, BUFFER_LEN)))
{ process_data (data, readcount, sfinfo.channels) ;
sf_write_double (outfile, data, readcount) ;
} ;
/* Close input and output files. */
sf_close (infile) ;
sf_close (outfile) ;
return 0 ;
} /* main */
static void
process_data (double *data, int count, int channels)
{ double channel_gain [MAX_CHANNELS] = { 0.5, 0.8, 0.1, 0.4, 0.4, 0.9 } ;
int k, chan ;
/* Process the data here.
** If the soundfile contains more then 1 channel you need to take care of
** the data interleaving youself.
** Current we just apply a channel dependant gain.
*/
for (chan = 0 ; chan < channels ; chan ++)
for (k = chan ; k < count ; k+= channels)
data [k] *= channel_gain [chan] ;
return ;
} /* process_data */
/*
** 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: de9fdd1e-b807-41ef-9d51-075ba383e536
*/

View File

@@ -0,0 +1,376 @@
/*
** 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

@@ -0,0 +1,354 @@
/*
** 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

@@ -0,0 +1,153 @@
/*
** 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

@@ -0,0 +1,960 @@
/*
** 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
*/