diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile.am | 23 | ||||
-rw-r--r-- | examples/Makefile.in | 385 | ||||
-rw-r--r-- | examples/adddcoffset.c | 99 | ||||
-rw-r--r-- | examples/irixread.c | 123 | ||||
-rw-r--r-- | examples/irixtestloop.c | 150 | ||||
-rw-r--r-- | examples/linuxtest.c | 170 | ||||
-rw-r--r-- | examples/osxplay.c | 257 | ||||
-rw-r--r-- | examples/power.c | 220 | ||||
-rw-r--r-- | examples/sgi.c | 109 | ||||
-rw-r--r-- | examples/sgi.h | 53 |
10 files changed, 1589 insertions, 0 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am new file mode 100644 index 0000000..00634ad --- /dev/null +++ b/examples/Makefile.am @@ -0,0 +1,23 @@ +INCLUDES = -I$(top_srcdir)/libaudiofile + +noinst_PROGRAMS = \ + adddcoffset \ + power \ + @TEST_BIN@ + +EXTRA_PROGRAMS = irixread irixtestloop linuxtest osxplay + +irixread_SOURCES = irixread.c sgi.c sgi.h +irixread_LDADD = $(top_builddir)/libaudiofile/libaudiofile.la @AUDIO_LIB@ + +irixtestloop_SOURCES = irixtestloop.c sgi.c sgi.h +irixtestloop_LDADD = $(top_builddir)/libaudiofile/libaudiofile.la @AUDIO_LIB@ + +linuxtest_SOURCES = linuxtest.c + +osxplay_SOURCES = osxplay.c +osxplay_LDFLAGS = -framework AudioUnit -framework CoreServices + +LDADD = $(top_builddir)/libaudiofile/libaudiofile.la + +DEPENDENCIES = $(top_builddir)/libaudiofile/libaudiofile.la diff --git a/examples/Makefile.in b/examples/Makefile.in new file mode 100644 index 0000000..a34583d --- /dev/null +++ b/examples/Makefile.in @@ -0,0 +1,385 @@ +# Makefile.in generated automatically by automake 1.5 from Makefile.am. + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +# 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@ + +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_HEADER = $(INSTALL_DATA) +transform = @program_transform_name@ +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ +AMTAR = @AMTAR@ +AS = @AS@ +AUDIOFILE_MAJOR_VERSION = @AUDIOFILE_MAJOR_VERSION@ +AUDIOFILE_MICRO_VERSION = @AUDIOFILE_MICRO_VERSION@ +AUDIOFILE_MINOR_VERSION = @AUDIOFILE_MINOR_VERSION@ +AUDIOFILE_VERSION = @AUDIOFILE_VERSION@ +AUDIOFILE_VERSION_INFO = @AUDIOFILE_VERSION_INFO@ +AUDIO_LIB = @AUDIO_LIB@ +AWK = @AWK@ +CC = @CC@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +EXEEXT = @EXEEXT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +STRIP = @STRIP@ +TEST_BIN = @TEST_BIN@ +VERSION = @VERSION@ +am__include = @am__include@ +am__quote = @am__quote@ +install_sh = @install_sh@ + +INCLUDES = -I$(top_srcdir)/libaudiofile + +noinst_PROGRAMS = \ + adddcoffset \ + power \ + @TEST_BIN@ + + +EXTRA_PROGRAMS = irixread irixtestloop linuxtest osxplay + +irixread_SOURCES = irixread.c sgi.c sgi.h +irixread_LDADD = $(top_builddir)/libaudiofile/libaudiofile.la @AUDIO_LIB@ + +irixtestloop_SOURCES = irixtestloop.c sgi.c sgi.h +irixtestloop_LDADD = $(top_builddir)/libaudiofile/libaudiofile.la @AUDIO_LIB@ + +linuxtest_SOURCES = linuxtest.c + +osxplay_SOURCES = osxplay.c +osxplay_LDFLAGS = -framework AudioUnit -framework CoreServices + +LDADD = $(top_builddir)/libaudiofile/libaudiofile.la + +DEPENDENCIES = $(top_builddir)/libaudiofile/libaudiofile.la +subdir = examples +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +EXTRA_PROGRAMS = irixread$(EXEEXT) irixtestloop$(EXEEXT) \ + linuxtest$(EXEEXT) osxplay$(EXEEXT) +noinst_PROGRAMS = adddcoffset$(EXEEXT) power$(EXEEXT) @TEST_BIN@ +PROGRAMS = $(noinst_PROGRAMS) + +adddcoffset_SOURCES = adddcoffset.c +adddcoffset_OBJECTS = adddcoffset.$(OBJEXT) +adddcoffset_LDADD = $(LDADD) +adddcoffset_DEPENDENCIES = $(top_builddir)/libaudiofile/libaudiofile.la +adddcoffset_LDFLAGS = +am_irixread_OBJECTS = irixread.$(OBJEXT) sgi.$(OBJEXT) +irixread_OBJECTS = $(am_irixread_OBJECTS) +irixread_DEPENDENCIES = $(top_builddir)/libaudiofile/libaudiofile.la +irixread_LDFLAGS = +am_irixtestloop_OBJECTS = irixtestloop.$(OBJEXT) sgi.$(OBJEXT) +irixtestloop_OBJECTS = $(am_irixtestloop_OBJECTS) +irixtestloop_DEPENDENCIES = $(top_builddir)/libaudiofile/libaudiofile.la +irixtestloop_LDFLAGS = +am_linuxtest_OBJECTS = linuxtest.$(OBJEXT) +linuxtest_OBJECTS = $(am_linuxtest_OBJECTS) +linuxtest_LDADD = $(LDADD) +linuxtest_DEPENDENCIES = $(top_builddir)/libaudiofile/libaudiofile.la +linuxtest_LDFLAGS = +am_osxplay_OBJECTS = osxplay.$(OBJEXT) +osxplay_OBJECTS = $(am_osxplay_OBJECTS) +osxplay_LDADD = $(LDADD) +osxplay_DEPENDENCIES = $(top_builddir)/libaudiofile/libaudiofile.la +power_SOURCES = power.c +power_OBJECTS = power.$(OBJEXT) +power_LDADD = $(LDADD) +power_DEPENDENCIES = $(top_builddir)/libaudiofile/libaudiofile.la +power_LDFLAGS = + +DEFS = @DEFS@ +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +depcomp = $(SHELL) $(top_srcdir)/depcomp +@AMDEP_TRUE@DEP_FILES = $(DEPDIR)/adddcoffset.Po $(DEPDIR)/irixread.Po \ +@AMDEP_TRUE@ $(DEPDIR)/irixtestloop.Po $(DEPDIR)/linuxtest.Po \ +@AMDEP_TRUE@ $(DEPDIR)/osxplay.Po $(DEPDIR)/power.Po \ +@AMDEP_TRUE@ $(DEPDIR)/sgi.Po +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \ + $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +CFLAGS = @CFLAGS@ +DIST_SOURCES = adddcoffset.c $(irixread_SOURCES) $(irixtestloop_SOURCES) \ + $(linuxtest_SOURCES) $(osxplay_SOURCES) power.c +DIST_COMMON = Makefile.am Makefile.in +SOURCES = adddcoffset.c $(irixread_SOURCES) $(irixtestloop_SOURCES) $(linuxtest_SOURCES) $(osxplay_SOURCES) power.c + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu examples/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && \ + CONFIG_HEADERS= CONFIG_LINKS= \ + CONFIG_FILES=$(subdir)/$@ $(SHELL) ./config.status + +clean-noinstPROGRAMS: + -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) +adddcoffset$(EXEEXT): $(adddcoffset_OBJECTS) $(adddcoffset_DEPENDENCIES) + @rm -f adddcoffset$(EXEEXT) + $(LINK) $(adddcoffset_LDFLAGS) $(adddcoffset_OBJECTS) $(adddcoffset_LDADD) $(LIBS) +irixread$(EXEEXT): $(irixread_OBJECTS) $(irixread_DEPENDENCIES) + @rm -f irixread$(EXEEXT) + $(LINK) $(irixread_LDFLAGS) $(irixread_OBJECTS) $(irixread_LDADD) $(LIBS) +irixtestloop$(EXEEXT): $(irixtestloop_OBJECTS) $(irixtestloop_DEPENDENCIES) + @rm -f irixtestloop$(EXEEXT) + $(LINK) $(irixtestloop_LDFLAGS) $(irixtestloop_OBJECTS) $(irixtestloop_LDADD) $(LIBS) +linuxtest$(EXEEXT): $(linuxtest_OBJECTS) $(linuxtest_DEPENDENCIES) + @rm -f linuxtest$(EXEEXT) + $(LINK) $(linuxtest_LDFLAGS) $(linuxtest_OBJECTS) $(linuxtest_LDADD) $(LIBS) +osxplay$(EXEEXT): $(osxplay_OBJECTS) $(osxplay_DEPENDENCIES) + @rm -f osxplay$(EXEEXT) + $(LINK) $(osxplay_LDFLAGS) $(osxplay_OBJECTS) $(osxplay_LDADD) $(LIBS) +power$(EXEEXT): $(power_OBJECTS) $(power_DEPENDENCIES) + @rm -f power$(EXEEXT) + $(LINK) $(power_LDFLAGS) $(power_OBJECTS) $(power_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) core *.core + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/adddcoffset.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/irixread.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/irixtestloop.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/linuxtest.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/osxplay.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/power.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/sgi.Po@am__quote@ + +distclean-depend: + -rm -rf $(DEPDIR) + +.c.o: +@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + $(COMPILE) -c `test -f $< || echo '$(srcdir)/'`$< + +.c.obj: +@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + $(COMPILE) -c `cygpath -w $<` + +.c.lo: +@AMDEP_TRUE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + $(LTCOMPILE) -c -o $@ `test -f $< || echo '$(srcdir)/'`$< +CCDEPMODE = @CCDEPMODE@ +uninstall-info-am: + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(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 $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(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 "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || etags $(ETAGS_ARGS) $$tags $$unique $(LISP) + +GTAGS: + here=`CDPATH=: && cd $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH + +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + +top_distdir = .. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + @for file in $(DISTFILES); do \ + if test -f $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + $(mkinstalldirs) "$(distdir)/$$dir"; \ + fi; \ + if test -d $$d/$$file; then \ + cp -pR $$d/$$file $(distdir) \ + || 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: + +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)" \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) stamp-h stamp-h[0-9]* + +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-generic clean-libtool clean-noinstPROGRAMS \ + mostlyclean-am + +distclean: distclean-am + +distclean-am: clean-am distclean-compile distclean-depend \ + distclean-generic distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +uninstall-am: uninstall-info-am + +.PHONY: GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstPROGRAMS distclean distclean-compile \ + distclean-depend distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am info info-am install \ + install-am 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 \ + tags uninstall uninstall-am 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: diff --git a/examples/adddcoffset.c b/examples/adddcoffset.c new file mode 100644 index 0000000..cadc6cb --- /dev/null +++ b/examples/adddcoffset.c @@ -0,0 +1,99 @@ +/* + Audio File Library + + Copyright 1998, Michael Pruett <michael@68k.org> + + 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. +*/ + +/* + adddcoffset.c + + This program adds a user-specified DC offset term to a sound file. + It's not very useful. +*/ + +#include <stdio.h> +#include <stdlib.h> + +#ifdef __USE_SGI_HEADERS__ +#include <dmedia/audiofile.h> +#else +#include "audiofile.h" +#endif + +void adddcoffset (float offset, char *infilename, char *outfilename); +void usageerror (void); + +int main (int ac, char **av) +{ + float offset; + + if (ac != 4) + usageerror(); + + offset = atof(av[1]); + adddcoffset(offset, av[2], av[3]); + return 0; +} + +void adddcoffset (float offset, char *infilename, char *outfilename) +{ + AFfilehandle infile = afOpenFile(infilename, "r", NULL); + int channelCount, frameCount; + short *buffer; + int i; + + AFfilesetup outfilesetup = afNewFileSetup(); + AFfilehandle outfile; + + frameCount = afGetFrameCount(infile, AF_DEFAULT_TRACK); + channelCount = afGetChannels(infile, AF_DEFAULT_TRACK); + + afInitFileFormat(outfilesetup, AF_FILE_AIFF); + afInitByteOrder(outfilesetup, AF_DEFAULT_TRACK, AF_BYTEORDER_BIGENDIAN); + afInitChannels(outfilesetup, AF_DEFAULT_TRACK, channelCount); + afInitRate(outfilesetup, AF_DEFAULT_TRACK, 44100.0); + afInitSampleFormat(outfilesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); + + outfile = afOpenFile(outfilename, "w", outfilesetup); + + if (infile == NULL) + { + printf("unable to open input file '%s'.\n", infilename); + return; + } + + printf("afGetFrameCount: %d\n", (int)afGetFrameCount(infile, AF_DEFAULT_TRACK)); + printf("afGetChannels: %d\n", afGetChannels(infile, AF_DEFAULT_TRACK)); + + buffer = (short *) malloc(frameCount * channelCount * sizeof (short)); + afReadFrames(infile, AF_DEFAULT_TRACK, (void *) buffer, frameCount); + + for (i=0; i<frameCount; i++) + { + buffer[i] += offset; + } + + afWriteFrames(outfile, AF_DEFAULT_TRACK, (void *) buffer, frameCount); + afCloseFile(outfile); +} + +void usageerror (void) +{ + fprintf(stderr, "usage: adddcoffset offset infile outfile\n"); + exit(EXIT_FAILURE); +} diff --git a/examples/irixread.c b/examples/irixread.c new file mode 100644 index 0000000..567949c --- /dev/null +++ b/examples/irixread.c @@ -0,0 +1,123 @@ +/* + Audio File Library + + Copyright (C) 1998-1999, Michael Pruett <michael@68k.org> + Copyright (C) 2001, Silicon Graphics, Inc. + + 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. +*/ + +/* + irixread.c + + This program reads and plays a given audio file using Irix's + default audio output device. This file will not work on any + operating system other than Irix. + + The only difference between this program and irixtest is that this + program does not load the entire audio track into memory at once. + Only a small number of frames are read into a buffer and then + written to the audio port. While there are more frames to be + read, this process is repeated. +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <dmedia/audio.h> +#include <dmedia/audiofile.h> + +#include "sgi.h" + +const int BUFFERED_FRAME_COUNT = 65536; + +void usage (void) +{ + fprintf(stderr, "usage: irixread filename\n"); + exit(EXIT_FAILURE); +} + +main (int argc, char **argv) +{ + AFfilehandle file; + AFframecount count, frameCount; + int channelCount, sampleFormat, sampleWidth; + float frameSize; + void *buffer; + double sampleRate; + + ALport outport; + ALconfig outportconfig; + + if (argc < 2) + usage(); + + file = afOpenFile(argv[1], "r", NULL); + if (file == AF_NULL_FILEHANDLE) + { + fprintf(stderr, "Could not open file %s.\n", argv[1]); + exit(EXIT_FAILURE); + } + + frameCount = afGetFrameCount(file, AF_DEFAULT_TRACK); + frameSize = afGetVirtualFrameSize(file, AF_DEFAULT_TRACK, 1); + channelCount = afGetVirtualChannels(file, AF_DEFAULT_TRACK); + sampleRate = afGetRate(file, AF_DEFAULT_TRACK); + afGetVirtualSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, + &sampleWidth); + + if (sampleFormat == AF_SAMPFMT_UNSIGNED) + { + afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, + AF_SAMPFMT_TWOSCOMP, sampleWidth); + } + + printf("frame count: %lld\n", frameCount); + printf("frame size: %d bytes\n", (int) frameSize); + printf("channel count: %d\n", channelCount); + printf("sample rate: %.2f Hz\n", sampleRate); + buffer = malloc(BUFFERED_FRAME_COUNT * frameSize); + + outportconfig = alNewConfig(); + setwidth(outportconfig, sampleWidth); + setsampleformat(outportconfig, sampleFormat); + alSetChannels(outportconfig, channelCount); + + count = afReadFrames(file, AF_DEFAULT_TRACK, buffer, BUFFERED_FRAME_COUNT); + + outport = alOpenPort("irixread", "w", outportconfig); + setrate(outport, sampleRate); + + do + { + printf("count = %lld\n", count); + alWriteFrames(outport, buffer, count); + + count = afReadFrames(file, AF_DEFAULT_TRACK, buffer, + BUFFERED_FRAME_COUNT); + } while (count > 0); + + waitport(outport); + + alClosePort(outport); + alFreeConfig(outportconfig); + + afCloseFile(file); +} diff --git a/examples/irixtestloop.c b/examples/irixtestloop.c new file mode 100644 index 0000000..514a4f5 --- /dev/null +++ b/examples/irixtestloop.c @@ -0,0 +1,150 @@ +/* + Audio File Library + + Copyright (C) 1998-1999, Michael Pruett <michael@68k.org> + Copyright (C) 2001, Silicon Graphics, Inc. + + 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. +*/ + +/* + irixtestloop.c + + This file reads the loop points from a file (presumably AIFF) and + loops that part of the file several times. Audio output is routed + to IRIX's default audio output device. This program will not + compile on any platform other than IRIX. +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <dmedia/audio.h> +#include <dmedia/audiofile.h> + +#include "sgi.h" + +const int REPEAT_COUNT = 3; + +void usage (void) +{ + printf("usage: irixtestloop file\n"); + printf("where file is of a format which contains a loop (e.g. AIFF)\n"); + exit(EXIT_FAILURE); +} + +main (int argc, char **argv) +{ + AFfilehandle file; + void *buffer; + + AFframecount frameCount; + int sampleFormat, sampleWidth, channelCount; + float frameSize; + double sampleRate; + + int *loopids, *markids; + int i, loopCount, markCount; + int startmarkid, endmarkid; + AFframecount startloop, endloop; + + ALport outport; + ALconfig outportconfig; + + if (argc < 2) + usage(); + + file = afOpenFile(argv[1], "r", NULL); + frameCount = afGetFrameCount(file, AF_DEFAULT_TRACK); + frameSize = afGetVirtualFrameSize(file, AF_DEFAULT_TRACK, 1); + channelCount = afGetVirtualChannels(file, AF_DEFAULT_TRACK); + afGetVirtualSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); + sampleRate = afGetRate(file, AF_DEFAULT_TRACK); + + /* + If the file's sample format is unsigned integer data, + change the virtual sample format to two's complement + since the SGI Audio Library won't accept unsigned + data. + */ + if (sampleFormat == AF_SAMPFMT_UNSIGNED) + { + afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, + AF_SAMPFMT_TWOSCOMP, sampleWidth); + } + + printf("frame count: %lld\n", frameCount); + printf("frame size: %d bytes\n", frameSize); + printf("channel count: %d\n", channelCount); + printf("sample rate: %.2f Hz\n", sampleRate); + + buffer = malloc(frameCount * frameSize); + afReadFrames(file, AF_DEFAULT_TRACK, buffer, frameCount); + + loopCount = afGetLoopIDs(file, AF_DEFAULT_INST, NULL); + loopids = malloc(sizeof (int) * loopCount); + afGetLoopIDs(file, AF_DEFAULT_INST, loopids); + + markCount = afGetMarkIDs(file, AF_DEFAULT_TRACK, NULL); + markids = malloc(sizeof (int) * markCount); + afGetMarkIDs(file, AF_DEFAULT_TRACK, markids); + + printf("loop ids:"); + for (i=0; i<loopCount; i++) + printf(" %d", loopids[i]); + printf("\n"); + + printf("mark ids:"); + for (i=0; i<markCount; i++) + printf(" %d", markids[i]); + printf("\n"); + + startmarkid = afGetLoopStart(file, AF_DEFAULT_INST, 1); + endmarkid = afGetLoopEnd(file, AF_DEFAULT_INST, 1); + startloop = afGetMarkPosition(file, AF_DEFAULT_TRACK, startmarkid); + endloop = afGetMarkPosition(file, AF_DEFAULT_TRACK, endmarkid); + + afCloseFile(file); + + outportconfig = alNewConfig(); + setwidth(outportconfig, sampleWidth); + setsampleformat(outportconfig, sampleFormat); + alSetChannels(outportconfig, channelCount); + + outport = alOpenPort("irixtestloop", "w", outportconfig); + setrate(outport, sampleRate); + + alWriteFrames(outport, buffer, startloop); + for (i=0; i<REPEAT_COUNT; i++) + { + printf("iteration %d: start %lld, end %lld, length %lld\n", + i, endloop, startloop, endloop - startloop); + alWriteFrames(outport, + (char *) buffer + (int) (startloop * frameSize), + endloop - startloop); + } + + waitport(outport); + + alClosePort(outport); + alFreeConfig(outportconfig); + + free(buffer); +} diff --git a/examples/linuxtest.c b/examples/linuxtest.c new file mode 100644 index 0000000..710083d --- /dev/null +++ b/examples/linuxtest.c @@ -0,0 +1,170 @@ +/* + Audio File Library + + Copyright (c) 1998-1999, Michael Pruett <michael@68k.org> + Copyright (c) 2001, Silicon Graphics, Inc. + + 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. +*/ + +/* + linuxtest.c + + This file plays a 16-bit, 44.1 kHz monophonic or stereophonic + audio file through a PC sound card on a Linux system. This file + will not compile under any operating system that does not support + the Open Sound System API. +*/ + +#include <stdio.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <linux/soundcard.h> + +#include <audiofile.h> + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +/* + If it's not defined already, define the native audio hardware + byte order. +*/ + +#ifndef AFMT_S16_NE +#ifdef WORDS_BIGENDIAN /* defined in config.h */ +#define AFMT_S16_NE AFMT_S16_BE +#else +#define AFMT_S16_NE AFMT_S16_LE +#endif /* WORDS_BIGENDIAN */ +#endif /* AFMT_S16_NE */ + +void setupdsp (int audiofd, int channelCount); +void usage (void); + +/* BUFFER_FRAMES represents the size of the buffer in frames. */ +#define BUFFER_FRAMES 4096 + +int main (int argc, char **argv) +{ + AFfilehandle file; + AFframecount frameCount, framesRead; + int sampleFormat, sampleWidth, channelCount; + float frameSize; + void *buffer; + int audiofd; + + if (argc != 2) + usage(); + + file = afOpenFile(argv[1], "r", NULL); + frameCount = afGetFrameCount(file, AF_DEFAULT_TRACK); + printf("frame count: %d\n", (int) frameCount); + + channelCount = afGetVirtualChannels(file, AF_DEFAULT_TRACK); + afGetVirtualSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, + &sampleWidth); + + frameSize = afGetVirtualFrameSize(file, AF_DEFAULT_TRACK, 1); + + printf("sample format: %d, sample width: %d, channels: %d\n", + sampleFormat, sampleWidth, channelCount); + + if ((sampleFormat != AF_SAMPFMT_TWOSCOMP) && + (sampleFormat != AF_SAMPFMT_UNSIGNED)) + { + fprintf(stderr, "The audio file must contain integer data in two's complement or unsigned format.\n"); + exit(EXIT_FAILURE); + } + + if ((sampleWidth != 16) || (channelCount > 2)) + { + fprintf(stderr, "The audio file must be of a 16-bit monophonic or stereophonic format.\n"); + exit(EXIT_FAILURE); + } + + buffer = malloc(BUFFER_FRAMES * frameSize); + + audiofd = open("/dev/dsp", O_WRONLY); + if (audiofd < 0) + { + perror("open"); + exit(EXIT_FAILURE); + } + + setupdsp(audiofd, channelCount); + + framesRead = afReadFrames(file, AF_DEFAULT_TRACK, buffer, + BUFFER_FRAMES); + + while (framesRead > 0) + { + printf("read %ld frames\n", framesRead); + write(audiofd, buffer, framesRead * frameSize); + framesRead = afReadFrames(file, AF_DEFAULT_TRACK, buffer, + BUFFER_FRAMES); + } + + close(audiofd); + free(buffer); + + return 0; +} + +void setupdsp (int audiofd, int channelCount) +{ + int format, frequency, channels; + + format = AFMT_S16_NE; + if (ioctl(audiofd, SNDCTL_DSP_SETFMT, &format) == -1) + { + perror("set format"); + exit(EXIT_FAILURE); + } + + if (format != AFMT_S16_NE) + { + fprintf(stderr, "format not correct.\n"); + exit(EXIT_FAILURE); + } + + channels = channelCount; + if (ioctl(audiofd, SNDCTL_DSP_CHANNELS, &channels) == -1) + { + perror("set channels"); + exit(EXIT_FAILURE); + } + + frequency = 44100; + if (ioctl(audiofd, SNDCTL_DSP_SPEED, &frequency) == -1) + { + perror("set frequency"); + exit(EXIT_FAILURE); + } +} + +void usage (void) +{ + fprintf(stderr, "usage: linuxtest file\n"); + fprintf(stderr, + "where file refers to a 16-bit monophonic or stereophonic 44.1 kHz audio file\n"); + exit(EXIT_FAILURE); +} diff --git a/examples/osxplay.c b/examples/osxplay.c new file mode 100644 index 0000000..0708c68 --- /dev/null +++ b/examples/osxplay.c @@ -0,0 +1,257 @@ +/* + Audio File Library + + Copyright (c) 2003, Michael Pruett. All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, are permitted provided that the following + conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + 3. The name of the author may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* + osxplay.c + + This program demonstrates audio file playback using the Audio + File Library and Core Audio. +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <audiofile.h> + +#include <CoreServices/CoreServices.h> +#include <AudioUnit/AudioUnit.h> +#include <CoreAudio/CoreAudio.h> + +#define BUFFER_FRAME_COUNT 1024 + +int isPlaying = 1; +void *buffer = NULL; + +void getASBDForFile (AFfilehandle file, int track, + AudioStreamBasicDescription *asbd) +{ + int sampleFormat, sampleWidth, channelCount; + double rate; + + afGetVirtualSampleFormat(file, track, &sampleFormat, &sampleWidth); + channelCount = afGetChannels(file, track); + rate = afGetRate(file, track); + + asbd->mSampleRate = rate; + asbd->mFormatID = kAudioFormatLinearPCM; + switch (sampleFormat) + { + case AF_SAMPFMT_TWOSCOMP: + asbd->mFormatFlags = kAudioFormatFlagIsSignedInteger; + asbd->mBitsPerChannel = sampleWidth; + break; + case AF_SAMPFMT_UNSIGNED: + asbd->mFormatFlags = 0; + asbd->mBitsPerChannel = sampleWidth; + break; + case AF_SAMPFMT_FLOAT: + asbd->mFormatFlags = kAudioFormatFlagIsFloat; + asbd->mBitsPerChannel = 32; + break; + case AF_SAMPFMT_DOUBLE: + asbd->mFormatFlags = kAudioFormatFlagIsFloat; + asbd->mBitsPerChannel = 64; + break; + } + + asbd->mChannelsPerFrame = channelCount; + asbd->mFramesPerPacket = 1; + asbd->mBytesPerFrame = ceilf(afGetVirtualFrameSize(file, track, 1)); + asbd->mBytesPerPacket = asbd->mBytesPerFrame; + + if (afGetVirtualByteOrder(file, track) == AF_BYTEORDER_BIGENDIAN) + asbd->mFormatFlags |= kAudioFormatFlagIsBigEndian; +} + +OSStatus openOutput (AudioUnit *outputUnit) +{ + OSStatus status = noErr; + ComponentDescription description; + Component component; + + description.componentType = kAudioUnitType_Output; + description.componentSubType = kAudioUnitSubType_DefaultOutput; + description.componentManufacturer = kAudioUnitManufacturer_Apple; + description.componentFlags = 0; + description.componentFlagsMask = 0; + + component = FindNextComponent(NULL, &description); + if (component == NULL) + { + fprintf(stderr, "Could not find audio output device.\n"); + exit(EXIT_FAILURE); + } + + status = OpenAComponent(component, outputUnit); + if (status != noErr) + { + fprintf(stderr, "Could not open audio output device.\n"); + exit(EXIT_FAILURE); + } + + status = AudioUnitInitialize(*outputUnit); + if (status != noErr) + { + fprintf(stderr, "Could not initialize audio output device.\n"); + exit(EXIT_FAILURE); + } + + return status; +} + +OSStatus fileRenderProc (void *inRefCon, + AudioUnitRenderActionFlags *inActionFlags, + const AudioTimeStamp *inTimeStamp, + UInt32 inBusNumber, + UInt32 inNumFrames, + AudioBufferList *ioData) +{ + AFfilehandle file = (AFfilehandle) inRefCon; + AFframecount framesToRead, framesRead; + + framesToRead = inNumFrames; + if (framesToRead > BUFFER_FRAME_COUNT) + framesToRead = BUFFER_FRAME_COUNT; + + framesRead = afReadFrames(file, AF_DEFAULT_TRACK, + buffer, framesToRead); + if (framesRead > 0) + { + ioData->mBuffers[0].mData = buffer; + ioData->mBuffers[0].mDataByteSize = framesRead * + afGetVirtualFrameSize(file, AF_DEFAULT_TRACK, 1); + } + else + isPlaying = 0; + + return noErr; +} + +OSStatus setupOutput (AudioUnit *outputUnit, AFfilehandle file) +{ + OSStatus status = noErr; + UInt32 size; + Boolean outWritable; + + AudioStreamBasicDescription fileASBD, inputASBD, outputASBD; + AURenderCallbackStruct renderCallback; + + /* Set virtual sample format to single-precision floating-point. */ + afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, AF_SAMPFMT_FLOAT, 32); + + /* Get ASBD for virtual sample format. */ + getASBDForFile(file, AF_DEFAULT_TRACK, &fileASBD); + + status = AudioUnitGetPropertyInfo(*outputUnit, + kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, + 0, &size, &outWritable); + + status = AudioUnitGetProperty(*outputUnit, + kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, + 0, &outputASBD, &size); + + if (outWritable) + { + outputASBD = fileASBD; + + status = AudioUnitSetProperty(*outputUnit, + kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, + 0, &outputASBD, size); + } + + inputASBD = fileASBD; + + status = AudioUnitSetProperty(*outputUnit, + kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, + 0, &inputASBD, size); + if (status != noErr) + { + fprintf(stderr, "Could not set input stream format.\n"); + exit(EXIT_FAILURE); + } + + /* + Set the render callback to a procedure which will + read from the file. + */ + renderCallback.inputProc = fileRenderProc; + renderCallback.inputProcRefCon = file; + + status = AudioUnitSetProperty(*outputUnit, + kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, + &renderCallback, sizeof (AURenderCallbackStruct)); + if (status != noErr) + { + fprintf(stderr, "Could not set render callback.\n"); + exit(EXIT_FAILURE); + } + + return status; +} + +int main (int argc, char **argv) +{ + AFfilehandle file; + AudioUnit outputUnit; + + if (argc < 2) + { + fprintf(stderr, "usage: %s filename\n", argv[0]); + exit(EXIT_FAILURE); + } + + file = afOpenFile(argv[1], "r", AF_NULL_FILESETUP); + if (file == AF_NULL_FILEHANDLE) + { + fprintf(stderr, "Could not open file '%s' for reading.\n", argv[1]); + exit(EXIT_FAILURE); + } + + openOutput(&outputUnit); + setupOutput(&outputUnit, file); + AudioOutputUnitStart(outputUnit); + + buffer = malloc(BUFFER_FRAME_COUNT * + afGetVirtualFrameSize(file, AF_DEFAULT_TRACK, 1)); + + while (isPlaying) + usleep(250000); + + AudioOutputUnitStop(outputUnit); + AudioUnitUninitialize(outputUnit); + CloseComponent(outputUnit); + + free(buffer); + + afCloseFile(file); +} diff --git a/examples/power.c b/examples/power.c new file mode 100644 index 0000000..01bfe5d --- /dev/null +++ b/examples/power.c @@ -0,0 +1,220 @@ +/* + This program is derived from Chris Vaill's normalize program + and has been modified to use the Audio File Library for file + reading and audio data conversion. + + Copyright (C) 2001, Silicon Graphics, Inc. + Copyright (C) 1999-2001, Chris Vaill + + 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. +*/ + +/* + power.c + + Calculate the power and peak amplitudes of an audio file. +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <audiofile.h> + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +struct smooth +{ + double *buf; + int length, start, n; +}; + +static double get_smoothed_data (struct smooth *s) +{ + int i; + double smoothed; + + smoothed = 0; + for (i = 0; i < s->n; i++) + smoothed += s->buf[i]; + smoothed = smoothed / s->n; + + return smoothed; +} + +void print_power (char *filename); + +int main (int argc, char **argv) +{ + int i; + + if (argc < 2) + { + fprintf(stderr, "usage: %s filename [more filenames...]\n", + argv[0]); + exit(EXIT_FAILURE); + } + + for (i=1; i<argc; i++) + print_power(argv[i]); + + return 0; +} + +void print_power (char *filename) +{ + AFfilehandle file; + double *sums, *frames; + int channelCount, windowSize, frameCount; + int i, c; + struct smooth *powsmooth; + int winStart, winEnd; + int lastWindow = FALSE; + double pow, maxpow; + + double level, peak, minSample = 1, maxSample = -1; + + file = afOpenFile(filename, "r", NULL); + if (file == AF_NULL_FILEHANDLE) + { + fprintf(stderr, "Could not open file %s.\n", filename); + return; + } + + channelCount = afGetChannels(file, AF_DEFAULT_TRACK); + windowSize = afGetRate(file, AF_DEFAULT_TRACK) / 100; + frameCount = afGetFrameCount(file, AF_DEFAULT_TRACK); + + sums = calloc(channelCount, sizeof (double)); + for (c=0; c<channelCount; c++) + sums[c] = 0; + + frames = calloc(channelCount * windowSize, sizeof (double)); + + afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, AF_SAMPFMT_DOUBLE, + sizeof (double)); + + powsmooth = calloc(channelCount, sizeof (struct smooth)); + for (c=0; c<channelCount; c++) + { + /* Use a 100-element (1 second) window. */ + powsmooth[c].length = 100; + powsmooth[c].buf = calloc(powsmooth[c].length, sizeof (double)); + powsmooth[c].start = 0; + powsmooth[c].n = 0; + } + + winStart = 0; + winEnd = 0; + lastWindow = FALSE; + maxpow = 0; + + do + { + winEnd = winStart + windowSize; + + if (winEnd >= frameCount) + { + winEnd = frameCount; + lastWindow = TRUE; + } + + afReadFrames(file, AF_DEFAULT_TRACK, frames, windowSize); + + for (c=0; c<channelCount; c++) + { + sums[c] = 0; + + for (i=0; i < winEnd - winStart; i++) + { + double sample; + + sample = frames[i*channelCount + c]; + sums[c] += sample*sample; + + if (sample > maxSample) + maxSample = sample; + if (sample < minSample) + minSample = sample; + } + } + + /* Compute power for each channel. */ + for (c=0; c<channelCount; c++) + { + double pow; + int end; + + pow = sums[c] / (winEnd - winStart); + + end = (powsmooth[c].start + powsmooth[c].n) % + powsmooth[c].length; + powsmooth[c].buf[end] = pow; + + if (powsmooth[c].n == powsmooth[c].length) + { + powsmooth[c].start = (powsmooth[c].start + 1) % powsmooth[c].length; + pow = get_smoothed_data(&powsmooth[c]); + if (pow > maxpow) + maxpow = pow; + } + else + { + powsmooth[c].n++; + } + } + + winStart += windowSize; + } while (!lastWindow); + + for (c = 0; c < channelCount; c++) + { + pow = get_smoothed_data(&powsmooth[c]); + if (pow > maxpow) + maxpow = pow; + } + + free(sums); + free(frames); + for (c=0; c<channelCount; c++) + free(powsmooth[c].buf); + free(powsmooth); + + level = sqrt(maxpow); + + afCloseFile(file); + + printf("file: %s\n", filename); + + printf("level (dB): %f\n", 20 * log10(level)); + printf("peak-: %f\n", minSample); + printf("peak+: %f\n", maxSample); + + peak = abs(minSample); + if (peak < abs(maxSample)) + peak = abs(maxSample); + + printf("peak (dB): %f\n", 20 * log10(peak)); +} diff --git a/examples/sgi.c b/examples/sgi.c new file mode 100644 index 0000000..12346d2 --- /dev/null +++ b/examples/sgi.c @@ -0,0 +1,109 @@ +/* + Audio File Library + + Copyright 1998-1999, Michael Pruett <michael@68k.org> + + 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. +*/ + +/* + sgi.c + + These routines are used in SGI-specific test programs. +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <unistd.h> + +#include <audiofile.h> + +#include <dmedia/audio.h> + +/* + Set the sample width of an audio configuration. +*/ +void setwidth (ALconfig config, int sampleWidth) +{ + if (sampleWidth <= 8) + { + printf("setting width to 8\n"); + alSetWidth(config, AL_SAMPLE_8); + } + else if (sampleWidth <= 16) + { + printf("setting width to 16\n"); + alSetWidth(config, AL_SAMPLE_16); + } + else if (sampleWidth <= 24) + { + printf("setting width to 24\n"); + alSetWidth(config, AL_SAMPLE_24); + } +} + +/* + Set the sample format of an audio configuration. +*/ +void setsampleformat (ALconfig config, int audioFileSampleFormat) +{ + if (audioFileSampleFormat == AF_SAMPFMT_TWOSCOMP) + { + printf("setting sample format to 2's complement\n"); + alSetSampFmt(config, AL_SAMPFMT_TWOSCOMP); + } + else if (audioFileSampleFormat == AF_SAMPFMT_FLOAT) + { + printf("setting sample format to float\n"); + alSetSampFmt(config, AL_SAMPFMT_FLOAT); + } + else if (audioFileSampleFormat == AF_SAMPFMT_DOUBLE) + { + printf("setting sample format to double\n"); + alSetSampFmt(config, AL_SAMPFMT_DOUBLE); + } +} + +/* + Set the sample rate of an audio port. +*/ +void setrate (ALport port, double rate) +{ + int rv; + ALpv params; + + rv = alGetResource(port); + + params.param = AL_RATE; + params.value.ll = alDoubleToFixed(rate); + + if (alSetParams(rv, ¶ms, 1) < 0) + { + printf("alSetParams failed: %s\n", alGetErrorString(oserror())); + } +} + +/* + Wait until the audio port has no more samples to play. +*/ +void waitport (ALport port) +{ + while (alGetFilled(port) > 0) + sginap(1); +} diff --git a/examples/sgi.h b/examples/sgi.h new file mode 100644 index 0000000..ebb6e5b --- /dev/null +++ b/examples/sgi.h @@ -0,0 +1,53 @@ +/* + Audio File Library + + Copyright 1998-1999, Michael Pruett <michael@68k.org> + + 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. +*/ + +/* + sgi.h + + These routines are used in SGI-specific test programs. +*/ + +#ifndef SGI_H +#define SGI_H + +#include <dmedia/audio.h> + +/* + Set the sample width of an audio configuration. +*/ +void setwidth (ALconfig config, int width); + +/* + Set the sample format of an audio configuration. +*/ +void setsampleformat (ALconfig config, int width); + +/* + Set the sample rate of an audio port. +*/ +void setrate (ALport port, double rate); + +/* + Wait until the audio port has no more samples to play. +*/ +void waitport (ALport port); + +#endif |