Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make libsamplerate work with other libs/frameworks such as JUCE. #67

Merged
merged 2 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ include(CheckSymbolExists)
include(CheckTypeSize)
include(CMakePushCheckState)
include(ClipMode)
add_definitions(-DHAVE_CONFIG_H)

set(SAMPLERATE_SRC
${PROJECT_SOURCE_DIR}/src/samplerate.c
Expand Down
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ CLEANFILES = src/src_sinc.s
# MinGW requires -no-undefined if a DLL is to be built.
src_libsamplerate_la_LDFLAGS = -no-undefined -version-info $(SHARED_VERSION_INFO) $(SHLIB_VERSION_ARG)
src_libsamplerate_la_SOURCES = src/samplerate.c src/src_sinc.c src/src_zoh.c src/src_linear.c \
src/common.h src/float_cast.h src/fastest_coeffs.h src/mid_qual_coeffs.h src/high_qual_coeffs.h
src/common.h src/float_cast.h src/fastest_coeffs.h src/mid_qual_coeffs.h src/high_qual_coeffs.h \
src/src_config.h

#-------------------------------------------------------------------------------
# An extra check for bad asm.
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ dnl ============================================================================
dnl Compiler stuff.

AS_IF([test "x$enable_flags_setting" = "xyes"], [
AX_APPEND_COMPILE_FLAGS([-O2 -pipe], [CFLAGS])
AX_APPEND_COMPILE_FLAGS([-DHAVE_CONFIG_H -O2 -pipe], [CFLAGS])

AS_CASE([${host_os}],
[darwin*], [
Expand Down
2 changes: 1 addition & 1 deletion examples/audio_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <string.h>
#include <unistd.h>

#include <config.h>
#include "src_config.h"

#include "audio_out.h"

Expand Down
2 changes: 1 addition & 1 deletion examples/timewarp-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
*/

#include "config.h"
#include "src_config.h"

#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/varispeed-play.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <unistd.h>
#include <string.h>

#include "config.h"
#include "src_config.h"

#include <float_cast.h>

Expand Down
9 changes: 9 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ typedef long int32_t ;

#define MAKE_MAGIC(a,b,c,d,e,f) ((a) + ((b) << 4) + ((c) << 8) + ((d) << 12) + ((e) << 16) + ((f) << 20))

/*
** Adds casting needed if compiled/included within cpp
*/
#ifdef __cplusplus
#define ZERO_ALLOC(type, size) static_cast<type*>(calloc(1, size))
#else // __cplusplus
#define ZERO_ALLOC(type, size) calloc(1, size)
#endif

/*
** Inspiration : http://sourcefrog.net/weblog/software/languages/C/unused.html
*/
Expand Down
2 changes: 1 addition & 1 deletion src/float_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
** long int lrint (double x) ;
*/

#include "config.h"
#include "src_config.h"

/*
** The presence of the required functions are detected during the configure
Expand Down
6 changes: 3 additions & 3 deletions src/samplerate.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdlib.h>
#include <string.h>

#include "config.h"
#include "src_config.h"

#include "samplerate.h"
#include "float_cast.h"
Expand All @@ -32,7 +32,7 @@ src_new (int converter_type, int channels, int *error)
return NULL ;
} ;

if ((psrc = calloc (1, sizeof (*psrc))) == NULL)
if ((psrc = ZERO_ALLOC (SRC_PRIVATE, sizeof (*psrc))) == NULL)
{ if (error)
*error = SRC_ERR_MALLOC_FAILED ;
return NULL ;
Expand Down Expand Up @@ -62,7 +62,7 @@ src_clone (SRC_STATE* orig, int *error)
if (error)
*error = SRC_ERR_NO_ERROR ;

if ((psrc = calloc (1, sizeof (*psrc))) == NULL)
if ((psrc = ZERO_ALLOC (SRC_PRIVATE, sizeof (*psrc))) == NULL)
{ if (error)
*error = SRC_ERR_MALLOC_FAILED ;
return NULL ;
Expand Down
12 changes: 12 additions & 0 deletions src/src_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
** Copyright (c) 1999-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
** All rights reserved.
**
** This code is released under 2-clause BSD license. Please see the
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
*/

// allow config.h to be optional
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
6 changes: 3 additions & 3 deletions src/src_linear.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdlib.h>
#include <string.h>

#include "config.h"
#include "src_config.h"
#include "float_cast.h"
#include "common.h"

Expand Down Expand Up @@ -171,7 +171,7 @@ linear_set_converter (SRC_PRIVATE *psrc, int src_enum)
} ;

if (psrc->private_data == NULL)
{ priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
{ priv = ZERO_ALLOC (LINEAR_DATA, sizeof (*priv) + psrc->channels * sizeof (float)) ;
psrc->private_data = priv ;
} ;

Expand Down Expand Up @@ -219,7 +219,7 @@ linear_copy (SRC_PRIVATE *from, SRC_PRIVATE *to)
LINEAR_DATA* from_priv = (LINEAR_DATA*) from->private_data ;
size_t private_size = sizeof (*to_priv) + from_priv->channels * sizeof (float) ;

if ((to_priv = calloc (1, private_size)) == NULL)
if ((to_priv = ZERO_ALLOC (LINEAR_DATA, private_size)) == NULL)
return SRC_ERR_MALLOC_FAILED ;

memcpy (to_priv, from_priv, private_size) ;
Expand Down
6 changes: 3 additions & 3 deletions src/src_sinc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdlib.h>
#include <string.h>

#include "config.h"
#include "src_config.h"
#include "float_cast.h"
#include "common.h"

Expand Down Expand Up @@ -216,7 +216,7 @@ sinc_set_converter (SRC_PRIVATE *psrc, int src_enum)
temp_filter.b_len = MAX (temp_filter.b_len, 4096) ;
temp_filter.b_len *= temp_filter.channels ;

if ((filter = calloc (1, sizeof (SINC_FILTER) + sizeof (filter->buffer [0]) * (temp_filter.b_len + temp_filter.channels))) == NULL)
if ((filter = ZERO_ALLOC (SINC_FILTER, sizeof (SINC_FILTER) + sizeof (filter->buffer [0]) * (temp_filter.b_len + temp_filter.channels))) == NULL)
return SRC_ERR_MALLOC_FAILED ;

*filter = temp_filter ;
Expand Down Expand Up @@ -265,7 +265,7 @@ sinc_copy (SRC_PRIVATE *from, SRC_PRIVATE *to)
SINC_FILTER* from_filter = (SINC_FILTER*) from->private_data ;
size_t private_length = sizeof (SINC_FILTER) + sizeof (from_filter->buffer [0]) * (from_filter->b_len + from_filter->channels) ;

if ((to_filter = calloc (1, private_length)) == NULL)
if ((to_filter = ZERO_ALLOC (SINC_FILTER, private_length)) == NULL)
return SRC_ERR_MALLOC_FAILED ;

memcpy (to_filter, from_filter, private_length) ;
Expand Down
6 changes: 3 additions & 3 deletions src/src_zoh.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdlib.h>
#include <string.h>

#include "config.h"
#include "src_config.h"
#include "float_cast.h"
#include "common.h"

Expand Down Expand Up @@ -162,7 +162,7 @@ zoh_set_converter (SRC_PRIVATE *psrc, int src_enum)
} ;

if (psrc->private_data == NULL)
{ priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
{ priv = ZERO_ALLOC (ZOH_DATA, sizeof (*priv) + psrc->channels * sizeof (float)) ;
psrc->private_data = priv ;
} ;

Expand Down Expand Up @@ -210,7 +210,7 @@ zoh_copy (SRC_PRIVATE *from, SRC_PRIVATE *to)
ZOH_DATA* from_priv = (ZOH_DATA*) from->private_data ;
size_t private_size = sizeof (*to_priv) + from_priv->channels * sizeof (float) ;

if ((to_priv = calloc (1, private_size)) == NULL)
if ((to_priv = ZERO_ALLOC (ZOH_DATA, private_size)) == NULL)
return SRC_ERR_MALLOC_FAILED ;

memcpy (to_priv, from_priv, private_size) ;
Expand Down
2 changes: 1 addition & 1 deletion tests/calc_snr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
*/

#include "config.h"
#include "src_config.h"

#include "util.h"

Expand Down
2 changes: 1 addition & 1 deletion tests/callback_hang_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
*/

#include "config.h"
#include "src_config.h"

#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/multi_channel_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
*/

#include "config.h"
#include "src_config.h"

#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/multichan_throughput_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <samplerate.h>

#include "config.h"
#include "src_config.h"

#include "util.h"
#include "float_cast.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/snr_bw_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
*/

#include "config.h"
#include "src_config.h"

#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/src-evaluate.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <string.h>
#include <ctype.h>

#include "config.h"
#include "src_config.h"

#if (HAVE_FFTW3 && HAVE_SNDFILE && HAVE_SYS_TIMES_H)

Expand Down
2 changes: 1 addition & 1 deletion tests/throughput_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <samplerate.h>

#include "config.h"
#include "src_config.h"

#include "util.h"
#include "float_cast.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
*/

#include "config.h"
#include "src_config.h"

#define ABS(a) (((a) < 0) ? - (a) : (a))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
Expand Down
2 changes: 1 addition & 1 deletion tests/varispeed_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
*/

#include "config.h"
#include "src_config.h"

#include <stdio.h>
#include <stdlib.h>
Expand Down