mirror of
https://github.com/cookiengineer/audacity
synced 2026-04-24 23:13:42 +02:00
Move library tree where it belongs
This commit is contained in:
26
lib-src/libsamplerate/examples/Makefile.am
Normal file
26
lib-src/libsamplerate/examples/Makefile.am
Normal file
@@ -0,0 +1,26 @@
|
||||
# This file was automatically generated
|
||||
# DO NOT EDIT!
|
||||
|
||||
bin_PROGRAMS = sndfile-resample
|
||||
|
||||
noinst_PROGRAMS = varispeed-play timewarp-file
|
||||
|
||||
SAMPLERATEDIR =../src
|
||||
INCLUDES = -I$(srcdir)/$(SAMPLERATEDIR) @OS_SPECIFIC_INCLUDES@
|
||||
|
||||
OS_SPECIFIC_LINKS = @OS_SPECIFIC_LINKS@
|
||||
|
||||
SNDFILE_LIBS = @SNDFILE_LIBS@
|
||||
AM_CFLAGS = @SNDFILE_CFLAGS@
|
||||
|
||||
#===============================================================================
|
||||
|
||||
sndfile_resample_SOURCES = sndfile-resample.c
|
||||
sndfile_resample_LDADD = $(SAMPLERATEDIR)/libsamplerate.la $(SNDFILE_LIBS)
|
||||
|
||||
varispeed_play_SOURCES = varispeed-play.c audio_out.c audio_out.h
|
||||
varispeed_play_LDADD = $(SAMPLERATEDIR)/libsamplerate.la $(SNDFILE_LIBS) $(OS_SPECIFIC_LINKS)
|
||||
|
||||
timewarp_file_SOURCES = timewarp-file.c
|
||||
timewarp_file_LDADD = $(SAMPLERATEDIR)/libsamplerate.la $(SNDFILE_LIBS)
|
||||
|
||||
532
lib-src/libsamplerate/examples/Makefile.in
Normal file
532
lib-src/libsamplerate/examples/Makefile.in
Normal file
@@ -0,0 +1,532 @@
|
||||
# Makefile.in generated by automake 1.10.2 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005, 2006, 2007, 2008 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@
|
||||
|
||||
# This file was automatically generated
|
||||
# DO NOT EDIT!
|
||||
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
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-resample$(EXEEXT)
|
||||
noinst_PROGRAMS = varispeed-play$(EXEEXT) timewarp-file$(EXEEXT)
|
||||
subdir = examples
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/M4/clip_mode.m4 \
|
||||
$(top_srcdir)/M4/endian.m4 $(top_srcdir)/M4/libtool.m4 \
|
||||
$(top_srcdir)/M4/lrint.m4 $(top_srcdir)/M4/lrintf.m4 \
|
||||
$(top_srcdir)/M4/ltoptions.m4 $(top_srcdir)/M4/ltsugar.m4 \
|
||||
$(top_srcdir)/M4/ltversion.m4 $(top_srcdir)/M4/lt~obsolete.m4 \
|
||||
$(top_srcdir)/M4/pkg.m4 $(top_srcdir)/M4/signal.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_sndfile_resample_OBJECTS = sndfile-resample.$(OBJEXT)
|
||||
sndfile_resample_OBJECTS = $(am_sndfile_resample_OBJECTS)
|
||||
am__DEPENDENCIES_1 =
|
||||
sndfile_resample_DEPENDENCIES = $(SAMPLERATEDIR)/libsamplerate.la \
|
||||
$(am__DEPENDENCIES_1)
|
||||
am_timewarp_file_OBJECTS = timewarp-file.$(OBJEXT)
|
||||
timewarp_file_OBJECTS = $(am_timewarp_file_OBJECTS)
|
||||
timewarp_file_DEPENDENCIES = $(SAMPLERATEDIR)/libsamplerate.la \
|
||||
$(am__DEPENDENCIES_1)
|
||||
am_varispeed_play_OBJECTS = varispeed-play.$(OBJEXT) \
|
||||
audio_out.$(OBJEXT)
|
||||
varispeed_play_OBJECTS = $(am_varispeed_play_OBJECTS)
|
||||
varispeed_play_DEPENDENCIES = $(SAMPLERATEDIR)/libsamplerate.la \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
|
||||
depcomp = $(SHELL) $(top_srcdir)/Cfg/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(sndfile_resample_SOURCES) $(timewarp_file_SOURCES) \
|
||||
$(varispeed_play_SOURCES)
|
||||
DIST_SOURCES = $(sndfile_resample_SOURCES) $(timewarp_file_SOURCES) \
|
||||
$(varispeed_play_SOURCES)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@
|
||||
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@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DLLTOOL = @DLLTOOL@
|
||||
DLLWRAP = @DLLWRAP@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
DUMPBIN = @DUMPBIN@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
FFTW3_CFLAGS = @FFTW3_CFLAGS@
|
||||
FFTW3_LIBS = @FFTW3_LIBS@
|
||||
FGREP = @FGREP@
|
||||
GCC_MAJOR_VERSION = @GCC_MAJOR_VERSION@
|
||||
GREP = @GREP@
|
||||
HAVE_FFTW3 = @HAVE_FFTW3@
|
||||
HAVE_SNDFILE = @HAVE_SNDFILE@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LD = @LD@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LIPO = @LIPO@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAINT = @MAINT@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
NM = @NM@
|
||||
NMEDIT = @NMEDIT@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
OS_SPECIFIC_INCLUDES = @OS_SPECIFIC_INCLUDES@
|
||||
OS_SPECIFIC_LINKS = @OS_SPECIFIC_LINKS@
|
||||
OTOOL = @OTOOL@
|
||||
OTOOL64 = @OTOOL64@
|
||||
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@
|
||||
PEXPORTS = @PEXPORTS@
|
||||
PKG_CONFIG = @PKG_CONFIG@
|
||||
RANLIB = @RANLIB@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHARED_VERSION_INFO = @SHARED_VERSION_INFO@
|
||||
SHELL = @SHELL@
|
||||
SHLIB_VERSION_ARG = @SHLIB_VERSION_ARG@
|
||||
SNDFILE_CFLAGS = @SNDFILE_CFLAGS@
|
||||
SNDFILE_LIBS = @SNDFILE_LIBS@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
abs_top_srcdir = @abs_top_srcdir@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
builddir = @builddir@
|
||||
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@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
lt_ECHO = @lt_ECHO@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target = @target@
|
||||
target_alias = @target_alias@
|
||||
target_cpu = @target_cpu@
|
||||
target_os = @target_os@
|
||||
target_vendor = @target_vendor@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
SAMPLERATEDIR = ../src
|
||||
INCLUDES = -I$(srcdir)/$(SAMPLERATEDIR) @OS_SPECIFIC_INCLUDES@
|
||||
AM_CFLAGS = @SNDFILE_CFLAGS@
|
||||
|
||||
#===============================================================================
|
||||
sndfile_resample_SOURCES = sndfile-resample.c
|
||||
sndfile_resample_LDADD = $(SAMPLERATEDIR)/libsamplerate.la $(SNDFILE_LIBS)
|
||||
varispeed_play_SOURCES = varispeed-play.c audio_out.c audio_out.h
|
||||
varispeed_play_LDADD = $(SAMPLERATEDIR)/libsamplerate.la $(SNDFILE_LIBS) $(OS_SPECIFIC_LINKS)
|
||||
timewarp_file_SOURCES = timewarp-file.c
|
||||
timewarp_file_LDADD = $(SAMPLERATEDIR)/libsamplerate.la $(SNDFILE_LIBS)
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .lo .o .obj
|
||||
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
|
||||
&& { if test -f $@; then exit 0; else break; fi; }; \
|
||||
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: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(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) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
|
||||
$(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --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
|
||||
sndfile-resample$(EXEEXT): $(sndfile_resample_OBJECTS) $(sndfile_resample_DEPENDENCIES)
|
||||
@rm -f sndfile-resample$(EXEEXT)
|
||||
$(LINK) $(sndfile_resample_OBJECTS) $(sndfile_resample_LDADD) $(LIBS)
|
||||
timewarp-file$(EXEEXT): $(timewarp_file_OBJECTS) $(timewarp_file_DEPENDENCIES)
|
||||
@rm -f timewarp-file$(EXEEXT)
|
||||
$(LINK) $(timewarp_file_OBJECTS) $(timewarp_file_LDADD) $(LIBS)
|
||||
varispeed-play$(EXEEXT): $(varispeed_play_OBJECTS) $(varispeed_play_DEPENDENCIES)
|
||||
@rm -f varispeed-play$(EXEEXT)
|
||||
$(LINK) $(varispeed_play_OBJECTS) $(varispeed_play_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audio_out.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sndfile-resample.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timewarp-file.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/varispeed-play.Po@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@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@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@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@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
|
||||
@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
|
||||
|
||||
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; nonempty = 1; } \
|
||||
END { if (nonempty) { 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; nonempty = 1; } \
|
||||
END { if (nonempty) { 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=; \
|
||||
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; nonempty = 1; } \
|
||||
END { if (nonempty) { 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)'; \
|
||||
dist_files=`for file in $$list; do echo $$file; done | \
|
||||
sed -e "s|^$$srcdirstrip/||;t" \
|
||||
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
|
||||
case $$dist_files in \
|
||||
*/*) $(MKDIR_P) `echo "$$dist_files" | \
|
||||
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
|
||||
sort -u` ;; \
|
||||
esac; \
|
||||
for file in $$dist_files; do \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
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-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am:
|
||||
|
||||
install-dvi: install-dvi-am
|
||||
|
||||
install-exec-am: install-binPROGRAMS
|
||||
|
||||
install-html: install-html-am
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
install-pdf: install-pdf-am
|
||||
|
||||
install-ps: install-ps-am
|
||||
|
||||
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
|
||||
|
||||
.MAKE: install-am install-strip
|
||||
|
||||
.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-dvi install-dvi-am \
|
||||
install-exec install-exec-am install-html install-html-am \
|
||||
install-info install-info-am install-man install-pdf \
|
||||
install-pdf-am install-ps install-ps-am 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
|
||||
|
||||
# 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:
|
||||
820
lib-src/libsamplerate/examples/audio_out.c
Normal file
820
lib-src/libsamplerate/examples/audio_out.c
Normal file
@@ -0,0 +1,820 @@
|
||||
/*
|
||||
** Copyright (C) 1999-2008 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 <unistd.h>
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "audio_out.h"
|
||||
|
||||
#if (HAVE_SNDFILE)
|
||||
|
||||
#include <float_cast.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#define BUFFER_LEN (2048)
|
||||
|
||||
#define MAKE_MAGIC(a,b,c,d,e,f,g,h) \
|
||||
((a) + ((b) << 1) + ((c) << 2) + ((d) << 3) + ((e) << 4) + ((f) << 5) + ((g) << 6) + ((h) << 7))
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
** Linux/OSS functions for playing a sound.
|
||||
*/
|
||||
|
||||
#if defined (__linux__)
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/soundcard.h>
|
||||
|
||||
#define LINUX_MAGIC MAKE_MAGIC ('L', 'i', 'n', 'u', 'x', 'O', 'S', 'S')
|
||||
|
||||
typedef struct
|
||||
{ int magic ;
|
||||
int fd ;
|
||||
int channels ;
|
||||
} LINUX_AUDIO_OUT ;
|
||||
|
||||
static AUDIO_OUT *linux_open (int channels, int samplerate) ;
|
||||
static void linux_play (get_audio_callback_t callback, AUDIO_OUT *audio_out, void *callback_data) ;
|
||||
static void linux_close (AUDIO_OUT *audio_out) ;
|
||||
|
||||
|
||||
static AUDIO_OUT *
|
||||
linux_open (int channels, int samplerate)
|
||||
{ LINUX_AUDIO_OUT *linux_out ;
|
||||
int stereo, fmt, error ;
|
||||
|
||||
if ((linux_out = malloc (sizeof (LINUX_AUDIO_OUT))) == NULL)
|
||||
{ perror ("linux_open : malloc ") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
linux_out->magic = LINUX_MAGIC ;
|
||||
linux_out->channels = channels ;
|
||||
|
||||
if ((linux_out->fd = open ("/dev/dsp", O_WRONLY, 0)) == -1)
|
||||
{ perror ("linux_open : open ") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
stereo = 0 ;
|
||||
if (ioctl (linux_out->fd, SNDCTL_DSP_STEREO, &stereo) == -1)
|
||||
{ /* Fatal error */
|
||||
perror ("linux_open : stereo ") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (ioctl (linux_out->fd, SNDCTL_DSP_RESET, 0))
|
||||
{ perror ("linux_open : reset ") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
fmt = CPU_IS_BIG_ENDIAN ? AFMT_S16_BE : AFMT_S16_LE ;
|
||||
if (ioctl (linux_out->fd, SNDCTL_DSP_SETFMT, &fmt) != 0)
|
||||
{ perror ("linux_open_dsp_device : set format ") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((error = ioctl (linux_out->fd, SNDCTL_DSP_CHANNELS, &channels)) != 0)
|
||||
{ perror ("linux_open : channels ") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((error = ioctl (linux_out->fd, SNDCTL_DSP_SPEED, &samplerate)) != 0)
|
||||
{ perror ("linux_open : sample rate ") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((error = ioctl (linux_out->fd, SNDCTL_DSP_SYNC, 0)) != 0)
|
||||
{ perror ("linux_open : sync ") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return (AUDIO_OUT*) linux_out ;
|
||||
} /* linux_open */
|
||||
|
||||
static void
|
||||
linux_play (get_audio_callback_t callback, AUDIO_OUT *audio_out, void *callback_data)
|
||||
{ LINUX_AUDIO_OUT *linux_out ;
|
||||
static float float_buffer [BUFFER_LEN] ;
|
||||
static short buffer [BUFFER_LEN] ;
|
||||
int k, readcount, ignored ;
|
||||
|
||||
if ((linux_out = (LINUX_AUDIO_OUT*) audio_out) == NULL)
|
||||
{ printf ("linux_play : AUDIO_OUT is NULL.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (linux_out->magic != LINUX_MAGIC)
|
||||
{ printf ("linux_play : Bad magic number.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
while ((readcount = callback (callback_data, float_buffer, BUFFER_LEN / linux_out->channels)))
|
||||
{ for (k = 0 ; k < readcount * linux_out->channels ; k++)
|
||||
buffer [k] = lrint (32767.0 * float_buffer [k]) ;
|
||||
ignored = write (linux_out->fd, buffer, readcount * linux_out->channels * sizeof (short)) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* linux_play */
|
||||
|
||||
static void
|
||||
linux_close (AUDIO_OUT *audio_out)
|
||||
{ LINUX_AUDIO_OUT *linux_out ;
|
||||
|
||||
if ((linux_out = (LINUX_AUDIO_OUT*) audio_out) == NULL)
|
||||
{ printf ("linux_close : AUDIO_OUT is NULL.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (linux_out->magic != LINUX_MAGIC)
|
||||
{ printf ("linux_close : Bad magic number.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
memset (linux_out, 0, sizeof (LINUX_AUDIO_OUT)) ;
|
||||
|
||||
free (linux_out) ;
|
||||
|
||||
return ;
|
||||
} /* linux_close */
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
** Mac OS X functions for playing a sound.
|
||||
*/
|
||||
|
||||
#if (defined (__MACH__) && defined (__APPLE__)) /* MacOSX */
|
||||
|
||||
#include <Carbon.h>
|
||||
#include <CoreAudio/AudioHardware.h>
|
||||
|
||||
#define MACOSX_MAGIC MAKE_MAGIC ('M', 'a', 'c', ' ', 'O', 'S', ' ', 'X')
|
||||
|
||||
typedef struct
|
||||
{ int magic ;
|
||||
AudioStreamBasicDescription format ;
|
||||
|
||||
UInt32 buf_size ;
|
||||
AudioDeviceID device ;
|
||||
|
||||
int channels ;
|
||||
int samplerate ;
|
||||
int buffer_size ;
|
||||
int done_playing ;
|
||||
|
||||
get_audio_callback_t callback ;
|
||||
|
||||
void *callback_data ;
|
||||
} MACOSX_AUDIO_OUT ;
|
||||
|
||||
static AUDIO_OUT *macosx_open (int channels, int samplerate) ;
|
||||
static void macosx_play (get_audio_callback_t callback, AUDIO_OUT *audio_out, void *callback_data) ;
|
||||
static void macosx_close (AUDIO_OUT *audio_out) ;
|
||||
|
||||
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) ;
|
||||
|
||||
|
||||
static AUDIO_OUT *
|
||||
macosx_open (int channels, int samplerate)
|
||||
{ MACOSX_AUDIO_OUT *macosx_out ;
|
||||
OSStatus err ;
|
||||
size_t count ;
|
||||
|
||||
if ((macosx_out = malloc (sizeof (MACOSX_AUDIO_OUT))) == NULL)
|
||||
{ perror ("macosx_open : malloc ") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
macosx_out->magic = MACOSX_MAGIC ;
|
||||
macosx_out->channels = channels ;
|
||||
macosx_out->samplerate = samplerate ;
|
||||
|
||||
macosx_out->device = kAudioDeviceUnknown ;
|
||||
|
||||
/* get the default output device for the HAL */
|
||||
count = sizeof (AudioDeviceID) ;
|
||||
if ((err = AudioHardwareGetProperty (kAudioHardwarePropertyDefaultOutputDevice,
|
||||
&count, (void *) &(macosx_out->device))) != noErr)
|
||||
{ printf ("AudioHardwareGetProperty failed.\n") ;
|
||||
free (macosx_out) ;
|
||||
return NULL ;
|
||||
} ;
|
||||
|
||||
/* get the buffersize that the default device uses for IO */
|
||||
count = sizeof (UInt32) ;
|
||||
if ((err = AudioDeviceGetProperty (macosx_out->device, 0, false, kAudioDevicePropertyBufferSize,
|
||||
&count, &(macosx_out->buffer_size))) != noErr)
|
||||
{ printf ("AudioDeviceGetProperty (AudioDeviceGetProperty) failed.\n") ;
|
||||
free (macosx_out) ;
|
||||
return NULL ;
|
||||
} ;
|
||||
|
||||
/* get a description of the data format used by the default device */
|
||||
count = sizeof (AudioStreamBasicDescription) ;
|
||||
if ((err = AudioDeviceGetProperty (macosx_out->device, 0, false, kAudioDevicePropertyStreamFormat,
|
||||
&count, &(macosx_out->format))) != noErr)
|
||||
{ printf ("AudioDeviceGetProperty (kAudioDevicePropertyStreamFormat) failed.\n") ;
|
||||
free (macosx_out) ;
|
||||
return NULL ;
|
||||
} ;
|
||||
|
||||
macosx_out->format.mSampleRate = samplerate ;
|
||||
macosx_out->format.mChannelsPerFrame = channels ;
|
||||
|
||||
if ((err = AudioDeviceSetProperty (macosx_out->device, NULL, 0, false, kAudioDevicePropertyStreamFormat,
|
||||
sizeof (AudioStreamBasicDescription), &(macosx_out->format))) != noErr)
|
||||
{ printf ("AudioDeviceSetProperty (kAudioDevicePropertyStreamFormat) failed.\n") ;
|
||||
free (macosx_out) ;
|
||||
return NULL ;
|
||||
} ;
|
||||
|
||||
/* we want linear pcm */
|
||||
if (macosx_out->format.mFormatID != kAudioFormatLinearPCM)
|
||||
{ free (macosx_out) ;
|
||||
return NULL ;
|
||||
} ;
|
||||
|
||||
macosx_out->done_playing = 0 ;
|
||||
|
||||
/* Fire off the device. */
|
||||
if ((err = AudioDeviceAddIOProc (macosx_out->device, macosx_audio_out_callback,
|
||||
(void *) macosx_out)) != noErr)
|
||||
{ printf ("AudioDeviceAddIOProc failed.\n") ;
|
||||
free (macosx_out) ;
|
||||
return NULL ;
|
||||
} ;
|
||||
|
||||
return (MACOSX_AUDIO_OUT *) macosx_out ;
|
||||
} /* macosx_open */
|
||||
|
||||
static void
|
||||
macosx_play (get_audio_callback_t callback, AUDIO_OUT *audio_out, void *callback_data)
|
||||
{ MACOSX_AUDIO_OUT *macosx_out ;
|
||||
OSStatus err ;
|
||||
|
||||
if ((macosx_out = (MACOSX_AUDIO_OUT*) audio_out) == NULL)
|
||||
{ printf ("macosx_play : AUDIO_OUT is NULL.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (macosx_out->magic != MACOSX_MAGIC)
|
||||
{ printf ("macosx_play : Bad magic number.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
/* Set the callback function and callback data. */
|
||||
macosx_out->callback = callback ;
|
||||
macosx_out->callback_data = callback_data ;
|
||||
|
||||
err = AudioDeviceStart (macosx_out->device, macosx_audio_out_callback) ;
|
||||
if (err != noErr)
|
||||
printf ("AudioDeviceStart failed.\n") ;
|
||||
|
||||
while (macosx_out->done_playing == SF_FALSE)
|
||||
usleep (10 * 1000) ; /* 10 000 milliseconds. */
|
||||
|
||||
return ;
|
||||
} /* macosx_play */
|
||||
|
||||
static void
|
||||
macosx_close (AUDIO_OUT *audio_out)
|
||||
{ MACOSX_AUDIO_OUT *macosx_out ;
|
||||
OSStatus err ;
|
||||
|
||||
if ((macosx_out = (MACOSX_AUDIO_OUT*) audio_out) == NULL)
|
||||
{ printf ("macosx_close : AUDIO_OUT is NULL.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (macosx_out->magic != MACOSX_MAGIC)
|
||||
{ printf ("macosx_close : Bad magic number.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
|
||||
if ((err = AudioDeviceStop (macosx_out->device, macosx_audio_out_callback)) != noErr)
|
||||
{ printf ("AudioDeviceStop failed.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
err = AudioDeviceRemoveIOProc (macosx_out->device, macosx_audio_out_callback) ;
|
||||
if (err != noErr)
|
||||
{ printf ("AudioDeviceRemoveIOProc failed.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
} /* macosx_close */
|
||||
|
||||
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)
|
||||
{ MACOSX_AUDIO_OUT *macosx_out ;
|
||||
int k, size, sample_count, read_count ;
|
||||
float *buffer ;
|
||||
|
||||
if ((macosx_out = (MACOSX_AUDIO_OUT*) client_data) == NULL)
|
||||
{ printf ("macosx_play : AUDIO_OUT is NULL.\n") ;
|
||||
return 42 ;
|
||||
} ;
|
||||
|
||||
if (macosx_out->magic != MACOSX_MAGIC)
|
||||
{ printf ("macosx_play : Bad magic number.\n") ;
|
||||
return 42 ;
|
||||
} ;
|
||||
|
||||
size = data_out->mBuffers [0].mDataByteSize ;
|
||||
sample_count = size / sizeof (float) / macosx_out->channels ;
|
||||
|
||||
buffer = (float*) data_out->mBuffers [0].mData ;
|
||||
|
||||
read_count = macosx_out->callback (macosx_out->callback_data, buffer, sample_count) ;
|
||||
|
||||
if (read_count < sample_count)
|
||||
{ memset (&(buffer [read_count]), 0, (sample_count - read_count) * sizeof (float)) ;
|
||||
macosx_out->done_playing = 1 ;
|
||||
} ;
|
||||
|
||||
return noErr ;
|
||||
} /* macosx_audio_out_callback */
|
||||
|
||||
#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 (defined (_WIN32) || defined (WIN32))
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
#define WIN32_BUFFER_LEN (1<<15)
|
||||
#define WIN32_MAGIC MAKE_MAGIC ('W', 'i', 'n', '3', '2', 's', 'u', 'x')
|
||||
|
||||
typedef struct
|
||||
{ int magic ;
|
||||
|
||||
HWAVEOUT hwave ;
|
||||
WAVEHDR whdr [2] ;
|
||||
|
||||
HANDLE Event ;
|
||||
|
||||
short short_buffer [WIN32_BUFFER_LEN / sizeof (short)] ;
|
||||
float float_buffer [WIN32_BUFFER_LEN / sizeof (short) / 2] ;
|
||||
|
||||
int bufferlen, current ;
|
||||
|
||||
int channels ;
|
||||
|
||||
get_audio_callback_t callback ;
|
||||
|
||||
void *callback_data ;
|
||||
} WIN32_AUDIO_OUT ;
|
||||
|
||||
static AUDIO_OUT *win32_open (int channels, int samplerate) ;
|
||||
static void win32_play (get_audio_callback_t callback, AUDIO_OUT *audio_out, void *callback_data) ;
|
||||
static void win32_close (AUDIO_OUT *audio_out) ;
|
||||
|
||||
static DWORD CALLBACK
|
||||
win32_audio_out_callback (HWAVEOUT hwave, UINT msg, DWORD data, DWORD param1, DWORD param2) ;
|
||||
|
||||
static AUDIO_OUT*
|
||||
win32_open (int channels, int samplerate)
|
||||
{ WIN32_AUDIO_OUT *win32_out ;
|
||||
|
||||
WAVEFORMATEX wf ;
|
||||
int error ;
|
||||
|
||||
if ((win32_out = malloc (sizeof (WIN32_AUDIO_OUT))) == NULL)
|
||||
{ perror ("win32_open : malloc ") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
win32_out->magic = WIN32_MAGIC ;
|
||||
win32_out->channels = channels ;
|
||||
|
||||
win32_out->current = 0 ;
|
||||
|
||||
win32_out->Event = CreateEvent (0, FALSE, FALSE, 0) ;
|
||||
|
||||
wf.nChannels = channels ;
|
||||
wf.nSamplesPerSec = samplerate ;
|
||||
wf.nBlockAlign = channels * sizeof (short) ;
|
||||
|
||||
wf.wFormatTag = WAVE_FORMAT_PCM ;
|
||||
wf.cbSize = 0 ;
|
||||
wf.wBitsPerSample = 16 ;
|
||||
wf.nAvgBytesPerSec = wf.nBlockAlign * wf.nSamplesPerSec ;
|
||||
|
||||
error = waveOutOpen (&(win32_out->hwave), WAVE_MAPPER, &wf, (DWORD) win32_audio_out_callback,
|
||||
(DWORD) win32_out, CALLBACK_FUNCTION) ;
|
||||
if (error)
|
||||
{ puts ("waveOutOpen failed.") ;
|
||||
free (win32_out) ;
|
||||
return NULL ;
|
||||
} ;
|
||||
|
||||
waveOutPause (win32_out->hwave) ;
|
||||
|
||||
return (WIN32_AUDIO_OUT *) win32_out ;
|
||||
} /* win32_open */
|
||||
|
||||
static void
|
||||
win32_play (get_audio_callback_t callback, AUDIO_OUT *audio_out, void *callback_data)
|
||||
{ WIN32_AUDIO_OUT *win32_out ;
|
||||
int error ;
|
||||
|
||||
if ((win32_out = (WIN32_AUDIO_OUT*) audio_out) == NULL)
|
||||
{ printf ("win32_play : AUDIO_OUT is NULL.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (win32_out->magic != WIN32_MAGIC)
|
||||
{ printf ("win32_play : Bad magic number (%d %d).\n", win32_out->magic, WIN32_MAGIC) ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
/* Set the callback function and callback data. */
|
||||
win32_out->callback = callback ;
|
||||
win32_out->callback_data = callback_data ;
|
||||
|
||||
win32_out->whdr [0].lpData = (char*) win32_out->short_buffer ;
|
||||
win32_out->whdr [1].lpData = ((char*) win32_out->short_buffer) + sizeof (win32_out->short_buffer) / 2 ;
|
||||
|
||||
win32_out->whdr [0].dwBufferLength = sizeof (win32_out->short_buffer) / 2 ;
|
||||
win32_out->whdr [1].dwBufferLength = sizeof (win32_out->short_buffer) / 2 ;
|
||||
|
||||
win32_out->bufferlen = sizeof (win32_out->short_buffer) / 2 / sizeof (short) ;
|
||||
|
||||
/* Prepare the WAVEHDRs */
|
||||
if ((error = waveOutPrepareHeader (win32_out->hwave, &(win32_out->whdr [0]), sizeof (WAVEHDR))))
|
||||
{ printf ("waveOutPrepareHeader [0] failed : %08X\n", error) ;
|
||||
waveOutClose (win32_out->hwave) ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if ((error = waveOutPrepareHeader (win32_out->hwave, &(win32_out->whdr [1]), sizeof (WAVEHDR))))
|
||||
{ printf ("waveOutPrepareHeader [1] failed : %08X\n", error) ;
|
||||
waveOutUnprepareHeader (win32_out->hwave, &(win32_out->whdr [0]), sizeof (WAVEHDR)) ;
|
||||
waveOutClose (win32_out->hwave) ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
waveOutRestart (win32_out->hwave) ;
|
||||
|
||||
/* Fake 2 calls to the callback function to queue up enough audio. */
|
||||
win32_audio_out_callback (0, MM_WOM_DONE, (DWORD) win32_out, 0, 0) ;
|
||||
win32_audio_out_callback (0, MM_WOM_DONE, (DWORD) win32_out, 0, 0) ;
|
||||
|
||||
/* Wait for playback to finish. The callback notifies us when all
|
||||
** wave data has been played.
|
||||
*/
|
||||
WaitForSingleObject (win32_out->Event, INFINITE) ;
|
||||
|
||||
waveOutPause (win32_out->hwave) ;
|
||||
waveOutReset (win32_out->hwave) ;
|
||||
|
||||
waveOutUnprepareHeader (win32_out->hwave, &(win32_out->whdr [0]), sizeof (WAVEHDR)) ;
|
||||
waveOutUnprepareHeader (win32_out->hwave, &(win32_out->whdr [1]), sizeof (WAVEHDR)) ;
|
||||
|
||||
waveOutClose (win32_out->hwave) ;
|
||||
win32_out->hwave = 0 ;
|
||||
|
||||
return ;
|
||||
} /* win32_play */
|
||||
|
||||
static void
|
||||
win32_close (AUDIO_OUT *audio_out)
|
||||
{ WIN32_AUDIO_OUT *win32_out ;
|
||||
|
||||
if ((win32_out = (WIN32_AUDIO_OUT*) audio_out) == NULL)
|
||||
{ printf ("win32_close : AUDIO_OUT is NULL.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (win32_out->magic != WIN32_MAGIC)
|
||||
{ printf ("win32_close : Bad magic number.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
memset (win32_out, 0, sizeof (WIN32_AUDIO_OUT)) ;
|
||||
|
||||
free (win32_out) ;
|
||||
} /* win32_close */
|
||||
|
||||
static DWORD CALLBACK
|
||||
win32_audio_out_callback (HWAVEOUT hwave, UINT msg, DWORD data, DWORD param1, DWORD param2)
|
||||
{ WIN32_AUDIO_OUT *win32_out ;
|
||||
int read_count, sample_count, k ;
|
||||
short *sptr ;
|
||||
|
||||
/*
|
||||
** I consider this technique of passing a pointer via an integer as
|
||||
** fundamentally broken but thats the way microsoft has defined the
|
||||
** interface.
|
||||
*/
|
||||
if ((win32_out = (WIN32_AUDIO_OUT*) data) == NULL)
|
||||
{ printf ("win32_audio_out_callback : AUDIO_OUT is NULL.\n") ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
if (win32_out->magic != WIN32_MAGIC)
|
||||
{ printf ("win32_audio_out_callback : Bad magic number (%d %d).\n", win32_out->magic, WIN32_MAGIC) ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
if (msg != MM_WOM_DONE)
|
||||
return 0 ;
|
||||
|
||||
/* Do the actual audio. */
|
||||
sample_count = win32_out->bufferlen ;
|
||||
|
||||
read_count = win32_out->callback (win32_out->callback_data, win32_out->float_buffer, sample_count) ;
|
||||
|
||||
sptr = (short*) win32_out->whdr [win32_out->current].lpData ;
|
||||
|
||||
for (k = 0 ; k < read_count ; k++)
|
||||
sptr [k] = lrint (32767.0 * win32_out->float_buffer [k]) ;
|
||||
|
||||
if (read_count > 0)
|
||||
{ /* Fix buffer length is only a partial block. */
|
||||
if (read_count * sizeof (short) < win32_out->bufferlen)
|
||||
win32_out->whdr [win32_out->current].dwBufferLength = read_count * sizeof (short) ;
|
||||
|
||||
/* Queue the WAVEHDR */
|
||||
waveOutWrite (win32_out->hwave, (LPWAVEHDR) &(win32_out->whdr [win32_out->current]), sizeof (WAVEHDR)) ;
|
||||
}
|
||||
else
|
||||
{ /* Stop playback */
|
||||
waveOutPause (win32_out->hwave) ;
|
||||
|
||||
SetEvent (win32_out->Event) ;
|
||||
} ;
|
||||
|
||||
win32_out->current = (win32_out->current + 1) % 2 ;
|
||||
|
||||
return 0 ;
|
||||
} /* win32_audio_out_callback */
|
||||
|
||||
#endif /* Win32 */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
** Solaris.
|
||||
*/
|
||||
|
||||
#if (defined (sun) && defined (unix)) /* ie Solaris */
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/audioio.h>
|
||||
|
||||
#define SOLARIS_MAGIC MAKE_MAGIC ('S', 'o', 'l', 'a', 'r', 'i', 's', ' ')
|
||||
|
||||
typedef struct
|
||||
{ int magic ;
|
||||
int fd ;
|
||||
int channels ;
|
||||
int samplerate ;
|
||||
} SOLARIS_AUDIO_OUT ;
|
||||
|
||||
static AUDIO_OUT *solaris_open (int channels, int samplerate) ;
|
||||
static void solaris_play (get_audio_callback_t callback, AUDIO_OUT *audio_out, void *callback_data) ;
|
||||
static void solaris_close (AUDIO_OUT *audio_out) ;
|
||||
|
||||
static AUDIO_OUT *
|
||||
solaris_open (int channels, int samplerate)
|
||||
{ SOLARIS_AUDIO_OUT *solaris_out ;
|
||||
audio_info_t audio_info ;
|
||||
int error ;
|
||||
|
||||
if ((solaris_out = malloc (sizeof (SOLARIS_AUDIO_OUT))) == NULL)
|
||||
{ perror ("solaris_open : malloc ") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
solaris_out->magic = SOLARIS_MAGIC ;
|
||||
solaris_out->channels = channels ;
|
||||
solaris_out->samplerate = channels ;
|
||||
|
||||
/* open the audio device - write only, non-blocking */
|
||||
if ((solaris_out->fd = open ("/dev/audio", O_WRONLY | O_NONBLOCK)) < 0)
|
||||
{ perror ("open (/dev/audio) failed") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Retrive standard values. */
|
||||
AUDIO_INITINFO (&audio_info) ;
|
||||
|
||||
audio_info.play.sample_rate = samplerate ;
|
||||
audio_info.play.channels = 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 (solaris_out->fd, AUDIO_SETINFO, &audio_info)))
|
||||
{ perror ("ioctl (AUDIO_SETINFO) failed") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return (AUDIO_OUT*) solaris_out ;
|
||||
} /* solaris_open */
|
||||
|
||||
static void
|
||||
solaris_play (get_audio_callback_t callback, AUDIO_OUT *audio_out, void *callback_data)
|
||||
{ SOLARIS_AUDIO_OUT *solaris_out ;
|
||||
static float float_buffer [BUFFER_LEN] ;
|
||||
static short buffer [BUFFER_LEN] ;
|
||||
int k, readcount ;
|
||||
|
||||
if ((solaris_out = (SOLARIS_AUDIO_OUT*) audio_out) == NULL)
|
||||
{ printf ("solaris_play : AUDIO_OUT is NULL.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (solaris_out->magic != SOLARIS_MAGIC)
|
||||
{ printf ("solaris_play : Bad magic number.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
while ((readcount = callback (callback_data, float_buffer, BUFFER_LEN / solaris_out->channels)))
|
||||
{ for (k = 0 ; k < readcount * solaris_out->channels ; k++)
|
||||
buffer [k] = lrint (32767.0 * float_buffer [k]) ;
|
||||
write (solaris_out->fd, buffer, readcount * solaris_out->channels * sizeof (short)) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* solaris_play */
|
||||
|
||||
static void
|
||||
solaris_close (AUDIO_OUT *audio_out)
|
||||
{ SOLARIS_AUDIO_OUT *solaris_out ;
|
||||
|
||||
if ((solaris_out = (SOLARIS_AUDIO_OUT*) audio_out) == NULL)
|
||||
{ printf ("solaris_close : AUDIO_OUT is NULL.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (solaris_out->magic != SOLARIS_MAGIC)
|
||||
{ printf ("solaris_close : Bad magic number.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
memset (solaris_out, 0, sizeof (SOLARIS_AUDIO_OUT)) ;
|
||||
|
||||
free (solaris_out) ;
|
||||
|
||||
return ;
|
||||
} /* solaris_close */
|
||||
|
||||
#endif /* Solaris */
|
||||
|
||||
/*==============================================================================
|
||||
** Main function.
|
||||
*/
|
||||
|
||||
AUDIO_OUT *
|
||||
audio_open (int channels, int samplerate)
|
||||
{
|
||||
#if defined (__linux__)
|
||||
return linux_open (channels, samplerate) ;
|
||||
#elif (defined (__MACH__) && defined (__APPLE__))
|
||||
return macosx_open (channels, samplerate) ;
|
||||
#elif (defined (sun) && defined (unix))
|
||||
return solaris_open (channels, samplerate) ;
|
||||
#elif (defined (_WIN32) || defined (WIN32))
|
||||
return win32_open (channels, samplerate) ;
|
||||
#else
|
||||
#warning "*** Playing sound not yet supported on this platform."
|
||||
#warning "*** Please feel free to submit a patch."
|
||||
printf ("Error : Playing sound not yet supported on this platform.\n") ;
|
||||
return NULL ;
|
||||
#endif
|
||||
|
||||
|
||||
return NULL ;
|
||||
} /* audio_open */
|
||||
|
||||
void
|
||||
audio_play (get_audio_callback_t callback, AUDIO_OUT *audio_out, void *callback_data)
|
||||
{
|
||||
|
||||
if (callback == NULL)
|
||||
{ printf ("Error : bad callback pointer.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (audio_out == NULL)
|
||||
{ printf ("Error : bad audio_out pointer.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (callback_data == NULL)
|
||||
{ printf ("Error : bad callback_data pointer.\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
#if defined (__linux__)
|
||||
linux_play (callback, audio_out, callback_data) ;
|
||||
#elif (defined (__MACH__) && defined (__APPLE__))
|
||||
macosx_play (callback, audio_out, callback_data) ;
|
||||
#elif (defined (sun) && defined (unix))
|
||||
solaris_play (callback, audio_out, callback_data) ;
|
||||
#elif (defined (_WIN32) || defined (WIN32))
|
||||
win32_play (callback, audio_out, callback_data) ;
|
||||
#else
|
||||
#warning "*** Playing sound not yet supported on this platform."
|
||||
#warning "*** Please feel free to submit a patch."
|
||||
printf ("Error : Playing sound not yet supported on this platform.\n") ;
|
||||
return ;
|
||||
#endif
|
||||
|
||||
return ;
|
||||
} /* audio_play */
|
||||
|
||||
void
|
||||
audio_close (AUDIO_OUT *audio_out)
|
||||
{
|
||||
#if defined (__linux__)
|
||||
linux_close (audio_out) ;
|
||||
#elif (defined (__MACH__) && defined (__APPLE__))
|
||||
macosx_close (audio_out) ;
|
||||
#elif (defined (sun) && defined (unix))
|
||||
solaris_close (audio_out) ;
|
||||
#elif (defined (_WIN32) || defined (WIN32))
|
||||
win32_close (audio_out) ;
|
||||
#else
|
||||
#warning "*** Playing sound not yet supported on this platform."
|
||||
#warning "*** Please feel free to submit a patch."
|
||||
printf ("Error : Playing sound not yet supported on this platform.\n") ;
|
||||
return ;
|
||||
#endif
|
||||
|
||||
return ;
|
||||
} /* audio_close */
|
||||
|
||||
#else /* (HAVE_SNDFILE == 0) */
|
||||
|
||||
/* Do not have libsndfile installed so just return. */
|
||||
|
||||
AUDIO_OUT *
|
||||
audio_open (int channels, int samplerate)
|
||||
{
|
||||
(void) channels ;
|
||||
(void) samplerate ;
|
||||
|
||||
return NULL ;
|
||||
} /* audio_open */
|
||||
|
||||
void
|
||||
audio_play (get_audio_callback_t callback, AUDIO_OUT *audio_out, void *callback_data)
|
||||
{
|
||||
(void) callback ;
|
||||
(void) audio_out ;
|
||||
(void) callback_data ;
|
||||
|
||||
return ;
|
||||
} /* audio_play */
|
||||
|
||||
void
|
||||
audio_close (AUDIO_OUT *audio_out)
|
||||
{
|
||||
audio_out = audio_out ;
|
||||
|
||||
return ;
|
||||
} /* audio_close */
|
||||
|
||||
#endif /* HAVE_SNDFILE */
|
||||
|
||||
37
lib-src/libsamplerate/examples/audio_out.h
Normal file
37
lib-src/libsamplerate/examples/audio_out.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
** Copyright (C) 1999-2008 Erik de Castro Lopo <erikd@zip.com.au>
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
typedef void AUDIO_OUT ;
|
||||
|
||||
typedef int (*get_audio_callback_t) (void *callback_data, float *samples, int frames) ;
|
||||
|
||||
/* A general audio ooutput function (Linux/OSS, Win32, MacOSX, Solaris)
|
||||
** which retrieves data using the callback function in the above struct.
|
||||
**
|
||||
** audio_open - opens the device and returns an anonymous pointer to its
|
||||
** own private data.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
AUDIO_OUT *audio_open (int channels, int samplerate) ;
|
||||
|
||||
void audio_play (get_audio_callback_t callback, AUDIO_OUT *audio_out, void *callback_data) ;
|
||||
|
||||
void audio_close (AUDIO_OUT *audio_data) ;
|
||||
|
||||
331
lib-src/libsamplerate/examples/sndfile-resample.c
Normal file
331
lib-src/libsamplerate/examples/sndfile-resample.c
Normal file
@@ -0,0 +1,331 @@
|
||||
/*
|
||||
** Copyright (C) 2002-2008 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 "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#if (HAVE_SNDFILE)
|
||||
|
||||
#include <samplerate.h>
|
||||
#include <sndfile.h>
|
||||
|
||||
#define DEFAULT_CONVERTER SRC_SINC_MEDIUM_QUALITY
|
||||
|
||||
#define BUFFER_LEN 4096 /*-(1<<16)-*/
|
||||
|
||||
static void usage_exit (const char *progname) ;
|
||||
static sf_count_t sample_rate_convert (SNDFILE *infile, SNDFILE *outfile, int converter, double src_ratio, int channels, double * gain) ;
|
||||
static double apply_gain (float * data, long frames, int channels, double max, double gain) ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ SNDFILE *infile, *outfile ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
sf_count_t count ;
|
||||
double src_ratio = -1.0, gain = 1.0 ;
|
||||
int new_sample_rate = -1, k, converter, max_speed = SF_FALSE ;
|
||||
|
||||
if (argc == 2 && strcmp (argv [1], "--version") == 0)
|
||||
{ char buffer [64], *cptr ;
|
||||
|
||||
if ((cptr = strrchr (argv [0], '/')) != NULL)
|
||||
argv [0] = cptr + 1 ;
|
||||
if ((cptr = strrchr (argv [0], '\\')) != NULL)
|
||||
argv [0] = cptr + 1 ;
|
||||
|
||||
sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
|
||||
|
||||
printf ("%s (%s,%s)\n", argv [0], src_get_version (), buffer) ;
|
||||
exit (0) ;
|
||||
} ;
|
||||
|
||||
if (argc != 5 && argc != 7 && argc != 8)
|
||||
usage_exit (argv [0]) ;
|
||||
|
||||
/* Set default converter. */
|
||||
converter = DEFAULT_CONVERTER ;
|
||||
|
||||
for (k = 1 ; k < argc - 2 ; k++)
|
||||
{ if (strcmp (argv [k], "--max-speed") == 0)
|
||||
max_speed = SF_TRUE ;
|
||||
else if (strcmp (argv [k], "-to") == 0)
|
||||
{ k ++ ;
|
||||
new_sample_rate = atoi (argv [k]) ;
|
||||
}
|
||||
else if (strcmp (argv [k], "-by") == 0)
|
||||
{ k ++ ;
|
||||
src_ratio = atof (argv [k]) ;
|
||||
}
|
||||
else if (strcmp (argv [k], "-c") == 0)
|
||||
{ k ++ ;
|
||||
converter = atoi (argv [k]) ;
|
||||
}
|
||||
else
|
||||
usage_exit (argv [0]) ;
|
||||
} ;
|
||||
|
||||
if (new_sample_rate <= 0 && src_ratio <= 0.0)
|
||||
usage_exit (argv [0]) ;
|
||||
|
||||
if (src_get_name (converter) == NULL)
|
||||
{ printf ("Error : bad converter number.\n") ;
|
||||
usage_exit (argv [0]) ;
|
||||
} ;
|
||||
|
||||
if (strcmp (argv [argc - 2], argv [argc - 1]) == 0)
|
||||
{ printf ("Error : input and output file names are the same.\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((infile = sf_open (argv [argc - 2], SFM_READ, &sfinfo)) == NULL)
|
||||
{ printf ("Error : Not able to open input file '%s'\n", argv [argc - 2]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
printf ("Input File : %s\n", argv [argc - 2]) ;
|
||||
printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
|
||||
printf ("Input Frames : %ld\n\n", (long) sfinfo.frames) ;
|
||||
|
||||
if (new_sample_rate > 0)
|
||||
{ src_ratio = (1.0 * new_sample_rate) / sfinfo.samplerate ;
|
||||
sfinfo.samplerate = new_sample_rate ;
|
||||
}
|
||||
else if (src_is_valid_ratio (src_ratio))
|
||||
sfinfo.samplerate = (int) floor (sfinfo.samplerate * src_ratio) ;
|
||||
else
|
||||
{ printf ("Not able to determine new sample rate. Exiting.\n") ;
|
||||
sf_close (infile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fabs (src_ratio - 1.0) < 1e-20)
|
||||
{ printf ("Target samplerate and input samplerate are the same. Exiting.\n") ;
|
||||
sf_close (infile) ;
|
||||
exit (0) ;
|
||||
} ;
|
||||
|
||||
printf ("SRC Ratio : %f\n", src_ratio) ;
|
||||
printf ("Converter : %s\n\n", src_get_name (converter)) ;
|
||||
|
||||
if (src_is_valid_ratio (src_ratio) == 0)
|
||||
{ printf ("Error : Sample rate change out of valid range.\n") ;
|
||||
sf_close (infile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Delete the output file length to zero if already exists. */
|
||||
remove (argv [argc - 1]) ;
|
||||
|
||||
if ((outfile = sf_open (argv [argc - 1], SFM_WRITE, &sfinfo)) == NULL)
|
||||
{ printf ("Error : Not able to open output file '%s'\n", argv [argc - 1]) ;
|
||||
sf_close (infile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (max_speed)
|
||||
{ /* This is mainly for the comparison program tests/src-evaluate.c */
|
||||
sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
|
||||
}
|
||||
else
|
||||
{ /* Update the file header after every write. */
|
||||
sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
|
||||
} ;
|
||||
|
||||
sf_command (outfile, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
||||
|
||||
printf ("Output file : %s\n", argv [argc - 1]) ;
|
||||
printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
|
||||
|
||||
do
|
||||
count = sample_rate_convert (infile, outfile, converter, src_ratio, sfinfo.channels, &gain) ;
|
||||
while (count < 0) ;
|
||||
|
||||
printf ("Output Frames : %ld\n\n", (long) count) ;
|
||||
|
||||
sf_close (infile) ;
|
||||
sf_close (outfile) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static sf_count_t
|
||||
sample_rate_convert (SNDFILE *infile, SNDFILE *outfile, int converter, double src_ratio, int channels, double * gain)
|
||||
{ static float input [BUFFER_LEN] ;
|
||||
static float output [BUFFER_LEN] ;
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
SRC_DATA src_data ;
|
||||
int error ;
|
||||
double max = 0.0 ;
|
||||
sf_count_t output_count = 0 ;
|
||||
|
||||
sf_seek (infile, 0, SEEK_SET) ;
|
||||
sf_seek (outfile, 0, SEEK_SET) ;
|
||||
|
||||
/* Initialize the sample rate converter. */
|
||||
if ((src_state = src_new (converter, channels, &error)) == NULL)
|
||||
{ printf ("\n\nError : src_new() failed : %s.\n\n", src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_data.end_of_input = 0 ; /* Set this later. */
|
||||
|
||||
/* Start with zero to force load in while loop. */
|
||||
src_data.input_frames = 0 ;
|
||||
src_data.data_in = input ;
|
||||
|
||||
src_data.src_ratio = src_ratio ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = BUFFER_LEN /channels ;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* If the input buffer is empty, refill it. */
|
||||
if (src_data.input_frames == 0)
|
||||
{ src_data.input_frames = sf_readf_float (infile, input, BUFFER_LEN / channels) ;
|
||||
src_data.data_in = input ;
|
||||
|
||||
/* The last read will not be a full buffer, so snd_of_input. */
|
||||
if (src_data.input_frames < BUFFER_LEN / channels)
|
||||
src_data.end_of_input = SF_TRUE ;
|
||||
} ;
|
||||
|
||||
if ((error = src_process (src_state, &src_data)))
|
||||
{ printf ("\nError : %s\n", src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Terminate if done. */
|
||||
if (src_data.end_of_input && src_data.output_frames_gen == 0)
|
||||
break ;
|
||||
|
||||
max = apply_gain (src_data.data_out, src_data.output_frames_gen, channels, max, *gain) ;
|
||||
|
||||
/* Write output. */
|
||||
sf_writef_float (outfile, output, src_data.output_frames_gen) ;
|
||||
output_count += src_data.output_frames_gen ;
|
||||
|
||||
src_data.data_in += src_data.input_frames_used * channels ;
|
||||
src_data.input_frames -= src_data.input_frames_used ;
|
||||
} ;
|
||||
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
if (max > 1.0)
|
||||
{ *gain = 1.0 / max ;
|
||||
printf ("\nOutput has clipped. Restarting conversion to prevent clipping.\n\n") ;
|
||||
output_count = 0 ;
|
||||
sf_command (outfile, SFC_FILE_TRUNCATE, &output_count, sizeof (output_count)) ;
|
||||
return -1 ;
|
||||
} ;
|
||||
|
||||
return output_count ;
|
||||
} /* sample_rate_convert */
|
||||
|
||||
static double
|
||||
apply_gain (float * data, long frames, int channels, double max, double gain)
|
||||
{
|
||||
long k ;
|
||||
|
||||
for (k = 0 ; k < frames * channels ; k++)
|
||||
{ data [k] *= gain ;
|
||||
|
||||
if (fabs (data [k]) > max)
|
||||
max = fabs (data [k]) ;
|
||||
} ;
|
||||
|
||||
return max ;
|
||||
} /* apply_gain */
|
||||
|
||||
static void
|
||||
usage_exit (const char *progname)
|
||||
{ char lsf_ver [128] ;
|
||||
const char *cptr ;
|
||||
int k ;
|
||||
|
||||
if ((cptr = strrchr (progname, '/')) != NULL)
|
||||
progname = cptr + 1 ;
|
||||
|
||||
if ((cptr = strrchr (progname, '\\')) != NULL)
|
||||
progname = cptr + 1 ;
|
||||
|
||||
|
||||
sf_command (NULL, SFC_GET_LIB_VERSION, lsf_ver, sizeof (lsf_ver)) ;
|
||||
|
||||
printf ("\n"
|
||||
" A Sample Rate Converter using libsndfile for file I/O and Secret \n"
|
||||
" Rabbit Code (aka libsamplerate) for performing the conversion.\n"
|
||||
" It works on any file format supported by libsndfile with any \n"
|
||||
" number of channels (limited only by host memory).\n"
|
||||
"\n"
|
||||
" %s\n"
|
||||
" %s\n"
|
||||
"\n"
|
||||
" Usage : \n"
|
||||
" %s -to <new sample rate> [-c <number>] <input file> <output file>\n"
|
||||
" %s -by <amount> [-c <number>] <input file> <output file>\n"
|
||||
"\n", src_get_version (), lsf_ver, progname, progname) ;
|
||||
|
||||
puts (
|
||||
" The optional -c argument allows the converter type to be chosen from\n"
|
||||
" the following list :"
|
||||
"\n"
|
||||
) ;
|
||||
|
||||
for (k = 0 ; (cptr = src_get_name (k)) != NULL ; k++)
|
||||
printf (" %d : %s%s\n", k, cptr, k == DEFAULT_CONVERTER ? " (default)" : "") ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
exit (1) ;
|
||||
} /* usage_exit */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
#else /* (HAVE_SNFILE == 0) */
|
||||
|
||||
/* Alternative main function when libsndfile is not available. */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ puts (
|
||||
"\n"
|
||||
"****************************************************************\n"
|
||||
" This example program was compiled without libsndfile \n"
|
||||
" (http://www.mega-nerd.com/libsndfile/).\n"
|
||||
" It is therefore completely broken and non-functional.\n"
|
||||
"****************************************************************\n"
|
||||
"\n"
|
||||
) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
#endif
|
||||
|
||||
240
lib-src/libsamplerate/examples/timewarp-file.c
Normal file
240
lib-src/libsamplerate/examples/timewarp-file.c
Normal file
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
** Copyright (C) 2005-2008 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 "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#if (HAVE_SNDFILE)
|
||||
|
||||
#include <samplerate.h>
|
||||
#include <sndfile.h>
|
||||
|
||||
#define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
|
||||
|
||||
#define DEFAULT_CONVERTER SRC_SINC_MEDIUM_QUALITY
|
||||
|
||||
#define BUFFER_LEN 1024
|
||||
#define INPUT_STEP_SIZE 8
|
||||
|
||||
typedef struct
|
||||
{ sf_count_t index ;
|
||||
double ratio ;
|
||||
} TIMEWARP_FACTOR ;
|
||||
|
||||
static void usage_exit (const char *progname) ;
|
||||
static sf_count_t timewarp_convert (SNDFILE *infile, SNDFILE *outfile, int converter, int channels) ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ SNDFILE *infile, *outfile ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t count ;
|
||||
|
||||
if (argc != 3)
|
||||
usage_exit (argv [0]) ;
|
||||
|
||||
putchar ('\n') ;
|
||||
printf ("Input File : %s\n", argv [argc - 2]) ;
|
||||
if ((infile = sf_open (argv [argc - 2], SFM_READ, &sfinfo)) == NULL)
|
||||
{ printf ("Error : Not able to open input file '%s'\n", argv [argc - 2]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (INPUT_STEP_SIZE * sfinfo.channels > BUFFER_LEN)
|
||||
{ printf ("\n\nError : INPUT_STEP_SIZE * sfinfo.channels > BUFFER_LEN\n\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
|
||||
/* Delete the output file length to zero if already exists. */
|
||||
remove (argv [argc - 1]) ;
|
||||
|
||||
if ((outfile = sf_open (argv [argc - 1], SFM_WRITE, &sfinfo)) == NULL)
|
||||
{ printf ("Error : Not able to open output file '%s'\n", argv [argc - 1]) ;
|
||||
sf_close (infile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_command (outfile, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
||||
|
||||
printf ("Output file : %s\n", argv [argc - 1]) ;
|
||||
printf ("Converter : %s\n", src_get_name (DEFAULT_CONVERTER)) ;
|
||||
|
||||
count = timewarp_convert (infile, outfile, DEFAULT_CONVERTER, sfinfo.channels) ;
|
||||
|
||||
printf ("Output Frames : %ld\n\n", (long) count) ;
|
||||
|
||||
sf_close (infile) ;
|
||||
sf_close (outfile) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static TIMEWARP_FACTOR warp [] =
|
||||
{ { 0 , 1.00000001 },
|
||||
{ 20000 , 1.01000000 },
|
||||
{ 20200 , 1.00000001 },
|
||||
{ 40000 , 1.20000000 },
|
||||
{ 40300 , 1.00000001 },
|
||||
{ 60000 , 1.10000000 },
|
||||
{ 60400 , 1.00000001 },
|
||||
{ 80000 , 1.50000000 },
|
||||
{ 81000 , 1.00000001 },
|
||||
} ;
|
||||
|
||||
static sf_count_t
|
||||
timewarp_convert (SNDFILE *infile, SNDFILE *outfile, int converter, int channels)
|
||||
{ static float input [BUFFER_LEN] ;
|
||||
static float output [BUFFER_LEN] ;
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
SRC_DATA src_data ;
|
||||
int error, warp_index = 0 ;
|
||||
sf_count_t input_count = 0, output_count = 0 ;
|
||||
|
||||
sf_seek (infile, 0, SEEK_SET) ;
|
||||
sf_seek (outfile, 0, SEEK_SET) ;
|
||||
|
||||
/* Initialize the sample rate converter. */
|
||||
if ((src_state = src_new (converter, channels, &error)) == NULL)
|
||||
{ printf ("\n\nError : src_new() failed : %s.\n\n", src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_data.end_of_input = 0 ; /* Set this later. */
|
||||
|
||||
/* Start with zero to force load in while loop. */
|
||||
src_data.input_frames = 0 ;
|
||||
src_data.data_in = input ;
|
||||
|
||||
if (warp [0].index > 0)
|
||||
src_data.src_ratio = 1.0 ;
|
||||
else
|
||||
{ src_data.src_ratio = warp [0].ratio ;
|
||||
warp_index ++ ;
|
||||
} ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = BUFFER_LEN /channels ;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (warp_index < ARRAY_LEN (warp) - 1 && input_count >= warp [warp_index].index)
|
||||
{ src_data.src_ratio = warp [warp_index].ratio ;
|
||||
warp_index ++ ;
|
||||
} ;
|
||||
|
||||
/* If the input buffer is empty, refill it. */
|
||||
if (src_data.input_frames == 0)
|
||||
{ src_data.input_frames = sf_readf_float (infile, input, INPUT_STEP_SIZE) ;
|
||||
input_count += src_data.input_frames ;
|
||||
src_data.data_in = input ;
|
||||
|
||||
/* The last read will not be a full buffer, so snd_of_input. */
|
||||
if (src_data.input_frames < INPUT_STEP_SIZE)
|
||||
src_data.end_of_input = SF_TRUE ;
|
||||
} ;
|
||||
|
||||
/* Process current block. */
|
||||
if ((error = src_process (src_state, &src_data)))
|
||||
{ printf ("\nError : %s\n", src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Terminate if done. */
|
||||
if (src_data.end_of_input && src_data.output_frames_gen == 0)
|
||||
break ;
|
||||
|
||||
/* Write output. */
|
||||
sf_writef_float (outfile, output, src_data.output_frames_gen) ;
|
||||
output_count += src_data.output_frames_gen ;
|
||||
|
||||
src_data.data_in += src_data.input_frames_used * channels ;
|
||||
src_data.input_frames -= src_data.input_frames_used ;
|
||||
} ;
|
||||
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
return output_count ;
|
||||
} /* timewarp_convert */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void
|
||||
usage_exit (const char *progname)
|
||||
{ const char *cptr ;
|
||||
|
||||
if ((cptr = strrchr (progname, '/')) != NULL)
|
||||
progname = cptr + 1 ;
|
||||
|
||||
if ((cptr = strrchr (progname, '\\')) != NULL)
|
||||
progname = cptr + 1 ;
|
||||
|
||||
printf ("\n"
|
||||
" A program demonstrating the time warping capabilities of libsamplerate."
|
||||
" It uses libsndfile for file I/O and Secret Rabbit Code (aka libsamplerate)"
|
||||
" for performing the warping.\n"
|
||||
" It works on any file format supported by libsndfile with any \n"
|
||||
" number of channels (limited only by host memory).\n"
|
||||
"\n"
|
||||
" The warping is dependant on a table hard code into the source code.\n"
|
||||
"\n"
|
||||
" libsamplerate version : %s\n"
|
||||
"\n"
|
||||
" Usage : \n"
|
||||
" %s <input file> <output file>\n"
|
||||
"\n", src_get_version (), progname) ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
exit (1) ;
|
||||
} /* usage_exit */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
#else /* (HAVE_SNFILE == 0) */
|
||||
|
||||
/* Alternative main function when libsndfile is not available. */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ puts (
|
||||
"\n"
|
||||
"****************************************************************\n"
|
||||
" This example program was compiled without libsndfile \n"
|
||||
" (http://www.mega-nerd.com/libsndfile/).\n"
|
||||
" It is therefore completely broken and non-functional.\n"
|
||||
"****************************************************************\n"
|
||||
"\n"
|
||||
) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
#endif
|
||||
|
||||
282
lib-src/libsamplerate/examples/varispeed-play.c
Normal file
282
lib-src/libsamplerate/examples/varispeed-play.c
Normal file
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
** Copyright (C) 2002-2008 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 <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <float_cast.h>
|
||||
|
||||
#if (HAVE_SNDFILE)
|
||||
|
||||
#include <samplerate.h>
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "audio_out.h"
|
||||
|
||||
#define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
|
||||
|
||||
#define BUFFER_LEN 4096
|
||||
#define INPUT_FRAMES 100
|
||||
|
||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
#define MAGIC_NUMBER ((int) ('S' << 16) + ('R' << 8) + ('C'))
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846264338
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct
|
||||
{ int magic ;
|
||||
|
||||
SNDFILE *sndfile ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
SRC_DATA src_data ;
|
||||
|
||||
int freq_point ;
|
||||
int buffer_out_start, buffer_out_end ;
|
||||
|
||||
float buffer_in [BUFFER_LEN] ;
|
||||
float buffer_out [BUFFER_LEN] ;
|
||||
} CALLBACK_DATA ;
|
||||
|
||||
static int varispeed_get_data (CALLBACK_DATA *data, float *samples, int frames) ;
|
||||
static void varispeed_play (const char *filename, int converter) ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ const char *cptr, *progname, *filename ;
|
||||
int k, converter ;
|
||||
|
||||
converter = SRC_SINC_FASTEST ;
|
||||
|
||||
progname = argv [0] ;
|
||||
|
||||
if ((cptr = strrchr (progname, '/')) != NULL)
|
||||
progname = cptr + 1 ;
|
||||
|
||||
if ((cptr = strrchr (progname, '\\')) != NULL)
|
||||
progname = cptr + 1 ;
|
||||
|
||||
printf ("\n"
|
||||
" %s\n"
|
||||
"\n"
|
||||
" This is a demo program which plays the given file at a slowly \n"
|
||||
" varying speed. Lots of fun with drum loops and full mixes.\n"
|
||||
"\n"
|
||||
" It uses Secret Rabbit Code (aka libsamplerate) to perform the \n"
|
||||
" vari-speeding and libsndfile for file I/O.\n"
|
||||
"\n", progname) ;
|
||||
|
||||
if (argc == 2)
|
||||
filename = argv [1] ;
|
||||
else if (argc == 4 && strcmp (argv [1], "-c") == 0)
|
||||
{ filename = argv [3] ;
|
||||
converter = atoi (argv [2]) ;
|
||||
}
|
||||
else
|
||||
{ printf (" Usage :\n\n %s [-c <number>] <input file>\n\n", progname) ;
|
||||
puts (
|
||||
" The optional -c argument allows the converter type to be chosen from\n"
|
||||
" the following list :"
|
||||
"\n"
|
||||
) ;
|
||||
|
||||
for (k = 0 ; (cptr = src_get_name (k)) != NULL ; k++)
|
||||
printf (" %d : %s\n", k, cptr) ;
|
||||
|
||||
puts ("") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
varispeed_play (filename, converter) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
varispeed_play (const char *filename, int converter)
|
||||
{ CALLBACK_DATA *data ;
|
||||
AUDIO_OUT *audio_out ;
|
||||
int error ;
|
||||
|
||||
/* Allocate memory for the callback data. */
|
||||
if ((data = calloc (1, sizeof (CALLBACK_DATA))) == NULL)
|
||||
{ printf ("\n\n%s:%d Calloc failed!\n", __FILE__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
data->magic = MAGIC_NUMBER ;
|
||||
|
||||
if ((data->sndfile = sf_open (filename, SFM_READ, &data->sfinfo)) == NULL)
|
||||
{ puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Initialize the sample rate converter. */
|
||||
if ((data->src_state = src_new (converter, data->sfinfo.channels, &error)) == NULL)
|
||||
{ printf ("\n\nError : src_new() failed : %s.\n\n", src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
printf (
|
||||
|
||||
" Playing : %s\n"
|
||||
" Converter : %s\n"
|
||||
"\n"
|
||||
" Press <control-c> to exit.\n"
|
||||
"\n",
|
||||
filename, src_get_name (converter)) ;
|
||||
|
||||
if ((audio_out = audio_open (data->sfinfo.channels, data->sfinfo.samplerate)) == NULL)
|
||||
{ printf ("\n\nError : audio_open () failed.\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Set up sample rate converter info. */
|
||||
data->src_data.end_of_input = 0 ; /* Set this later. */
|
||||
|
||||
/* Start with zero to force load in while loop. */
|
||||
data->src_data.input_frames = 0 ;
|
||||
data->src_data.data_in = data->buffer_in ;
|
||||
|
||||
/* Start with output frames also zero. */
|
||||
data->src_data.output_frames_gen = 0 ;
|
||||
|
||||
data->buffer_out_start = data->buffer_out_end = 0 ;
|
||||
data->src_data.src_ratio = 1.0 ;
|
||||
|
||||
/* Pass the data and the callbacl function to audio_play */
|
||||
audio_play ((get_audio_callback_t) varispeed_get_data, audio_out, data) ;
|
||||
|
||||
/* Cleanup */
|
||||
audio_close (audio_out) ;
|
||||
sf_close (data->sndfile) ;
|
||||
src_delete (data->src_state) ;
|
||||
|
||||
free (data) ;
|
||||
|
||||
} /* varispeed_play */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static int
|
||||
varispeed_get_data (CALLBACK_DATA *data, float *samples, int frames)
|
||||
{ int error, readframes, frame_count, direct_out ;
|
||||
|
||||
if (data->magic != MAGIC_NUMBER)
|
||||
{ printf ("\n\n%s:%d Eeeek, something really bad happened!\n", __FILE__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
frame_count = 0 ;
|
||||
|
||||
if (data->buffer_out_start < data->buffer_out_end)
|
||||
{ frame_count = MIN (data->buffer_out_end - data->buffer_out_start, frames) ;
|
||||
memcpy (samples, data->buffer_out + data->sfinfo.channels * data->buffer_out_start, data->sfinfo.channels * frame_count * sizeof (float)) ;
|
||||
data->buffer_out_start += frame_count ;
|
||||
} ;
|
||||
|
||||
data->buffer_out_start = data->buffer_out_end = 0 ;
|
||||
|
||||
while (frame_count < frames)
|
||||
{
|
||||
/* Read INPUT_FRAMES frames worth looping at end of file. */
|
||||
for (readframes = 0 ; readframes < INPUT_FRAMES ; )
|
||||
{ sf_count_t position ;
|
||||
|
||||
readframes += sf_readf_float (data->sndfile, data->buffer_in + data->sfinfo.channels * readframes, INPUT_FRAMES - readframes) ;
|
||||
|
||||
position = sf_seek (data->sndfile, 0, SEEK_CUR) ;
|
||||
|
||||
if (position < 0 || position == data->sfinfo.frames)
|
||||
sf_seek (data->sndfile, 0, SEEK_SET) ;
|
||||
} ;
|
||||
|
||||
data->src_data.input_frames = readframes ;
|
||||
|
||||
data->src_data.src_ratio = 1.0 - 0.5 * sin (data->freq_point * 2 * M_PI / 20000) ;
|
||||
data->freq_point ++ ;
|
||||
|
||||
direct_out = (data->src_data.src_ratio * readframes < frames - frame_count) ? 1 : 0 ;
|
||||
|
||||
if (direct_out)
|
||||
{ data->src_data.data_out = samples + frame_count * data->sfinfo.channels ;
|
||||
data->src_data.output_frames = frames - frame_count ;
|
||||
}
|
||||
else
|
||||
{ data->src_data.data_out = data->buffer_out ;
|
||||
data->src_data.output_frames = BUFFER_LEN / data->sfinfo.channels ;
|
||||
} ;
|
||||
|
||||
if ((error = src_process (data->src_state, &data->src_data)))
|
||||
{ printf ("\nError : %s\n\n", src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (direct_out)
|
||||
{ frame_count += data->src_data.output_frames_gen ;
|
||||
continue ;
|
||||
} ;
|
||||
|
||||
memcpy (samples + frame_count * data->sfinfo.channels, data->buffer_out, (frames - frame_count) * data->sfinfo.channels * sizeof (float)) ;
|
||||
|
||||
data->buffer_out_start = frames - frame_count ;
|
||||
data->buffer_out_end = data->src_data.output_frames_gen ;
|
||||
|
||||
frame_count += frames - frame_count ;
|
||||
} ;
|
||||
|
||||
return frame_count ;
|
||||
} /* varispeed_get_data */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
#else /* (HAVE_SNFILE == 0) */
|
||||
|
||||
/* Alternative main function when libsndfile is not available. */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ puts (
|
||||
"\n"
|
||||
"****************************************************************\n"
|
||||
" This example program was compiled without libsndfile \n"
|
||||
" (http://www.zip.com.au/~erikd/libsndfile/).\n"
|
||||
" It is therefore completely broken and non-functional.\n"
|
||||
"****************************************************************\n"
|
||||
"\n"
|
||||
) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user