add a simple example/test of lsr-bindings

master
Rob Sykes 2013-01-08 21:19:12 +00:00
parent 54fdbf1e3b
commit 441593182a
4 changed files with 63 additions and 12 deletions

View File

@ -44,5 +44,4 @@ int main(int argc, char const * arg[])
free(out); /* Tidy up. */
return !!error;
(void)argc, (void)arg; /* Not used in this example. */
}

37
examples/1a-lsr.c 100644
View File

@ -0,0 +1,37 @@
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */
/* Example 1a: Variant of example 1 using libsamplerate-like bindings. */
#include <soxr-lsr.h>
#include "examples-common.h"
float in[] = { /* Input: 12 cycles of a sine wave with freq. = irate/4 */
0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1,
0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1};
int main(int argc, char const * arg[])
{
double irate = argc > 1? atof(arg[1]) : 1; /* Default to upsampling */
double orate = argc > 2? atof(arg[2]) : 2; /* by a factor of 2. */
size_t olen = (size_t)(AL(in) * orate / irate + .5); /* Assay output len. */
float * out = malloc(sizeof(*out) * olen); /* Allocate output buffer. */
int error, i = 0;
SRC_DATA data;
data.data_in = in;
data.data_out = out;
data.input_frames = AL(in);
data.output_frames = (int)olen;
data.src_ratio = orate / irate;
error = src_simple(&data, SRC_SINC_FASTEST, 1);
while (i++ < data.output_frames_gen) /* Print out the resampled data... */
printf("%5.2f%c", out[i-1], " \n"[!(i&7) || i == data.output_frames_gen]);
puts(src_strerror(error)); /* ...and the reported result. */
free(out); /* Tidy up. */
return !!error;
}

View File

@ -2,20 +2,33 @@
# Licence for this file: LGPL v2.1 See LICENCE for details.
if (${BUILD_EXAMPLES})
project (soxr)
file (GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.[cC])
if (NOT BUILD_SHARED_LIBS AND OPENMP_FOUND)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_C_FLAGS}")
endif ()
else ()
project (soxr) # Adds c++ compiler
file (GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/[1-9]-*.[cC])
elseif (${BUILD_TESTS})
file (GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/3*.c)
endif ()
if (${BUILD_EXAMPLES} OR ${BUILD_TESTS})
if (${WITH_LSR_BINDINGS})
set (LSR_SOURCES 1a-lsr.c)
endif ()
endif ()
if (NOT BUILD_SHARED_LIBS AND OPENMP_FOUND)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_C_FLAGS}")
endif ()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PROJECT_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PROJECT_CXX_FLAGS}")
link_libraries (${PROJECT_NAME})
foreach (fe ${SOURCES})
foreach (fe ${SOURCES} ${LSR_SOURCES})
get_filename_component (f ${fe} NAME_WE)
add_executable (${f} ${fe})
if (${f} STREQUAL "1a-lsr")
target_link_libraries (${f} soxr-lsr)
endif ()
endforeach ()
if (${BUILD_TESTS} AND ${WITH_LSR_BINDINGS})
add_test (lsr-bindings 1a-lsr)
endif ()

View File

@ -1,18 +1,20 @@
SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
These simple examples show the different ways that an application may
interface with libsoxr. Note that real-world applications may also have to
interface with soxr. Note that real-world applications may also have to
deal with file-formats, codecs, (more sophisticated) dithering, etc., which
are not covered here.
With libsoxr installed, the examples may be built using commands similar to
the following. On unix-like systems:
With the library installed, the examples may be built using commands similar
to the following. On unix-like systems:
cc 1-single-block.c -lsoxr
cc 1a-lsr.c -lsoxr-lsr
or, on MS-Windows:
or, with MSVC on MS-Windows:
cl 1-single-block.c -I"C:/Program Files/soxr/include" "C:/Program Files/soxr/lib/soxr.lib"
cl 1a-lsr.c -I"C:/Program Files/soxr/include" "C:/Program Files/soxr/lib/soxr-lsr.lib"
IDEs may hide such commands behind configuration screens and build menus --
where applicable, consult your IDE's user-manual.