simpleaudio: benchmark backend

This commit is contained in:
Kamal Mostafa 2012-08-13 15:50:04 -07:00
parent 9948e7c7dd
commit 23ecd6f5a7
9 changed files with 167 additions and 1 deletions

View File

@ -24,6 +24,9 @@
/* Define to 1 to enable ALSA support */ /* Define to 1 to enable ALSA support */
#undef USE_ALSA #undef USE_ALSA
/* Define to 1 to enable internal benchmarks */
#undef USE_BENCHMARKS
/* Define to 1 to enable pulseaudio support */ /* Define to 1 to enable pulseaudio support */
#undef USE_PULSEAUDIO #undef USE_PULSEAUDIO

24
configure vendored
View File

@ -659,6 +659,7 @@ enable_dependency_tracking
with_alsa with_alsa
with_pulseaudio with_pulseaudio
with_sndfile with_sndfile
with_benchmarks
' '
ac_precious_vars='build_alias ac_precious_vars='build_alias
host_alias host_alias
@ -1298,6 +1299,7 @@ Optional Packages:
--without-alsa build without ALSA support --without-alsa build without ALSA support
--without-pulseaudio build without pulseaudio support --without-pulseaudio build without pulseaudio support
--without-sndfile build without sndfile support --without-sndfile build without sndfile support
--disable-benchmarks build without internal benchmarks
Some influential environment variables: Some influential environment variables:
CC C compiler command CC C compiler command
@ -3355,6 +3357,26 @@ cat >>confdefs.h <<_ACEOF
_ACEOF _ACEOF
# benchmarks
# Check whether --with-benchmarks was given.
if test "${with_benchmarks+set}" = set; then :
withval=$with_benchmarks;
fi
if test "x$with_benchmarks" == "xno"; then :
# then
use_benchmarks=0
else
# else
use_benchmarks=1
fi
cat >>confdefs.h <<_ACEOF
#define USE_BENCHMARKS $use_benchmarks
_ACEOF
# Checks for libraries. # Checks for libraries.
@ -5051,11 +5073,13 @@ fi
--with-pulseaudio $with_pulseaudio ($use_pulseaudio) --with-pulseaudio $with_pulseaudio ($use_pulseaudio)
--with-alsa $with_alsa ($use_alsa) --with-alsa $with_alsa ($use_alsa)
--with-sndfile $with_sndfile ($use_sndfile) --with-sndfile $with_sndfile ($use_sndfile)
--with-benchmarks $with_benchmarks ($use_benchmarks)
deps_packages: $deps_packages deps_packages: $deps_packages
" >&5 " >&5
$as_echo "minimodem 0.8.2 configuration summary: $as_echo "minimodem 0.8.2 configuration summary:
--with-pulseaudio $with_pulseaudio ($use_pulseaudio) --with-pulseaudio $with_pulseaudio ($use_pulseaudio)
--with-alsa $with_alsa ($use_alsa) --with-alsa $with_alsa ($use_alsa)
--with-sndfile $with_sndfile ($use_sndfile) --with-sndfile $with_sndfile ($use_sndfile)
--with-benchmarks $with_benchmarks ($use_benchmarks)
deps_packages: $deps_packages deps_packages: $deps_packages
" >&6; } " >&6; }

View File

