diff options
Diffstat (limited to 'alsa-lib/test')
-rw-r--r-- | alsa-lib/test/Makefile.am | 23 | ||||
-rw-r--r-- | alsa-lib/test/Makefile.in | 630 | ||||
-rw-r--r-- | alsa-lib/test/client_event_filter.c | 46 | ||||
-rw-r--r-- | alsa-lib/test/control.c | 106 | ||||
-rw-r--r-- | alsa-lib/test/latency.c | 689 | ||||
-rw-r--r-- | alsa-lib/test/midifile.3 | 336 | ||||
-rw-r--r-- | alsa-lib/test/midifile.c | 1173 | ||||
-rw-r--r-- | alsa-lib/test/midifile.h | 132 | ||||
-rw-r--r-- | alsa-lib/test/midiloop.c | 190 | ||||
-rw-r--r-- | alsa-lib/test/namehint.c | 22 | ||||
-rw-r--r-- | alsa-lib/test/oldapi.c | 42 | ||||
-rw-r--r-- | alsa-lib/test/pcm.c | 902 | ||||
-rw-r--r-- | alsa-lib/test/pcm_min.c | 51 | ||||
-rw-r--r-- | alsa-lib/test/playmidi1.c | 617 | ||||
-rw-r--r-- | alsa-lib/test/queue_timer.c | 128 | ||||
-rw-r--r-- | alsa-lib/test/rawmidi.c | 241 | ||||
-rw-r--r-- | alsa-lib/test/seq-decoder.c | 353 | ||||
-rw-r--r-- | alsa-lib/test/seq-sender.c | 272 | ||||
-rw-r--r-- | alsa-lib/test/seq.c | 233 | ||||
-rw-r--r-- | alsa-lib/test/timer.c | 193 |
20 files changed, 0 insertions, 6379 deletions
diff --git a/alsa-lib/test/Makefile.am b/alsa-lib/test/Makefile.am deleted file mode 100644 index 2d7e92b..0000000 --- a/alsa-lib/test/Makefile.am +++ /dev/null @@ -1,23 +0,0 @@ -check_PROGRAMS=control pcm pcm_min latency seq \ - playmidi1 timer rawmidi midiloop \ - oldapi queue_timer namehint client_event_filter - -control_LDADD=../src/libasound.la -pcm_LDADD=../src/libasound.la -pcm_min_LDADD=../src/libasound.la -latency_LDADD=../src/libasound.la -seq_LDADD=../src/libasound.la -playmidi1_LDADD=../src/libasound.la -timer_LDADD=../src/libasound.la -rawmidi_LDADD=../src/libasound.la -midiloop_LDADD=../src/libasound.la -oldapi_LDADD=../src/libasound.la -queue_timer_LDADD=../src/libasound.la -namehint_LDADD=../src/libasound.la -client_event_filter_LDADD=../src/libasound.la -code_CFLAGS=-Wall -pipe -g -O2 - -INCLUDES=-I$(top_srcdir)/include -AM_CFLAGS=-Wall -pipe -g - -EXTRA_DIST=seq-decoder.c seq-sender.c midifile.h midifile.c midifile.3 diff --git a/alsa-lib/test/Makefile.in b/alsa-lib/test/Makefile.in deleted file mode 100644 index d1a6a43..0000000 --- a/alsa-lib/test/Makefile.in +++ /dev/null @@ -1,630 +0,0 @@ -# Makefile.in generated by automake 1.9.6 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -top_builddir = .. -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -INSTALL = @INSTALL@ -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = @build@ -host_triplet = @host@ -check_PROGRAMS = control$(EXEEXT) pcm$(EXEEXT) pcm_min$(EXEEXT) \ - latency$(EXEEXT) seq$(EXEEXT) playmidi1$(EXEEXT) \ - timer$(EXEEXT) rawmidi$(EXEEXT) midiloop$(EXEEXT) \ - oldapi$(EXEEXT) queue_timer$(EXEEXT) namehint$(EXEEXT) \ - client_event_filter$(EXEEXT) -subdir = test -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ - $(top_srcdir)/configure.in -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/include/config.h -CONFIG_CLEAN_FILES = -client_event_filter_SOURCES = client_event_filter.c -client_event_filter_OBJECTS = client_event_filter.$(OBJEXT) -client_event_filter_DEPENDENCIES = ../src/libasound.la -control_SOURCES = control.c -control_OBJECTS = control.$(OBJEXT) -control_DEPENDENCIES = ../src/libasound.la -latency_SOURCES = latency.c -latency_OBJECTS = latency.$(OBJEXT) -latency_DEPENDENCIES = ../src/libasound.la -midiloop_SOURCES = midiloop.c -midiloop_OBJECTS = midiloop.$(OBJEXT) -midiloop_DEPENDENCIES = ../src/libasound.la -namehint_SOURCES = namehint.c -namehint_OBJECTS = namehint.$(OBJEXT) -namehint_DEPENDENCIES = ../src/libasound.la -oldapi_SOURCES = oldapi.c -oldapi_OBJECTS = oldapi.$(OBJEXT) -oldapi_DEPENDENCIES = ../src/libasound.la -pcm_SOURCES = pcm.c -pcm_OBJECTS = pcm.$(OBJEXT) -pcm_DEPENDENCIES = ../src/libasound.la -pcm_min_SOURCES = pcm_min.c -pcm_min_OBJECTS = pcm_min.$(OBJEXT) -pcm_min_DEPENDENCIES = ../src/libasound.la -playmidi1_SOURCES = playmidi1.c -playmidi1_OBJECTS = playmidi1.$(OBJEXT) -playmidi1_DEPENDENCIES = ../src/libasound.la -queue_timer_SOURCES = queue_timer.c -queue_timer_OBJECTS = queue_timer.$(OBJEXT) -queue_timer_DEPENDENCIES = ../src/libasound.la -rawmidi_SOURCES = rawmidi.c -rawmidi_OBJECTS = rawmidi.$(OBJEXT) -rawmidi_DEPENDENCIES = ../src/libasound.la -seq_SOURCES = seq.c -seq_OBJECTS = seq.$(OBJEXT) -seq_DEPENDENCIES = ../src/libasound.la -timer_SOURCES = timer.c -timer_OBJECTS = timer.$(OBJEXT) -timer_DEPENDENCIES = ../src/libasound.la -DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__depfiles_maybe = depfiles -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ - $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = client_event_filter.c control.c latency.c midiloop.c \ - namehint.c oldapi.c pcm.c pcm_min.c playmidi1.c queue_timer.c \ - rawmidi.c seq.c timer.c -DIST_SOURCES = client_event_filter.c control.c latency.c midiloop.c \ - namehint.c oldapi.c pcm.c pcm_min.c playmidi1.c queue_timer.c \ - rawmidi.c seq.c timer.c -ETAGS = etags -CTAGS = ctags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -ALSA_CONFIG_DIR = @ALSA_CONFIG_DIR@ -ALSA_DEPLIBS = @ALSA_DEPLIBS@ -ALSA_HSEARCH_R_FALSE = @ALSA_HSEARCH_R_FALSE@ -ALSA_HSEARCH_R_TRUE = @ALSA_HSEARCH_R_TRUE@ -ALSA_PLUGIN_DIR = @ALSA_PLUGIN_DIR@ -AMDEP_FALSE = @AMDEP_FALSE@ -AMDEP_TRUE = @AMDEP_TRUE@ -AMTAR = @AMTAR@ -AR = @AR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -BUILD_ALISP_FALSE = @BUILD_ALISP_FALSE@ -BUILD_ALISP_TRUE = @BUILD_ALISP_TRUE@ -BUILD_CTL_PLUGIN_EXT_FALSE = @BUILD_CTL_PLUGIN_EXT_FALSE@ -BUILD_CTL_PLUGIN_EXT_TRUE = @BUILD_CTL_PLUGIN_EXT_TRUE@ -BUILD_CTL_PLUGIN_FALSE = @BUILD_CTL_PLUGIN_FALSE@ -BUILD_CTL_PLUGIN_SHM_FALSE = @BUILD_CTL_PLUGIN_SHM_FALSE@ -BUILD_CTL_PLUGIN_SHM_TRUE = @BUILD_CTL_PLUGIN_SHM_TRUE@ -BUILD_CTL_PLUGIN_TRUE = @BUILD_CTL_PLUGIN_TRUE@ -BUILD_HWDEP_FALSE = @BUILD_HWDEP_FALSE@ -BUILD_HWDEP_TRUE = @BUILD_HWDEP_TRUE@ -BUILD_MIXER_FALSE = @BUILD_MIXER_FALSE@ -BUILD_MIXER_TRUE = @BUILD_MIXER_TRUE@ -BUILD_MODULES_FALSE = @BUILD_MODULES_FALSE@ -BUILD_MODULES_TRUE = @BUILD_MODULES_TRUE@ -BUILD_PCM_FALSE = @BUILD_PCM_FALSE@ -BUILD_PCM_PLUGIN_ADPCM_FALSE = @BUILD_PCM_PLUGIN_ADPCM_FALSE@ -BUILD_PCM_PLUGIN_ADPCM_TRUE = @BUILD_PCM_PLUGIN_ADPCM_TRUE@ -BUILD_PCM_PLUGIN_ALAW_FALSE = @BUILD_PCM_PLUGIN_ALAW_FALSE@ -BUILD_PCM_PLUGIN_ALAW_TRUE = @BUILD_PCM_PLUGIN_ALAW_TRUE@ -BUILD_PCM_PLUGIN_ASYM_FALSE = @BUILD_PCM_PLUGIN_ASYM_FALSE@ -BUILD_PCM_PLUGIN_ASYM_TRUE = @BUILD_PCM_PLUGIN_ASYM_TRUE@ -BUILD_PCM_PLUGIN_COPY_FALSE = @BUILD_PCM_PLUGIN_COPY_FALSE@ -BUILD_PCM_PLUGIN_COPY_TRUE = @BUILD_PCM_PLUGIN_COPY_TRUE@ -BUILD_PCM_PLUGIN_DMIX_FALSE = @BUILD_PCM_PLUGIN_DMIX_FALSE@ -BUILD_PCM_PLUGIN_DMIX_TRUE = @BUILD_PCM_PLUGIN_DMIX_TRUE@ -BUILD_PCM_PLUGIN_DSHARE_FALSE = @BUILD_PCM_PLUGIN_DSHARE_FALSE@ -BUILD_PCM_PLUGIN_DSHARE_TRUE = @BUILD_PCM_PLUGIN_DSHARE_TRUE@ -BUILD_PCM_PLUGIN_DSNOOP_FALSE = @BUILD_PCM_PLUGIN_DSNOOP_FALSE@ -BUILD_PCM_PLUGIN_DSNOOP_TRUE = @BUILD_PCM_PLUGIN_DSNOOP_TRUE@ -BUILD_PCM_PLUGIN_EMPTY_FALSE = @BUILD_PCM_PLUGIN_EMPTY_FALSE@ -BUILD_PCM_PLUGIN_EMPTY_TRUE = @BUILD_PCM_PLUGIN_EMPTY_TRUE@ -BUILD_PCM_PLUGIN_EXTPLUG_FALSE = @BUILD_PCM_PLUGIN_EXTPLUG_FALSE@ -BUILD_PCM_PLUGIN_EXTPLUG_TRUE = @BUILD_PCM_PLUGIN_EXTPLUG_TRUE@ -BUILD_PCM_PLUGIN_FALSE = @BUILD_PCM_PLUGIN_FALSE@ -BUILD_PCM_PLUGIN_FILE_FALSE = @BUILD_PCM_PLUGIN_FILE_FALSE@ -BUILD_PCM_PLUGIN_FILE_TRUE = @BUILD_PCM_PLUGIN_FILE_TRUE@ -BUILD_PCM_PLUGIN_HOOKS_FALSE = @BUILD_PCM_PLUGIN_HOOKS_FALSE@ -BUILD_PCM_PLUGIN_HOOKS_TRUE = @BUILD_PCM_PLUGIN_HOOKS_TRUE@ -BUILD_PCM_PLUGIN_IEC958_FALSE = @BUILD_PCM_PLUGIN_IEC958_FALSE@ -BUILD_PCM_PLUGIN_IEC958_TRUE = @BUILD_PCM_PLUGIN_IEC958_TRUE@ -BUILD_PCM_PLUGIN_IOPLUG_FALSE = @BUILD_PCM_PLUGIN_IOPLUG_FALSE@ -BUILD_PCM_PLUGIN_IOPLUG_TRUE = @BUILD_PCM_PLUGIN_IOPLUG_TRUE@ -BUILD_PCM_PLUGIN_LADSPA_FALSE = @BUILD_PCM_PLUGIN_LADSPA_FALSE@ -BUILD_PCM_PLUGIN_LADSPA_TRUE = @BUILD_PCM_PLUGIN_LADSPA_TRUE@ -BUILD_PCM_PLUGIN_LFLOAT_FALSE = @BUILD_PCM_PLUGIN_LFLOAT_FALSE@ -BUILD_PCM_PLUGIN_LFLOAT_TRUE = @BUILD_PCM_PLUGIN_LFLOAT_TRUE@ -BUILD_PCM_PLUGIN_LINEAR_FALSE = @BUILD_PCM_PLUGIN_LINEAR_FALSE@ -BUILD_PCM_PLUGIN_LINEAR_TRUE = @BUILD_PCM_PLUGIN_LINEAR_TRUE@ -BUILD_PCM_PLUGIN_METER_FALSE = @BUILD_PCM_PLUGIN_METER_FALSE@ -BUILD_PCM_PLUGIN_METER_TRUE = @BUILD_PCM_PLUGIN_METER_TRUE@ -BUILD_PCM_PLUGIN_MMAP_EMUL_FALSE = @BUILD_PCM_PLUGIN_MMAP_EMUL_FALSE@ -BUILD_PCM_PLUGIN_MMAP_EMUL_TRUE = @BUILD_PCM_PLUGIN_MMAP_EMUL_TRUE@ -BUILD_PCM_PLUGIN_MULAW_FALSE = @BUILD_PCM_PLUGIN_MULAW_FALSE@ -BUILD_PCM_PLUGIN_MULAW_TRUE = @BUILD_PCM_PLUGIN_MULAW_TRUE@ -BUILD_PCM_PLUGIN_MULTI_FALSE = @BUILD_PCM_PLUGIN_MULTI_FALSE@ -BUILD_PCM_PLUGIN_MULTI_TRUE = @BUILD_PCM_PLUGIN_MULTI_TRUE@ -BUILD_PCM_PLUGIN_NULL_FALSE = @BUILD_PCM_PLUGIN_NULL_FALSE@ -BUILD_PCM_PLUGIN_NULL_TRUE = @BUILD_PCM_PLUGIN_NULL_TRUE@ -BUILD_PCM_PLUGIN_PLUG_FALSE = @BUILD_PCM_PLUGIN_PLUG_FALSE@ -BUILD_PCM_PLUGIN_PLUG_TRUE = @BUILD_PCM_PLUGIN_PLUG_TRUE@ -BUILD_PCM_PLUGIN_RATE_FALSE = @BUILD_PCM_PLUGIN_RATE_FALSE@ -BUILD_PCM_PLUGIN_RATE_TRUE = @BUILD_PCM_PLUGIN_RATE_TRUE@ -BUILD_PCM_PLUGIN_ROUTE_FALSE = @BUILD_PCM_PLUGIN_ROUTE_FALSE@ -BUILD_PCM_PLUGIN_ROUTE_TRUE = @BUILD_PCM_PLUGIN_ROUTE_TRUE@ -BUILD_PCM_PLUGIN_SHARE_FALSE = @BUILD_PCM_PLUGIN_SHARE_FALSE@ -BUILD_PCM_PLUGIN_SHARE_TRUE = @BUILD_PCM_PLUGIN_SHARE_TRUE@ -BUILD_PCM_PLUGIN_SHM_FALSE = @BUILD_PCM_PLUGIN_SHM_FALSE@ -BUILD_PCM_PLUGIN_SHM_TRUE = @BUILD_PCM_PLUGIN_SHM_TRUE@ -BUILD_PCM_PLUGIN_SOFTVOL_FALSE = @BUILD_PCM_PLUGIN_SOFTVOL_FALSE@ -BUILD_PCM_PLUGIN_SOFTVOL_TRUE = @BUILD_PCM_PLUGIN_SOFTVOL_TRUE@ -BUILD_PCM_PLUGIN_TRUE = @BUILD_PCM_PLUGIN_TRUE@ -BUILD_PCM_TRUE = @BUILD_PCM_TRUE@ -BUILD_PYTHON_FALSE = @BUILD_PYTHON_FALSE@ -BUILD_PYTHON_TRUE = @BUILD_PYTHON_TRUE@ -BUILD_RAWMIDI_FALSE = @BUILD_RAWMIDI_FALSE@ -BUILD_RAWMIDI_TRUE = @BUILD_RAWMIDI_TRUE@ -BUILD_SEQ_FALSE = @BUILD_SEQ_FALSE@ -BUILD_SEQ_TRUE = @BUILD_SEQ_TRUE@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -ECHO = @ECHO@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -F77 = @F77@ -FFLAGS = @FFLAGS@ -GREP = @GREP@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_M4_FALSE = @INSTALL_M4_FALSE@ -INSTALL_M4_TRUE = @INSTALL_M4_TRUE@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -KEEP_OLD_SYMBOLS_FALSE = @KEEP_OLD_SYMBOLS_FALSE@ -KEEP_OLD_SYMBOLS_TRUE = @KEEP_OLD_SYMBOLS_TRUE@ -LDFLAGS = @LDFLAGS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LIBTOOL = @LIBTOOL@ -LIBTOOL_VERSION_INFO = @LIBTOOL_VERSION_INFO@ -LN_S = @LN_S@ -LTLIBOBJS = @LTLIBOBJS@ -MAKEINFO = @MAKEINFO@ -OBJEXT = @OBJEXT@ -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@ -PYTHON_INCLUDES = @PYTHON_INCLUDES@ -PYTHON_LIBS = @PYTHON_LIBS@ -RANLIB = @RANLIB@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -SND_LIB_EXTRAVER = @SND_LIB_EXTRAVER@ -SND_LIB_MAJOR = @SND_LIB_MAJOR@ -SND_LIB_MINOR = @SND_LIB_MINOR@ -SND_LIB_SUBMINOR = @SND_LIB_SUBMINOR@ -SND_LIB_VERSION = @SND_LIB_VERSION@ -STRIP = @STRIP@ -SYMBOLIC_FUNCTIONS_FALSE = @SYMBOLIC_FUNCTIONS_FALSE@ -SYMBOLIC_FUNCTIONS_TRUE = @SYMBOLIC_FUNCTIONS_TRUE@ -SYMBOL_PREFIX = @SYMBOL_PREFIX@ -VERSION = @VERSION@ -VERSIONED_SYMBOLS_FALSE = @VERSIONED_SYMBOLS_FALSE@ -VERSIONED_SYMBOLS_TRUE = @VERSIONED_SYMBOLS_TRUE@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_F77 = @ac_ct_F77@ -am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ -am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ -am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ -am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -datadir = @datadir@ -datarootdir = @datarootdir@ -docdir = @docdir@ -dvidir = @dvidir@ -exec_prefix = @exec_prefix@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -htmldir = @htmldir@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -control_LDADD = ../src/libasound.la -pcm_LDADD = ../src/libasound.la -pcm_min_LDADD = ../src/libasound.la -latency_LDADD = ../src/libasound.la -seq_LDADD = ../src/libasound.la -playmidi1_LDADD = ../src/libasound.la -timer_LDADD = ../src/libasound.la -rawmidi_LDADD = ../src/libasound.la -midiloop_LDADD = ../src/libasound.la -oldapi_LDADD = ../src/libasound.la -queue_timer_LDADD = ../src/libasound.la -namehint_LDADD = ../src/libasound.la -client_event_filter_LDADD = ../src/libasound.la -code_CFLAGS = -Wall -pipe -g -O2 -INCLUDES = -I$(top_srcdir)/include -AM_CFLAGS = -Wall -pipe -g -EXTRA_DIST = seq-decoder.c seq-sender.c midifile.h midifile.c midifile.3 -all: all-am - -.SUFFIXES: -.SUFFIXES: .c .lo .o .obj -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign test/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --foreign test/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -clean-checkPROGRAMS: - @list='$(check_PROGRAMS)'; for p in $$list; do \ - f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ - echo " rm -f $$p $$f"; \ - rm -f $$p $$f ; \ - done -client_event_filter$(EXEEXT): $(client_event_filter_OBJECTS) $(client_event_filter_DEPENDENCIES) - @rm -f client_event_filter$(EXEEXT) - $(LINK) $(client_event_filter_LDFLAGS) $(client_event_filter_OBJECTS) $(client_event_filter_LDADD) $(LIBS) -control$(EXEEXT): $(control_OBJECTS) $(control_DEPENDENCIES) - @rm -f control$(EXEEXT) - $(LINK) $(control_LDFLAGS) $(control_OBJECTS) $(control_LDADD) $(LIBS) -latency$(EXEEXT): $(latency_OBJECTS) $(latency_DEPENDENCIES) - @rm -f latency$(EXEEXT) - $(LINK) $(latency_LDFLAGS) $(latency_OBJECTS) $(latency_LDADD) $(LIBS) -midiloop$(EXEEXT): $(midiloop_OBJECTS) $(midiloop_DEPENDENCIES) - @rm -f midiloop$(EXEEXT) - $(LINK) $(midiloop_LDFLAGS) $(midiloop_OBJECTS) $(midiloop_LDADD) $(LIBS) -namehint$(EXEEXT): $(namehint_OBJECTS) $(namehint_DEPENDENCIES) - @rm -f namehint$(EXEEXT) - $(LINK) $(namehint_LDFLAGS) $(namehint_OBJECTS) $(namehint_LDADD) $(LIBS) -oldapi$(EXEEXT): $(oldapi_OBJECTS) $(oldapi_DEPENDENCIES) - @rm -f oldapi$(EXEEXT) - $(LINK) $(oldapi_LDFLAGS) $(oldapi_OBJECTS) $(oldapi_LDADD) $(LIBS) -pcm$(EXEEXT): $(pcm_OBJECTS) $(pcm_DEPENDENCIES) - @rm -f pcm$(EXEEXT) - $(LINK) $(pcm_LDFLAGS) $(pcm_OBJECTS) $(pcm_LDADD) $(LIBS) -pcm_min$(EXEEXT): $(pcm_min_OBJECTS) $(pcm_min_DEPENDENCIES) - @rm -f pcm_min$(EXEEXT) - $(LINK) $(pcm_min_LDFLAGS) $(pcm_min_OBJECTS) $(pcm_min_LDADD) $(LIBS) -playmidi1$(EXEEXT): $(playmidi1_OBJECTS) $(playmidi1_DEPENDENCIES) - @rm -f playmidi1$(EXEEXT) - $(LINK) $(playmidi1_LDFLAGS) $(playmidi1_OBJECTS) $(playmidi1_LDADD) $(LIBS) -queue_timer$(EXEEXT): $(queue_timer_OBJECTS) $(queue_timer_DEPENDENCIES) - @rm -f queue_timer$(EXEEXT) - $(LINK) $(queue_timer_LDFLAGS) $(queue_timer_OBJECTS) $(queue_timer_LDADD) $(LIBS) -rawmidi$(EXEEXT): $(rawmidi_OBJECTS) $(rawmidi_DEPENDENCIES) - @rm -f rawmidi$(EXEEXT) - $(LINK) $(rawmidi_LDFLAGS) $(rawmidi_OBJECTS) $(rawmidi_LDADD) $(LIBS) -seq$(EXEEXT): $(seq_OBJECTS) $(seq_DEPENDENCIES) - @rm -f seq$(EXEEXT) - $(LINK) $(seq_LDFLAGS) $(seq_OBJECTS) $(seq_LDADD) $(LIBS) -timer$(EXEEXT): $(timer_OBJECTS) $(timer_DEPENDENCIES) - @rm -f timer$(EXEEXT) - $(LINK) $(timer_LDFLAGS) $(timer_OBJECTS) $(timer_LDADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/client_event_filter.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/control.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/latency.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/midiloop.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/namehint.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oldapi.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pcm.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pcm_min.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/playmidi1.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/queue_timer.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rawmidi.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/seq.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@ - -.c.o: -@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c $< - -.c.obj: -@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` - -.c.lo: -@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs - -distclean-libtool: - -rm -f libtool -uninstall-info-am: - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique; \ - fi -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ - list='$(DISTFILES)'; for file in $$list; do \ - case $$file in \ - $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ - $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ - esac; \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test "$$dir" != "$$file" && test "$$dir" != "."; then \ - dir="/$$dir"; \ - $(mkdir_p) "$(distdir)$$dir"; \ - else \ - dir=''; \ - fi; \ - if test -d $$d/$$file; then \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ - fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ - else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ - || exit 1; \ - fi; \ - done -check-am: all-am - $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) -check: check-am -all-am: Makefile -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)" \ - 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-checkPROGRAMS clean-generic clean-libtool \ - mostlyclean-am - -distclean: distclean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-libtool distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -info: info-am - -info-am: - -install-data-am: - -install-exec-am: - -install-info: install-info-am - -install-man: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-info-am - -.PHONY: CTAGS GTAGS all all-am check check-am clean \ - clean-checkPROGRAMS clean-generic clean-libtool ctags \ - distclean distclean-compile distclean-generic \ - distclean-libtool distclean-tags distdir dvi dvi-am html \ - html-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 pdf pdf-am ps ps-am \ - 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/alsa-lib/test/client_event_filter.c b/alsa-lib/test/client_event_filter.c deleted file mode 100644 index 0650314..0000000 --- a/alsa-lib/test/client_event_filter.c +++ /dev/null @@ -1,46 +0,0 @@ -#include <alsa/asoundlib.h> - -void dump_event_filter(snd_seq_client_info_t *client_info) { - int i, b; - - for (i = 0; i <= 255;) { - b = snd_seq_client_info_event_filter_check(client_info, i); - i++; - printf("%c%s%s", (b ? 'X' : '.'), - (i % 8 == 0 ? " " : ""), - (i % 32 == 0 ? "\n" : "")); - } - printf("\n"); -} - -int main(void) { - snd_seq_client_info_t *client_info; - - snd_seq_client_info_alloca(&client_info); - - printf("first client_info_event_filter :\n"); - dump_event_filter(client_info); - - snd_seq_client_info_event_filter_add(client_info, SND_SEQ_EVENT_NOTEON); - printf("after snd_seq_client_info_event_filter_add(client_info, SND_SEQ_EVENT_NOTEON);\n"); - dump_event_filter(client_info); - - snd_seq_client_info_event_filter_add(client_info, SND_SEQ_EVENT_PGMCHANGE); - printf("after snd_seq_client_info_event_filter_add(client_info, SND_SEQ_EVENT_PGMCHANGE);\n"); - dump_event_filter(client_info); - - snd_seq_client_info_event_filter_del(client_info, SND_SEQ_EVENT_NOTEON); - printf("after snd_seq_client_info_event_filter_del(client_info, SND_SEQ_EVENT_NOTEON);\n"); - dump_event_filter(client_info); - - snd_seq_client_info_event_filter_clear(client_info); - printf("after snd_seq_client_info_event_filter_clear(client_info);\n"); - dump_event_filter(client_info); - - snd_seq_client_info_event_filter_add(client_info, SND_SEQ_EVENT_NOTEON); - printf("after snd_seq_client_info_event_filter_add(client_info, SND_SEQ_EVENT_NOTEON);\n"); - dump_event_filter(client_info); - - return 0; -} - diff --git a/alsa-lib/test/control.c b/alsa-lib/test/control.c deleted file mode 100644 index f4b437e..0000000 --- a/alsa-lib/test/control.c +++ /dev/null @@ -1,106 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include "../include/asoundlib.h" - -int main(void) -{ - int idx, dev, err; - snd_ctl_t *handle; - snd_ctl_card_info_t *info; - snd_pcm_info_t *pcminfo; - snd_rawmidi_info_t *rawmidiinfo; - char str[128]; - - snd_ctl_card_info_alloca(&info); - snd_pcm_info_alloca(&pcminfo); - snd_rawmidi_info_alloca(&rawmidiinfo); - - idx = -1; - while (1) { - if ((err = snd_card_next(&idx)) < 0) { - printf("Card next error: %s\n", snd_strerror(err)); - break; - } - if (idx < 0) - break; - sprintf(str, "hw:CARD=%i", idx); - if ((err = snd_ctl_open(&handle, str, 0)) < 0) { - printf("Open error: %s\n", snd_strerror(err)); - continue; - } - if ((err = snd_ctl_card_info(handle, info)) < 0) { - printf("HW info error: %s\n", snd_strerror(err)); - continue; - } - printf("Soundcard #%i:\n", idx + 1); - printf(" card - %i\n", snd_ctl_card_info_get_card(info)); - printf(" id - '%s'\n", snd_ctl_card_info_get_id(info)); - printf(" driver - '%s'\n", snd_ctl_card_info_get_driver(info)); - printf(" name - '%s'\n", snd_ctl_card_info_get_name(info)); - printf(" longname - '%s'\n", snd_ctl_card_info_get_longname(info)); - printf(" mixername - '%s'\n", snd_ctl_card_info_get_mixername(info)); - printf(" components - '%s'\n", snd_ctl_card_info_get_components(info)); - dev = -1; - while (1) { - snd_pcm_sync_id_t sync; - if ((err = snd_ctl_pcm_next_device(handle, &dev)) < 0) { - printf(" PCM next device error: %s\n", snd_strerror(err)); - break; - } - if (dev < 0) - break; - snd_pcm_info_set_device(pcminfo, dev); - snd_pcm_info_set_subdevice(pcminfo, 0); - snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK); - if ((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) { - printf(" PCM info error: %s\n", snd_strerror(err)); - continue; - } - printf("PCM info, device #%i:\n", dev); - printf(" device - %i\n", snd_pcm_info_get_device(pcminfo)); - printf(" subdevice - %i\n", snd_pcm_info_get_subdevice(pcminfo)); - printf(" stream - %i\n", snd_pcm_info_get_stream(pcminfo)); - printf(" card - %i\n", snd_pcm_info_get_card(pcminfo)); - printf(" id - '%s'\n", snd_pcm_info_get_id(pcminfo)); - printf(" name - '%s'\n", snd_pcm_info_get_name(pcminfo)); - printf(" subdevice name - '%s'\n", snd_pcm_info_get_subdevice_name(pcminfo)); - printf(" class - 0x%x\n", snd_pcm_info_get_class(pcminfo)); - printf(" subclass - 0x%x\n", snd_pcm_info_get_subclass(pcminfo)); - printf(" subdevices count - %i\n", snd_pcm_info_get_subdevices_count(pcminfo)); - printf(" subdevices avail - %i\n", snd_pcm_info_get_subdevices_avail(pcminfo)); - sync = snd_pcm_info_get_sync(pcminfo); - printf(" sync - 0x%x,0x%x,0x%x,0x%x\n", sync.id32[0], sync.id32[1], sync.id32[2], sync.id32[3]); - } - dev = -1; - while (1) { - if ((err = snd_ctl_rawmidi_next_device(handle, &dev)) < 0) { - printf(" RAWMIDI next device error: %s\n", snd_strerror(err)); - break; - } - if (dev < 0) - break; - snd_rawmidi_info_set_device(rawmidiinfo, dev); - snd_rawmidi_info_set_subdevice(rawmidiinfo, 0); - snd_rawmidi_info_set_stream(rawmidiinfo, SND_RAWMIDI_STREAM_OUTPUT); - if ((err = snd_ctl_rawmidi_info(handle, rawmidiinfo)) < 0) { - printf(" RAWMIDI info error: %s\n", snd_strerror(err)); - continue; - } - printf("RAWMIDI info, device #%i:\n", dev); - printf(" device - %i\n", snd_rawmidi_info_get_device(rawmidiinfo)); - printf(" subdevice - %i\n", snd_rawmidi_info_get_subdevice(rawmidiinfo)); - printf(" stream - %i\n", snd_rawmidi_info_get_stream(rawmidiinfo)); - printf(" card - %i\n", snd_rawmidi_info_get_card(rawmidiinfo)); - printf(" flags - 0x%x\n", snd_rawmidi_info_get_flags(rawmidiinfo)); - printf(" id - '%s'\n", snd_rawmidi_info_get_id(rawmidiinfo)); - printf(" name - '%s'\n", snd_rawmidi_info_get_name(rawmidiinfo)); - printf(" subname - '%s'\n", snd_rawmidi_info_get_subdevice_name(rawmidiinfo)); - printf(" subdevices count - %i\n", snd_rawmidi_info_get_subdevices_count(rawmidiinfo)); - printf(" subdevices avail - %i\n", snd_rawmidi_info_get_subdevices_avail(rawmidiinfo)); - } - snd_ctl_close(handle); - } - - snd_config_update_free_global(); - return 0; -} diff --git a/alsa-lib/test/latency.c b/alsa-lib/test/latency.c deleted file mode 100644 index 304e012..0000000 --- a/alsa-lib/test/latency.c +++ /dev/null @@ -1,689 +0,0 @@ -/* - * Latency test program - * - * Author: Jaroslav Kysela <perex@perex.cz> - * - * Author of bandpass filter sweep effect: - * Maarten de Boer <mdeboer@iua.upf.es> - * - * This small demo program can be used for measuring latency between - * capture and playback. This latency is measured from driver (diff when - * playback and capture was started). Scheduler is set to SCHED_RR. - * - * - * 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 <sched.h> -#include <errno.h> -#include <getopt.h> -#include "../include/asoundlib.h" -#include <sys/time.h> -#include <math.h> - -char *pdevice = "hw:0,0"; -char *cdevice = "hw:0,0"; -snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE; -int rate = 22050; -int channels = 2; -int buffer_size = 0; /* auto */ -int period_size = 0; /* auto */ -int latency_min = 32; /* in frames / 2 */ -int latency_max = 2048; /* in frames / 2 */ -int loop_sec = 30; /* seconds */ -int block = 0; /* block mode */ -int use_poll = 0; -int resample = 1; -unsigned long loop_limit; - -snd_output_t *output = NULL; - -int setparams_stream(snd_pcm_t *handle, - snd_pcm_hw_params_t *params, - const char *id) -{ - int err; - unsigned int rrate; - - err = snd_pcm_hw_params_any(handle, params); - if (err < 0) { - printf("Broken configuration for %s PCM: no configurations available: %s\n", snd_strerror(err), id); - return err; - } - err = snd_pcm_hw_params_set_rate_resample(handle, params, resample); - if (err < 0) { - printf("Resample setup failed for %s (val %i): %s\n", id, resample, snd_strerror(err)); - return err; - } - err = snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); - if (err < 0) { - printf("Access type not available for %s: %s\n", id, snd_strerror(err)); - return err; - } - err = snd_pcm_hw_params_set_format(handle, params, format); - if (err < 0) { - printf("Sample format not available for %s: %s\n", id, snd_strerror(err)); - return err; - } - err = snd_pcm_hw_params_set_channels(handle, params, channels); - if (err < 0) { - printf("Channels count (%i) not available for %s: %s\n", channels, id, snd_strerror(err)); - return err; - } - rrate = rate; - err = snd_pcm_hw_params_set_rate_near(handle, params, &rrate, 0); - if (err < 0) { - printf("Rate %iHz not available for %s: %s\n", rate, id, snd_strerror(err)); - return err; - } - if ((int)rrate != rate) { - printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err); - return -EINVAL; - } - return 0; -} - -int setparams_bufsize(snd_pcm_t *handle, - snd_pcm_hw_params_t *params, - snd_pcm_hw_params_t *tparams, - snd_pcm_uframes_t bufsize, - const char *id) -{ - int err; - snd_pcm_uframes_t periodsize; - - snd_pcm_hw_params_copy(params, tparams); - periodsize = bufsize * 2; - err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &periodsize); - if (err < 0) { - printf("Unable to set buffer size %li for %s: %s\n", bufsize * 2, id, snd_strerror(err)); - return err; - } - if (period_size > 0) - periodsize = period_size; - else - periodsize /= 2; - err = snd_pcm_hw_params_set_period_size_near(handle, params, &periodsize, 0); - if (err < 0) { - printf("Unable to set period size %li for %s: %s\n", periodsize, id, snd_strerror(err)); - return err; - } - return 0; -} - -int setparams_set(snd_pcm_t *handle, - snd_pcm_hw_params_t *params, - snd_pcm_sw_params_t *swparams, - const char *id) -{ - int err; - snd_pcm_uframes_t val; - - err = snd_pcm_hw_params(handle, params); - if (err < 0) { - printf("Unable to set hw params for %s: %s\n", id, snd_strerror(err)); - return err; - } - err = snd_pcm_sw_params_current(handle, swparams); - if (err < 0) { - printf("Unable to determine current swparams for %s: %s\n", id, snd_strerror(err)); - return err; - } - err = snd_pcm_sw_params_set_start_threshold(handle, swparams, 0x7fffffff); - if (err < 0) { - printf("Unable to set start threshold mode for %s: %s\n", id, snd_strerror(err)); - return err; - } - if (!block) - val = 4; - else - snd_pcm_hw_params_get_period_size(params, &val, NULL); - err = snd_pcm_sw_params_set_avail_min(handle, swparams, val); - if (err < 0) { - printf("Unable to set avail min for %s: %s\n", id, snd_strerror(err)); - return err; - } - err = snd_pcm_sw_params(handle, swparams); - if (err < 0) { - printf("Unable to set sw params for %s: %s\n", id, snd_strerror(err)); - return err; - } - return 0; -} - -int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int *bufsize) -{ - int err, last_bufsize = *bufsize; - snd_pcm_hw_params_t *pt_params, *ct_params; /* templates with rate, format and channels */ - snd_pcm_hw_params_t *p_params, *c_params; - snd_pcm_sw_params_t *p_swparams, *c_swparams; - snd_pcm_uframes_t p_size, c_size, p_psize, c_psize; - unsigned int p_time, c_time; - - snd_pcm_hw_params_alloca(&p_params); - snd_pcm_hw_params_alloca(&c_params); - snd_pcm_hw_params_alloca(&pt_params); - snd_pcm_hw_params_alloca(&ct_params); - snd_pcm_sw_params_alloca(&p_swparams); - snd_pcm_sw_params_alloca(&c_swparams); - if ((err = setparams_stream(phandle, pt_params, "playback")) < 0) { - printf("Unable to set parameters for playback stream: %s\n", snd_strerror(err)); - exit(0); - } - if ((err = setparams_stream(chandle, ct_params, "capture")) < 0) { - printf("Unable to set parameters for playback stream: %s\n", snd_strerror(err)); - exit(0); - } - - if (buffer_size > 0) { - *bufsize = buffer_size; - goto __set_it; - } - - __again: - if (buffer_size > 0) - return -1; - if (last_bufsize == *bufsize) - *bufsize += 4; - last_bufsize = *bufsize; - if (*bufsize > latency_max) - return -1; - __set_it: - if ((err = setparams_bufsize(phandle, p_params, pt_params, *bufsize, "playback")) < 0) { - printf("Unable to set sw parameters for playback stream: %s\n", snd_strerror(err)); - exit(0); - } - if ((err = setparams_bufsize(chandle, c_params, ct_params, *bufsize, "capture")) < 0) { - printf("Unable to set sw parameters for playback stream: %s\n", snd_strerror(err)); - exit(0); - } - - snd_pcm_hw_params_get_period_size(p_params, &p_psize, NULL); - if (p_psize > (unsigned int)*bufsize) - *bufsize = p_psize; - snd_pcm_hw_params_get_period_size(c_params, &c_psize, NULL); - if (c_psize > (unsigned int)*bufsize) - *bufsize = c_psize; - snd_pcm_hw_params_get_period_time(p_params, &p_time, NULL); - snd_pcm_hw_params_get_period_time(c_params, &c_time, NULL); - if (p_time != c_time) - goto __again; - - snd_pcm_hw_params_get_buffer_size(p_params, &p_size); - if (p_psize * 2 < p_size) - goto __again; - snd_pcm_hw_params_get_buffer_size(c_params, &c_size); - if (c_psize * 2 < c_size) - goto __again; - - if ((err = setparams_set(phandle, p_params, p_swparams, "playback")) < 0) { - printf("Unable to set sw parameters for playback stream: %s\n", snd_strerror(err)); - exit(0); - } - if ((err = setparams_set(chandle, c_params, c_swparams, "capture")) < 0) { - printf("Unable to set sw parameters for playback stream: %s\n", snd_strerror(err)); - exit(0); - } - - if ((err = snd_pcm_prepare(phandle)) < 0) { - printf("Prepare error: %s\n", snd_strerror(err)); - exit(0); - } - - snd_pcm_dump(phandle, output); - snd_pcm_dump(chandle, output); - fflush(stdout); - return 0; -} - -void showstat(snd_pcm_t *handle, size_t frames) -{ - int err; - snd_pcm_status_t *status; - - snd_pcm_status_alloca(&status); - if ((err = snd_pcm_status(handle, status)) < 0) { - printf("Stream status error: %s\n", snd_strerror(err)); - exit(0); - } - printf("*** frames = %li ***\n", (long)frames); - snd_pcm_status_dump(status, output); -} - -void showlatency(size_t latency) -{ - double d; - latency *= 2; - d = (double)latency / (double)rate; - printf("Trying latency %li frames, %.3fus, %.6fms (%.4fHz)\n", (long)latency, d * 1000000, d * 1000, (double)1 / d); -} - -void showinmax(size_t in_max) -{ - double d; - - printf("Maximum read: %li frames\n", (long)in_max); - d = (double)in_max / (double)rate; - printf("Maximum read latency: %.3fus, %.6fms (%.4fHz)\n", d * 1000000, d * 1000, (double)1 / d); -} - -void gettimestamp(snd_pcm_t *handle, snd_timestamp_t *timestamp) -{ - int err; - snd_pcm_status_t *status; - - snd_pcm_status_alloca(&status); - if ((err = snd_pcm_status(handle, status)) < 0) { - printf("Stream status error: %s\n", snd_strerror(err)); - exit(0); - } - snd_pcm_status_get_trigger_tstamp(status, timestamp); -} - -void setscheduler(void) -{ - struct sched_param sched_param; - - if (sched_getparam(0, &sched_param) < 0) { - printf("Scheduler getparam failed...\n"); - return; - } - sched_param.sched_priority = sched_get_priority_max(SCHED_RR); - if (!sched_setscheduler(0, SCHED_RR, &sched_param)) { - printf("Scheduler set to Round Robin with priority %i...\n", sched_param.sched_priority); - fflush(stdout); - return; - } - printf("!!!Scheduler set to Round Robin with priority %i FAILED!!!\n", sched_param.sched_priority); -} - -long timediff(snd_timestamp_t t1, snd_timestamp_t t2) -{ - signed long l; - - t1.tv_sec -= t2.tv_sec; - l = (signed long) t1.tv_usec - (signed long) t2.tv_usec; - if (l < 0) { - t1.tv_sec--; - l = -l; - l %= 1000000; - } - return (t1.tv_sec * 1000000) + l; -} - -long readbuf(snd_pcm_t *handle, char *buf, long len, size_t *frames, size_t *max) -{ - long r; - - if (!block) { - do { - r = snd_pcm_readi(handle, buf, len); - } while (r == -EAGAIN); - if (r > 0) { - *frames += r; - if ((long)*max < r) - *max = r; - } - // printf("read = %li\n", r); - } else { - int frame_bytes = (snd_pcm_format_width(format) / 8) * channels; - do { - r = snd_pcm_readi(handle, buf, len); - if (r > 0) { - buf += r * frame_bytes; - len -= r; - *frames += r; - if ((long)*max < r) - *max = r; - } - // printf("r = %li, len = %li\n", r, len); - } while (r >= 1 && len > 0); - } - // showstat(handle, 0); - return r; -} - -long writebuf(snd_pcm_t *handle, char *buf, long len, size_t *frames) -{ - long r; - - while (len > 0) { - r = snd_pcm_writei(handle, buf, len); - if (r == -EAGAIN) - continue; - // printf("write = %li\n", r); - if (r < 0) - return r; - // showstat(handle, 0); - buf += r * 4; - len -= r; - *frames += r; - } - return 0; -} - -#define FILTERSWEEP_LFO_CENTER 2000. -#define FILTERSWEEP_LFO_DEPTH 1800. -#define FILTERSWEEP_LFO_FREQ 0.2 -#define FILTER_BANDWIDTH 50 - -/* filter the sweep variables */ -float lfo,dlfo,fs,fc,BW,C,D,a0,a1,a2,b1,b2,*x[3],*y[3]; - -void applyeffect(char* buffer,int r) -{ - short* samples = (short*) buffer; - int i; - for (i=0;i<r;i++) - { - int chn; - - fc = sin(lfo)*FILTERSWEEP_LFO_DEPTH+FILTERSWEEP_LFO_CENTER; - lfo += dlfo; - if (lfo>2.*M_PI) lfo -= 2.*M_PI; - C = 1./tan(M_PI*BW/fs); - D = 2.*cos(2*M_PI*fc/fs); - a0 = 1./(1.+C); - a1 = 0; - a2 = -a0; - b1 = -C*D*a0; - b2 = (C-1)*a0; - - for (chn=0;chn<channels;chn++) - { - x[chn][2] = x[chn][1]; - x[chn][1] = x[chn][0]; - - y[chn][2] = y[chn][1]; - y[chn][1] = y[chn][0]; - - x[chn][0] = samples[i*channels+chn]; - y[chn][0] = a0*x[chn][0] + a1*x[chn][1] + a2*x[chn][2] - - b1*y[chn][1] - b2*y[chn][2]; - samples[i*channels+chn] = y[chn][0]; - } - } -} - -void help(void) -{ - int k; - printf( -"Usage: latency [OPTION]... [FILE]...\n" -"-h,--help help\n" -"-P,--pdevice playback device\n" -"-C,--cdevice capture device\n" -"-m,--min minimum latency in frames\n" -"-M,--max maximum latency in frames\n" -"-F,--frames frames to transfer\n" -"-f,--format sample format\n" -"-c,--channels channels\n" -"-r,--rate rate\n" -"-B,--buffer buffer size in frames\n" -"-E,--period period size in frames\n" -"-s,--seconds duration of test in seconds\n" -"-b,--block block mode\n" -"-p,--poll use poll (wait for event - reduces CPU usage)\n" -"-e,--effect apply an effect (bandpass filter sweep)\n" -); - printf("Recognized sample formats are:"); - for (k = 0; k < SND_PCM_FORMAT_LAST; ++k) { - const char *s = snd_pcm_format_name(k); - if (s) - printf(" %s", s); - } - printf("\n\n"); - printf( -"Tip #1 (usable latency with large periods, non-blocking mode, good CPU usage,\n" -" superb xrun prevention):\n" -" latency -m 8192 -M 8192 -t 1 -p\n" -"Tip #2 (superb latency, non-blocking mode, but heavy CPU usage):\n" -" latency -m 128 -M 128\n" -); -} - -int main(int argc, char *argv[]) -{ - struct option long_option[] = - { - {"help", 0, NULL, 'h'}, - {"pdevice", 1, NULL, 'P'}, - {"cdevice", 1, NULL, 'C'}, - {"min", 1, NULL, 'm'}, - {"max", 1, NULL, 'M'}, - {"frames", 1, NULL, 'F'}, - {"format", 1, NULL, 'f'}, - {"channels", 1, NULL, 'c'}, - {"rate", 1, NULL, 'r'}, - {"buffer", 1, NULL, 'B'}, - {"period", 1, NULL, 'E'}, - {"seconds", 1, NULL, 's'}, - {"block", 0, NULL, 'b'}, - {"poll", 0, NULL, 'p'}, - {"effect", 0, NULL, 'e'}, - {NULL, 0, NULL, 0}, - }; - snd_pcm_t *phandle, *chandle; - char *buffer; - int err, latency, morehelp; - int ok; - snd_timestamp_t p_tstamp, c_tstamp; - ssize_t r; - size_t frames_in, frames_out, in_max; - int effect = 0; - morehelp = 0; - while (1) { - int c; - if ((c = getopt_long(argc, argv, "hP:C:m:M:F:f:c:r:s:bpen", long_option, NULL)) < 0) - break; - switch (c) { - case 'h': - morehelp++; - break; - case 'P': - pdevice = strdup(optarg); - break; - case 'C': - cdevice = strdup(optarg); - break; - case 'm': - err = atoi(optarg) / 2; - latency_min = err >= 4 ? err : 4; - if (latency_max < latency_min) - latency_max = latency_min; - break; - case 'M': - err = atoi(optarg) / 2; - latency_max = latency_min > err ? latency_min : err; - break; - case 'f': - format = snd_pcm_format_value(optarg); - if (format == SND_PCM_FORMAT_UNKNOWN) { - printf("Unknown format, setting to default S16_LE\n"); - format = SND_PCM_FORMAT_S16_LE; - } - break; - case 'c': - err = atoi(optarg); - channels = err >= 1 && err < 1024 ? err : 1; - break; - case 'r': - err = atoi(optarg); - rate = err >= 4000 && err < 200000 ? err : 44100; - break; - case 'B': - err = atoi(optarg); - buffer_size = err >= 32 && err < 200000 ? err : 0; - break; - case 'E': - err = atoi(optarg); - period_size = err >= 32 && err < 200000 ? err : 0; - break; - case 's': - err = atoi(optarg); - loop_sec = err >= 1 && err <= 100000 ? err : 30; - break; - case 'b': - block = 1; - break; - case 'p': - use_poll = 1; - break; - case 'e': - effect = 1; - break; - case 'n': - resample = 0; - break; - } - } - - if (morehelp) { - help(); - return 0; - } - err = snd_output_stdio_attach(&output, stdout, 0); - if (err < 0) { - printf("Output failed: %s\n", snd_strerror(err)); - return 0; - } - - loop_limit = loop_sec * rate; - latency = latency_min - 4; - buffer = malloc((latency_max * snd_pcm_format_width(format) / 8) * 2); - - setscheduler(); - - printf("Playback device is %s\n", pdevice); - printf("Capture device is %s\n", cdevice); - printf("Parameters are %iHz, %s, %i channels, %s mode\n", rate, snd_pcm_format_name(format), channels, block ? "blocking" : "non-blocking"); - printf("Poll mode: %s\n", use_poll ? "yes" : "no"); - printf("Loop limit is %li frames, minimum latency = %i, maximum latency = %i\n", loop_limit, latency_min * 2, latency_max * 2); - - if ((err = snd_pcm_open(&phandle, pdevice, SND_PCM_STREAM_PLAYBACK, block ? 0 : SND_PCM_NONBLOCK)) < 0) { - printf("Playback open error: %s\n", snd_strerror(err)); - return 0; - } - if ((err = snd_pcm_open(&chandle, cdevice, SND_PCM_STREAM_CAPTURE, block ? 0 : SND_PCM_NONBLOCK)) < 0) { - printf("Record open error: %s\n", snd_strerror(err)); - return 0; - } - - /* initialize the filter sweep variables */ - if (effect) { - fs = (float) rate; - BW = FILTER_BANDWIDTH; - - lfo = 0; - dlfo = 2.*M_PI*FILTERSWEEP_LFO_FREQ/fs; - - x[0] = (float*) malloc(channels*sizeof(float)); - x[1] = (float*) malloc(channels*sizeof(float)); - x[2] = (float*) malloc(channels*sizeof(float)); - y[0] = (float*) malloc(channels*sizeof(float)); - y[1] = (float*) malloc(channels*sizeof(float)); - y[2] = (float*) malloc(channels*sizeof(float)); - } - - while (1) { - frames_in = frames_out = 0; - if (setparams(phandle, chandle, &latency) < 0) - break; - showlatency(latency); - if ((err = snd_pcm_link(chandle, phandle)) < 0) { - printf("Streams link error: %s\n", snd_strerror(err)); - exit(0); - } - if (snd_pcm_format_set_silence(format, buffer, latency*channels) < 0) { - fprintf(stderr, "silence error\n"); - break; - } - if (writebuf(phandle, buffer, latency, &frames_out) < 0) { - fprintf(stderr, "write error\n"); - break; - } - if (writebuf(phandle, buffer, latency, &frames_out) < 0) { - fprintf(stderr, "write error\n"); - break; - } - - if ((err = snd_pcm_start(chandle)) < 0) { - printf("Go error: %s\n", snd_strerror(err)); - exit(0); - } - gettimestamp(phandle, &p_tstamp); - gettimestamp(chandle, &c_tstamp); -#if 0 - printf("Playback:\n"); - showstat(phandle, frames_out); - printf("Capture:\n"); - showstat(chandle, frames_in); -#endif - - ok = 1; - in_max = 0; - while (ok && frames_in < loop_limit) { - if (use_poll) { - /* use poll to wait for next event */ - snd_pcm_wait(chandle, 1000); - } - if ((r = readbuf(chandle, buffer, latency, &frames_in, &in_max)) < 0) - ok = 0; - else { - if (effect) - applyeffect(buffer,r); - if (writebuf(phandle, buffer, r, &frames_out) < 0) - ok = 0; - } - } - if (ok) - printf("Success\n"); - else - printf("Failure\n"); - printf("Playback:\n"); - showstat(phandle, frames_out); - printf("Capture:\n"); - showstat(chandle, frames_in); - showinmax(in_max); - if (p_tstamp.tv_sec == p_tstamp.tv_sec && - p_tstamp.tv_usec == c_tstamp.tv_usec) - printf("Hardware sync\n"); - snd_pcm_drop(chandle); - snd_pcm_nonblock(phandle, 0); - snd_pcm_drain(phandle); - snd_pcm_nonblock(phandle, !block ? 1 : 0); - if (ok) { -#if 1 - printf("Playback time = %li.%i, Record time = %li.%i, diff = %li\n", - p_tstamp.tv_sec, - (int)p_tstamp.tv_usec, - c_tstamp.tv_sec, - (int)c_tstamp.tv_usec, - timediff(p_tstamp, c_tstamp)); -#endif - break; - } - snd_pcm_unlink(chandle); - snd_pcm_hw_free(phandle); - snd_pcm_hw_free(chandle); - } - snd_pcm_close(phandle); - snd_pcm_close(chandle); - return 0; -} diff --git a/alsa-lib/test/midifile.3 b/alsa-lib/test/midifile.3 deleted file mode 100644 index 3aadb6d..0000000 --- a/alsa-lib/test/midifile.3 +++ /dev/null @@ -1,336 +0,0 @@ -.TH MIDIFILE 3 -.SH NAME -mfread,mfwrite \- read and write a standard MIDI file -.SH SYNOPSIS -\fC#include "mfread.h" - -mfread () - -.nf -int (*Mf_getc) (); -int (*Mf_putc) (); -int (*Mf_error) (char *msg); -int (*Mf_header) (int format, int ntrks, int division); -int (*Mf_trackstart) (); -int (*Mf_trackend) (); -int (*Mf_noteon) (int chan, int pitch, int vol); -int (*Mf_noteoff) (int chan, int pitch, int vol); -int (*Mf_pressure) (int chan, int pitch, int pressure); -int (*Mf_parameter) (int chan, int control, int value); -int (*Mf_pitchbend) (int chan, int msb, int lsb); -int (*Mf_program) (int chan, int program); -int (*Mf_chanpressure) (int chan, int pressure); -int (*Mf_sysex) (int leng, char *msg); -int (*Mf_metamisc) (int type, int leng, int msg); -int (*Mf_seqspecific) (int type, int leng, int msg); -int (*Mf_seqnum) (int num); -int (*Mf_text) (int type, int leng, int msg); -int (*Mf_eot) (); -int (*Mf_timesig) (int numer, int denom, int clocks, int qnotes); -int (*Mf_smpte) (int hour, int min, int sec, int frame, int fract); -int (*Mf_tempo) (int microsecs); -int (*Mf_keysig) (int sharpflat, int minor); -int (*Mf_arbitrary) (int leng, int msg); -int Mf_nomerge; -long Mf_currtime; -.fi -.sp 1 -mfwrite(int format, int ntracks, int division, FILE *fp) -.sp 1 -.nf -int (*Mf_writetrack)(int track); -int (*Mf_writetempotrack)(); - -void mf_write_midi_event(delta, type, chan, data, size) -unsigned long delta; -unsigned int type,chan,size; -char *data; - -void mf_write_meta_event(delta, type, data, size) -unsigned long delta; -unsigned int type,chan,size; -char *data; - -void mf_write_tempo(tempo) -unsigned long tempo; - -unsigned long mf_sec2ticks(float seconds, int division, int tempo) -float seconds; -int division; -unsigned int tempo; - -float mf_ticks2sec(ticks, division, tempo) -unsigned long ticks; -int division; -unsigned int tempo; -.fi - -.SH DESCRIPTION -The \fCmfread\fR function reads and interprets a standard MIDI file. -To use it you need to understand the general form of a -MIDI file and the type of information it contains, but you don't -need to know much, if anything, about the detailed format of the file -and the mechanics of reading it reliably and portably. - -The \fCmfwrite\fR function writes a standard MIDI file making -use of user-defined functions that access the program's -data structure. To use it you need to define your own Mf_writetrack -routine and then make use of the write_* family of routines to -write out the MIDI data. The \fCmfwrite\fR routine takes -care of the file format and writing the file and track chunk headers. - -.SH READING STANDARD MIDI FILES -A single call to \fCmfread\fR will read an entire MIDI file. -The interface to \fCmfread\fR is a set of external variables -named \fCMf_*\fR, most of which are function pointers to be called -from within \fCmfread\fR during the process of parsing the MIDI file. -Before calling \fCmfread\fR, the only -requirement is that you assign a value -to \fCMf_getc\fR - a pointer to a function that will return -characters from the MIDI file, using \-1 to indicate EOF. -All the rest of the function -pointers are initialized to NULL, and the default action for each -is to do nothing. The following is a complete program using \fCmfread\fR -that could serve as a 'syntax checker' for MIDI files: - -.in +1i -.ft C -.nf -#include <stdio.h> -#include "midifile.h" - -mygetc() -{ - /* use standard input */ - return(getchar()); -} - -main() -{ - Mf_getc = mygetc; - mfread(); - exit(0); -} -.fi -.ft R -.in -1i - -This takes advantage of the default action when an error is detected, which -is to exit silently with a return code of 1. An error function of your -own can be used by giving a value to \fCMf_error\fR; the function will be -called with the error message as an argument. -The other \fCMf_* variables can similarly be used to call arbitrary -functions while parsing the MIDI file. The descriptions below -of the information passed to these functions is sparse; refer to -the MIDI file standard for the complete descriptions. - -\fCMf_header\fR is the first function to be called, and its arguments -contain information from the MIDI file's header; the format (0,1, or 2), -the number of tracks, and the division of a quarter-note that defines -the times units. -\fCMf_trackstart\fR and -\fCMf_trackend\fR are called at the beginning and end of each track. - -Once inside a track, each separate message causes a function to be called. -For example, each note-on message causes \fCMf_noteon\fR to be called -with the channel, pitch, and volume as arguments. The time at which -the message occurred is stored in \fCMf_currtime\fR - one of the few -external variables that isn't a function pointer. The other channel messages -are handled in a similar and obvious fashion - -\fCMf_noteoff\fR, -\fCMf_pressure\fR, -\fCMf_parameter\fR, -\fCMf_pitchbend\fR, -\fCMf_program\fR, -and \fCMf_chanpressure\fR. See the declarations above for the arguments -that are passed to each. - -System exclusive messages are handled by calling \fCMf_sysex\fR, passing -as arguments the message length and a pointer to a static buffer containing -the entire message. -The buffer is expanded when necessary; memory availability is the only limit -to its size. Normally, 'continued' system exclusives are automatically -merged, and \fCMf_sysex\fR is only called once. It you want to disable this -you can set \fCMf_nomerge\fR to 1, causing \fCMf_sysex\fR to be called -once for each part of the message. - -\fCMf_seqnum\fR is called by the \fImeta\fR message that provides -a sequence number, -which if present must appear at the beginning of a track. -The tempo \fImeta\fR message causes \fCMf_tempo\fR to be called; its -argument is the number of microseconds per MIDI quarter-note (24 MIDI clocks). -The end-of-track \fImeta\fR message causes \fCMf_eot\fR to be called. -The key signature \fImeta\fR message causes \fCMf_keysig\fR to be called; -the first argument conveys the number of sharps or flats, the second -argument is 1 if the key is minor. - -The \fCMf_timesig\fR and \fCMf_smpte\fR functions are called when the -corresponding \fImeta\fR messages are seen. See the MIDI file standard -for a description of their arguments. - -The \fItext\fR messages in the MIDI file standard are of the following -types: - -.in +1i -.nf -0x01 Text Event -0x02 Copyright -0x03 Sequence/Track Name -0x04 Instrument -0x05 Lyric -0x06 Marker -0x07 Cue Point -0x08-0x0F Reserved but Undefined -.fi -.in -1i - -\fCMf_text\fR is called for each of these; the arguments are -the type number, the message length, and a pointer to the message buffer. - -Miscellaneous \fImeta\fR messages are handled by \fCMf_metamisc\fR, -sequencer-specific messages are handled by \fCMf_seqspecific\fR, and -arbitrary "escape" messages (started with 0xF7) are handled by -\fCMf_arbitrary\fR. -.SH READING EXAMPLE -The following is a \fCstrings\fR-like program for MIDI files: - -.in +1i -.ft C -.nf -#include <stdio.h> -#include <ctype.h> -#include "midifile.h" - -FILE *F; - -mygetc() { return(getc(F)); } - -mytext(type,leng,msg) -char *msg; -{ - char *p; - char *ep = msg + leng; - - for ( p=msg; p<ep ; p++ ) - putchar( isprint(*p) ? *p : '?' ); - putchar('\n'); -} - -main(argc,argv) -char **argv; -{ - if ( argc > 1 ) - F = fopen(argv[1],"r"); - else - F = stdin; - - Mf_getc = mygetc; - Mf_text = mytext; - - mfread(); - - exit(0); -} -.fi -.ft R -.in -1i -.sp -.SH WRITING STANDARD MIDI FILES -A single call to \fCmfwrite\fR will write an entire MIDI file. Before -calling \fCmfwrite\fR, you must assign values to function pointers -\fCMf_writetrack\fR and \fCMf_putc\fR. The first is a routine to -access your MIDI data structure, which can make use of other library -routines to write the actual MIDI data. The routine -\fCMf_writetrack\fR will be passed a single parameter which is the -number of the track to be written. The pointer \fCMf_putc\fR should be -set to point to a routine that accepts a character as input, writes that -character to a file, and returns the value that was written. In the -case of a format 1 file, a routine has to be written to write a tempo -map, and assigned to the function pointer \fCMf_writetempotrack\fR. -This is because format 1 files assume the first track written is a -tempo track. - -\fCmf_write_midi_event\fR and \fCmf_write_meta_event\fR are routines -that should be called from your \fCMf_writetrack\fR routine to write -out MIDI events. The delta time param is the number of ticks since the -last event. The int "type" is the type of MIDI message. The int "chan" -is the MIDI channel, which can be between 1 and 16. The char pointer -"data" points to an array containing the data bytes, if any exist. The -int "size" is the number of data bytes. - -\fCmf_sec2ticks\fR and \fCmf_ticks2sec\fR are utility routines -to help you convert between the MIDI file parameter of ticks -and the more standard seconds. The int "division" is the same -division parameter from the file header, and tempo is expressed -in microseconds per MIDI quarter-note, or "24ths of a microsecond -per MIDI clock". The division has two meanings, depending on -whether bit 15 is set or not. If bit 15 of division is zero, -bits 14 through 0 represent the number of delta-time "ticks" -which make up a quarter note. If bit 15 of division is a one, -delta-times in a file correspond to subdivisions of a second -similar to SMPTE and MIDI time code. In this format bits -14 through 8 contain one of four values \-24, \-25, \-29, or \-30, -corresponding to the four standard SMPTE and MIDI time code -frame per second formats, where \-29 represents 30 drop frame. -The second byte consisting of bits 7 through 0 corresponds -the the resolution within a frame. Refer the Standard MIDI Files -1.0 spec for more details. - -.SH WRITING EXAMPLE -The following is a simple program to demonstrate writing MIDI files. -The track would consist of a series of quarter notes from lowest to -highest in pitch at constant velocity, each separated by a quarter-note -rest. -.sp -.in +1i -.ft C -.nf -#include <stdio.h> -#include <ctype.h> -#include "midifile.h" - -FILE *fp; -myputc(c) { return(putc(c,fp));} - -int mywritetrack(track) -int track; -{ - int i; - char data[2]; - - /* 120 beats/per/second */ - mf_write_tempo((long)500000); - - for(i = 1 ; i < 128; i++){ - data[0] = i; /* note number */ - data[1] = 64; /* velocity */ - if(!mf_write_midi_event(480,note_on,1,data,2)) - return(\-1); - if(!mf_write_midi_event(480,note_off,1,data,2)) - return(\-1); - } - - return(1); -} /* end of write_track() */ - -main(argc,argv) -char **argv; -{ - if((fp = fopen(argv[1],"w")) == 0L) - exit(1); - - Mf_putc = myputc; - Mf_writetrack = mywritetrack; - - /* write a single track */ - mfwrite(0,1,480,fp); -} -.sp -.fi -.ft R -.in -1i -.sp -.SH AUTHOR -Tim Thompson (att!twitch!glimmer!tjt) -.SH CONTRIBUTORS -Michael Czeiszperger (mike@pan.com) diff --git a/alsa-lib/test/midifile.c b/alsa-lib/test/midifile.c deleted file mode 100644 index 8d6ba90..0000000 --- a/alsa-lib/test/midifile.c +++ /dev/null @@ -1,1173 +0,0 @@ -/* - * midifile 1.11 - * - * Read and write a MIDI file. Externally-assigned function pointers are - * called upon recognizing things in the file. - * - * Original release ? - * June 1989 - Added writing capability, M. Czeiszperger. - * - * The file format implemented here is called - * Standard MIDI Files, and is part of the Musical - * instrument Digital Interface specification. - * The spec is available from: - * - * International MIDI Association - * 5316 West 57th Street - * Los Angeles, CA 90056 - * - * An in-depth description of the spec can also be found - * in the article "Introducing Standard MIDI Files", published - * in Electronic Musician magazine, April, 1989. - * - * February 1993 - Minor adjustments, Greg Lee: - * (1) can now set the global variable Mf_interactive to 1 to prevent the - * reading functions from looking for file and track headers - * (2) can now write system exclusive data with - * mf_write_midi_event(delta_time, system_exclusive, 0, data, size) - * (3) changed definition of 'sequencer_specific' in midifile.h to 0x7f - * (4) changed mf_write_tempo to take additional delta_time as first argument - * (since delta need not be zero) - * (5) added function mf_write_seqnum(unsigned long delta_time, unsigned seqnum) - * (6) changed mf_write_midi_event to use running status - * (7) removed the code to write an end of track meta event automatically - * -- this must now be done by the user of the library (I changed - * it because I need to be able to control the time delta of this - * meta event) - * (8) added global variables Mf_division, Mf_currtempo, Mf_realtime, which - * are updated by the reading functions. Mf_realtime is useful, - * because Mf_currtime does not really measure time at all, since - * its units change value at every tempo change. Mf_realtime is - * the midi-time elapsed in units of 1/16 of a centisecond (but it - * does not handle SMPTE times) - * (9) maintains a history of tempo settings to update Mf_currtempo, - * to handle tempo tracks. - * (10) if there is an Mf_error function, the error routine no longer - * exits, leaving it to the application to do this. - * (11) chanmessage skips over invalid c1 command bytes > 127 and - * adjusts invalid c2 argument byte > 127 to 127. - * (12) readmt returns EOF when it encounters a 0 or 0x1a byte instead of an expected - * header string (some midi files have padding at end). - */ -#define NO_LC_DEFINES -#include "midifile.h" -#ifdef NO_LC_DEFINES -#define system_exclusive 0xf0 -#define meta_event 0xFF -#define set_tempo 0x51 -#define lowerbyte(x) ((unsigned char)(x & 0xff)) -#define upperbyte(x) ((unsigned char)((x & 0xff00)>>8)) -#endif - -#define NULLFUNC 0 -#if 0 -#define NULL 0 -#endif - -#define THINK - -#ifdef THINK -#include <stdlib.h> -#endif - -#include <stdio.h> -#include <values.h> - -#include <string.h> -/*void exit(), free();*/ - -/* public stuff */ - -/* Functions to be called while processing the MIDI file. */ -int (*Mf_getc) () = NULLFUNC; -void (*Mf_error) () = NULLFUNC; -void (*Mf_header) () = NULLFUNC; -void (*Mf_trackstart) () = NULLFUNC; -void (*Mf_trackend) () = NULLFUNC; -void (*Mf_noteon) () = NULLFUNC; -void (*Mf_noteoff) () = NULLFUNC; -void (*Mf_pressure) () = NULLFUNC; -void (*Mf_parameter) () = NULLFUNC; -void (*Mf_pitchbend) () = NULLFUNC; -void (*Mf_program) () = NULLFUNC; -void (*Mf_chanpressure) () = NULLFUNC; -void (*Mf_sysex) () = NULLFUNC; -void (*Mf_arbitrary) () = NULLFUNC; -void (*Mf_metamisc) () = NULLFUNC; -void (*Mf_seqnum) () = NULLFUNC; -void (*Mf_eot) () = NULLFUNC; -void (*Mf_smpte) () = NULLFUNC; -void (*Mf_tempo) () = NULLFUNC; -void (*Mf_timesig) () = NULLFUNC; -void (*Mf_keysig) () = NULLFUNC; -void (*Mf_seqspecific) () = NULLFUNC; -void (*Mf_text) () = NULLFUNC; - -/* Functions to implement in order to write a MIDI file */ -int (*Mf_putc) () = NULLFUNC; -int (*Mf_writetrack) () = NULLFUNC; -int (*Mf_writetempotrack) () = NULLFUNC; - -int Mf_nomerge = 0; /* 1 => continue'ed system exclusives are */ - /* not collapsed. */ -int Mf_interactive = 0; /* 1 => file and track headers are not required */ -unsigned long Mf_currtime = 0L; /* current time in delta-time units */ -unsigned long Mf_realtime = 0L; /* current time in 1/16 centisecond-time units */ -static double Mf_f_realtime = 0;/* as above, floating */ -static double old_f_realtime = 0; -int Mf_division = 96; -unsigned long Mf_currtempo = 500000; -static unsigned long old_currtempo = 500000; -static unsigned long old_realtime = 0; -static unsigned long old_currtime = 0; -static unsigned long revised_time = 0; -static unsigned long tempo_change_time = 0; - -#define MAX_HISTORY 512 -static unsigned long tempo_history[MAX_HISTORY]; -static unsigned long tempo_history_time[MAX_HISTORY]; -static int tempo_history_count = 0; - -/* private stuff */ -static long Mf_toberead = 0L; -static long Mf_numbyteswritten = 0L; - -static long readvarinum (); -static long read32bit (); -static long to32bit (); -static int read16bit (); -static int to16bit (); -static char *msg (); -static void readheader (); -static int readtrack (); -static void badbyte (); -static void metaevent (); -static void sysex (); -static void chanmessage (); -static void msginit (); -static int msgleng (); -static void msgadd (); -static void biggermsg (); -static int eputc (unsigned char c); - -double mf_ticks2sec (unsigned long ticks, int division, unsigned long tempo); -int mf_write_meta_event (); -void mf_write_tempo (); -void mf_write_seqnum (); -void WriteVarLen (); - -#ifdef READ_MODS -#include "mp_mod.c" -static int mod_file_flag = 0; -#endif /* READ_MODS */ -static int force_exit; - -void -mfread () -{ - force_exit = 0; - if (Mf_getc == NULLFUNC) - mferror ("mfread() called without setting Mf_getc"); - - readheader (); -#ifdef READ_MODS - if (mod_file_flag) - do_module(); - else -#endif - while (readtrack () && !force_exit) - ; -} - -/* for backward compatibility with the original lib */ -void -midifile () -{ - mfread (); -} - -static -int -readmt (s) /* read through the "MThd" or "MTrk" header string */ - char *s; -{ - int n = 0; - char *p = s; - int c; - - while (n++ < 4 && (c = (*Mf_getc) ()) != EOF) - { - if (c != *p++) - { - char buff[32]; - if (!c) return(EOF); - if (c == 0x1a) return(EOF); - (void) strcpy (buff, "expecting "); - (void) strcat (buff, s); - mferror (buff); - break; - } - } - return (c); -} - -static -int -egetc () /* read a single character and abort on EOF */ -{ - int c = (*Mf_getc) (); - - if (c == EOF) { - mferror ("premature EOF"); - force_exit = 1; - } - Mf_toberead--; - return (c); -} - -static -void -readheader () /* read a header chunk */ -{ - int format, ntrks, division; - - - Mf_division = 96; - Mf_currtempo = 500000; - old_currtempo = 500000; - tempo_history_count = 0; - tempo_history[tempo_history_count] = Mf_currtempo; - tempo_history_time[tempo_history_count] = 0; - - if (Mf_interactive) - { - Mf_toberead = 0; - format = 0; - ntrks = 1; - division = 96; - } - else -#ifdef READ_MODS - if (!strncmp(Mf_file_contents, "MThd", 4)) -#endif - { - if (readmt ("MThd") == EOF) - return; - - Mf_toberead = read32bit (); - format = read16bit (); - ntrks = read16bit (); - Mf_division = division = read16bit (); - } -#ifdef READ_MODS - else - { - format = 0; - ntrks = 1; - division = Mf_division; - Mf_toberead = 0; - mod_file_flag = 1; - } -#endif - - if (Mf_header) - (*Mf_header) (format, ntrks, division); - - /* flush any extra stuff, in case the length of header is not 6 */ - while (Mf_toberead > 0 && !force_exit) - (void) egetc (); -} - - -/*#define DEBUG_TIMES*/ -static -unsigned long -find_tempo() -{ - int i; - unsigned long old_tempo = Mf_currtempo; - unsigned long new_tempo = Mf_currtempo; - - for (i = 0; i <= tempo_history_count; i++) { - if (tempo_history_time[i] <= Mf_currtime) old_tempo = tempo_history[i]; - new_tempo = tempo_history[i]; - if (tempo_history_time[i] > revised_time) break; - } - if (i > tempo_history_count || tempo_history_time[i] > Mf_currtime) { -#ifdef DEBUG_TIMES -printf("[past %d, old_tempo %d]\n", tempo_history_time[i], old_tempo); -#endif - revised_time = Mf_currtime; - return(old_tempo); - } - tempo_change_time = revised_time = tempo_history_time[i]; -#ifdef DEBUG_TIMES -printf("[revised_time %d, new_tempo %d]\n", revised_time, new_tempo); -#endif - return(new_tempo); -} - -static -int -readtrack () /* read a track chunk */ -{ - /* This array is indexed by the high half of a status byte. It's */ - /* value is either the number of bytes needed (1 or 2) for a channel */ - /* message, or 0 (meaning it's not a channel message). */ - static int chantype[] = - { - 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 through 0x70 */ - 2, 2, 2, 2, 1, 1, 2, 0 /* 0x80 through 0xf0 */ - }; - long lookfor; - int c, c1, type; - int sysexcontinue = 0; /* 1 if last message was an unfinished sysex */ - int running = 0; /* 1 when running status used */ - int status = 0; /* status value (e.g. 0x90==note-on) */ - int needed; - - if (Mf_interactive) - { - Mf_toberead = MAXINT; - } - else - { - if (readmt ("MTrk") == EOF) - return (0); - - Mf_toberead = read32bit (); - } - Mf_currtime = Mf_realtime = 0; - Mf_f_realtime = old_f_realtime = 0; - old_currtime = old_realtime = 0; - Mf_currtempo = find_tempo(); - - if (Mf_trackstart) - (*Mf_trackstart) (); - - while (!force_exit && (Mf_interactive || Mf_toberead > 0)) - { - - if (Mf_interactive) - Mf_currtime += 1; - else - { - double delta_secs; - unsigned long delta_ticks = readvarinum (); - revised_time = Mf_currtime; - Mf_currtime += delta_ticks; /* delta time */ - -/* - * Step through each tempo change from old_currtime up to now, - * revising Mf_realtime after each change. - */ - - while (revised_time < Mf_currtime) { - unsigned long save_time = revised_time; - unsigned long save_tempo = Mf_currtempo; - Mf_currtempo = find_tempo(); - - if (Mf_currtempo != old_currtempo) { - old_currtempo = Mf_currtempo; - old_realtime = Mf_realtime; - if (revised_time != tempo_change_time) { - old_f_realtime = Mf_f_realtime; - old_currtime = save_time; - } - delta_secs = mf_ticks2sec (revised_time-old_currtime, Mf_division, save_tempo); -#ifdef DEBUG_TIMES -printf("d(rev %d - old %d, div %d, tempo %d) = %.3f\n", -revised_time, old_currtime, Mf_division, save_tempo, delta_secs * 1600.0); -#endif - Mf_f_realtime = old_f_realtime + delta_secs * 1600.0; - Mf_realtime = (unsigned long)(0.5 + Mf_f_realtime); -#ifdef DEBUG_TIMES -printf("\tt=%d ticks ( = %d csec/16 < old %.2f + %.2f)\n", Mf_currtime, Mf_realtime, -old_f_realtime, delta_secs * 1600.0); -#endif - if (revised_time == tempo_change_time) { - old_currtime = revised_time; - old_f_realtime = Mf_f_realtime; - } - } - else { - delta_secs = mf_ticks2sec (revised_time-old_currtime, Mf_division, Mf_currtempo); -#ifdef DEBUG_TIMES -printf("d(rev %d - old %d, div %d, tempo %d) = %.3f\n", -revised_time, old_currtime, Mf_division, Mf_currtempo, delta_secs * 1600.0); -#endif - Mf_f_realtime = old_f_realtime + delta_secs * 1600.0; - Mf_realtime = (unsigned long)(0.5 + Mf_f_realtime); -#ifdef DEBUG_TIMES -printf("\tt=%d ticks ( = %d csec/16 < old %.2f + %.2f)\n", Mf_currtime, Mf_realtime, -old_f_realtime, delta_secs * 1600.0); -#endif - } - - - } - } - - c = egetc (); - - if (sysexcontinue && c != 0xf7) - mferror ("didn't find expected continuation of a sysex"); - - if ((c & 0x80) == 0) - { /* running status? */ - if (status == 0) - mferror ("unexpected running status"); - running = 1; - } - else - { - status = c; - running = 0; - } - - needed = chantype[(status >> 4) & 0xf]; - - if (needed) - { /* ie. is it a channel message? */ - - if (running) - c1 = c; - else - c1 = egetc (); - chanmessage (status, c1, (needed > 1) ? egetc () : 0); - continue;; - } - - switch (c) - { - - case 0xff: /* meta event */ - - type = egetc (); - lookfor = Mf_toberead - readvarinum (); - msginit (); - - while (Mf_toberead > lookfor) - msgadd (egetc ()); - - metaevent (type); - break; - - case 0xf0: /* start of system exclusive */ - - lookfor = Mf_toberead - readvarinum (); - msginit (); - msgadd (0xf0); - - while (Mf_toberead > lookfor) - msgadd (c = egetc ()); - - if (c == 0xf7 || Mf_nomerge == 0) - sysex (); - else - sysexcontinue = 1; /* merge into next msg */ - break; - - case 0xf7: /* sysex continuation or arbitrary stuff */ - - lookfor = Mf_toberead - readvarinum (); - - if (!sysexcontinue) - msginit (); - - while (Mf_toberead > lookfor) - msgadd (c = egetc ()); - - if (!sysexcontinue) - { - if (Mf_arbitrary) - (*Mf_arbitrary) (msgleng (), msg ()); - } - else if (c == 0xf7) - { - sysex (); - sysexcontinue = 0; - } - break; - default: - badbyte (c); - break; - } - } - if (Mf_trackend) - (*Mf_trackend) (); - return (1); -} - -static -void -badbyte (c) - int c; -{ - char buff[32]; - - (void) sprintf (buff, "unexpected byte: 0x%02x", c); - mferror (buff); -} - -static -void -metaevent (int type) -{ - int leng = msgleng (); - char *m = msg (); - - switch (type) - { - case 0x00: - if (Mf_seqnum) - (*Mf_seqnum) (to16bit (m[0], m[1])); - break; - case 0x01: /* Text event */ - case 0x02: /* Copyright notice */ - case 0x03: /* Sequence/Track name */ - case 0x04: /* Instrument name */ - case 0x05: /* Lyric */ - case 0x06: /* Marker */ - case 0x07: /* Cue point */ - case 0x08: - case 0x09: - case 0x0a: - case 0x0b: - case 0x0c: - case 0x0d: - case 0x0e: - case 0x0f: - /* These are all text events */ - if (Mf_text) - (*Mf_text) (type, leng, m); - break; - case 0x2f: /* End of Track */ - if (Mf_eot) - (*Mf_eot) (); - break; - case 0x51: /* Set tempo */ - if (Mf_tempo) - (*Mf_tempo) (Mf_currtempo = to32bit (0, m[0], m[1], m[2])); - if (tempo_history[tempo_history_count] == Mf_currtempo) break; - if (tempo_history_time[tempo_history_count] > Mf_currtime) break; - if (tempo_history_count < MAX_HISTORY - 1) tempo_history_count++; - tempo_history[tempo_history_count] = Mf_currtempo; - tempo_history_time[tempo_history_count] = Mf_currtime; - break; - case 0x54: - if (Mf_smpte) - (*Mf_smpte) (m[0], m[1], m[2], m[3], m[4]); - break; - case 0x58: - if (Mf_timesig) - (*Mf_timesig) (m[0], m[1], m[2], m[3]); - break; - case 0x59: - if (Mf_keysig) - (*Mf_keysig) (m[0], m[1]); - break; - case 0x7f: - if (Mf_seqspecific) - (*Mf_seqspecific) (leng, m); - break; - default: - if (Mf_metamisc) - (*Mf_metamisc) (type, leng, m); - } -} - -static -void -sysex () -{ - if (Mf_sysex) - (*Mf_sysex) (msgleng (), msg ()); -} - -static -void -chanmessage (status, c1, c2) - int status; - int c1, c2; -{ - int chan = status & 0xf; - - /* I found a midi file with Mod Wheel values 128. --gl */ - - if (c1 > 127) /*mferror("chanmessage: bad c1") ??*/ return; - if (c2 > 127) c2 = 127; - - switch (status & 0xf0) - { - case 0x80: - if (Mf_noteoff) - (*Mf_noteoff) (chan, c1, c2); - break; - case 0x90: - if (Mf_noteon) - (*Mf_noteon) (chan, c1, c2); - break; - case 0xa0: - if (Mf_pressure) - (*Mf_pressure) (chan, c1, c2); - break; - case 0xb0: - if (Mf_parameter) - (*Mf_parameter) (chan, c1, c2); - break; - case 0xe0: - if (Mf_pitchbend) - (*Mf_pitchbend) (chan, c1, c2); - break; - case 0xc0: - if (Mf_program) - (*Mf_program) (chan, c1); - break; - case 0xd0: - if (Mf_chanpressure) - (*Mf_chanpressure) (chan, c1); - break; - } -} - -/* readvarinum - read a varying-length number, and return the */ -/* number of characters it took. */ - -static long -readvarinum () -{ - long value; - int c; - - c = egetc (); - value = c; - if (c & 0x80) - { - value &= 0x7f; - do - { - c = egetc (); - value = (value << 7) + (c & 0x7f); - } - while (c & 0x80); - } - return (value); -} - -static long -to32bit (int c1, int c2, int c3, int c4) -{ - long value = 0L; - - value = (c1 & 0xff); - value = (value << 8) + (c2 & 0xff); - value = (value << 8) + (c3 & 0xff); - value = (value << 8) + (c4 & 0xff); - return (value); -} - -static int -to16bit (c1, c2) - int c1, c2; -{ - return ((c1 & 0xff) << 8) + (c2 & 0xff); -} - -static long -read32bit () -{ - int c1, c2, c3, c4; - - c1 = egetc (); - c2 = egetc (); - c3 = egetc (); - c4 = egetc (); - return to32bit (c1, c2, c3, c4); -} - -static int -read16bit () -{ - int c1, c2; - c1 = egetc (); - c2 = egetc (); - return to16bit (c1, c2); -} - -/* static */ -void -mferror (s) - char *s; -{ - if (Mf_error) - (*Mf_error) (s); - else exit (1); -} - -/* The code below allows collection of a system exclusive message of */ -/* arbitrary length. The Msgbuff is expanded as necessary. The only */ -/* visible data/routines are msginit(), msgadd(), msg(), msgleng(). */ - -#define MSGINCREMENT 128 -static char *Msgbuff = NULL; /* message buffer */ -static int Msgsize = 0; /* Size of currently allocated Msg */ -static int Msgindex = 0; /* index of next available location in Msg */ - -static -void -msginit () -{ - Msgindex = 0; -} - -static char * -msg () -{ - return (Msgbuff); -} - -static -int -msgleng () -{ - return (Msgindex); -} - -static -void -msgadd (c) - int c; -{ - /* If necessary, allocate larger message buffer. */ - if (Msgindex >= Msgsize) - biggermsg (); - Msgbuff[Msgindex++] = c; -} - -static -void -biggermsg () -{ -/* char *malloc(); */ - char *newmess; - char *oldmess = Msgbuff; - int oldleng = Msgsize; - - Msgsize += MSGINCREMENT; - newmess = (char *) malloc ((unsigned) (sizeof (char) * Msgsize)); - - if (newmess == NULL) - mferror ("malloc error!"); - - /* copy old message into larger new one */ - if (oldmess != NULL) - { - register char *p = newmess; - register char *q = oldmess; - register char *endq = &oldmess[oldleng]; - - for (; q != endq; p++, q++) - *p = *q; - free (oldmess); - } - Msgbuff = newmess; -} - -static int laststatus = 0; - -/* - * mfwrite() - The only function you'll need to call to write out - * a midi file. - * - * format 0 - Single multi-channel track - * 1 - Multiple simultaneous tracks - * 2 - One or more sequentially independent - * single track patterns - * ntracks The number of tracks in the file. - * division This is kind of tricky, it can represent two - * things, depending on whether it is positive or negative - * (bit 15 set or not). If bit 15 of division is zero, - * bits 14 through 0 represent the number of delta-time - * "ticks" which make up a quarter note. If bit 15 of - * division is a one, delta-times in a file correspond to - * subdivisions of a second similar to SMPTE and MIDI - * time code. In this format bits 14 through 8 contain - * one of four values - 24, -25, -29, or -30, - * corresponding to the four standard SMPTE and MIDI - * time code frame per second formats, where -29 - * represents 30 drop frame. The second byte - * consisting of bits 7 through 0 corresponds the the - * resolution within a frame. Refer the Standard MIDI - * Files 1.0 spec for more details. - * fp This should be the open file pointer to the file you - * want to write. It will have be a global in order - * to work with Mf_putc. - */ -void -mfwrite (format, ntracks, division, fp) - int format, ntracks, division; - FILE *fp; -{ - int i; - void mf_write_track_chunk (), mf_write_header_chunk (); - - if (Mf_putc == NULLFUNC) - mferror ("mfmf_write() called without setting Mf_putc"); - - if (Mf_writetrack == NULLFUNC) - mferror ("mfmf_write() called without setting Mf_mf_writetrack"); - - laststatus = 0; - - /* every MIDI file starts with a header */ - mf_write_header_chunk (format, ntracks, division); - - laststatus = 0; - - /* In format 1 files, the first track is a tempo map */ - if (format == 1 && (Mf_writetempotrack)) - { - (*Mf_writetempotrack) (); - } - - /* The rest of the file is a series of tracks */ - for (i = 0; i < ntracks; i++) - mf_write_track_chunk (i, fp); -} - -void -mf_write_track_chunk (which_track, fp) - int which_track; - FILE *fp; -{ - unsigned long trkhdr, trklength; - long offset, place_marker; - void write16bit (), write32bit (); - - - laststatus = 0; - - trkhdr = MTrk; - trklength = 0; - - /* Remember where the length was written, because we don't - know how long it will be until we've finished writing */ - offset = ftell (fp); - -#ifdef DEBUG - printf ("offset = %d\n", (int) offset); -#endif - - /* Write the track chunk header */ - write32bit (trkhdr); - write32bit (trklength); - - Mf_numbyteswritten = 0L; /* the header's length doesn't count */ - - if (Mf_writetrack) - { - (*Mf_writetrack) (which_track); - } - - /* mf_write End of track meta event */ -/* but this does not necessarily have a delta of 0, so - * I don't want to do it -- leave it up to the user of the - * library functions to do - * --gl - eputc(0); - eputc(laststatus = meta_event); - eputc(end_of_track); - - eputc(0); - */ - - /* It's impossible to know how long the track chunk will be beforehand, - so the position of the track length data is kept so that it can - be written after the chunk has been generated */ - place_marker = ftell (fp); - - /* This method turned out not to be portable because the - parameter returned from ftell is not guaranteed to be - in bytes on every machine */ - /* track.length = place_marker - offset - (long) sizeof(track); */ - -#ifdef DEBUG - printf ("length = %d\n", (int) trklength); -#endif - - if (fseek (fp, offset, 0) < 0) - mferror ("error seeking during final stage of write"); - - trklength = Mf_numbyteswritten; - - /* Re-mf_write the track chunk header with right length */ - write32bit (trkhdr); - write32bit (trklength); - - fseek (fp, place_marker, 0); -} /* End gen_track_chunk() */ - - -void -mf_write_header_chunk (format, ntracks, division) - int format, ntracks, division; -{ - unsigned long ident, length; - void write16bit (), write32bit (); - - ident = MThd; /* Head chunk identifier */ - length = 6; /* Chunk length */ - - /* individual bytes of the header must be written separately - to preserve byte order across cpu types :-( */ - write32bit (ident); - write32bit (length); - write16bit (format); - write16bit (ntracks); - write16bit (division); -} /* end gen_header_chunk() */ - - -/* - * mf_write_midi_event() - * - * Library routine to mf_write a single MIDI track event in the standard MIDI - * file format. The format is: - * - * <delta-time><event> - * - * In this case, event can be any multi-byte midi message, such as - * "note on", "note off", etc. - * - * delta_time - the time in ticks since the last event. - * type - the type of meta event. - * chan - The midi channel. - * data - A pointer to a block of chars containing the META EVENT, - * data. - * size - The length of the meta-event data. - */ -int -mf_write_midi_event (delta_time, type, chan, data, size) - unsigned long delta_time; - int chan, type; - unsigned long size; - char *data; -{ - int i; - unsigned char c; - - WriteVarLen (delta_time); - - /* all MIDI events start with the type in the first four bits, - and the channel in the lower four bits */ - if (type == system_exclusive || type == 0xf7) - { - c = type; - laststatus = 0; - } - else - c = type | chan; - - if (chan > 15) - perror ("error: MIDI channel greater than 16\n"); - - if (laststatus != c) - eputc (laststatus = c); - - if (type == system_exclusive || type == 0xf7) - WriteVarLen (size); - - /* write out the data bytes */ - for (i = 0; i < (int)size; i++) - eputc (data[i]); - - return (size); -} /* end mf_write MIDI event */ - -/* - * mf_write_meta_event() - * - * Library routine to mf_write a single meta event in the standard MIDI - * file format. The format of a meta event is: - * - * <delta-time><FF><type><length><bytes> - * - * delta_time - the time in ticks since the last event. - * type - the type of meta event. - * data - A pointer to a block of chars containing the META EVENT, - * data. - * size - The length of the meta-event data. - */ -int -mf_write_meta_event (delta_time, type, data, size) - unsigned long delta_time; - unsigned char *data, type; - unsigned long size; -{ - int i; - - WriteVarLen (delta_time); - - /* This marks the fact we're writing a meta-event */ - eputc (laststatus = meta_event); - - /* The type of meta event */ - eputc (type); - - /* The length of the data bytes to follow */ - WriteVarLen (size); - - for (i = 0; i < (int)size; i++) - { - if (eputc (data[i]) != data[i]) - return (-1); - } - return (size); -} /* end mf_write_meta_event */ - -void -mf_write_tempo (delta_time, tempo) - unsigned long delta_time; - unsigned long tempo; -{ - /* Write tempo */ - /* all tempos are written as 120 beats/minute, */ - /* expressed in microseconds/quarter note */ - - WriteVarLen (delta_time); - eputc (laststatus = meta_event); - eputc (set_tempo); - - eputc (3); - eputc ((unsigned) (0xff & (tempo >> 16))); - eputc ((unsigned) (0xff & (tempo >> 8))); - eputc ((unsigned) (0xff & tempo)); -} - -void -mf_write_seqnum (delta_time, seqnum) - unsigned long delta_time; - unsigned seqnum; -{ - - WriteVarLen (delta_time); - eputc (laststatus = meta_event); - eputc (0); - - eputc ((unsigned) (0xff & (seqnum >> 8))); - eputc ((unsigned) (0xff & seqnum)); -} - -unsigned long -mf_sec2ticks (secs, division, tempo) - int division; - unsigned long tempo; - double secs; -{ - return (unsigned long) (((secs * 1000.0) / 4.0 * division) / tempo); -} - -/* - * Write multi-length bytes to MIDI format files - */ -void -WriteVarLen (value) - unsigned long value; -{ - unsigned long buffer; - - buffer = value & 0x7f; - while ((value >>= 7) > 0) - { - buffer <<= 8; - buffer |= 0x80; - buffer += (value & 0x7f); - } - while (1) - { - eputc ((unsigned) (buffer & 0xff)); - - if (buffer & 0x80) - buffer >>= 8; - else - return; - } -} /* end of WriteVarLen */ - -/* - * This routine converts delta times in ticks into seconds. The - * else statement is needed because the formula is different for tracks - * based on notes and tracks based on SMPTE times. - * - */ -double -mf_ticks2sec (ticks, division, tempo) - int division; - unsigned long tempo; - unsigned long ticks; -{ - double smpte_format, smpte_resolution; - - if (division > 0) - return ((double) (((double) (ticks) * (double) (tempo)) / ((double) (division) * 1000000.0))); - else - { - smpte_format = upperbyte (division); - smpte_resolution = lowerbyte (division); - return (double) ((double) ticks / (smpte_format * smpte_resolution * 1000000.0)); - } -} /* end of ticks2sec() */ - - -/* - * write32bit() - * write16bit() - * - * These routines are used to make sure that the byte order of - * the various data types remains constant between machines. This - * helps make sure that the code will be portable from one system - * to the next. It is slightly dangerous that it assumes that longs - * have at least 32 bits and ints have at least 16 bits, but this - * has been true at least on PCs, UNIX machines, and Macintosh's. - * - */ -void -write32bit (data) - unsigned long data; -{ - eputc ((unsigned) ((data >> 24) & 0xff)); - eputc ((unsigned) ((data >> 16) & 0xff)); - eputc ((unsigned) ((data >> 8) & 0xff)); - eputc ((unsigned) (data & 0xff)); -} - -void -write16bit (data) - int data; -{ - eputc ((unsigned) ((data & 0xff00) >> 8)); - eputc ((unsigned) (data & 0xff)); -} - -/* write a single character and abort on error */ -static int -eputc (c) - unsigned char c; -{ - int return_val; - - if ((Mf_putc) == NULLFUNC) - { - mferror ("Mf_putc undefined"); - return (-1); - } - - return_val = (*Mf_putc) (c); - - if (return_val == EOF) - mferror ("error writing"); - - Mf_numbyteswritten++; - return (return_val); -} diff --git a/alsa-lib/test/midifile.h b/alsa-lib/test/midifile.h deleted file mode 100644 index 7dd4626..0000000 --- a/alsa-lib/test/midifile.h +++ /dev/null @@ -1,132 +0,0 @@ -/* definitions for MIDI file parsing code */ -extern int (*Mf_getc)(); -extern void (*Mf_header)(); -extern void (*Mf_trackstart)(); -extern void (*Mf_trackend)(); -extern void (*Mf_noteon)(); -extern void (*Mf_noteoff)(); -extern void (*Mf_pressure)(); -extern void (*Mf_parameter)(); -extern void (*Mf_pitchbend)(); -extern void (*Mf_program)(); -extern void (*Mf_chanpressure)(); -extern void (*Mf_sysex)(); -extern void (*Mf_metamisc)(); -extern void (*Mf_seqspecific)(); -extern void (*Mf_seqnum)(); -extern void (*Mf_text)(); -extern void (*Mf_eot)(); -extern void (*Mf_timesig)(); -extern void (*Mf_smpte)(); -extern void (*Mf_tempo)(); -extern void (*Mf_keysig)(); -extern void (*Mf_arbitrary)(); -extern void (*Mf_error)(); -extern unsigned long Mf_currtime; -extern unsigned long Mf_realtime; -extern unsigned long Mf_currtempo; -extern int Mf_division; -extern int Mf_nomerge; -#ifdef READ_MODS -extern unsigned char *Mf_file_contents; -extern int Mf_file_size; -#endif - -/* definitions for MIDI file writing code */ -extern int (*Mf_putc)(); -extern int (*Mf_writetrack)(); -extern int (*Mf_writetempotrack)(); - -extern void midifile(); -extern unsigned long mf_sec2ticks(); -extern void mfwrite(); -extern int mf_write_meta_event(); -extern int mf_write_midi_event(unsigned long delta_time, int type, - int chan, char *data, unsigned long size); -extern double mf_ticks2sec(unsigned long ticks,int division,unsigned long tempo); -extern void mf_write_tempo(); -extern void mf_write_seqnum(); -extern void mfread(); -extern void mferror(char *s); - -#ifndef NO_LC_DEFINES -/* MIDI status commands most significant bit is 1 */ -#define note_off 0x80 -#define note_on 0x90 -#define poly_aftertouch 0xa0 -#define control_change 0xb0 -#define program_chng 0xc0 -#define channel_aftertouch 0xd0 -#define pitch_wheel 0xe0 -#define system_exclusive 0xf0 -#define delay_packet (1111) - -/* 7 bit controllers */ -#define damper_pedal 0x40 -#define portamento 0x41 -#define sustenuto 0x42 -#define soft_pedal 0x43 -#define general_4 0x44 -#define hold_2 0x45 -#define general_5 0x50 -#define general_6 0x51 -#define general_7 0x52 -#define general_8 0x53 -#ifndef PLAYMIDI -#define tremolo_depth 0x5c -#define ctrl_chorus_depth 0x5d -#define detune 0x5e -#define phaser_depth 0x5f -#endif - -/* parameter values */ -#define data_inc 0x60 -#define data_dec 0x61 - -/* parameter selection */ -#define non_reg_lsb 0x62 -#define non_reg_msb 0x63 -#define reg_lsb 0x64 -#define reg_msb 0x65 - -/* Standard MIDI Files meta event definitions */ -#define meta_event 0xFF -#define sequence_number 0x00 -#define text_event 0x01 -#define copyright_notice 0x02 -#define sequence_name 0x03 -#define instrument_name 0x04 -#define lyric 0x05 -#define marker 0x06 -#define cue_point 0x07 -#define channel_prefix 0x20 -#define end_of_track 0x2f -#define set_tempo 0x51 -#define smpte_offset 0x54 -#define time_signature 0x58 -#define key_signature 0x59 -#define sequencer_specific 0x74 - -/* Manufacturer's ID number */ -#define Seq_Circuits (0x01) /* Sequential Circuits Inc. */ -#define Big_Briar (0x02) /* Big Briar Inc. */ -#define Octave (0x03) /* Octave/Plateau */ -#define Moog (0x04) /* Moog Music */ -#define Passport (0x05) /* Passport Designs */ -#define Lexicon (0x06) /* Lexicon */ -#define Tempi (0x20) /* Bon Tempi */ -#define Siel (0x21) /* S.I.E.L. */ -#define Kawai (0x41) -#define Roland (0x42) -#define Korg (0x42) -#define Yamaha (0x43) -#endif - -/* miscellaneous definitions */ -#define MThd 0x4d546864 -#define MTrk 0x4d54726b - -#ifndef NO_LC_DEFINES -#define lowerbyte(x) ((unsigned char)(x & 0xff)) -#define upperbyte(x) ((unsigned char)((x & 0xff00)>>8)) -#endif diff --git a/alsa-lib/test/midiloop.c b/alsa-lib/test/midiloop.c deleted file mode 100644 index 31fbcd3..0000000 --- a/alsa-lib/test/midiloop.c +++ /dev/null @@ -1,190 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> -#include <ctype.h> -#include <sys/time.h> -#include "../include/asoundlib.h" -#include <string.h> -#include <signal.h> - -static void usage(void) -{ - fprintf(stderr, "Usage: midiloop [options]\n"); - fprintf(stderr, " options:\n"); - fprintf(stderr, " -v: verbose mode\n"); - fprintf(stderr, " -i <rawmidi device> : test input device\n"); - fprintf(stderr, " -o <rawmidi device> : test output device\n"); -} - -int stop = 0; - -void sighandler(int dummy ATTRIBUTE_UNUSED) -{ - stop=1; -} - -long long timediff(struct timeval t1, struct timeval t2) -{ - signed long l; - - t1.tv_sec -= t2.tv_sec; - l = (signed long) t1.tv_usec - (signed long) t2.tv_usec; - if (l < 0) { - t1.tv_sec--; - l = -l; - l %= 1000000; - } - return ((long long)t1.tv_sec * (long long)1000000) + (long long)l; -} - -int writepattern(snd_rawmidi_t *handle_out, unsigned char *obuf) -{ - int patsize, i; - - patsize = 0; - for (i = 0; i < 15; i++) { - obuf[patsize++] = 0x90 + i; - obuf[patsize++] = 0x40; - obuf[patsize++] = 0x3f; - obuf[patsize++] = 0xb0 + i; - obuf[patsize++] = 0x2e; - obuf[patsize++] = 0x7a; - obuf[patsize++] = 0x80 + i; - obuf[patsize++] = 0x23; - obuf[patsize++] = 0x24; - obuf[patsize++] = 0xf0; - obuf[patsize++] = i; - obuf[patsize++] = 0xf7; - } - i = snd_rawmidi_write(handle_out, obuf, patsize); - if (i != patsize) { - printf("Written only %i bytes from %i bytes\n", i, patsize); - exit(EXIT_FAILURE); - } - return patsize; -} - -int main(int argc, char** argv) -{ - int i, j, k, opos, ipos, patsize; - int err; - int verbose = 0; - snd_rawmidi_t *handle_in = NULL, *handle_out = NULL; - unsigned char ibuf[512], obuf[512]; - char *iname = "hw:0,0", *oname = "hw:0,0"; - struct timeval start, end; - long long diff; - snd_rawmidi_status_t *istat, *ostat; - - for (i = 1 ; i<argc ; i++) { - if (argv[i][0]=='-') { - if (!strcmp(argv[i], "--help")) { - usage(); - return 0; - } - switch (argv[i][1]) { - case 'h': - usage(); - return 0; - case 'v': - verbose = 1; - break; - case 'i': - if (i + 1 < argc) - iname = argv[++i]; - break; - case 'o': - if (i + 1 < argc) - oname = argv[++i]; - break; - } - } - } - - if (iname == NULL) - iname = oname; - if (oname == NULL) - oname = iname; - - if (verbose) { - fprintf(stderr, "Using: \n"); - fprintf(stderr, " Input: %s Output: %s\n", iname, oname); - } - - err = snd_rawmidi_open(&handle_in, NULL, iname, SND_RAWMIDI_NONBLOCK); - if (err) { - fprintf(stderr,"snd_rawmidi_open %s failed: %d\n",iname,err); - exit(EXIT_FAILURE); - } - - err = snd_rawmidi_open(NULL, &handle_out, oname, 0); - if (err) { - fprintf(stderr,"snd_rawmidi_open %s failed: %d\n",oname,err); - exit(EXIT_FAILURE); - } - - signal(SIGINT, sighandler); - - i = snd_rawmidi_read(handle_in, ibuf, sizeof(ibuf)); - if (i > 0) { - printf("Read ahead: %i\n", i); - for (j = 0; j < i; j++) - printf("%02x:", ibuf[j]); - printf("\n"); - exit(EXIT_FAILURE); - } - - snd_rawmidi_nonblock(handle_in, 0); - - patsize = writepattern(handle_out, obuf); - gettimeofday(&start, NULL); - patsize = writepattern(handle_out, obuf); - - k = ipos = opos = err = 0; - while (!stop) { - i = snd_rawmidi_read(handle_in, ibuf, sizeof(ibuf)); - for (j = 0; j < i; j++, ipos++) - if (obuf[k] != ibuf[j]) { - printf("ipos = %i, i[0x%x] != o[0x%x]\n", ipos, ibuf[j], obuf[k]); - if (opos > 0) - stop = 1; - } else { - printf("match success: ipos = %i, opos = %i [%i:0x%x]\n", ipos, opos, k, obuf[k]); - k++; opos++; - if (k >= patsize) { - patsize = writepattern(handle_out, obuf); - k = 0; - } - } - } - - gettimeofday(&end, NULL); - - printf("End...\n"); - - snd_rawmidi_status_alloca(&istat); - snd_rawmidi_status_alloca(&ostat); - err = snd_rawmidi_status(handle_in, istat); - if (err < 0) - fprintf(stderr, "input stream status error: %d\n", err); - err = snd_rawmidi_status(handle_out, ostat); - if (err < 0) - fprintf(stderr, "output stream status error: %d\n", err); - printf("input.status.avail = %i\n", snd_rawmidi_status_get_avail(istat)); - printf("input.status.xruns = %i\n", snd_rawmidi_status_get_xruns(istat)); - printf("output.status.avail = %i\n", snd_rawmidi_status_get_avail(ostat)); - printf("output.status.xruns = %i\n", snd_rawmidi_status_get_xruns(ostat)); - - diff = timediff(end, start); - printf("Time diff: %Liusec (%Li bytes/sec)\n", diff, ((long long)opos * 1000000) / diff); - - if (verbose) { - fprintf(stderr,"Closing\n"); - } - - snd_rawmidi_drain(handle_in); - snd_rawmidi_close(handle_in); - snd_rawmidi_drain(handle_out); - snd_rawmidi_close(handle_out); - - return 0; -} diff --git a/alsa-lib/test/namehint.c b/alsa-lib/test/namehint.c deleted file mode 100644 index e978d5c..0000000 --- a/alsa-lib/test/namehint.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "../include/asoundlib.h" -#include <err.h> - -int main(int argc, char *argv[]) -{ - const char *iface = "pcm"; - char **hints, **n; - int err; - - if (argc > 1) - iface = argv[1]; - err = snd_device_name_hint(-1, iface, &hints); - if (err < 0) - errx(1, "snd_device_name_hint error: %s", snd_strerror(err)); - n = hints; - while (*n != NULL) { - printf("%s\n", *n); - n++; - } - snd_device_name_free_hint(hints); - return 0; -} diff --git a/alsa-lib/test/oldapi.c b/alsa-lib/test/oldapi.c deleted file mode 100644 index e325f4c..0000000 --- a/alsa-lib/test/oldapi.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Old PCM API compilation test - * - * Author: Jaroslav Kysela <perex@perex.cz> - * - * - * 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 <sched.h> -#include <errno.h> -#include <getopt.h> -#define ALSA_PCM_OLD_HW_PARAMS_API -#define ALSA_PCM_OLD_SW_PARAMS_API -#include "../include/asoundlib.h" -#include <sys/time.h> - -typedef void (myfcn)(void *); - -int main(int argc ATTRIBUTE_UNUSED, char *argv[] ATTRIBUTE_UNUSED) -{ - myfcn *fcn; - snd_pcm_hw_params_get_access(NULL); - fcn = &snd_pcm_hw_params_get_access; - return 0; -} diff --git a/alsa-lib/test/pcm.c b/alsa-lib/test/pcm.c deleted file mode 100644 index ee27422..0000000 --- a/alsa-lib/test/pcm.c +++ /dev/null @@ -1,902 +0,0 @@ -/* - * This small demo sends a simple sinusoidal wave to your speakers. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sched.h> -#include <errno.h> -#include <getopt.h> -#include "../include/asoundlib.h" -#include <sys/time.h> -#include <math.h> - -static char *device = "plughw:0,0"; /* playback device */ -static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */ -static unsigned int rate = 44100; /* stream rate */ -static unsigned int channels = 1; /* count of channels */ -static unsigned int buffer_time = 500000; /* ring buffer length in us */ -static unsigned int period_time = 100000; /* period time in us */ -static double freq = 440; /* sinusoidal wave frequency in Hz */ -static int verbose = 0; /* verbose flag */ -static int resample = 1; /* enable alsa-lib resampling */ -static int period_event = 0; /* produce poll event after each period */ - -static snd_pcm_sframes_t buffer_size; -static snd_pcm_sframes_t period_size; -static snd_output_t *output = NULL; - -static void generate_sine(const snd_pcm_channel_area_t *areas, - snd_pcm_uframes_t offset, - int count, double *_phase) -{ - static double max_phase = 2. * M_PI; - double phase = *_phase; - double step = max_phase*freq/(double)rate; - double res; - unsigned char *samples[channels], *tmp; - int steps[channels]; - unsigned int chn, byte; - union { - int i; - unsigned char c[4]; - } ires; - unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1; - int bps = snd_pcm_format_width(format) / 8; /* bytes per sample */ - - /* verify and prepare the contents of areas */ - for (chn = 0; chn < channels; chn++) { - if ((areas[chn].first % 8) != 0) { - printf("areas[%i].first == %i, aborting...\n", chn, areas[chn].first); - exit(EXIT_FAILURE); - } - samples[chn] = /*(signed short *)*/(((unsigned char *)areas[chn].addr) + (areas[chn].first / 8)); - if ((areas[chn].step % 16) != 0) { - printf("areas[%i].step == %i, aborting...\n", chn, areas[chn].step); - exit(EXIT_FAILURE); - } - steps[chn] = areas[chn].step / 8; - samples[chn] += offset * steps[chn]; - } - /* fill the channel areas */ - while (count-- > 0) { - res = sin(phase) * maxval; - ires.i = res; - tmp = ires.c; - for (chn = 0; chn < channels; chn++) { - for (byte = 0; byte < (unsigned int)bps; byte++) - *(samples[chn] + byte) = tmp[byte]; - samples[chn] += steps[chn]; - } - phase += step; - if (phase >= max_phase) - phase -= max_phase; - } - *_phase = phase; -} - -static int set_hwparams(snd_pcm_t *handle, - snd_pcm_hw_params_t *params, - snd_pcm_access_t access) -{ - unsigned int rrate; - snd_pcm_uframes_t size; - int err, dir; - - /* choose all parameters */ - err = snd_pcm_hw_params_any(handle, params); - if (err < 0) { - printf("Broken configuration for playback: no configurations available: %s\n", snd_strerror(err)); - return err; - } - /* set hardware resampling */ - err = snd_pcm_hw_params_set_rate_resample(handle, params, resample); - if (err < 0) { - printf("Resampling setup failed for playback: %s\n", snd_strerror(err)); - return err; - } - /* set the interleaved read/write format */ - err = snd_pcm_hw_params_set_access(handle, params, access); - if (err < 0) { - printf("Access type not available for playback: %s\n", snd_strerror(err)); - return err; - } - /* set the sample format */ - err = snd_pcm_hw_params_set_format(handle, params, format); - if (err < 0) { - printf("Sample format not available for playback: %s\n", snd_strerror(err)); - return err; - } - /* set the count of channels */ - err = snd_pcm_hw_params_set_channels(handle, params, channels); - if (err < 0) { - printf("Channels count (%i) not available for playbacks: %s\n", channels, snd_strerror(err)); - return err; - } - /* set the stream rate */ - rrate = rate; - err = snd_pcm_hw_params_set_rate_near(handle, params, &rrate, 0); - if (err < 0) { - printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err)); - return err; - } - if (rrate != rate) { - printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err); - return -EINVAL; - } - /* set the buffer time */ - err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, &dir); - if (err < 0) { - printf("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err)); - return err; - } - err = snd_pcm_hw_params_get_buffer_size(params, &size); - if (err < 0) { - printf("Unable to get buffer size for playback: %s\n", snd_strerror(err)); - return err; - } - buffer_size = size; - /* set the period time */ - err = snd_pcm_hw_params_set_period_time_near(handle, params, &period_time, &dir); - if (err < 0) { - printf("Unable to set period time %i for playback: %s\n", period_time, snd_strerror(err)); - return err; - } - err = snd_pcm_hw_params_get_period_size(params, &size, &dir); - if (err < 0) { - printf("Unable to get period size for playback: %s\n", snd_strerror(err)); - return err; - } - period_size = size; - /* write the parameters to device */ - err = snd_pcm_hw_params(handle, params); - if (err < 0) { - printf("Unable to set hw params for playback: %s\n", snd_strerror(err)); - return err; - } - return 0; -} - -static int set_swparams(snd_pcm_t *handle, snd_pcm_sw_params_t *swparams) -{ - int err; - - /* get the current swparams */ - err = snd_pcm_sw_params_current(handle, swparams); - if (err < 0) { - printf("Unable to determine current swparams for playback: %s\n", snd_strerror(err)); - return err; - } - /* start the transfer when the buffer is almost full: */ - /* (buffer_size / avail_min) * avail_min */ - err = snd_pcm_sw_params_set_start_threshold(handle, swparams, (buffer_size / period_size) * period_size); - if (err < 0) { - printf("Unable to set start threshold mode for playback: %s\n", snd_strerror(err)); - return err; - } - /* allow the transfer when at least period_size samples can be processed */ - /* or disable this mechanism when period event is enabled (aka interrupt like style processing) */ - err = snd_pcm_sw_params_set_avail_min(handle, swparams, period_event ? buffer_size : period_size); - if (err < 0) { - printf("Unable to set avail min for playback: %s\n", snd_strerror(err)); - return err; - } - /* enable period events when requested */ - if (period_event) { - err = snd_pcm_sw_params_set_period_event(handle, swparams, 1); - if (err < 0) { - printf("Unable to set period event: %s\n", snd_strerror(err)); - return err; - } - } - /* write the parameters to the playback device */ - err = snd_pcm_sw_params(handle, swparams); - if (err < 0) { - printf("Unable to set sw params for playback: %s\n", snd_strerror(err)); - return err; - } - return 0; -} - -/* - * Underrun and suspend recovery - */ - -static int xrun_recovery(snd_pcm_t *handle, int err) -{ - if (verbose) - printf("stream recovery\n"); - if (err == -EPIPE) { /* under-run */ - err = snd_pcm_prepare(handle); - if (err < 0) - printf("Can't recovery from underrun, prepare failed: %s\n", snd_strerror(err)); - return 0; - } else if (err == -ESTRPIPE) { - while ((err = snd_pcm_resume(handle)) == -EAGAIN) - sleep(1); /* wait until the suspend flag is released */ - if (err < 0) { - err = snd_pcm_prepare(handle); - if (err < 0) - printf("Can't recovery from suspend, prepare failed: %s\n", snd_strerror(err)); - } - return 0; - } - return err; -} - -/* - * Transfer method - write only - */ - -static int write_loop(snd_pcm_t *handle, - signed short *samples, - snd_pcm_channel_area_t *areas) -{ - double phase = 0; - signed short *ptr; - int err, cptr; - - while (1) { - generate_sine(areas, 0, period_size, &phase); - ptr = samples; - cptr = period_size; - while (cptr > 0) { - err = snd_pcm_writei(handle, ptr, cptr); - if (err == -EAGAIN) - continue; - if (err < 0) { - if (xrun_recovery(handle, err) < 0) { - printf("Write error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - break; /* skip one period */ - } - ptr += err * channels; - cptr -= err; - } - } -} - -/* - * Transfer method - write and wait for room in buffer using poll - */ - -static int wait_for_poll(snd_pcm_t *handle, struct pollfd *ufds, unsigned int count) -{ - unsigned short revents; - - while (1) { - poll(ufds, count, -1); - snd_pcm_poll_descriptors_revents(handle, ufds, count, &revents); - if (revents & POLLERR) - return -EIO; - if (revents & POLLOUT) - return 0; - } -} - -static int write_and_poll_loop(snd_pcm_t *handle, - signed short *samples, - snd_pcm_channel_area_t *areas) -{ - struct pollfd *ufds; - double phase = 0; - signed short *ptr; - int err, count, cptr, init; - - count = snd_pcm_poll_descriptors_count (handle); - if (count <= 0) { - printf("Invalid poll descriptors count\n"); - return count; - } - - ufds = malloc(sizeof(struct pollfd) * count); - if (ufds == NULL) { - printf("No enough memory\n"); - return -ENOMEM; - } - if ((err = snd_pcm_poll_descriptors(handle, ufds, count)) < 0) { - printf("Unable to obtain poll descriptors for playback: %s\n", snd_strerror(err)); - return err; - } - - init = 1; - while (1) { - if (!init) { - err = wait_for_poll(handle, ufds, count); - if (err < 0) { - if (snd_pcm_state(handle) == SND_PCM_STATE_XRUN || - snd_pcm_state(handle) == SND_PCM_STATE_SUSPENDED) { - err = snd_pcm_state(handle) == SND_PCM_STATE_XRUN ? -EPIPE : -ESTRPIPE; - if (xrun_recovery(handle, err) < 0) { - printf("Write error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - init = 1; - } else { - printf("Wait for poll failed\n"); - return err; - } - } - } - - generate_sine(areas, 0, period_size, &phase); - ptr = samples; - cptr = period_size; - while (cptr > 0) { - err = snd_pcm_writei(handle, ptr, cptr); - if (err < 0) { - if (xrun_recovery(handle, err) < 0) { - printf("Write error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - init = 1; - break; /* skip one period */ - } - if (snd_pcm_state(handle) == SND_PCM_STATE_RUNNING) - init = 0; - ptr += err * channels; - cptr -= err; - if (cptr == 0) - break; - /* it is possible, that the initial buffer cannot store */ - /* all data from the last period, so wait awhile */ - err = wait_for_poll(handle, ufds, count); - if (err < 0) { - if (snd_pcm_state(handle) == SND_PCM_STATE_XRUN || - snd_pcm_state(handle) == SND_PCM_STATE_SUSPENDED) { - err = snd_pcm_state(handle) == SND_PCM_STATE_XRUN ? -EPIPE : -ESTRPIPE; - if (xrun_recovery(handle, err) < 0) { - printf("Write error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - init = 1; - } else { - printf("Wait for poll failed\n"); - return err; - } - } - } - } -} - -/* - * Transfer method - asynchronous notification - */ - -struct async_private_data { - signed short *samples; - snd_pcm_channel_area_t *areas; - double phase; -}; - -static void async_callback(snd_async_handler_t *ahandler) -{ - snd_pcm_t *handle = snd_async_handler_get_pcm(ahandler); - struct async_private_data *data = snd_async_handler_get_callback_private(ahandler); - signed short *samples = data->samples; - snd_pcm_channel_area_t *areas = data->areas; - snd_pcm_sframes_t avail; - int err; - - avail = snd_pcm_avail_update(handle); - while (avail >= period_size) { - generate_sine(areas, 0, period_size, &data->phase); - err = snd_pcm_writei(handle, samples, period_size); - if (err < 0) { - printf("Write error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - if (err != period_size) { - printf("Write error: written %i expected %li\n", err, period_size); - exit(EXIT_FAILURE); - } - avail = snd_pcm_avail_update(handle); - } -} - -static int async_loop(snd_pcm_t *handle, - signed short *samples, - snd_pcm_channel_area_t *areas) -{ - struct async_private_data data; - snd_async_handler_t *ahandler; - int err, count; - - data.samples = samples; - data.areas = areas; - data.phase = 0; - err = snd_async_add_pcm_handler(&ahandler, handle, async_callback, &data); - if (err < 0) { - printf("Unable to register async handler\n"); - exit(EXIT_FAILURE); - } - for (count = 0; count < 2; count++) { - generate_sine(areas, 0, period_size, &data.phase); - err = snd_pcm_writei(handle, samples, period_size); - if (err < 0) { - printf("Initial write error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - if (err != period_size) { - printf("Initial write error: written %i expected %li\n", err, period_size); - exit(EXIT_FAILURE); - } - } - if (snd_pcm_state(handle) == SND_PCM_STATE_PREPARED) { - err = snd_pcm_start(handle); - if (err < 0) { - printf("Start error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - } - - /* because all other work is done in the signal handler, - suspend the process */ - while (1) { - sleep(1); - } -} - -/* - * Transfer method - asynchronous notification + direct write - */ - -static void async_direct_callback(snd_async_handler_t *ahandler) -{ - snd_pcm_t *handle = snd_async_handler_get_pcm(ahandler); - struct async_private_data *data = snd_async_handler_get_callback_private(ahandler); - const snd_pcm_channel_area_t *my_areas; - snd_pcm_uframes_t offset, frames, size; - snd_pcm_sframes_t avail, commitres; - snd_pcm_state_t state; - int first = 0, err; - - while (1) { - state = snd_pcm_state(handle); - if (state == SND_PCM_STATE_XRUN) { - err = xrun_recovery(handle, -EPIPE); - if (err < 0) { - printf("XRUN recovery failed: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - first = 1; - } else if (state == SND_PCM_STATE_SUSPENDED) { - err = xrun_recovery(handle, -ESTRPIPE); - if (err < 0) { - printf("SUSPEND recovery failed: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - } - avail = snd_pcm_avail_update(handle); - if (avail < 0) { - err = xrun_recovery(handle, avail); - if (err < 0) { - printf("avail update failed: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - first = 1; - continue; - } - if (avail < period_size) { - if (first) { - first = 0; - err = snd_pcm_start(handle); - if (err < 0) { - printf("Start error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - } else { - break; - } - continue; - } - size = period_size; - while (size > 0) { - frames = size; - err = snd_pcm_mmap_begin(handle, &my_areas, &offset, &frames); - if (err < 0) { - if ((err = xrun_recovery(handle, err)) < 0) { - printf("MMAP begin avail error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - first = 1; - } - generate_sine(my_areas, offset, frames, &data->phase); - commitres = snd_pcm_mmap_commit(handle, offset, frames); - if (commitres < 0 || (snd_pcm_uframes_t)commitres != frames) { - if ((err = xrun_recovery(handle, commitres >= 0 ? -EPIPE : commitres)) < 0) { - printf("MMAP commit error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - first = 1; - } - size -= frames; - } - } -} - -static int async_direct_loop(snd_pcm_t *handle, - signed short *samples ATTRIBUTE_UNUSED, - snd_pcm_channel_area_t *areas ATTRIBUTE_UNUSED) -{ - struct async_private_data data; - snd_async_handler_t *ahandler; - const snd_pcm_channel_area_t *my_areas; - snd_pcm_uframes_t offset, frames, size; - snd_pcm_sframes_t commitres; - int err, count; - - data.samples = NULL; /* we do not require the global sample area for direct write */ - data.areas = NULL; /* we do not require the global areas for direct write */ - data.phase = 0; - err = snd_async_add_pcm_handler(&ahandler, handle, async_direct_callback, &data); - if (err < 0) { - printf("Unable to register async handler\n"); - exit(EXIT_FAILURE); - } - for (count = 0; count < 2; count++) { - size = period_size; - while (size > 0) { - frames = size; - err = snd_pcm_mmap_begin(handle, &my_areas, &offset, &frames); - if (err < 0) { - if ((err = xrun_recovery(handle, err)) < 0) { - printf("MMAP begin avail error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - } - generate_sine(my_areas, offset, frames, &data.phase); - commitres = snd_pcm_mmap_commit(handle, offset, frames); - if (commitres < 0 || (snd_pcm_uframes_t)commitres != frames) { - if ((err = xrun_recovery(handle, commitres >= 0 ? -EPIPE : commitres)) < 0) { - printf("MMAP commit error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - } - size -= frames; - } - } - err = snd_pcm_start(handle); - if (err < 0) { - printf("Start error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - - /* because all other work is done in the signal handler, - suspend the process */ - while (1) { - sleep(1); - } -} - -/* - * Transfer method - direct write only - */ - -static int direct_loop(snd_pcm_t *handle, - signed short *samples ATTRIBUTE_UNUSED, - snd_pcm_channel_area_t *areas ATTRIBUTE_UNUSED) -{ - double phase = 0; - const snd_pcm_channel_area_t *my_areas; - snd_pcm_uframes_t offset, frames, size; - snd_pcm_sframes_t avail, commitres; - snd_pcm_state_t state; - int err, first = 1; - - while (1) { - state = snd_pcm_state(handle); - if (state == SND_PCM_STATE_XRUN) { - err = xrun_recovery(handle, -EPIPE); - if (err < 0) { - printf("XRUN recovery failed: %s\n", snd_strerror(err)); - return err; - } - first = 1; - } else if (state == SND_PCM_STATE_SUSPENDED) { - err = xrun_recovery(handle, -ESTRPIPE); - if (err < 0) { - printf("SUSPEND recovery failed: %s\n", snd_strerror(err)); - return err; - } - } - avail = snd_pcm_avail_update(handle); - if (avail < 0) { - err = xrun_recovery(handle, avail); - if (err < 0) { - printf("avail update failed: %s\n", snd_strerror(err)); - return err; - } - first = 1; - continue; - } - if (avail < period_size) { - if (first) { - first = 0; - err = snd_pcm_start(handle); - if (err < 0) { - printf("Start error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - } else { - err = snd_pcm_wait(handle, -1); - if (err < 0) { - if ((err = xrun_recovery(handle, err)) < 0) { - printf("snd_pcm_wait error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - first = 1; - } - } - continue; - } - size = period_size; - while (size > 0) { - frames = size; - err = snd_pcm_mmap_begin(handle, &my_areas, &offset, &frames); - if (err < 0) { - if ((err = xrun_recovery(handle, err)) < 0) { - printf("MMAP begin avail error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - first = 1; - } - generate_sine(my_areas, offset, frames, &phase); - commitres = snd_pcm_mmap_commit(handle, offset, frames); - if (commitres < 0 || (snd_pcm_uframes_t)commitres != frames) { - if ((err = xrun_recovery(handle, commitres >= 0 ? -EPIPE : commitres)) < 0) { - printf("MMAP commit error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - first = 1; - } - size -= frames; - } - } -} - -/* - * Transfer method - direct write only using mmap_write functions - */ - -static int direct_write_loop(snd_pcm_t *handle, - signed short *samples, - snd_pcm_channel_area_t *areas) -{ - double phase = 0; - signed short *ptr; - int err, cptr; - - while (1) { - generate_sine(areas, 0, period_size, &phase); - ptr = samples; - cptr = period_size; - while (cptr > 0) { - err = snd_pcm_mmap_writei(handle, ptr, cptr); - if (err == -EAGAIN) - continue; - if (err < 0) { - if (xrun_recovery(handle, err) < 0) { - printf("Write error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - break; /* skip one period */ - } - ptr += err * channels; - cptr -= err; - } - } -} - -/* - * - */ - -struct transfer_method { - const char *name; - snd_pcm_access_t access; - int (*transfer_loop)(snd_pcm_t *handle, - signed short *samples, - snd_pcm_channel_area_t *areas); -}; - -static struct transfer_method transfer_methods[] = { - { "write", SND_PCM_ACCESS_RW_INTERLEAVED, write_loop }, - { "write_and_poll", SND_PCM_ACCESS_RW_INTERLEAVED, write_and_poll_loop }, - { "async", SND_PCM_ACCESS_RW_INTERLEAVED, async_loop }, - { "async_direct", SND_PCM_ACCESS_MMAP_INTERLEAVED, async_direct_loop }, - { "direct_interleaved", SND_PCM_ACCESS_MMAP_INTERLEAVED, direct_loop }, - { "direct_noninterleaved", SND_PCM_ACCESS_MMAP_NONINTERLEAVED, direct_loop }, - { "direct_write", SND_PCM_ACCESS_MMAP_INTERLEAVED, direct_write_loop }, - { NULL, SND_PCM_ACCESS_RW_INTERLEAVED, NULL } -}; - -static void help(void) -{ - int k; - printf( -"Usage: pcm [OPTION]... [FILE]...\n" -"-h,--help help\n" -"-D,--device playback device\n" -"-r,--rate stream rate in Hz\n" -"-c,--channels count of channels in stream\n" -"-f,--frequency sine wave frequency in Hz\n" -"-b,--buffer ring buffer size in us\n" -"-p,--period period size in us\n" -"-m,--method transfer method\n" -"-o,--format sample format\n" -"-v,--verbose show the PCM setup parameters\n" -"-n,--noresample do not resample\n" -"-e,--pevent enable poll event after each period\n" -"\n"); - printf("Recognized sample formats are:"); - for (k = 0; k < SND_PCM_FORMAT_LAST; ++k) { - const char *s = snd_pcm_format_name(k); - if (s) - printf(" %s", s); - } - printf("\n"); - printf("Recognized transfer methods are:"); - for (k = 0; transfer_methods[k].name; k++) - printf(" %s", transfer_methods[k].name); - printf("\n"); -} - -int main(int argc, char *argv[]) -{ - struct option long_option[] = - { - {"help", 0, NULL, 'h'}, - {"device", 1, NULL, 'D'}, - {"rate", 1, NULL, 'r'}, - {"channels", 1, NULL, 'c'}, - {"frequency", 1, NULL, 'f'}, - {"buffer", 1, NULL, 'b'}, - {"period", 1, NULL, 'p'}, - {"method", 1, NULL, 'm'}, - {"format", 1, NULL, 'o'}, - {"verbose", 1, NULL, 'v'}, - {"noresample", 1, NULL, 'n'}, - {"pevent", 1, NULL, 'e'}, - {NULL, 0, NULL, 0}, - }; - snd_pcm_t *handle; - int err, morehelp; - snd_pcm_hw_params_t *hwparams; - snd_pcm_sw_params_t *swparams; - int method = 0; - signed short *samples; - unsigned int chn; - snd_pcm_channel_area_t *areas; - - snd_pcm_hw_params_alloca(&hwparams); - snd_pcm_sw_params_alloca(&swparams); - - morehelp = 0; - while (1) { - int c; - if ((c = getopt_long(argc, argv, "hD:r:c:f:b:p:m:o:vne", long_option, NULL)) < 0) - break; - switch (c) { - case 'h': - morehelp++; - break; - case 'D': - device = strdup(optarg); - break; - case 'r': - rate = atoi(optarg); - rate = rate < 4000 ? 4000 : rate; - rate = rate > 196000 ? 196000 : rate; - break; - case 'c': - channels = atoi(optarg); - channels = channels < 1 ? 1 : channels; - channels = channels > 1024 ? 1024 : channels; - break; - case 'f': - freq = atoi(optarg); - freq = freq < 50 ? 50 : freq; - freq = freq > 5000 ? 5000 : freq; - break; - case 'b': - buffer_time = atoi(optarg); - buffer_time = buffer_time < 1000 ? 1000 : buffer_time; - buffer_time = buffer_time > 1000000 ? 1000000 : buffer_time; - break; - case 'p': - period_time = atoi(optarg); - period_time = period_time < 1000 ? 1000 : period_time; - period_time = period_time > 1000000 ? 1000000 : period_time; - break; - case 'm': - for (method = 0; transfer_methods[method].name; method++) - if (!strcasecmp(transfer_methods[method].name, optarg)) - break; - if (transfer_methods[method].name == NULL) - method = 0; - break; - case 'o': - for (format = 0; format < SND_PCM_FORMAT_LAST; format++) { - const char *format_name = snd_pcm_format_name(format); - if (format_name) - if (!strcasecmp(format_name, optarg)) - break; - } - if (format == SND_PCM_FORMAT_LAST) - format = SND_PCM_FORMAT_S16; - break; - case 'v': - verbose = 1; - break; - case 'n': - resample = 0; - break; - case 'e': - period_event = 1; - break; - } - } - - if (morehelp) { - help(); - return 0; - } - - err = snd_output_stdio_attach(&output, stdout, 0); - if (err < 0) { - printf("Output failed: %s\n", snd_strerror(err)); - return 0; - } - - printf("Playback device is %s\n", device); - printf("Stream parameters are %iHz, %s, %i channels\n", rate, snd_pcm_format_name(format), channels); - printf("Sine wave rate is %.4fHz\n", freq); - printf("Using transfer method: %s\n", transfer_methods[method].name); - - if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { - printf("Playback open error: %s\n", snd_strerror(err)); - return 0; - } - - if ((err = set_hwparams(handle, hwparams, transfer_methods[method].access)) < 0) { - printf("Setting of hwparams failed: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - if ((err = set_swparams(handle, swparams)) < 0) { - printf("Setting of swparams failed: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - - if (verbose > 0) - snd_pcm_dump(handle, output); - - samples = malloc((period_size * channels * snd_pcm_format_physical_width(format)) / 8); - if (samples == NULL) { - printf("No enough memory\n"); - exit(EXIT_FAILURE); - } - - areas = calloc(channels, sizeof(snd_pcm_channel_area_t)); - if (areas == NULL) { - printf("No enough memory\n"); - exit(EXIT_FAILURE); - } - for (chn = 0; chn < channels; chn++) { - areas[chn].addr = samples; - areas[chn].first = chn * snd_pcm_format_physical_width(format); - areas[chn].step = channels * snd_pcm_format_physical_width(format); - } - - err = transfer_methods[method].transfer_loop(handle, samples, areas); - if (err < 0) - printf("Transfer failed: %s\n", snd_strerror(err)); - - free(areas); - free(samples); - snd_pcm_close(handle); - return 0; -} - diff --git a/alsa-lib/test/pcm_min.c b/alsa-lib/test/pcm_min.c deleted file mode 100644 index e971405..0000000 --- a/alsa-lib/test/pcm_min.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This extra small demo sends a random samples to your speakers. - */ - -#include "../include/asoundlib.h" - -static char *device = "default"; /* playback device */ - -snd_output_t *output = NULL; -unsigned char buffer[16*1024]; /* some random data */ - -int main(void) -{ - int err; - unsigned int i; - snd_pcm_t *handle; - snd_pcm_sframes_t frames; - - for (i = 0; i < sizeof(buffer); i++) - buffer[i] = random() & 0xff; - - if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { - printf("Playback open error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - if ((err = snd_pcm_set_params(handle, - SND_PCM_FORMAT_U8, - SND_PCM_ACCESS_RW_INTERLEAVED, - 1, - 48000, - 1, - 500000)) < 0) { /* 0.5sec */ - printf("Playback open error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - - for (i = 0; i < 16; i++) { - frames = snd_pcm_writei(handle, buffer, sizeof(buffer)); - if (frames < 0) - frames = snd_pcm_recover(handle, frames, 0); - if (frames < 0) { - printf("snd_pcm_writei failed: %s\n", snd_strerror(err)); - break; - } - if (frames > 0 && frames < (long)sizeof(buffer)) - printf("Short write (expected %li, wrote %li)\n", (long)sizeof(buffer), frames); - } - - snd_pcm_close(handle); - return 0; -} diff --git a/alsa-lib/test/playmidi1.c b/alsa-lib/test/playmidi1.c deleted file mode 100644 index a7f3a63..0000000 --- a/alsa-lib/test/playmidi1.c +++ /dev/null @@ -1,617 +0,0 @@ -/* - * MIDI file player for ALSA sequencer - * (type 0 only!, the library that is used doesn't support merging of tracks) - * - * Copyright (c) 1998 by Frank van de Pol <F.K.W.van.de.Pol@inter.nl.net> - * - * Modified so that this uses alsa-lib - * 1999 Jan. by Isaku Yamahata <yamahata@kusm.kyoto-u.ac.jp> - * - * 19990604 Takashi Iwai <iwai@ww.uni-erlangen.de> - * - use blocking mode - * - fix tempo event bug - * - add command line options - * - * 19990827 Takashi Iwai <iwai@ww.uni-erlangen.de> - * - use snd_seq_alloc_queue() - * - * 19990916 Takashi Iwai <iwai@ww.uni-erlangen.de> - * - use middle-level sequencer routines and macros - * - * 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 <ctype.h> -#include <fcntl.h> -#include <stdlib.h> -#include <sys/ioctl.h> -#include <unistd.h> -#include <errno.h> -#include <string.h> - -#include "midifile.h" /* SMF library header */ -#include "midifile.c" /* SMF library code */ - -#include "../include/asoundlib.h" - -/* send the real-time time stamps (instead of midi ticks) to the ALSA sequencer */ -static int use_realtime = 0; - -/* control the event buffering by using a blocking mode */ -static int use_blocking_mode = 1; - -/* default destination queue, client and port numbers */ -#define DEST_CLIENT_NUMBER 65 -#define DEST_PORT_NUMBER 0 - -/* event pool size */ -#define WRITE_POOL_SIZE 200 -#define WRITE_POOL_SPACE 10 -#define READ_POOL_SIZE 10 /* we need to read the pool only for echoing */ - -static FILE *F; -static snd_seq_t *seq_handle = NULL; -static int ppq = 96; -static int slave_ppq = 96; - -static double local_secs = 0; -static int local_ticks = 0; -static int local_tempo = 500000; - -static int dest_queue = -1; -static int shared_queue = 0; -static int tick_offset = 0; -static int dest_client = DEST_CLIENT_NUMBER; -static int dest_port = DEST_PORT_NUMBER; -static int my_port = 0; - -static int verbose = 0; -static int slave = 0; /* allow external sync */ - -#define VERB_INFO 1 -#define VERB_MUCH 2 -#define VERB_EVENT 3 - -static void alsa_start_timer(void); -static void alsa_stop_timer(void); -static void wait_start(void); - - -static inline double tick2time_dbl(int tick) -{ - return local_secs + ((double) (tick - local_ticks) * (double) local_tempo * 1.0E-6 / (double) ppq); -} - -static void tick2time(snd_seq_real_time_t * tm, int tick) -{ - double secs = tick2time_dbl(tick); - tm->tv_sec = secs; - tm->tv_nsec = (secs - tm->tv_sec) * 1.0E9; -} - -static void write_ev(snd_seq_event_t *ev) -{ - int rc; - - if (use_blocking_mode) { - rc = snd_seq_event_output(seq_handle, ev); - if (rc < 0) { - printf("written = %i (%s)\n", rc, snd_strerror(rc)); - exit(1); - } - return; - } - while ((rc = snd_seq_event_output(seq_handle, ev)) < 0) { - int npfds = snd_seq_poll_descriptors_count(seq_handle, POLLOUT); - struct pollfd *pfds = alloca(sizeof(*pfds) * npfds); - snd_seq_poll_descriptors(seq_handle, pfds, npfds, POLLOUT); - if ((rc = poll(pfds, npfds, -1)) < 0) { - printf("poll error = %i (%s)\n", rc, snd_strerror(errno)); - exit(1); - } - } -} - -/* read the byte */ -static int mygetc(void) -{ - return getc(F); -} - -/* print out the text */ -static void mytext(int type ATTRIBUTE_UNUSED, int leng, char *msg) -{ - char *p; - char *ep = msg + leng; - - if (verbose >= VERB_INFO) { - for (p = msg; p < ep; p++) - putchar(isprint(*p) ? *p : '?'); - putchar('\n'); - } -} - -static void do_header(int format, int ntracks, int division) -{ - snd_seq_queue_tempo_t *tempo; - - if (verbose >= VERB_INFO) - printf("smf format %d, %d tracks, %d ppq\n", format, ntracks, division); - ppq = division; - - if (format != 0 || ntracks != 1) { - printf("This player does not support merging of tracks.\n"); - if (! shared_queue) - alsa_stop_timer(); - exit(1); - } - /* set the ppq */ - snd_seq_queue_tempo_alloca(&tempo); - /* ppq must be set before starting the timer */ - if (snd_seq_get_queue_tempo(seq_handle, dest_queue, tempo) < 0) { - perror("get_queue_tempo"); - exit(1); - } - if ((slave_ppq = snd_seq_queue_tempo_get_ppq(tempo)) != ppq) { - snd_seq_queue_tempo_set_ppq(tempo, ppq); - if (snd_seq_set_queue_tempo(seq_handle, dest_queue, tempo) < 0) { - perror("set_queue_tempo"); - if (!slave && !shared_queue) - exit(1); - else - printf("different PPQ %d in SMF from queue PPQ %d\n", ppq, slave_ppq); - } else - slave_ppq = ppq; - if (verbose >= VERB_INFO) - printf("ALSA Timer updated, PPQ = %d\n", snd_seq_queue_tempo_get_ppq(tempo)); - } - - /* start playing... */ - if (slave) { - if (verbose >= VERB_INFO) - printf("Wait till timer starts...\n"); - wait_start(); - if (verbose >= VERB_INFO) - printf("Go!\n"); - } else if (shared_queue) { - snd_seq_queue_status_t *stat; - snd_seq_queue_status_alloca(&stat); - snd_seq_get_queue_status(seq_handle, dest_queue, stat); - tick_offset = snd_seq_queue_status_get_tick_time(stat); - fprintf(stderr, "tick offset = %d\n", tick_offset); - } else { - alsa_start_timer(); - tick_offset = 0; - } -} - -/* fill the event time */ -static void set_event_time(snd_seq_event_t *ev, unsigned int currtime) -{ - if (use_realtime) { - snd_seq_real_time_t rtime; - if (ppq != slave_ppq) - currtime = (currtime * slave_ppq) / ppq; - tick2time(&rtime, currtime); - snd_seq_ev_schedule_real(ev, dest_queue, 0, &rtime); - } else { - if (ppq != slave_ppq) - currtime = (currtime * slave_ppq) / ppq; - currtime += tick_offset; - snd_seq_ev_schedule_tick(ev, dest_queue, 0, currtime); - } -} - -/* fill the normal event header */ -static void set_event_header(snd_seq_event_t *ev) -{ - snd_seq_ev_clear(ev); - snd_seq_ev_set_dest(ev, dest_client, dest_port); - snd_seq_ev_set_source(ev, my_port); - set_event_time(ev, Mf_currtime); -} - -/* start the timer */ -static void alsa_start_timer(void) -{ - snd_seq_start_queue(seq_handle, dest_queue, NULL); -} - -/* stop the timer */ -static void alsa_stop_timer(void) -{ - snd_seq_event_t ev; - set_event_header(&ev); - snd_seq_stop_queue(seq_handle, dest_queue, &ev); -} - -/* change the tempo */ -static void do_tempo(int us) -{ - snd_seq_event_t ev; - - if (verbose >= VERB_MUCH) { - double bpm; - bpm = 60.0E6 / (double) us; - printf("Tempo %d us/beat, %.2f bpm\n", us, bpm); - } - - /* store the new tempo and timestamp of the tempo change */ - local_secs = tick2time_dbl(Mf_currtime); - local_ticks = Mf_currtime; - local_tempo = us; - - set_event_header(&ev); - if (!slave) - snd_seq_change_queue_tempo(seq_handle, dest_queue, us, &ev); -} - -static void do_noteon(int chan, int pitch, int vol) -{ - snd_seq_event_t ev; - - if (verbose >= VERB_EVENT) - printf("%ld: NoteOn (%d) %d %d\n", Mf_currtime, chan, pitch, vol); - set_event_header(&ev); - snd_seq_ev_set_noteon(&ev, chan, pitch, vol); - write_ev(&ev); -} - - -static void do_noteoff(int chan, int pitch, int vol) -{ - snd_seq_event_t ev; - - if (verbose >= VERB_EVENT) - printf("%ld: NoteOff (%d) %d %d\n", Mf_currtime, chan, pitch, vol); - set_event_header(&ev); - snd_seq_ev_set_noteoff(&ev, chan, pitch, vol); - write_ev(&ev); -} - - -static void do_program(int chan, int program) -{ - snd_seq_event_t ev; - - if (verbose >= VERB_EVENT) - printf("%ld: Program (%d) %d\n", Mf_currtime, chan, program); - set_event_header(&ev); - snd_seq_ev_set_pgmchange(&ev, chan, program); - write_ev(&ev); -} - - -static void do_parameter(int chan, int control, int value) -{ - snd_seq_event_t ev; - - if (verbose >= VERB_EVENT) - printf("%ld: Control (%d) %d %d\n", Mf_currtime, chan, control, value); - set_event_header(&ev); - snd_seq_ev_set_controller(&ev, chan, control, value); - write_ev(&ev); -} - - -static void do_pitchbend(int chan, int lsb, int msb) -{ /* !@#$% lsb & msb are in the wrong order in docs */ - snd_seq_event_t ev; - - if (verbose >= VERB_EVENT) - printf("%ld: Pitchbend (%d) %d %d\n", Mf_currtime, chan, lsb, msb); - set_event_header(&ev); - snd_seq_ev_set_pitchbend(&ev, chan, (lsb + (msb << 7)) - 8192); - write_ev(&ev); -} - -static void do_pressure(int chan, int pitch, int pressure) -{ - snd_seq_event_t ev; - - if (verbose >= VERB_EVENT) - printf("%ld: KeyPress (%d) %d %d\n", Mf_currtime, chan, pitch, pressure); - set_event_header(&ev); - snd_seq_ev_set_keypress(&ev, chan, pitch, pressure); - write_ev(&ev); -} - -static void do_chanpressure(int chan, int pressure) -{ - snd_seq_event_t ev; - - if (verbose >= VERB_EVENT) - printf("%ld: ChanPress (%d) %d\n", Mf_currtime, chan, pressure); - set_event_header(&ev); - snd_seq_ev_set_chanpress(&ev, chan, pressure); - write_ev(&ev); -} - -static void do_sysex(int len, char *msg) -{ - snd_seq_event_t ev; - - if (verbose >= VERB_MUCH) { - int c; - printf("%ld: Sysex, len=%d\n", Mf_currtime, len); - for (c = 0; c < len; c++) { - printf(" %02x", (unsigned char)msg[c]); - if (c % 16 == 15) - putchar('\n'); - } - if (c % 16 != 15) - putchar('\n'); - } - - set_event_header(&ev); - snd_seq_ev_set_sysex(&ev, len, msg); - write_ev(&ev); -} - -static snd_seq_event_t *wait_for_event(void) -{ - int left; - snd_seq_event_t *input_event; - - if (use_blocking_mode) { - /* read the event - blocked until any event is read */ - left = snd_seq_event_input(seq_handle, &input_event); - } else { - /* read the event - using select syscall */ - while ((left = snd_seq_event_input(seq_handle, &input_event)) >= 0 && - input_event == NULL) { - int npfds = snd_seq_poll_descriptors_count(seq_handle, POLLIN); - struct pollfd *pfds = alloca(sizeof(*pfds) * npfds); - snd_seq_poll_descriptors(seq_handle, pfds, npfds, POLLIN); - if ((left = poll(pfds, npfds, -1)) < 0) { - printf("poll error = %i (%s)\n", errno, snd_strerror(errno)); - exit(1); - } - } - } - - if (left < 0) { - printf("alsa_sync error!:%s\n", snd_strerror(left)); - return NULL; - } - - return input_event; -} - -/* synchronize to the end of the event */ -static void alsa_sync(void) -{ - /* send the echo event to the self client. */ - if (verbose >= VERB_MUCH) - printf("alsa_sync syncing...\n"); - /* dump the buffer */ - snd_seq_drain_output(seq_handle); - snd_seq_sync_output_queue(seq_handle); - if (verbose >= VERB_MUCH) - printf("alsa_sync synced\n"); - sleep(1); /* give a time for note releasing.. */ -} - - -/* wait for the start of the queue */ -static void wait_start(void) -{ - snd_seq_event_t *input_event; - - /* wait for the start event from the system timer */ - for (;;) { - input_event = wait_for_event(); - if (input_event) { - if (verbose >= VERB_MUCH) - printf("wait_start got event. type=%d, flags=%d\n", - input_event->type, input_event->flags); - if (input_event->type == SND_SEQ_EVENT_START && - input_event->data.queue.queue == dest_queue) { - snd_seq_free_event(input_event); - break; - } - snd_seq_free_event(input_event); - } - } - if (verbose >= VERB_MUCH) - printf("start received\n"); -} - - -/* print the usage */ -static void usage(void) -{ - fprintf(stderr, "usage: playmidi1 [options] [file]\n"); - fprintf(stderr, " options:\n"); - fprintf(stderr, " -v: verbose mode\n"); - fprintf(stderr, " -a client:port : set destination address (default=%d:%d)\n", - DEST_CLIENT_NUMBER, DEST_PORT_NUMBER); - fprintf(stderr, " -q queue: use the specified queue\n"); - fprintf(stderr, " -s queue: slave mode (allow external clock synchronization)\n"); - fprintf(stderr, " -r : play on real-time mode\n"); - fprintf(stderr, " -b : play on non-blocking mode\n"); -} - -int main(int argc, char *argv[]) -{ - int tmp; - int c; - snd_seq_addr_t dest_addr; - const char *addr = "65:0"; - - while ((c = getopt(argc, argv, "s:a:p:q:vrb")) != -1) { - switch (c) { - case 'v': - verbose++; - break; - case 'a': - case 'p': - addr = optarg; - break; - case 'q': - dest_queue = atoi(optarg); - if (dest_queue < 0) { - fprintf(stderr, "invalid queue number %d\n", dest_queue); - exit(1); - } - break; - case 's': - slave = 1; - dest_queue = atoi(optarg); - if (dest_queue < 0) { - fprintf(stderr, "invalid queue number %d\n", dest_queue); - exit(1); - } - break; - case 'r': - use_realtime = 1; - break; - case 'b': - use_blocking_mode = 0; - break; - default: - usage(); - exit(1); - } - } - - if (verbose >= VERB_INFO) { - if (use_realtime) - printf("ALSA MIDI Player, feeding events to real-time queue\n"); - else - printf("ALSA MIDI Player, feeding events to song queue\n"); - } - - /* open the sequencer device */ - /* Here we open the device in read/write for slave mode. */ - tmp = snd_seq_open(&seq_handle, "hw", slave ? SND_SEQ_OPEN_DUPLEX : SND_SEQ_OPEN_OUTPUT, 0); - if (tmp < 0) { - perror("open /dev/snd/seq"); - exit(1); - } - - tmp = snd_seq_nonblock(seq_handle, !use_blocking_mode); - if (tmp < 0) { - perror("block_mode"); - exit(1); - } - - /* set the name */ - /* set the event filter to receive only the echo event */ - /* if running in slave mode, also listen for a START event */ - if (slave) - snd_seq_set_client_event_filter(seq_handle, SND_SEQ_EVENT_START); - snd_seq_set_client_name(seq_handle, "MIDI file player"); - - /* create the port */ - my_port = snd_seq_create_simple_port(seq_handle, "Port 0", - SND_SEQ_PORT_CAP_WRITE | - SND_SEQ_PORT_CAP_READ, - SND_SEQ_PORT_TYPE_MIDI_GENERIC); - if (my_port < 0) { - perror("create port"); - exit(1); - } - - if (snd_seq_parse_address(seq_handle, &dest_addr, addr) < 0) { - perror("invalid destination address"); - exit(1); - } - dest_client = dest_addr.client; - dest_port = dest_addr.port; - - /* set the queue */ - if (dest_queue >= 0) { - shared_queue = 1; - if (snd_seq_set_queue_usage(seq_handle, dest_queue, 1) < 0) { - perror("use queue"); - exit(1); - } - } else { - shared_queue = 0; - dest_queue = snd_seq_alloc_queue(seq_handle); - if (dest_queue < 0) { - perror("alloc queue"); - exit(1); - } - } - - /* set the subscriber */ - tmp = snd_seq_connect_to(seq_handle, my_port, dest_client, dest_port); - if (tmp < 0) { - perror("subscribe"); - exit(1); - } - - /* subscribe for the timer START event */ - if (slave) { - tmp = snd_seq_connect_from(seq_handle, my_port, - SND_SEQ_CLIENT_SYSTEM, - dest_queue + 16 /*snd_seq_queue_sync_port(dest_queue)*/); - if (tmp < 0) { - perror("subscribe"); - exit(1); - } - } - - /* change the pool size */ - if (snd_seq_set_client_pool_output(seq_handle, WRITE_POOL_SIZE) < 0 || - snd_seq_set_client_pool_input(seq_handle, READ_POOL_SIZE) < 0 || - snd_seq_set_client_pool_output_room(seq_handle, WRITE_POOL_SPACE) < 0) { - perror("pool"); - exit(1); - } - - if (optind < argc) { - F = fopen(argv[optind], "r"); - if (F == NULL) { - fprintf(stderr, "playmidi1: can't open file %s\n", argv[optind]); - exit(1); - } - } else - F = stdin; - - Mf_header = do_header; - Mf_tempo = do_tempo; - Mf_getc = mygetc; - Mf_text = mytext; - - Mf_noteon = do_noteon; - Mf_noteoff = do_noteoff; - Mf_program = do_program; - Mf_parameter = do_parameter; - Mf_pitchbend = do_pitchbend; - Mf_pressure = do_pressure; - Mf_chanpressure = do_chanpressure; - Mf_sysex = do_sysex; - - /* go.. go.. go.. */ - mfread(); - - alsa_sync(); - if (! shared_queue) - alsa_stop_timer(); - - snd_seq_close(seq_handle); - - if (verbose >= VERB_INFO) { - printf("Stopping at %f s, tick %f\n", - tick2time_dbl(Mf_currtime + 1), (double) (Mf_currtime + 1)); - } - - exit(0); -} diff --git a/alsa-lib/test/queue_timer.c b/alsa-lib/test/queue_timer.c deleted file mode 100644 index c4ffb19..0000000 --- a/alsa-lib/test/queue_timer.c +++ /dev/null @@ -1,128 +0,0 @@ -#include <unistd.h> -#include <sys/time.h> -#include <alsa/asoundlib.h> -#include <alsa/seq.h> - -void normalize(struct timeval *tv) -{ - if (tv->tv_sec == 0) { - while (tv->tv_usec <= -1000000) { tv->tv_usec += 1000000; --tv->tv_sec; } - while (tv->tv_usec >= 1000000) { tv->tv_usec -= 1000000; ++tv->tv_sec; } - } else if (tv->tv_sec < 0) { - while (tv->tv_usec <= -1000000) { tv->tv_usec += 1000000; --tv->tv_sec; } - while (tv->tv_usec > 0) { tv->tv_usec -= 1000000; ++tv->tv_sec; } - } else { - while (tv->tv_usec >= 1000000) { tv->tv_usec -= 1000000; ++tv->tv_sec; } - while (tv->tv_usec < 0) { tv->tv_usec += 1000000; --tv->tv_sec; } - } -} - -int -main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) -{ - snd_seq_t *handle; - int portid; - /* int npfd; - struct pollfd *pfd; - */ - int queue; - /* int i; - int rval;' - */ - struct timeval starttv, prevdiff; - int countdown = -1; - /* snd_seq_queue_timer_t *timer; - snd_timer_id_t *timerid; - */ - - if (snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0) < 0) { - fprintf(stderr, "failed to open ALSA sequencer interface\n"); - return 1; - } - - snd_seq_set_client_name(handle, "generator"); - - if ((portid = snd_seq_create_simple_port - (handle, "generator", - SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ, 0)) < 0) { - fprintf(stderr, "failed to create ALSA sequencer port\n"); - return 1; - } - - if ((queue = snd_seq_alloc_queue(handle)) < 0) { - fprintf(stderr, "failed to create ALSA sequencer queue\n"); - return 1; - } -/* - snd_seq_queue_timer_alloca(&timer); - snd_seq_get_queue_timer(handle, queue, timer); - snd_timer_id_alloca(&timerid); - snd_timer_id_set_class(timerid, SND_TIMER_CLASS_PCM); - snd_timer_id_set_sclass(timerid, SND_TIMER_SCLASS_NONE); - snd_timer_id_set_card(timerid, 0); - snd_timer_id_set_device(timerid, 0); - snd_timer_id_set_subdevice(timerid, 0); - snd_seq_queue_timer_set_id(timer, timerid); - snd_seq_set_queue_timer(handle, queue, timer); -*/ - snd_seq_start_queue(handle, queue, 0); - snd_seq_drain_output(handle); - - gettimeofday(&starttv, 0); - prevdiff.tv_sec = 0; - prevdiff.tv_usec = 0; - - while (countdown != 0) { - - snd_seq_queue_status_t *status; - const snd_seq_real_time_t *rtime; - struct timeval tv, diff, diffdiff; - struct timespec ts; - - snd_seq_queue_status_alloca(&status); - - snd_seq_get_queue_status(handle, queue, status); - rtime = snd_seq_queue_status_get_real_time(status); - - gettimeofday(&tv, 0); - - tv.tv_sec -= starttv.tv_sec; - tv.tv_usec -= starttv.tv_usec; - normalize(&tv); - - diff.tv_sec = tv.tv_sec - rtime->tv_sec; - diff.tv_usec = tv.tv_usec - rtime->tv_nsec / 1000; - normalize(&diff); - - diffdiff.tv_sec = diff.tv_sec - prevdiff.tv_sec; - diffdiff.tv_usec = diff.tv_usec - prevdiff.tv_usec; - normalize(&diffdiff); - prevdiff = diff; - - fprintf(stderr, " real time: %12ld sec %8ld usec\nqueue time: %12ld sec %8ld usec\n diff: %12ld sec %8ld usec\n diffdiff: %12ld sec %8ld usec\n", - tv.tv_sec, tv.tv_usec, - (long)rtime->tv_sec, (long)rtime->tv_nsec / 1000, - diff.tv_sec, diff.tv_usec, - (long)diffdiff.tv_sec, (long)diffdiff.tv_usec); - - if (diffdiff.tv_usec > 5000 || - diffdiff.tv_usec < -5000) { - fprintf(stderr, "oops! queue slipped\n"); - if (tv.tv_sec < 5) { - fprintf(stderr, "(ignoring in first few seconds)\n"); - } else { - countdown = 2; - } - } else { - if (countdown > 0) --countdown; - } - - fprintf(stderr, "\n"); -// sleep(1); - ts.tv_sec = 0; - ts.tv_nsec = 500000000; - nanosleep(&ts, 0); - } - return EXIT_SUCCESS; -} - diff --git a/alsa-lib/test/rawmidi.c b/alsa-lib/test/rawmidi.c deleted file mode 100644 index 67f585b..0000000 --- a/alsa-lib/test/rawmidi.c +++ /dev/null @@ -1,241 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <ctype.h> -#include "../include/asoundlib.h" -#include <signal.h> - -static void usage(void) -{ - fprintf(stderr, "usage: rawmidi [options]\n"); - fprintf(stderr, " options:\n"); - fprintf(stderr, " -v: verbose mode\n"); - fprintf(stderr, " -i device-id : test ALSA input device\n"); - fprintf(stderr, " -o device-id : test ALSA output device\n"); - fprintf(stderr, " -I node : test input node\n"); - fprintf(stderr, " -O node : test output node\n"); - fprintf(stderr, " -t: test midi thru\n"); - fprintf(stderr, " example:\n"); - fprintf(stderr, " rawmidi -i hw:0,0 -O /dev/midi1\n"); - fprintf(stderr, " tests input for card 0, device 0, using snd_rawmidi API\n"); - fprintf(stderr, " and /dev/midi1 using file descriptors\n"); -} - -int stop=0; - -void sighandler(int dum) -{ - stop=1; -} - -int main(int argc,char** argv) -{ - int i; - int err; - int thru=0; - int verbose = 0; - char *device_in = NULL; - char *device_out = NULL; - char *node_in = NULL; - char *node_out = NULL; - - int fd_in = -1,fd_out = -1; - snd_rawmidi_t *handle_in = 0,*handle_out = 0; - - if (argc==1) { - usage(); - exit(0); - } - - for (i = 1 ; i<argc ; i++) { - if (argv[i][0]=='-') { - switch (argv[i][1]) { - case 'h': - usage(); - break; - case 'v': - verbose = 1; - break; - case 't': - thru = 1; - break; - case 'i': - if (i + 1 < argc) - device_in = argv[++i]; - break; - case 'I': - if (i + 1 < argc) - node_in = argv[++i]; - break; - case 'o': - if (i + 1 < argc) - device_out = argv[++i]; - break; - case 'O': - if (i + 1 < argc) - node_out = argv[++i]; - break; - } - } - } - - if (verbose) { - fprintf(stderr,"Using: \n"); - fprintf(stderr,"Input: "); - if (device_in) { - fprintf(stderr,"device %s\n",device_in); - }else if (node_in){ - fprintf(stderr,"%s\n",node_in); - }else{ - fprintf(stderr,"NONE\n"); - } - fprintf(stderr,"Output: "); - if (device_out) { - fprintf(stderr,"device %s\n",device_out); - }else if (node_out){ - fprintf(stderr,"%s\n",node_out); - }else{ - fprintf(stderr,"NONE\n"); - } - } - - if (device_in) { - err = snd_rawmidi_open(&handle_in,NULL,device_in,0); - if (err) { - fprintf(stderr,"snd_rawmidi_open %s failed: %d\n",device_in,err); - } - } - if (node_in && (!node_out || strcmp(node_out,node_in))) { - fd_in = open(node_in,O_RDONLY); - if (fd_in<0) { - fprintf(stderr,"open %s for input failed\n",node_in); - } - } - - signal(SIGINT,sighandler); - - if (device_out) { - err = snd_rawmidi_open(NULL,&handle_out,device_out,0); - if (err) { - fprintf(stderr,"snd_rawmidi_open %s failed: %d\n",device_out,err); - } - } - if (node_out && (!node_in || strcmp(node_out,node_in))) { - fd_out = open(node_out,O_WRONLY); - if (fd_out<0) { - fprintf(stderr,"open %s for output failed\n",node_out); - } - } - - if (node_in && node_out && strcmp(node_out,node_in)==0) { - fd_in = fd_out = open(node_out,O_RDWR); - if (fd_out<0) { - fprintf(stderr,"open %s for input and output failed\n",node_out); - } - } - - - - if (!thru) { - if (handle_in || fd_in!=-1) { - fprintf(stderr,"Read midi in\n"); - fprintf(stderr,"Press ctrl-c to stop\n"); - } - - if (handle_in) { - unsigned char ch; - while (!stop) { - snd_rawmidi_read(handle_in,&ch,1); - if (verbose) { - fprintf(stderr,"read %02x\n",ch); - } - } - } - if (fd_in!=-1) { - unsigned char ch; - while (!stop) { - read(fd_in,&ch,1); - if (verbose) { - fprintf(stderr,"read %02x\n",ch); - } - } - } - - if (handle_out || fd_out!=-1) { - fprintf(stderr,"Writing note on / note off\n"); - } - - if (handle_out) { - unsigned char ch; - ch=0x90; snd_rawmidi_write(handle_out,&ch,1); - ch=60; snd_rawmidi_write(handle_out,&ch,1); - ch=100; snd_rawmidi_write(handle_out,&ch,1); - snd_rawmidi_drain(handle_out); - sleep(1); - ch=0x90; snd_rawmidi_write(handle_out,&ch,1); - ch=60; snd_rawmidi_write(handle_out,&ch,1); - ch=0; snd_rawmidi_write(handle_out,&ch,1); - snd_rawmidi_drain(handle_out); - } - if (fd_out!=-1) { - unsigned char ch; - ch=0x90; write(fd_out,&ch,1); - ch=60; write(fd_out,&ch,1); - ch=100; write(fd_out,&ch,1); - sleep(1); - ch=0x90; write(fd_out,&ch,1); - ch=60; write(fd_out,&ch,1); - ch=0; write(fd_out,&ch,1); - } - } else { - if ((handle_in || fd_in!=-1) && (handle_out || fd_out!=-1)) { - if (verbose) { - fprintf(stderr,"Testing midi thru in\n"); - } - while (!stop) { - unsigned char ch; - - if (handle_in) { - snd_rawmidi_read(handle_in,&ch,1); - } - if (fd_in!=-1) { - read(fd_in,&ch,1); - } - if (verbose) { - fprintf(stderr,"thru: %02x\n",ch); - } - - if (handle_out) { - snd_rawmidi_write(handle_out,&ch,1); - snd_rawmidi_drain(handle_out); - } - if (fd_out!=-1) { - write(fd_out,&ch,1); - } - } - }else{ - fprintf(stderr,"Testing midi thru needs both input and output\n"); - exit(-1); - } - } - - if (verbose) { - fprintf(stderr,"Closing\n"); - } - - if (handle_in) { - snd_rawmidi_drain(handle_in); - snd_rawmidi_close(handle_in); - } - if (handle_out) { - snd_rawmidi_drain(handle_out); - snd_rawmidi_close(handle_out); - } - if (fd_in!=-1) { - close(fd_in); - } - if (fd_out!=-1) { - close(fd_out); - } - - return 0; -} diff --git a/alsa-lib/test/seq-decoder.c b/alsa-lib/test/seq-decoder.c deleted file mode 100644 index b110e98..0000000 --- a/alsa-lib/test/seq-decoder.c +++ /dev/null @@ -1,353 +0,0 @@ -/* - * Simple event decoder - */ - -static char *event_names[256] = { - [SND_SEQ_EVENT_SYSTEM]= "System", - [SND_SEQ_EVENT_RESULT]= "Result", - [SND_SEQ_EVENT_NOTE]= "Note", - [SND_SEQ_EVENT_NOTEON]= "Note On", - [SND_SEQ_EVENT_NOTEOFF]= "Note Off", - [SND_SEQ_EVENT_KEYPRESS]= "Key Pressure", - [SND_SEQ_EVENT_CONTROLLER]= "Controller", - [SND_SEQ_EVENT_PGMCHANGE]= "Program Change", - [SND_SEQ_EVENT_CHANPRESS]= "Channel Pressure", - [SND_SEQ_EVENT_PITCHBEND]= "Pitchbend", - [SND_SEQ_EVENT_CONTROL14]= "Control14", - [SND_SEQ_EVENT_NONREGPARAM]= "Nonregparam", - [SND_SEQ_EVENT_REGPARAM]= "Regparam", - [SND_SEQ_EVENT_SONGPOS]= "Song Position", - [SND_SEQ_EVENT_SONGSEL]= "Song Select", - [SND_SEQ_EVENT_QFRAME]= "Qframe", - [SND_SEQ_EVENT_TIMESIGN]= "SMF Time Signature", - [SND_SEQ_EVENT_KEYSIGN]= "SMF Key Signature", - [SND_SEQ_EVENT_START]= "Start", - [SND_SEQ_EVENT_CONTINUE]= "Continue", - [SND_SEQ_EVENT_STOP]= "Stop", - [SND_SEQ_EVENT_SETPOS_TICK]= "Set Position Tick", - [SND_SEQ_EVENT_SETPOS_TIME]= "Set Position Time", - [SND_SEQ_EVENT_TEMPO]= "Tempo", - [SND_SEQ_EVENT_CLOCK]= "Clock", - [SND_SEQ_EVENT_TICK]= "Tick", - [SND_SEQ_EVENT_TUNE_REQUEST]= "Tune Request", - [SND_SEQ_EVENT_RESET]= "Reset", - [SND_SEQ_EVENT_SENSING]= "Active Sensing", - [SND_SEQ_EVENT_ECHO]= "Echo", - [SND_SEQ_EVENT_OSS]= "OSS", - [SND_SEQ_EVENT_CLIENT_START]= "Client Start", - [SND_SEQ_EVENT_CLIENT_EXIT]= "Client Exit", - [SND_SEQ_EVENT_CLIENT_CHANGE]= "Client Change", - [SND_SEQ_EVENT_PORT_START]= "Port Start", - [SND_SEQ_EVENT_PORT_EXIT]= "Port Exit", - [SND_SEQ_EVENT_PORT_CHANGE]= "Port Change", - [SND_SEQ_EVENT_PORT_SUBSCRIBED]= "Port Subscribed", - [SND_SEQ_EVENT_PORT_UNSUBSCRIBED]= "Port Unsubscribed", -#if 0 - [SND_SEQ_EVENT_SAMPLE]= "Sample", - [SND_SEQ_EVENT_SAMPLE_CLUSTER]= "Sample Cluster", - [SND_SEQ_EVENT_SAMPLE_START]= "Sample Start", - [SND_SEQ_EVENT_SAMPLE_STOP]= "Sample Stop", - [SND_SEQ_EVENT_SAMPLE_FREQ]= "Sample Freq", - [SND_SEQ_EVENT_SAMPLE_VOLUME]= "Sample Volume", - [SND_SEQ_EVENT_SAMPLE_LOOP]= "Sample Loop", - [SND_SEQ_EVENT_SAMPLE_POSITION]= "Sample Position", - [SND_SEQ_EVENT_SAMPLE_PRIVATE1]= "Sample Private1", -#endif - [SND_SEQ_EVENT_USR0]= "User 0", - [SND_SEQ_EVENT_USR1]= "User 1", - [SND_SEQ_EVENT_USR2]= "User 2", - [SND_SEQ_EVENT_USR3]= "User 3", - [SND_SEQ_EVENT_USR4]= "User 4", - [SND_SEQ_EVENT_USR5]= "User 5", - [SND_SEQ_EVENT_USR6]= "User 6", - [SND_SEQ_EVENT_USR7]= "User 7", - [SND_SEQ_EVENT_USR8]= "User 8", - [SND_SEQ_EVENT_USR9]= "User 9", -#if 0 - [SND_SEQ_EVENT_INSTR_BEGIN]= "Instr Begin", - [SND_SEQ_EVENT_INSTR_END]= "Instr End", - [SND_SEQ_EVENT_INSTR_INFO]= "Instr Info", - [SND_SEQ_EVENT_INSTR_INFO_RESULT]= "Instr Info Result", - [SND_SEQ_EVENT_INSTR_FINFO]= "Instr Font Info", - [SND_SEQ_EVENT_INSTR_FINFO_RESULT]= "Instr Font Info Result", - [SND_SEQ_EVENT_INSTR_RESET]= "Instr Reset", - [SND_SEQ_EVENT_INSTR_STATUS]= "Instr Status", - [SND_SEQ_EVENT_INSTR_STATUS_RESULT]= "Instr Status Result", - [SND_SEQ_EVENT_INSTR_PUT]= "Instr Put", - [SND_SEQ_EVENT_INSTR_GET]= "Instr Get", - [SND_SEQ_EVENT_INSTR_GET_RESULT]= "Instr Get Result", - [SND_SEQ_EVENT_INSTR_FREE]= "Instr Free", - [SND_SEQ_EVENT_INSTR_LIST]= "Instr List", - [SND_SEQ_EVENT_INSTR_LIST_RESULT]= "Instr List Result", - [SND_SEQ_EVENT_INSTR_CLUSTER]= "Instr Cluster", - [SND_SEQ_EVENT_INSTR_CLUSTER_GET]= "Instr Cluster Get", - [SND_SEQ_EVENT_INSTR_CLUSTER_RESULT]= "Instr Cluster Result", - [SND_SEQ_EVENT_INSTR_CHANGE]= "Instr Change", -#endif - [SND_SEQ_EVENT_SYSEX]= "Sysex", - [SND_SEQ_EVENT_BOUNCE]= "Bounce", - [SND_SEQ_EVENT_USR_VAR0]= "User Var0", - [SND_SEQ_EVENT_USR_VAR1]= "User Var1", - [SND_SEQ_EVENT_USR_VAR2]= "User Var2", - [SND_SEQ_EVENT_USR_VAR3]= "User Var3", - [SND_SEQ_EVENT_USR_VAR4]= "User Var4", -#if 0 - [SND_SEQ_EVENT_IPCSHM]= "IPC Shm", - [SND_SEQ_EVENT_USR_VARIPC0]= "User IPC0", - [SND_SEQ_EVENT_USR_VARIPC1]= "User IPC1", - [SND_SEQ_EVENT_USR_VARIPC2]= "User IPC2", - [SND_SEQ_EVENT_USR_VARIPC3]= "User IPC3", - [SND_SEQ_EVENT_USR_VARIPC4]= "User IPC4", -#endif - [SND_SEQ_EVENT_NONE]= "None", -}; - -int decode_event(snd_seq_event_t * ev) -{ - char *space = " "; - - printf("EVENT>>> Type = %d, flags = 0x%x", ev->type, ev->flags); - switch (ev->flags & SND_SEQ_TIME_STAMP_MASK) { - case SND_SEQ_TIME_STAMP_TICK: - printf(", time = %d ticks", - ev->time.tick); - break; - case SND_SEQ_TIME_STAMP_REAL: - printf(", time = %d.%09d", - (int)ev->time.time.tv_sec, - (int)ev->time.time.tv_nsec); - break; - } - printf("\n%sSource = %d.%d, dest = %d.%d, queue = %d\n", - space, - ev->source.client, - ev->source.port, - ev->dest.client, - ev->dest.port, - ev->queue); - - if (event_names[ev->type]) - printf("%sEvent = %s", space, event_names[ev->type]); - else - printf("%sEvent = Reserved %d\n", space, ev->type); - /* decode the actual event data... */ - switch (ev->type) { - case SND_SEQ_EVENT_NOTE: - printf("; ch=%d, note=%d, velocity=%d, off_velocity=%d, duration=%d\n", - ev->data.note.channel, - ev->data.note.note, - ev->data.note.velocity, - ev->data.note.off_velocity, - ev->data.note.duration); - break; - - case SND_SEQ_EVENT_NOTEON: - case SND_SEQ_EVENT_NOTEOFF: - case SND_SEQ_EVENT_KEYPRESS: - printf("; ch=%d, note=%d, velocity=%d\n", - ev->data.note.channel, - ev->data.note.note, - ev->data.note.velocity); - break; - - case SND_SEQ_EVENT_CONTROLLER: - printf("; ch=%d, param=%i, value=%i\n", - ev->data.control.channel, - ev->data.control.param, - ev->data.control.value); - break; - - case SND_SEQ_EVENT_PGMCHANGE: - printf("; ch=%d, program=%i\n", - ev->data.control.channel, - ev->data.control.value); - break; - - case SND_SEQ_EVENT_CHANPRESS: - case SND_SEQ_EVENT_PITCHBEND: - printf("; ch=%d, value=%i\n", - ev->data.control.channel, - ev->data.control.value); - break; - - case SND_SEQ_EVENT_SYSEX: - { - unsigned char *sysex = (unsigned char *) ev + sizeof(snd_seq_event_t); - unsigned int c; - - printf("; len=%d [", ev->data.ext.len); - - for (c = 0; c < ev->data.ext.len; c++) { - printf("%02x%s", sysex[c], c < ev->data.ext.len - 1 ? ":" : ""); - } - printf("]\n"); - } - break; - - case SND_SEQ_EVENT_QFRAME: - printf("; frame=0x%02x\n", ev->data.control.value); - break; - - case SND_SEQ_EVENT_CLOCK: - case SND_SEQ_EVENT_START: - case SND_SEQ_EVENT_CONTINUE: - case SND_SEQ_EVENT_STOP: - printf("; queue = %i\n", ev->data.queue.queue); - break; - - case SND_SEQ_EVENT_SENSING: - printf("\n"); - break; - - case SND_SEQ_EVENT_ECHO: - { - int i; - - printf("; "); - for (i = 0; i < 8; i++) { - printf("%02i%s", ev->data.raw8.d[i], i < 7 ? ":" : "\n"); - } - } - break; - - case SND_SEQ_EVENT_CLIENT_START: - case SND_SEQ_EVENT_CLIENT_EXIT: - case SND_SEQ_EVENT_CLIENT_CHANGE: - printf("; client=%i\n", ev->data.addr.client); - break; - - case SND_SEQ_EVENT_PORT_START: - case SND_SEQ_EVENT_PORT_EXIT: - case SND_SEQ_EVENT_PORT_CHANGE: - printf("; client=%i, port = %i\n", ev->data.addr.client, ev->data.addr.port); - break; - - case SND_SEQ_EVENT_PORT_SUBSCRIBED: - case SND_SEQ_EVENT_PORT_UNSUBSCRIBED: - printf("; %i:%i -> %i:%i\n", - ev->data.connect.sender.client, ev->data.connect.sender.port, - ev->data.connect.dest.client, ev->data.connect.dest.port); - break; - - default: - printf("; not implemented\n"); - } - - - switch (ev->flags & SND_SEQ_EVENT_LENGTH_MASK) { - case SND_SEQ_EVENT_LENGTH_FIXED: - return sizeof(snd_seq_event_t); - - case SND_SEQ_EVENT_LENGTH_VARIABLE: - return sizeof(snd_seq_event_t) + ev->data.ext.len; - } - - return 0; -} - -void event_decoder_start_timer(snd_seq_t *handle, int queue, - int client ATTRIBUTE_UNUSED, - int port ATTRIBUTE_UNUSED) -{ - int err; - - if ((err = snd_seq_start_queue(handle, queue, NULL))<0) - fprintf(stderr, "Timer event output error: %s\n", snd_strerror(err)); - while (snd_seq_drain_output(handle)>0) - sleep(1); -} - -void event_decoder(snd_seq_t *handle, int argc, char *argv[]) -{ - snd_seq_event_t *ev; - snd_seq_port_info_t *pinfo; - snd_seq_port_subscribe_t *sub; - snd_seq_addr_t addr; - int client, port, queue, max, err, v1, v2; - char *ptr; - struct pollfd *pfds; - - if ((client = snd_seq_client_id(handle))<0) { - fprintf(stderr, "Cannot determine client number: %s\n", snd_strerror(client)); - return; - } - printf("Client ID = %i\n", client); - if ((queue = snd_seq_alloc_queue(handle))<0) { - fprintf(stderr, "Cannot allocate queue: %s\n", snd_strerror(queue)); - return; - } - printf("Queue ID = %i\n", queue); - if ((err = snd_seq_nonblock(handle, 1))<0) - fprintf(stderr, "Cannot set nonblock mode: %s\n", snd_strerror(err)); - snd_seq_port_info_alloca(&pinfo); - snd_seq_port_info_set_name(pinfo, "Input"); - snd_seq_port_info_set_type(pinfo, SND_SEQ_PORT_TYPE_MIDI_GENERIC); - snd_seq_port_info_set_capability(pinfo, SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_WRITE); - if ((err = snd_seq_create_port(handle, pinfo)) < 0) { - fprintf(stderr, "Cannot create input port: %s\n", snd_strerror(err)); - return; - } - port = snd_seq_port_info_get_port(pinfo); - event_decoder_start_timer(handle, queue, client, port); - - snd_seq_port_subscribe_alloca(&sub); - addr.client = SND_SEQ_CLIENT_SYSTEM; - addr.port = SND_SEQ_PORT_SYSTEM_ANNOUNCE; - snd_seq_port_subscribe_set_sender(sub, &addr); - addr.client = client; - addr.port = port; - snd_seq_port_subscribe_set_dest(sub, &addr); - snd_seq_port_subscribe_set_queue(sub, queue); - snd_seq_port_subscribe_set_time_update(sub, 1); - snd_seq_port_subscribe_set_time_real(sub, 1); - if ((err = snd_seq_subscribe_port(handle, sub))<0) { - fprintf(stderr, "Cannot subscribe announce port: %s\n", snd_strerror(err)); - return; - } - - addr.client = SND_SEQ_CLIENT_SYSTEM; - addr.port = SND_SEQ_PORT_SYSTEM_TIMER; - snd_seq_port_subscribe_set_sender(sub, &addr); - if ((err = snd_seq_subscribe_port(handle, sub))<0) { - fprintf(stderr, "Cannot subscribe timer port: %s\n", snd_strerror(err)); - return; - } - - for (max = 0; max < argc; max++) { - ptr = argv[max]; - if (!ptr) - continue; - snd_seq_port_subscribe_set_time_real(sub, 0); - if (tolower(*ptr) == 'r') { - snd_seq_port_subscribe_set_time_real(sub, 1); - ptr++; - } - if (sscanf(ptr, "%i.%i", &v1, &v2) != 2) { - fprintf(stderr, "Wrong argument '%s'...\n", argv[max]); - return; - } - addr.client = v1; - addr.port = v2; - snd_seq_port_subscribe_set_sender(sub, &addr); - if ((err = snd_seq_subscribe_port(handle, sub))<0) { - fprintf(stderr, "Cannot subscribe port %i from client %i: %s\n", v2, v1, snd_strerror(err)); - return; - } - } - - max = snd_seq_poll_descriptors_count(handle, POLLIN); - pfds = alloca(sizeof(*pfds) * max); - while (1) { - snd_seq_poll_descriptors(handle, pfds, max, POLLIN); - if (poll(pfds, max, -1) < 0) - break; - do { - if ((err = snd_seq_event_input(handle, &ev))<0) - break; - if (!ev) - continue; - decode_event(ev); - snd_seq_free_event(ev); - } while (err > 0); - } -} diff --git a/alsa-lib/test/seq-sender.c b/alsa-lib/test/seq-sender.c deleted file mode 100644 index 5d8ac92..0000000 --- a/alsa-lib/test/seq-sender.c +++ /dev/null @@ -1,272 +0,0 @@ - -#ifdef USE_PCM // XXX not yet -/* - * PCM timer layer - */ - -int pcard = 0; -int pdevice = 0; -int period_size = 1024; - -void set_hwparams(snd_pcm_t *phandle) -{ - int err; - snd_pcm_hw_params_t *params; - - err = snd_output_stdio_attach(&log, stderr, 0); - if (err < 0) { - fprintf(stderr, "cannot attach output stdio\n"); - exit(0); - } - - snd_pcm_hw_params_alloca(¶ms); - err = snd_pcm_hw_params_any(phandle, params); - if (err < 0) { - fprintf(stderr, "Broken configuration for this PCM: no configurations available\n"); - exit(0); - } - - err = snd_pcm_hw_params_set_access(phandle, params, - SND_PCM_ACCESS_RW_INTERLEAVED); - if (err < 0) { - fprintf(stderr, "Access type not available\n"); - exit(0); - } - err = snd_pcm_hw_params_set_format(phandle, params, SND_PCM_FORMAT_S16_LE); - if (err < 0) { - fprintf(stderr, "cannot set format\n"); - exit(0); - } - err = snd_pcm_hw_params_set_channels(phandle, params, 2); - if (err < 0) { - fprintf(stderr, "cannot set channels 2\n"); - exit(0); - } - err = snd_pcm_hw_params_set_rate_near(phandle, params, 44100, 0); - if (err < 0) { - fprintf(stderr, "cannot set rate\n"); - exit(0); - } - err = snd_pcm_hw_params_set_period_size_near(phandle, params, period_size); - if (err < 0) { - fprintf(stderr, "cannot set period size\n"); - exit(0); - } - err = snd_pcm_hw_params(phandle, params); - if (err < 0) { - fprintf(stderr, "Unable to install hw params:\n"); - exit(0); - } - snd_pcm_hw_params_dump(params, log); -} - -#endif -/* - * Simple event sender - */ - -void event_sender_start_timer(snd_seq_t *handle, - int client ATTRIBUTE_UNUSED, - int queue, - snd_pcm_t *phandle ATTRIBUTE_UNUSED) -{ - int err; - -#ifdef USE_PCM - if (phandle) { - snd_pcm_playback_info_t pinfo; - snd_seq_queue_timer_t qtimer; - - if ((err = snd_pcm_playback_info(phandle, &pinfo)) < 0) { - fprintf(stderr, "Playback info error: %s\n", snd_strerror(err)); - exit(0); - } - bzero(&qtimer, sizeof(qtimer)); - qtimer.type = SND_SEQ_TIMER_MASTER; - /* note: last bit from the subdevices specifies playback */ - /* or capture direction for the timer specification */ - qtimer.number = SND_TIMER_PCM(pcard, pdevice, pinfo.subdevice << 1); - if ((err = snd_seq_set_queue_timer(handle, queue, &qtimer)) < 0) { - fprintf(stderr, "Sequencer PCM timer setup failed: %s\n", snd_strerror(err)); - exit(0); - } - } -#endif - if ((err = snd_seq_start_queue(handle, queue, NULL))<0) - fprintf(stderr, "Timer event output error: %s\n", snd_strerror(err)); - snd_seq_drain_output(handle); -} - -void event_sender_filter(snd_seq_t *handle) -{ - int err; - - if ((err = snd_seq_set_client_event_filter(handle, SND_SEQ_EVENT_ECHO)) < 0) { - fprintf(stderr, "Unable to set client info: %s\n", snd_strerror(err)); - return; - } -} - -void send_event(snd_seq_t *handle, int queue, int client, int port, - snd_seq_addr_t *dest, int *time) -{ - int err; - snd_seq_event_t ev; - - bzero(&ev, sizeof(ev)); - ev.queue = queue; - ev.source.client = ev.dest.client = client; - ev.source.port = ev.dest.port = port; - ev.flags = SND_SEQ_TIME_STAMP_REAL | SND_SEQ_TIME_MODE_ABS; - ev.time.time.tv_sec = *time; (*time)++; - ev.type = SND_SEQ_EVENT_ECHO; - if ((err = snd_seq_event_output(handle, &ev))<0) - fprintf(stderr, "Event output error: %s\n", snd_strerror(err)); - ev.dest = *dest; - ev.type = SND_SEQ_EVENT_PGMCHANGE; - ev.data.control.channel = 0; - ev.data.control.value = 16; - if ((err = snd_seq_event_output(handle, &ev))<0) - fprintf(stderr, "Event output error: %s\n", snd_strerror(err)); - ev.type = SND_SEQ_EVENT_NOTE; - ev.data.note.channel = 0; - ev.data.note.note = 64 + (queue*2); - ev.data.note.velocity = 127; - ev.data.note.off_velocity = 127; - ev.data.note.duration = 500; /* 0.5sec */ - if ((err = snd_seq_event_output(handle, &ev))<0) - fprintf(stderr, "Event output error: %s\n", snd_strerror(err)); - if ((err = snd_seq_drain_output(handle))<0) - fprintf(stderr, "Event drain error: %s\n", snd_strerror(err)); -} - -void event_sender(snd_seq_t *handle, int argc, char *argv[]) -{ - snd_seq_event_t *ev; - snd_seq_port_info_t *pinfo; - snd_seq_port_subscribe_t *sub; - snd_seq_addr_t addr; - struct pollfd *pfds; - int client, port, queue, max, err, v1, v2, time = 0, pcm_flag = 0; - char *ptr; - snd_pcm_t *phandle = NULL; - - if (argc < 1) { - fprintf(stderr, "Invalid destination...\n"); - return; - } - - if ((client = snd_seq_client_id(handle))<0) { - fprintf(stderr, "Cannot determine client number: %s\n", snd_strerror(client)); - return; - } - printf("Client ID = %i\n", client); - if ((queue = snd_seq_alloc_queue(handle))<0) { - fprintf(stderr, "Cannot allocate queue: %s\n", snd_strerror(queue)); - return; - } - printf("Queue ID = %i\n", queue); - event_sender_filter(handle); - if ((err = snd_seq_nonblock(handle, 1))<0) - fprintf(stderr, "Cannot set nonblock mode: %s\n", snd_strerror(err)); - - snd_seq_port_info_alloca(&pinfo); - snd_seq_port_info_set_capability(pinfo, SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_READ); - snd_seq_port_info_set_name(pinfo, "Output"); - if ((err = snd_seq_create_port(handle, pinfo)) < 0) { - fprintf(stderr, "Cannot create output port: %s\n", snd_strerror(err)); - return; - } - port = snd_seq_port_info_get_port(pinfo); - - snd_seq_port_subscribe_alloca(&sub); - addr.client = client; - addr.port = port; - snd_seq_port_subscribe_set_sender(sub, &addr); - - for (max = 0; max < argc; max++) { - ptr = argv[max]; - if (!ptr) - continue; - if (!strcmp(ptr, "pcm")) { - pcm_flag = 1; - continue; - } - if (sscanf(ptr, "%i.%i", &v1, &v2) != 2) { - fprintf(stderr, "Wrong argument '%s'...\n", argv[max]); - return; - } - addr.client = v1; - addr.port = v2; - snd_seq_port_subscribe_set_dest(sub, &addr); - if ((err = snd_seq_subscribe_port(handle, sub))<0) { - fprintf(stderr, "Cannot subscribe port %i from client %i: %s\n", v2, v1, snd_strerror(err)); - return; - } - } - - printf("Destination client = %i, port = %i\n", addr.client, addr.port); - -#ifdef USE_PCM - if (pcm_flag) { - if ((err = snd_pcm_open(&phandle, "default", SND_PCM_STREAM_PLAYBACK, 0)) < 0) { - fprintf(stderr, "Playback open error: %s\n", snd_strerror(err)); - exit(0); - } - set_hwparams(phandle); - pbuf = calloc(1, period_size * 4); - if (pbuf == NULL) { - fprintf(stderr, "No enough memory...\n"); - exit(0); - } - } -#endif - event_sender_start_timer(handle, client, queue, phandle); - - /* send the first event */ - send_event(handle, queue, client, port, &addr, &time); -#ifdef USE_PCM - if (phandle) - max += snd_pcm_poll_descriptors_count(phandle); -#endif - pfds = alloca(sizeof(*pfds) * max); - while (1) { - int nseqs = snd_seq_poll_descriptors_count(handle, POLLOUT|POLLIN); - if (snd_seq_event_output_pending(handle)) - snd_seq_poll_descriptors(handle, pfds, nseqs, POLLOUT|POLLIN); - else - snd_seq_poll_descriptors(handle, pfds, nseqs, POLLIN); - max = nseqs; -#ifdef USE_PCM - if (phandle) { - int pmax = snd_pcm_poll_descriptors_count(phandle); - snd_seq_poll_descriptors(phandle, pfds + max, pmax); - max += pmax; - } -#endif - if (poll(pfds, max, -1) < 0) - break; -#ifdef USE_PCM - if (phandle && (pfds[nseqs].revents & POLLOUT)) { - if (snd_pcm_writei(phandle, pbuf, period_size) != period_size) { - fprintf(stderr, "Playback write error!!\n"); - exit(0); - } - } -#endif - if (pfds[0].revents & POLLOUT) - snd_seq_drain_output(handle); - if (pfds[0].revents & POLLIN) { - do { - if ((err = snd_seq_event_input(handle, &ev))<0) - break; - if (!ev) - continue; - if (ev->type == SND_SEQ_EVENT_ECHO) - send_event(handle, queue, client, port, &addr, &time); - decode_event(ev); - snd_seq_free_event(ev); - } while (err > 0); - } - } -} diff --git a/alsa-lib/test/seq.c b/alsa-lib/test/seq.c deleted file mode 100644 index 34b000f..0000000 --- a/alsa-lib/test/seq.c +++ /dev/null @@ -1,233 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <ctype.h> -#include <getopt.h> -#include "../include/asoundlib.h" - -#include "seq-decoder.c" -#include "seq-sender.c" - -#define SEQ_VERSION "0.0.1" - -#define HELPID_HELP 1000 -#define HELPID_DEBUG 1001 -#define HELPID_VERBOSE 1002 -#define HELPID_VERSION 1003 - -int max_clients; -int max_ports; -int max_queues; -int debug = 0; -int verbose = 0; - -void set_name(snd_seq_t *handle) -{ - int err; - char name[64]; - - sprintf(name, "SeqUtil - %i", getpid()); - if ((err = snd_seq_set_client_name(handle, name)) < 0) { - fprintf(stderr, "Set client info error: %s\n", snd_strerror(err)); - exit(0); - } -} - -void system_info(snd_seq_t *handle) -{ - int err; - snd_seq_system_info_t *sysinfo; - - snd_seq_system_info_alloca(&sysinfo); - if ((err = snd_seq_system_info(handle, sysinfo))<0) { - fprintf(stderr, "System info error: %s\n", snd_strerror(err)); - exit(0); - } - max_clients = snd_seq_system_info_get_clients(sysinfo); - max_ports = snd_seq_system_info_get_ports(sysinfo); - max_queues = snd_seq_system_info_get_ports(sysinfo); -} - -void show_system_info(snd_seq_t *handle ATTRIBUTE_UNUSED) -{ - printf("System info\n"); - printf(" Max queues : %i\n", max_queues); - printf(" Max clients : %i\n", max_clients); - printf(" Max ports : %i\n", max_ports); -} - -void show_queue_status(snd_seq_t *handle, int queue) -{ - int err, idx, min, max; - snd_seq_queue_status_t *status; - - snd_seq_queue_status_alloca(&status); - min = queue < 0 ? 0 : queue; - max = queue < 0 ? max_queues : queue + 1; - for (idx = min; idx < max; idx++) { - if ((err = snd_seq_get_queue_status(handle, idx, status))<0) { - if (err == -ENOENT) - continue; - fprintf(stderr, "Client %i info error: %s\n", idx, snd_strerror(err)); - exit(0); - } - printf("Queue %i info\n", snd_seq_queue_status_get_queue(status)); - printf(" Tick : %u\n", snd_seq_queue_status_get_tick_time(status)); - printf(" Realtime : %i.%i\n", - snd_seq_queue_status_get_real_time(status)->tv_sec, - snd_seq_queue_status_get_real_time(status)->tv_nsec); - printf(" Flags : 0x%x\n", snd_seq_queue_status_get_status(status)); - } -} - -void show_port_info(snd_seq_t *handle, int client, int port) -{ - int err, idx, min, max; - snd_seq_port_info_t *info; - - snd_seq_port_info_alloca(&info); - min = port < 0 ? 0 : port; - max = port < 0 ? max_ports : port + 1; - for (idx = min; idx < max; idx++) { - if ((err = snd_seq_get_any_port_info(handle, client, idx, info))<0) { - if (err == -ENOENT) - continue; - fprintf(stderr, "Port %i/%i info error: %s\n", client, idx, snd_strerror(err)); - exit(0); - } - printf(" Port %i info\n", idx); - printf(" Client : %i\n", snd_seq_port_info_get_client(info)); - printf(" Port : %i\n", snd_seq_port_info_get_port(info)); - printf(" Name : %s\n", snd_seq_port_info_get_name(info)); - printf(" Capability : 0x%x\n", snd_seq_port_info_get_capability(info)); - printf(" Type : 0x%x\n", snd_seq_port_info_get_type(info)); - //printf(" Midi channels : %i\n", info.midi_channels); - //printf(" Synth voices : %i\n", info.synth_voices); - printf(" Output subs : %i\n", snd_seq_port_info_get_write_use(info)); - printf(" Input subs : %i\n", snd_seq_port_info_get_read_use(info)); - } -} - -void show_client_info(snd_seq_t *handle, int client) -{ - int err, idx, min, max; - snd_seq_client_info_t *info; - - snd_seq_client_info_alloca(&info); - min = client < 0 ? 0 : client; - max = client < 0 ? max_clients : client + 1; - for (idx = min; idx < max; idx++) { - if ((err = snd_seq_get_any_client_info(handle, idx, info))<0) { - if (err == -ENOENT) - continue; - fprintf(stderr, "Client %i info error: %s\n", idx, snd_strerror(err)); - exit(0); - } - printf("Client %i info\n", idx); - if (verbose) - printf(" Client : %i\n", snd_seq_client_info_get_client(info)); - printf(" Type : %s\n", snd_seq_client_info_get_type(info) == SND_SEQ_KERNEL_CLIENT ? "kernel" : "user"); - printf(" Name : %s\n", snd_seq_client_info_get_name(info)); - } -} - -static void help(void) -{ - printf("Usage: seq <options> command\n"); - printf("\nAvailable options:\n"); - printf(" -h,--help this help\n"); - printf(" -d,--debug debug mode\n"); - printf(" -v,--verbose verbose mode\n"); - printf(" -V,--version print version of this program\n"); - printf("\nAvailable commands:\n"); - printf(" system show basic sequencer info\n"); - printf(" queue [#] show all queues or specified queue\n"); - printf(" client [#] show all clients or specified client\n"); - printf(" port <client> [#] show all ports or specified port for specified client\n"); - printf(" decoder event decoder\n"); - printf(" sender <client.port> [<client.port>] ... event sender\n"); -} - -int main(int argc, char *argv[]) -{ - int morehelp, err, arg, arg1; - snd_seq_t *handle; - static struct option long_option[] = - { - {"help", 0, NULL, HELPID_HELP}, - {"debug", 0, NULL, HELPID_DEBUG}, - {"verbose", 0, NULL, HELPID_VERBOSE}, - {"version", 0, NULL, HELPID_VERSION}, - {NULL, 0, NULL, 0}, - }; - - morehelp = 0; - - while (1) { - int c; - - if ((c = getopt_long(argc, argv, "hdvV", long_option, NULL)) < 0) - break; - switch (c) { - case 'h': - case HELPID_HELP: - morehelp++; - break; - case 'd': - case HELPID_DEBUG: - debug = 1; - break; - case 'v': - case HELPID_VERBOSE: - verbose = 1; - break; - case 'V': - case HELPID_VERSION: - printf("alsactl version " SEQ_VERSION "\n"); - return 1; - default: - fprintf(stderr, "\07Invalid switch or option needs an argument.\n"); - morehelp++; - } - } - if (morehelp) { - help(); - return 1; - } - if (argc - optind <= 0) { - fprintf(stderr, "seq: Specify command...\n"); - return 0; - } - if ((err = snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0))<0) { - fprintf(stderr, "Open error: %s\n", snd_strerror(err)); - exit(0); - } - set_name(handle); - system_info(handle); - - if (!strcmp(argv[optind], "system")) { - show_system_info(handle); - } else if (!strcmp(argv[optind], "queue")) { - arg = argc - optind > 1 ? atoi(argv[optind + 1]) : -1; - show_queue_status(handle, arg); - } else if (!strcmp(argv[optind], "client")) { - arg = argc - optind > 1 ? atoi(argv[optind + 1]) : -1; - show_client_info(handle, arg); - } else if (!strcmp(argv[optind], "port")) { - arg = argc - optind > 1 ? atoi(argv[optind + 1]) : -1; - if (arg < 0) { - fprintf(stderr, "Specify port...\n"); - exit(0); - } - arg1 = argc - optind > 2 ? atoi(argv[optind + 2]) : -1; - show_port_info(handle, arg, arg1); - } else if (!strcmp(argv[optind], "decoder")) { - event_decoder(handle, argc - optind - 1, argv + optind + 1); - } else if (!strcmp(argv[optind], "sender")) { - event_sender(handle, argc - optind - 1, argv + optind + 1); - } else { - help(); - } - exit(1); -} diff --git a/alsa-lib/test/timer.c b/alsa-lib/test/timer.c deleted file mode 100644 index b05eb2f..0000000 --- a/alsa-lib/test/timer.c +++ /dev/null @@ -1,193 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/time.h> -#include "../include/asoundlib.h" - -void show_status(void *handle) -{ - int err; - snd_timer_status_t *status; - - snd_timer_status_alloca(&status); - if ((err = snd_timer_status(handle, status)) < 0) { - fprintf(stderr, "timer status %i (%s)\n", err, snd_strerror(err)); - return; - } - printf("STATUS:\n"); - printf(" resolution = %li\n", snd_timer_status_get_resolution(status)); - printf(" lost = %li\n", snd_timer_status_get_lost(status)); - printf(" overrun = %li\n", snd_timer_status_get_overrun(status)); - printf(" queue = %li\n", snd_timer_status_get_queue(status)); -} - -void read_loop(void *handle, int master_ticks, int timeout) -{ - int count, err; - struct pollfd *fds; - snd_timer_read_t tr; - - count = snd_timer_poll_descriptors_count(handle); - fds = calloc(count, sizeof(struct pollfd)); - if (fds == NULL) { - fprintf(stderr, "malloc error\n"); - exit(EXIT_FAILURE); - } - while (master_ticks-- > 0) { - if ((err = snd_timer_poll_descriptors(handle, fds, count)) < 0) { - fprintf(stderr, "snd_timer_poll_descriptors error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - if ((err = poll(fds, count, timeout)) < 0) { - fprintf(stderr, "poll error %i (%s)\n", err, strerror(err)); - exit(EXIT_FAILURE); - } - if (err == 0) { - fprintf(stderr, "timer time out!!\n"); - exit(EXIT_FAILURE); - } - while (snd_timer_read(handle, &tr, sizeof(tr)) == sizeof(tr)) { - printf("TIMER: resolution = %uns, ticks = %u\n", - tr.resolution, tr.ticks); - } - } - free(fds); -} - -static void async_callback(snd_async_handler_t *ahandler) -{ - snd_timer_t *handle = snd_async_handler_get_timer(ahandler); - int *acount = snd_async_handler_get_callback_private(ahandler); - snd_timer_read_t tr; - - while (snd_timer_read(handle, &tr, sizeof(tr)) == sizeof(tr)) { - printf("TIMER: resolution = %uns, ticks = %u\n", - tr.resolution, tr.ticks); - } - (*acount)++; -} - -int main(int argc, char *argv[]) -{ - int idx, err; - int class = SND_TIMER_CLASS_GLOBAL; - int sclass = SND_TIMER_CLASS_NONE; - int card = 0; - int device = SND_TIMER_GLOBAL_SYSTEM; - int subdevice = 0; - int list = 0; - int async = 0; - int acount = 0; - snd_timer_t *handle; - snd_timer_id_t *id; - snd_timer_info_t *info; - snd_timer_params_t *params; - char timername[64]; - snd_async_handler_t *ahandler; - - snd_timer_id_alloca(&id); - snd_timer_info_alloca(&info); - snd_timer_params_alloca(¶ms); - - idx = 1; - while (idx < argc) { - if (!strncmp(argv[idx], "class=", 5)) { - class = atoi(argv[idx]+6); - } else if (!strncmp(argv[idx], "sclass=", 6)) { - sclass = atoi(argv[idx]+7); - } else if (!strncmp(argv[idx], "card=", 5)) { - card = atoi(argv[idx]+5); - } else if (!strncmp(argv[idx], "device=", 7)) { - device = atoi(argv[idx]+7); - } else if (!strncmp(argv[idx], "subdevice=", 10)) { - subdevice = atoi(argv[idx]+10); - } else if (!strcmp(argv[idx], "list")) { - list = 1; - } else if (!strcmp(argv[idx], "async")) { - async = 1; - } - idx++; - } - if (class == SND_TIMER_CLASS_SLAVE && sclass == SND_TIMER_SCLASS_NONE) { - fprintf(stderr, "slave class is not set\n"); - exit(EXIT_FAILURE); - } - if (list) { - snd_timer_query_t *qhandle; - if ((err = snd_timer_query_open(&qhandle, "hw", 0)) < 0) { - fprintf(stderr, "snd_timer_query_open error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); - } - snd_timer_id_set_class(id, SND_TIMER_CLASS_NONE); - while (1) { - if ((err = snd_timer_query_next_device(qhandle, id)) < 0) { - fprintf(stderr, "timer next device error: %s\n", snd_strerror(err)); - break; - } - if (snd_timer_id_get_class(id) < 0) - break; - printf("Timer device: class %i, sclass %i, card %i, device %i, subdevice %i\n", - snd_timer_id_get_class(id), - snd_timer_id_get_sclass(id), - snd_timer_id_get_card(id), - snd_timer_id_get_device(id), - snd_timer_id_get_subdevice(id)); - } - snd_timer_query_close(qhandle); - exit(EXIT_SUCCESS); - } - sprintf(timername, "hw:CLASS=%i,SCLASS=%i,CARD=%i,DEV=%i,SUBDEV=%i", class, sclass, card, device, subdevice); - if ((err = snd_timer_open(&handle, timername, SND_TIMER_OPEN_NONBLOCK))<0) { - fprintf(stderr, "timer open %i (%s)\n", err, snd_strerror(err)); - exit(EXIT_FAILURE); - } - printf("Using timer class %i, slave class %i, card %i, device %i, subdevice %i\n", class, sclass, card, device, subdevice); - if ((err = snd_timer_info(handle, info)) < 0) { - fprintf(stderr, "timer info %i (%s)\n", err, snd_strerror(err)); - exit(0); - } - printf("Timer info:\n"); - printf(" slave = %s\n", snd_timer_info_is_slave(info) ? "yes" : "no"); - printf(" card = %i\n", snd_timer_info_get_card(info)); - printf(" id = '%s'\n", snd_timer_info_get_id(info)); - printf(" name = '%s'\n", snd_timer_info_get_name(info)); - printf(" average resolution = %li\n", snd_timer_info_get_resolution(info)); - snd_timer_params_set_auto_start(params, 1); - if (!snd_timer_info_is_slave(info)) { - snd_timer_params_set_ticks(params, (1000000000 / snd_timer_info_get_resolution(info)) / 50); /* 50Hz */ - if (snd_timer_params_get_ticks(params) < 1) - snd_timer_params_set_ticks(params, 1); - printf("Using %li tick(s)\n", snd_timer_params_get_ticks(params)); - } else { - snd_timer_params_set_ticks(params, 1); - } - if ((err = snd_timer_params(handle, params)) < 0) { - fprintf(stderr, "timer params %i (%s)\n", err, snd_strerror(err)); - exit(0); - } - show_status(handle); - if (async) { - err = snd_async_add_timer_handler(&ahandler, handle, async_callback, &acount); - if (err < 0) { - fprintf(stderr, "unable to add async handler %i (%s)\n", err, snd_strerror(err)); - exit(EXIT_FAILURE); - } - } - if ((err = snd_timer_start(handle)) < 0) { - fprintf(stderr, "timer start %i (%s)\n", err, snd_strerror(err)); - exit(EXIT_FAILURE); - } - if (async) { - /* because all other work is done in the signal handler, - suspend the process */ - while (acount < 25) - sleep(1); - snd_timer_stop(handle); - } else { - read_loop(handle, 25, snd_timer_info_is_slave(info) ? 10000 : 25); - } - show_status(handle); - snd_timer_close(handle); - printf("Done\n"); - return EXIT_SUCCESS; -} |