@ -69,6 +69,17 @@ AS_IF([test "x$with_sndfile" == "xno"],
AC_DEFINE_UNQUOTED(USE_SNDFILE, $use_sndfile, AC_DEFINE_UNQUOTED(USE_SNDFILE, $use_sndfile,
[Define to 1 to enable sndfile support]) [Define to 1 to enable sndfile support])
# benchmarks
AC_ARG_WITH([benchmarks],
AS_HELP_STRING([--disable-benchmarks], [build without internal benchmarks]))
AS_IF([test "x$with_benchmarks" == "xno"],
# then
use_benchmarks=0,
# else
use_benchmarks=1)
AC_DEFINE_UNQUOTED(USE_BENCHMARKS, $use_benchmarks,
[Define to 1 to enable internal benchmarks])
# Checks for libraries. # Checks for libraries.
PKG_CHECK_MODULES(DEPS, [ $deps_packages ]) PKG_CHECK_MODULES(DEPS, [ $deps_packages ])
@ -97,5 +108,6 @@ AC_MSG_RESULT([PKG_NAME PKG_VERSION configuration summary:
--with-pulseaudio $with_pulseaudio ($use_pulseaudio) --with-pulseaudio $with_pulseaudio ($use_pulseaudio)
--with-alsa $with_alsa ($use_alsa) --with-alsa $with_alsa ($use_alsa)
--with-sndfile $with_sndfile ($use_sndfile) --with-sndfile $with_sndfile ($use_sndfile)
--with-benchmarks $with_benchmarks ($use_benchmarks)
deps_packages: $deps_packages deps_packages: $deps_packages
]) ])

View File

@ -37,6 +37,7 @@ SIMPLEAUDIO_SRC = \
simple-tone-generator.c \ simple-tone-generator.c \
simpleaudio-pulse.c \ simpleaudio-pulse.c \
simpleaudio-alsa.c \ simpleaudio-alsa.c \
simpleaudio-benchmark.c \
simpleaudio-sndfile.c simpleaudio-sndfile.c
FSK_SRC = fsk.h fsk.c FSK_SRC = fsk.h fsk.c

View File

@ -69,7 +69,7 @@ am__objects_1 = baudot.$(OBJEXT)
am__objects_2 = fsk.$(OBJEXT) am__objects_2 = fsk.$(OBJEXT)
am__objects_3 = simpleaudio.$(OBJEXT) simple-tone-generator.$(OBJEXT) \ am__objects_3 = simpleaudio.$(OBJEXT) simple-tone-generator.$(OBJEXT) \
simpleaudio-pulse.$(OBJEXT) simpleaudio-alsa.$(OBJEXT) \ simpleaudio-pulse.$(OBJEXT) simpleaudio-alsa.$(OBJEXT) \
simpleaudio-sndfile.$(OBJEXT) simpleaudio-benchmark.$(OBJEXT) simpleaudio-sndfile.$(OBJEXT)
am_minimodem_OBJECTS = minimodem.$(OBJEXT) $(am__objects_1) \ am_minimodem_OBJECTS = minimodem.$(OBJEXT) $(am__objects_1) \
$(am__objects_2) $(am__objects_3) $(am__objects_2) $(am__objects_3)
minimodem_OBJECTS = $(am_minimodem_OBJECTS) minimodem_OBJECTS = $(am_minimodem_OBJECTS)
@ -220,6 +220,7 @@ SIMPLEAUDIO_SRC = \
simple-tone-generator.c \ simple-tone-generator.c \
simpleaudio-pulse.c \ simpleaudio-pulse.c \
simpleaudio-alsa.c \ simpleaudio-alsa.c \
simpleaudio-benchmark.c \
simpleaudio-sndfile.c simpleaudio-sndfile.c
FSK_SRC = fsk.h fsk.c FSK_SRC = fsk.h fsk.c
@ -314,6 +315,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/minimodem.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/minimodem.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simple-tone-generator.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simple-tone-generator.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simpleaudio-alsa.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simpleaudio-alsa.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simpleaudio-benchmark.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simpleaudio-pulse.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simpleaudio-pulse.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simpleaudio-sndfile.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simpleaudio-sndfile.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simpleaudio.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simpleaudio.Po@am__quote@

116
src/simpleaudio-benchmark.c Normal file
View File

@ -0,0 +1,116 @@
/*
* simpleaudio-benchmark.c
*
* Copyright (C) 2011 Kamal Mostafa <kamal@whence.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if USE_BENCHMARKS
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <assert.h>
#include <sys/time.h>
#include "simpleaudio.h"
#include "simpleaudio_internal.h"
/*
* benchmark backend for simpleaudio
*/
struct benchmark_data {
struct timeval tv_start;
unsigned long total_nframes;
};
static ssize_t
sa_benchmark_dummy_readwrite( simpleaudio *sa, void *buf, size_t nframes )
{
struct benchmark_data *d = sa->backend_handle;
d->total_nframes += nframes;
return nframes;
}
static void
sa_benchmark_close( simpleaudio *sa )
{
struct timeval tv_stop;
gettimeofday(&tv_stop, NULL);
struct benchmark_data *d = sa->backend_handle;
unsigned long runtime_usec, playtime_usec;
runtime_usec = (tv_stop.tv_sec - d->tv_start.tv_sec) * 1000000;
runtime_usec += tv_stop.tv_usec;
runtime_usec -= d->tv_start.tv_usec;
playtime_usec = d->total_nframes * 1000000 / sa->rate;
unsigned long performance = d->total_nframes * 1000000 / runtime_usec;
fprintf(stdout, " frames count: \t%lu\n", d->total_nframes);
fprintf(stdout, " audio playtime: \t%2lu.%06lu sec\n",
playtime_usec/1000000, playtime_usec%1000000);
fprintf(stdout, " elapsed runtime: \t%2lu.%06lu sec\n",
runtime_usec/1000000, runtime_usec%1000000);
fprintf(stdout, " performance: \t%lu samples/sec\n",
performance);
fflush(stdout);
free(sa->backend_handle);
}
static int
sa_benchmark_open_stream(
simpleaudio *sa,
sa_direction_t sa_stream_direction,
sa_format_t sa_format,
unsigned int rate, unsigned int channels,
char *app_name, char *stream_name )
{
struct benchmark_data *d = calloc(1, sizeof(struct benchmark_data));
if ( !d ) {
perror("malloc");
return 0;
}
sa->backend_handle = d;
sa->backend_framesize = sa->channels * sa->samplesize;
fprintf(stdout, " %s\n", stream_name);
fflush(stdout);
gettimeofday(&d->tv_start, NULL);
return 1;
}
const struct simpleaudio_backend simpleaudio_backend_benchmark = {
sa_benchmark_open_stream,
sa_benchmark_dummy_readwrite /* read */,
sa_benchmark_dummy_readwrite /* write */,
sa_benchmark_close,
};
#endif /* USE_BENCHMARKS */

View File

@ -71,6 +71,12 @@ simpleaudio_open_stream(
break; break;
#endif #endif
#if USE_BENCHMARKS
case SA_BACKEND_BENCHMARK:
sa->backend = &simpleaudio_backend_benchmark;
break;
#endif
case SA_BACKEND_SYSDEFAULT: case SA_BACKEND_SYSDEFAULT:
#if USE_PULSEAUDIO #if USE_PULSEAUDIO
sa->backend = &simpleaudio_backend_pulseaudio; sa->backend = &simpleaudio_backend_pulseaudio;

View File

@ -35,6 +35,7 @@ typedef struct simpleaudio simpleaudio;
typedef enum { typedef enum {
SA_BACKEND_SYSDEFAULT=0, SA_BACKEND_SYSDEFAULT=0,
SA_BACKEND_FILE, SA_BACKEND_FILE,
SA_BACKEND_BENCHMARK,
SA_BACKEND_ALSA, SA_BACKEND_ALSA,
SA_BACKEND_PULSEAUDIO, SA_BACKEND_PULSEAUDIO,
} sa_backend_t; } sa_backend_t;

View File

@ -57,6 +57,7 @@ struct simpleaudio_backend {
(*simpleaudio_close)( simpleaudio *sa ); (*simpleaudio_close)( simpleaudio *sa );
}; };
extern const struct simpleaudio_backend simpleaudio_backend_benchmark;
extern const struct simpleaudio_backend simpleaudio_backend_sndfile; extern const struct simpleaudio_backend simpleaudio_backend_sndfile;
extern const struct simpleaudio_backend simpleaudio_backend_alsa; extern const struct simpleaudio_backend simpleaudio_backend_alsa;
extern const struct simpleaudio_backend simpleaudio_backend_pulseaudio; extern const struct simpleaudio_backend simpleaudio_backend_pulseaudio;