mirror of https://github.com/PCSX2/pcsx2.git
3rd Party: Update Libsamplerate to 0.2.1
This commit is contained in:
parent
693de2a9dd
commit
ec09699fb0
|
@ -1 +1,13 @@
|
||||||
|
Original author:
|
||||||
|
|
||||||
Erik de Castro Lopo <erikd@mega-nerd.com>
|
Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||||
|
|
||||||
|
Current maintainers:
|
||||||
|
|
||||||
|
After the release of version 0.1.9, @erikd transferred the project to
|
||||||
|
[the libsndfile team](https://github.com/libsndfile) consisting of:
|
||||||
|
|
||||||
|
* Erik de Castro Lopo aka @erikd
|
||||||
|
* David Seifert aka @SoapGentoo
|
||||||
|
* Arthur Taylor aka @arthurt
|
||||||
|
* @evpobr
|
||||||
|
|
|
@ -1,3 +1,35 @@
|
||||||
|
Unreleased
|
||||||
|
* Switch to GCC's visibility for hiding more implementation details
|
||||||
|
* Check GNU ld instead of gcc for exported symbols control logic in
|
||||||
|
configure.ac
|
||||||
|
|
||||||
|
Version 0.2.1 (2021-01-23)
|
||||||
|
* Fix incorrect passing of -version-info to libtool, causing a
|
||||||
|
regression on versioned file name of the shared library (#140).
|
||||||
|
* Fix time resolution on GNU/Hurd for throughput_test
|
||||||
|
* Update AUTHORS and release manager details
|
||||||
|
|
||||||
|
Version 0.2.0 (2021-01-21)
|
||||||
|
* API:
|
||||||
|
* Add `src_clone()` function to clone a SRC_STATE* handle
|
||||||
|
* Cleanup Autotools build system.
|
||||||
|
* Require C99 compiler
|
||||||
|
* Move `sndfile-resample` to sndfile-tools package
|
||||||
|
* Add missing `src_get_channels`() export to windows def file
|
||||||
|
* Fix macOS compile errors and modernize audio api on that platform
|
||||||
|
* Add Octave scripts to generate filter coefficients
|
||||||
|
* Fix two potential undefined behaviours
|
||||||
|
* Fix a buffer out-of-bounds read error in src/src_sinc.c
|
||||||
|
* Improve multichan_throughput_test
|
||||||
|
* Replace buggy implementationg of Duffs device by regular loop
|
||||||
|
* CMake:
|
||||||
|
* Fix CMake generated shared library ABI compliance with Autotools build
|
||||||
|
* Documentation:
|
||||||
|
* Move site to new URL: http://libsndfile.github.io/libsamplerate/
|
||||||
|
* Convert documentation pages from HTML to Markdown
|
||||||
|
* Use GitHub's Jekyll static site generator to generate static HTML pages
|
||||||
|
for site
|
||||||
|
|
||||||
Version 0.1.9 (2016-09-23)
|
Version 0.1.9 (2016-09-23)
|
||||||
* Relicense under 2 clause BSD license.
|
* Relicense under 2 clause BSD license.
|
||||||
* Minor bug fixes and upates.
|
* Minor bug fixes and upates.
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
This is libsamplerate, 0.1.9
|
|
||||||
|
|
||||||
libsamplerate (also known as Secret Rabbit Code) is a library for
|
|
||||||
perfroming sample rate conversion of audio data.
|
|
||||||
|
|
||||||
The src/ directory contains the source code for library itself.
|
|
||||||
|
|
||||||
The doc/ directory contains the libsamplerate documentation.
|
|
||||||
|
|
||||||
The examples/ directory contains examples of how to write code using
|
|
||||||
libsamplerate.
|
|
||||||
|
|
||||||
The tests/ directory contains programs which link against
|
|
||||||
libsamplerate and test its functionality.
|
|
||||||
|
|
||||||
The Win32/ directory contains files and documentation to allow
|
|
||||||
libsamplerate to compile under Win32 with the Microsoft Visual C++
|
|
||||||
compiler.
|
|
||||||
|
|
||||||
Win32
|
|
||||||
-----
|
|
||||||
There are detailed instructions for building libsamplerate on Win32
|
|
||||||
in the file
|
|
||||||
|
|
||||||
doc/win32.html
|
|
||||||
|
|
||||||
|
|
||||||
MacOSX
|
|
||||||
------
|
|
||||||
Building on MacOSX should be the same as building it on any other
|
|
||||||
Unix.
|
|
||||||
|
|
||||||
|
|
||||||
OTHER PLATFORMS
|
|
||||||
---------------
|
|
||||||
To compile libsamplerate on platforms which have a Bourne Shell compatible
|
|
||||||
shell, an ANSI C compiler and a make utility should require no more that
|
|
||||||
the following three commands :
|
|
||||||
./configure
|
|
||||||
make
|
|
||||||
make install
|
|
||||||
|
|
||||||
CONTACTS
|
|
||||||
--------
|
|
||||||
|
|
||||||
libsamplerate was written by Erik de Castro Lopo (erikd AT mega-nerd DOT com).
|
|
||||||
The libsamplerate home page is at :
|
|
||||||
|
|
||||||
http://www.mega-nerd.com/libsamplerate/
|
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
![Logo](docs/SRC.png)
|
||||||
|
|
||||||
|
This is libsamplerate, `0.2.1`.
|
||||||
|
|
||||||
|
libsamplerate (also known as Secret Rabbit Code) is a library for performing sample rate conversion of audio data.
|
||||||
|
|
||||||
|
* The [`src/`](https://github.com/libsndfile/libsamplerate/tree/master/src) directory contains the source code for library itself.
|
||||||
|
* The [`docs/`](https://github.com/libsndfile/libsamplerate/tree/master/docs) directory contains the libsamplerate documentation.
|
||||||
|
* The [`examples/`](https://github.com/libsndfile/libsamplerate/tree/master/examples) directory contains examples of how to write code using libsamplerate.
|
||||||
|
* The [`tests/`](https://github.com/libsndfile/libsamplerate/tree/master/tests) directory contains programs which link against libsamplerate and test its functionality.
|
||||||
|
* The [`Win32/`](https://github.com/libsndfile/libsamplerate/tree/master/Win32) directory contains files and documentation to allow libsamplerate to compile under Win32 with the Microsoft Visual C++ compiler.
|
||||||
|
|
||||||
|
Additional references:
|
||||||
|
|
||||||
|
* [Official website](http://libsndfile.github.io/libsamplerate//)
|
||||||
|
* [GitHub](https://github.com/libsndfile/libsamplerate)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Build Status
|
||||||
|
|
||||||
|
| Branch | Status |
|
||||||
|
|----------------|-------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `master` | ![Build](https://github.com/libsndfile/libsamplerate/workflows/Build/badge.svg) |
|
||||||
|
|
||||||
|
Branches [actively built](https://github.com/libsndfile/libsamplerate/actions) by GitHub Actions.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Win32
|
||||||
|
|
||||||
|
There are detailed instructions for building libsamplerate on Win32 in the file [`docs/win32.md`](https://github.com/libsndfile/libsamplerate/tree/master/docs/win32.md).
|
||||||
|
|
||||||
|
## macOS
|
||||||
|
|
||||||
|
Building on macOS should be the same as building it on any other Unix platform.
|
||||||
|
|
||||||
|
## Other Platforms
|
||||||
|
|
||||||
|
To compile libsamplerate on platforms which have a Bourne compatible shell, an ANSI C compiler and a make utility should require no more that the following three commands:
|
||||||
|
```bash
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
|
## CMake
|
||||||
|
|
||||||
|
There is a new [CMake](https://cmake.org/download/)-based build system available:
|
||||||
|
```bash
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
* Use `cmake -DCMAKE_BUILD_TYPE=Release ..` to make a release build.
|
||||||
|
* Use `cmake -DBUILD_SHARED_LIBS=ON ..` to build a shared library.
|
||||||
|
|
||||||
|
## Contacts
|
||||||
|
|
||||||
|
libsamplerate was written by [Erik de Castro Lopo](mailto:erikd@mega-nerd.com).
|
|
@ -1,20 +1,25 @@
|
||||||
/*
|
/*
|
||||||
** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
|
** Copyright (c) 2002-2021, Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||||
** All rights reserved.
|
** All rights reserved.
|
||||||
**
|
**
|
||||||
** This code is released under 2-clause BSD license. Please see the
|
** This code is released under 2-clause BSD license. Please see the
|
||||||
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
|
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef COMMON_H_INCLUDED
|
#ifndef COMMON_H_INCLUDED
|
||||||
#define COMMON_H_INCLUDED
|
#define COMMON_H_INCLUDED
|
||||||
|
|
||||||
#ifdef HAVE_STDINT_H
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#elif (SIZEOF_INT == 4)
|
#include <stdbool.h>
|
||||||
typedef int int32_t ;
|
|
||||||
#elif (SIZEOF_LONG == 4)
|
#include <math.h>
|
||||||
typedef long int32_t ;
|
|
||||||
|
#if HAVE_VISIBILITY
|
||||||
|
#define LIBSAMPLERATE_DLL_PRIVATE __attribute__ ((visibility ("hidden")))
|
||||||
|
#elif defined (__APPLE__)
|
||||||
|
#define LIBSAMPLERATE_DLL_PRIVATE __private_extern__
|
||||||
|
#else
|
||||||
|
#define LIBSAMPLERATE_DLL_PRIVATE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SRC_MAX_RATIO 256
|
#define SRC_MAX_RATIO 256
|
||||||
|
@ -22,8 +27,13 @@ typedef long int32_t ;
|
||||||
|
|
||||||
#define SRC_MIN_RATIO_DIFF (1e-20)
|
#define SRC_MIN_RATIO_DIFF (1e-20)
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
|
#define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
|
||||||
#define OFFSETOF(type,member) ((int) (&((type*) 0)->member))
|
#define OFFSETOF(type,member) ((int) (&((type*) 0)->member))
|
||||||
|
@ -48,19 +58,22 @@ typedef long int32_t ;
|
||||||
# define WARN_UNUSED
|
# define WARN_UNUSED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "samplerate.h"
|
#include "samplerate.h"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{ SRC_FALSE = 0,
|
{ SRC_FALSE = 0,
|
||||||
SRC_TRUE = 1,
|
SRC_TRUE = 1,
|
||||||
|
|
||||||
SRC_MODE_PROCESS = 555,
|
|
||||||
SRC_MODE_CALLBACK = 556
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
enum
|
enum SRC_MODE
|
||||||
{ SRC_ERR_NO_ERROR = 0,
|
{
|
||||||
|
SRC_MODE_PROCESS = 0,
|
||||||
|
SRC_MODE_CALLBACK = 1
|
||||||
|
} ;
|
||||||
|
|
||||||
|
typedef enum SRC_ERROR
|
||||||
|
{
|
||||||
|
SRC_ERR_NO_ERROR = 0,
|
||||||
|
|
||||||
SRC_ERR_MALLOC_FAILED,
|
SRC_ERR_MALLOC_FAILED,
|
||||||
SRC_ERR_BAD_STATE,
|
SRC_ERR_BAD_STATE,
|
||||||
|
@ -87,53 +100,65 @@ enum
|
||||||
|
|
||||||
/* This must be the last error number. */
|
/* This must be the last error number. */
|
||||||
SRC_ERR_MAX_ERROR
|
SRC_ERR_MAX_ERROR
|
||||||
} ;
|
} SRC_ERROR ;
|
||||||
|
|
||||||
typedef struct SRC_PRIVATE_tag
|
typedef struct SRC_STATE_VT_tag
|
||||||
{ double last_ratio, last_position ;
|
{
|
||||||
|
/* Varispeed process function. */
|
||||||
|
SRC_ERROR (*vari_process) (SRC_STATE *state, SRC_DATA *data) ;
|
||||||
|
|
||||||
int error ;
|
/* Constant speed process function. */
|
||||||
|
SRC_ERROR (*const_process) (SRC_STATE *state, SRC_DATA *data) ;
|
||||||
|
|
||||||
|
/* State reset. */
|
||||||
|
void (*reset) (SRC_STATE *state) ;
|
||||||
|
|
||||||
|
/* State clone. */
|
||||||
|
SRC_STATE *(*copy) (SRC_STATE *state) ;
|
||||||
|
|
||||||
|
/* State close. */
|
||||||
|
void (*close) (SRC_STATE *state) ;
|
||||||
|
} SRC_STATE_VT ;
|
||||||
|
|
||||||
|
struct SRC_STATE_tag
|
||||||
|
{
|
||||||
|
SRC_STATE_VT *vt ;
|
||||||
|
|
||||||
|
double last_ratio, last_position ;
|
||||||
|
|
||||||
|
SRC_ERROR error ;
|
||||||
int channels ;
|
int channels ;
|
||||||
|
|
||||||
/* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
|
/* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
|
||||||
int mode ;
|
enum SRC_MODE mode ;
|
||||||
|
|
||||||
/* Pointer to data to converter specific data. */
|
|
||||||
void *private_data ;
|
|
||||||
|
|
||||||
/* Varispeed process function. */
|
|
||||||
int (*vari_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
|
|
||||||
|
|
||||||
/* Constant speed process function. */
|
|
||||||
int (*const_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
|
|
||||||
|
|
||||||
/* State reset. */
|
|
||||||
void (*reset) (struct SRC_PRIVATE_tag *psrc) ;
|
|
||||||
|
|
||||||
/* Data specific to SRC_MODE_CALLBACK. */
|
/* Data specific to SRC_MODE_CALLBACK. */
|
||||||
src_callback_t callback_func ;
|
src_callback_t callback_func ;
|
||||||
void *user_callback_data ;
|
void *user_callback_data ;
|
||||||
long saved_frames ;
|
long saved_frames ;
|
||||||
const float *saved_data ;
|
const float *saved_data ;
|
||||||
} SRC_PRIVATE ;
|
|
||||||
|
/* Pointer to data to converter specific data. */
|
||||||
|
void *private_data ;
|
||||||
|
} ;
|
||||||
|
|
||||||
/* In src_sinc.c */
|
/* In src_sinc.c */
|
||||||
const char* sinc_get_name (int src_enum) ;
|
const char* sinc_get_name (int src_enum) ;
|
||||||
const char* sinc_get_description (int src_enum) ;
|
const char* sinc_get_description (int src_enum) ;
|
||||||
|
|
||||||
int sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
|
SRC_STATE *sinc_state_new (int converter_type, int channels, SRC_ERROR *error) ;
|
||||||
|
|
||||||
/* In src_linear.c */
|
/* In src_linear.c */
|
||||||
const char* linear_get_name (int src_enum) ;
|
const char* linear_get_name (int src_enum) ;
|
||||||
const char* linear_get_description (int src_enum) ;
|
const char* linear_get_description (int src_enum) ;
|
||||||
|
|
||||||
int linear_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
|
SRC_STATE *linear_state_new (int channels, SRC_ERROR *error) ;
|
||||||
|
|
||||||
/* In src_zoh.c */
|
/* In src_zoh.c */
|
||||||
const char* zoh_get_name (int src_enum) ;
|
const char* zoh_get_name (int src_enum) ;
|
||||||
const char* zoh_get_description (int src_enum) ;
|
const char* zoh_get_description (int src_enum) ;
|
||||||
|
|
||||||
int zoh_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
|
SRC_STATE *zoh_state_new (int channels, SRC_ERROR *error) ;
|
||||||
|
|
||||||
/*----------------------------------------------------------
|
/*----------------------------------------------------------
|
||||||
** Common static inline functions.
|
** Common static inline functions.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
** All rights reserved.
|
** All rights reserved.
|
||||||
**
|
**
|
||||||
** This code is released under 2-clause BSD license. Please see the
|
** This code is released under 2-clause BSD license. Please see the
|
||||||
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
|
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -15,6 +15,11 @@
|
||||||
** increment : 128
|
** increment : 128
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning (push)
|
||||||
|
#pragma warning (disable: 4305)
|
||||||
|
#endif
|
||||||
|
|
||||||
static const struct fastest_coeffs_s
|
static const struct fastest_coeffs_s
|
||||||
{ int increment ;
|
{ int increment ;
|
||||||
coeff_t coeffs [2464] ;
|
coeff_t coeffs [2464] ;
|
||||||
|
@ -2487,3 +2492,7 @@ static const struct fastest_coeffs_s
|
||||||
0.0 /* Need a final zero coefficient */
|
0.0 /* Need a final zero coefficient */
|
||||||
}
|
}
|
||||||
} ; /* fastest_coeffs */
|
} ; /* fastest_coeffs */
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning (pop)
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,271 +0,0 @@
|
||||||
/*
|
|
||||||
** Copyright (c) 2001-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
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Version 1.5 */
|
|
||||||
|
|
||||||
#ifndef FLOAT_CAST_HEADER
|
|
||||||
#define FLOAT_CAST_HEADER
|
|
||||||
|
|
||||||
/*============================================================================
|
|
||||||
** On Intel Pentium processors (especially PIII and probably P4), converting
|
|
||||||
** from float to int is very slow. To meet the C specs, the code produced by
|
|
||||||
** most C compilers targeting Pentium needs to change the FPU rounding mode
|
|
||||||
** before the float to int conversion is performed.
|
|
||||||
**
|
|
||||||
** Changing the FPU rounding mode causes the FPU pipeline to be flushed. It
|
|
||||||
** is this flushing of the pipeline which is so slow.
|
|
||||||
**
|
|
||||||
** Fortunately the ISO C99 specifications define the functions lrint, lrintf,
|
|
||||||
** llrint and llrintf which fix this problem as a side effect.
|
|
||||||
**
|
|
||||||
** On Unix-like systems, the configure process should have detected the
|
|
||||||
** presence of these functions. If they weren't found we have to replace them
|
|
||||||
** here with a standard C cast.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
** The C99 prototypes for lrint and lrintf are as follows:
|
|
||||||
**
|
|
||||||
** long int lrintf (float x) ;
|
|
||||||
** long int lrint (double x) ;
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
** The presence of the required functions are detected during the configure
|
|
||||||
** process and the values HAVE_LRINT and HAVE_LRINTF are set accordingly in
|
|
||||||
** the config.h file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define HAVE_LRINT_REPLACEMENT 0
|
|
||||||
|
|
||||||
#if (HAVE_LRINT && HAVE_LRINTF)
|
|
||||||
|
|
||||||
/*
|
|
||||||
** These defines enable functionality introduced with the 1999 ISO C
|
|
||||||
** standard. They must be defined before the inclusion of math.h to
|
|
||||||
** engage them. If optimisation is enabled, these functions will be
|
|
||||||
** inlined. With optimisation switched off, you have to link in the
|
|
||||||
** maths library using -lm.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _ISOC9X_SOURCE 1
|
|
||||||
#define _ISOC99_SOURCE 1
|
|
||||||
|
|
||||||
#define __USE_ISOC9X 1
|
|
||||||
#define __USE_ISOC99 1
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#elif (defined (__CYGWIN__))
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#undef HAVE_LRINT_REPLACEMENT
|
|
||||||
#define HAVE_LRINT_REPLACEMENT 1
|
|
||||||
|
|
||||||
#undef lrint
|
|
||||||
#undef lrintf
|
|
||||||
|
|
||||||
#define lrint double2int
|
|
||||||
#define lrintf float2int
|
|
||||||
|
|
||||||
/*
|
|
||||||
** The native CYGWIN lrint and lrintf functions are buggy:
|
|
||||||
** http://sourceware.org/ml/cygwin/2005-06/msg00153.html
|
|
||||||
** http://sourceware.org/ml/cygwin/2005-09/msg00047.html
|
|
||||||
** and slow.
|
|
||||||
** These functions (pulled from the Public Domain MinGW math.h header)
|
|
||||||
** replace the native versions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static inline long double2int (double in)
|
|
||||||
{ long retval ;
|
|
||||||
|
|
||||||
__asm__ __volatile__
|
|
||||||
( "fistpl %0"
|
|
||||||
: "=m" (retval)
|
|
||||||
: "t" (in)
|
|
||||||
: "st"
|
|
||||||
) ;
|
|
||||||
|
|
||||||
return retval ;
|
|
||||||
} /* double2int */
|
|
||||||
|
|
||||||
static inline long float2int (float in)
|
|
||||||
{ long retval ;
|
|
||||||
|
|
||||||
__asm__ __volatile__
|
|
||||||
( "fistpl %0"
|
|
||||||
: "=m" (retval)
|
|
||||||
: "t" (in)
|
|
||||||
: "st"
|
|
||||||
) ;
|
|
||||||
|
|
||||||
return retval ;
|
|
||||||
} /* float2int */
|
|
||||||
|
|
||||||
#elif (defined (WIN64) || defined(_WIN64))
|
|
||||||
|
|
||||||
/* Win64 section should be places before Win32 one, because
|
|
||||||
** most likely both WIN32 and WIN64 will be defined in 64-bit case.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
/* Win64 doesn't seem to have these functions, nor inline assembly.
|
|
||||||
** Therefore implement inline versions of these functions here.
|
|
||||||
*/
|
|
||||||
#include <emmintrin.h>
|
|
||||||
#include <mmintrin.h>
|
|
||||||
|
|
||||||
__inline long int
|
|
||||||
lrint(double flt)
|
|
||||||
{
|
|
||||||
return _mm_cvtsd_si32(_mm_load_sd(&flt));
|
|
||||||
}
|
|
||||||
|
|
||||||
__inline long int
|
|
||||||
lrintf(float flt)
|
|
||||||
{
|
|
||||||
return _mm_cvtss_si32(_mm_load_ss(&flt));
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif (defined (WIN32) || defined (_WIN32))
|
|
||||||
|
|
||||||
#undef HAVE_LRINT_REPLACEMENT
|
|
||||||
#define HAVE_LRINT_REPLACEMENT 1
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Win32 doesn't seem to have these functions.
|
|
||||||
** Therefore implement inline versions of these functions here.
|
|
||||||
*/
|
|
||||||
|
|
||||||
__inline long int
|
|
||||||
lrint (double flt)
|
|
||||||
{ int intgr ;
|
|
||||||
|
|
||||||
_asm
|
|
||||||
{ fld flt
|
|
||||||
fistp intgr
|
|
||||||
} ;
|
|
||||||
|
|
||||||
return intgr ;
|
|
||||||
}
|
|
||||||
|
|
||||||
__inline long int
|
|
||||||
lrintf (float flt)
|
|
||||||
{ int intgr ;
|
|
||||||
|
|
||||||
_asm
|
|
||||||
{ fld flt
|
|
||||||
fistp intgr
|
|
||||||
} ;
|
|
||||||
|
|
||||||
return intgr ;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif (defined (__MWERKS__) && defined (macintosh))
|
|
||||||
|
|
||||||
/* This MacOS 9 solution was provided by Stephane Letz */
|
|
||||||
|
|
||||||
#undef HAVE_LRINT_REPLACEMENT
|
|
||||||
#define HAVE_LRINT_REPLACEMENT 1
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#undef lrint
|
|
||||||
#undef lrintf
|
|
||||||
|
|
||||||
#define lrint double2int
|
|
||||||
#define lrintf float2int
|
|
||||||
|
|
||||||
inline int
|
|
||||||
float2int (register float in)
|
|
||||||
{ long res [2] ;
|
|
||||||
|
|
||||||
asm
|
|
||||||
{ fctiw in, in
|
|
||||||
stfd in, res
|
|
||||||
}
|
|
||||||
return res [1] ;
|
|
||||||
} /* float2int */
|
|
||||||
|
|
||||||
inline int
|
|
||||||
double2int (register double in)
|
|
||||||
{ long res [2] ;
|
|
||||||
|
|
||||||
asm
|
|
||||||
{ fctiw in, in
|
|
||||||
stfd in, res
|
|
||||||
}
|
|
||||||
return res [1] ;
|
|
||||||
} /* double2int */
|
|
||||||
|
|
||||||
#elif (defined (__MACH__) && defined (__APPLE__))
|
|
||||||
|
|
||||||
/* For Apple MacOSX. */
|
|
||||||
|
|
||||||
#undef HAVE_LRINT_REPLACEMENT
|
|
||||||
#define HAVE_LRINT_REPLACEMENT 1
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#undef lrint
|
|
||||||
#undef lrintf
|
|
||||||
|
|
||||||
#define lrint double2int
|
|
||||||
#define lrintf float2int
|
|
||||||
|
|
||||||
inline static long
|
|
||||||
float2int (register float in)
|
|
||||||
{ int res [2] ;
|
|
||||||
|
|
||||||
__asm__ __volatile__
|
|
||||||
( "fctiw %1, %1\n\t"
|
|
||||||
"stfd %1, %0"
|
|
||||||
: "=m" (res) /* Output */
|
|
||||||
: "f" (in) /* Input */
|
|
||||||
: "memory"
|
|
||||||
) ;
|
|
||||||
|
|
||||||
return res [1] ;
|
|
||||||
} /* lrintf */
|
|
||||||
|
|
||||||
inline static long
|
|
||||||
double2int (register double in)
|
|
||||||
{ int res [2] ;
|
|
||||||
|
|
||||||
__asm__ __volatile__
|
|
||||||
( "fctiw %1, %1\n\t"
|
|
||||||
"stfd %1, %0"
|
|
||||||
: "=m" (res) /* Output */
|
|
||||||
: "f" (in) /* Input */
|
|
||||||
: "memory"
|
|
||||||
) ;
|
|
||||||
|
|
||||||
return res [1] ;
|
|
||||||
} /* lrint */
|
|
||||||
|
|
||||||
#else
|
|
||||||
#ifndef __sgi
|
|
||||||
#warning "Don't have the functions lrint() and lrintf()."
|
|
||||||
#warning "Replacing these functions with a standard C cast."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#define lrint(dbl) ((long) (dbl))
|
|
||||||
#define lrintf(flt) ((long) (flt))
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* FLOAT_CAST_HEADER */
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
** All rights reserved.
|
** All rights reserved.
|
||||||
**
|
**
|
||||||
** This code is released under 2-clause BSD license. Please see the
|
** This code is released under 2-clause BSD license. Please see the
|
||||||
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
|
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -15,6 +15,11 @@
|
||||||
** increment : 2381
|
** increment : 2381
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning (push)
|
||||||
|
#pragma warning (disable: 4305)
|
||||||
|
#endif
|
||||||
|
|
||||||
static const struct slow_high_qual_coeffs_s
|
static const struct slow_high_qual_coeffs_s
|
||||||
{ int increment ;
|
{ int increment ;
|
||||||
coeff_t coeffs [340239] ;
|
coeff_t coeffs [340239] ;
|
||||||
|
@ -340263,3 +340268,6 @@ static const struct slow_high_qual_coeffs_s
|
||||||
}
|
}
|
||||||
} ; /* high_qual_coeffs */
|
} ; /* high_qual_coeffs */
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning (pop)
|
||||||
|
#endif
|
||||||
|
|
|
@ -167,7 +167,6 @@
|
||||||
<ClInclude Include="common.h" />
|
<ClInclude Include="common.h" />
|
||||||
<ClInclude Include="config.h" />
|
<ClInclude Include="config.h" />
|
||||||
<ClInclude Include="fastest_coeffs.h" />
|
<ClInclude Include="fastest_coeffs.h" />
|
||||||
<ClInclude Include="float_cast.h" />
|
|
||||||
<ClInclude Include="high_qual_coeffs.h" />
|
<ClInclude Include="high_qual_coeffs.h" />
|
||||||
<ClInclude Include="mid_qual_coeffs.h" />
|
<ClInclude Include="mid_qual_coeffs.h" />
|
||||||
<ClInclude Include="samplerate.h" />
|
<ClInclude Include="samplerate.h" />
|
||||||
|
|
|
@ -27,9 +27,6 @@
|
||||||
<ClInclude Include="fastest_coeffs.h">
|
<ClInclude Include="fastest_coeffs.h">
|
||||||
<Filter>Headers</Filter>
|
<Filter>Headers</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="float_cast.h">
|
|
||||||
<Filter>Headers</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="high_qual_coeffs.h">
|
<ClInclude Include="high_qual_coeffs.h">
|
||||||
<Filter>Headers</Filter>
|
<Filter>Headers</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
** All rights reserved.
|
** All rights reserved.
|
||||||
**
|
**
|
||||||
** This code is released under 2-clause BSD license. Please see the
|
** This code is released under 2-clause BSD license. Please see the
|
||||||
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
|
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -15,6 +15,11 @@
|
||||||
** increment : 491
|
** increment : 491
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning (push)
|
||||||
|
#pragma warning (disable: 4305)
|
||||||
|
#endif
|
||||||
|
|
||||||
static const struct slow_mid_qual_coeffs_s
|
static const struct slow_mid_qual_coeffs_s
|
||||||
{ int increment ;
|
{ int increment ;
|
||||||
coeff_t coeffs [22438] ;
|
coeff_t coeffs [22438] ;
|
||||||
|
@ -22462,3 +22467,6 @@ static const struct slow_mid_qual_coeffs_s
|
||||||
}
|
}
|
||||||
} ; /* mid_qual_coeffs */
|
} ; /* mid_qual_coeffs */
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning (pop)
|
||||||
|
#endif
|
||||||
|
|
|
@ -3,59 +3,50 @@
|
||||||
** All rights reserved.
|
** All rights reserved.
|
||||||
**
|
**
|
||||||
** This code is released under 2-clause BSD license. Please see the
|
** This code is released under 2-clause BSD license. Please see the
|
||||||
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
|
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include "samplerate.h"
|
#include "samplerate.h"
|
||||||
#include "float_cast.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
static int psrc_set_converter (SRC_PRIVATE *psrc, int converter_type) ;
|
static SRC_STATE *psrc_set_converter (int converter_type, int channels, int *error) ;
|
||||||
|
|
||||||
|
|
||||||
SRC_STATE *
|
SRC_STATE *
|
||||||
src_new (int converter_type, int channels, int *error)
|
src_new (int converter_type, int channels, int *error)
|
||||||
{ SRC_PRIVATE *psrc ;
|
{
|
||||||
|
return psrc_set_converter (converter_type, channels, error) ;
|
||||||
if (error)
|
|
||||||
*error = SRC_ERR_NO_ERROR ;
|
|
||||||
|
|
||||||
if (channels < 1)
|
|
||||||
{ if (error)
|
|
||||||
*error = SRC_ERR_BAD_CHANNEL_COUNT ;
|
|
||||||
return NULL ;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
if ((psrc = calloc (1, sizeof (*psrc))) == NULL)
|
|
||||||
{ if (error)
|
|
||||||
*error = SRC_ERR_MALLOC_FAILED ;
|
|
||||||
return NULL ;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
psrc->channels = channels ;
|
|
||||||
psrc->mode = SRC_MODE_PROCESS ;
|
|
||||||
|
|
||||||
if (psrc_set_converter (psrc, converter_type) != SRC_ERR_NO_ERROR)
|
|
||||||
{ if (error)
|
|
||||||
*error = SRC_ERR_BAD_CONVERTER ;
|
|
||||||
free (psrc) ;
|
|
||||||
psrc = NULL ;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
src_reset ((SRC_STATE*) psrc) ;
|
|
||||||
|
|
||||||
return (SRC_STATE*) psrc ;
|
|
||||||
} /* src_new */
|
} /* src_new */
|
||||||
|
|
||||||
|
SRC_STATE*
|
||||||
|
src_clone (SRC_STATE* orig, int *error)
|
||||||
|
{
|
||||||
|
if (!orig)
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
*error = SRC_ERR_BAD_STATE ;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
if (error)
|
||||||
|
*error = SRC_ERR_NO_ERROR ;
|
||||||
|
|
||||||
|
SRC_STATE *state = orig->vt->copy (orig) ;
|
||||||
|
if (!state)
|
||||||
|
if (error)
|
||||||
|
*error = SRC_ERR_MALLOC_FAILED ;
|
||||||
|
|
||||||
|
return state ;
|
||||||
|
}
|
||||||
|
|
||||||
SRC_STATE*
|
SRC_STATE*
|
||||||
src_callback_new (src_callback_t func, int converter_type, int channels, int *error, void* cb_data)
|
src_callback_new (src_callback_t func, int converter_type, int channels, int *error, void* cb_data)
|
||||||
{ SRC_STATE *src_state ;
|
{ SRC_STATE *state ;
|
||||||
|
|
||||||
if (func == NULL)
|
if (func == NULL)
|
||||||
{ if (error)
|
{ if (error)
|
||||||
|
@ -66,46 +57,36 @@ src_callback_new (src_callback_t func, int converter_type, int channels, int *er
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
*error = 0 ;
|
*error = 0 ;
|
||||||
|
|
||||||
if ((src_state = src_new (converter_type, channels, error)) == NULL)
|
if ((state = src_new (converter_type, channels, error)) == NULL)
|
||||||
return NULL ;
|
return NULL ;
|
||||||
|
|
||||||
src_reset (src_state) ;
|
src_reset (state) ;
|
||||||
|
|
||||||
((SRC_PRIVATE*) src_state)->mode = SRC_MODE_CALLBACK ;
|
state->mode = SRC_MODE_CALLBACK ;
|
||||||
((SRC_PRIVATE*) src_state)->callback_func = func ;
|
state->callback_func = func ;
|
||||||
((SRC_PRIVATE*) src_state)->user_callback_data = cb_data ;
|
state->user_callback_data = cb_data ;
|
||||||
|
|
||||||
return src_state ;
|
return state ;
|
||||||
} /* src_callback_new */
|
} /* src_callback_new */
|
||||||
|
|
||||||
SRC_STATE *
|
SRC_STATE *
|
||||||
src_delete (SRC_STATE *state)
|
src_delete (SRC_STATE *state)
|
||||||
{ SRC_PRIVATE *psrc ;
|
{
|
||||||
|
if (state)
|
||||||
psrc = (SRC_PRIVATE*) state ;
|
state->vt->close (state) ;
|
||||||
if (psrc)
|
|
||||||
{ if (psrc->private_data)
|
|
||||||
free (psrc->private_data) ;
|
|
||||||
memset (psrc, 0, sizeof (SRC_PRIVATE)) ;
|
|
||||||
free (psrc) ;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
return NULL ;
|
return NULL ;
|
||||||
} /* src_state */
|
} /* src_state */
|
||||||
|
|
||||||
int
|
int
|
||||||
src_process (SRC_STATE *state, SRC_DATA *data)
|
src_process (SRC_STATE *state, SRC_DATA *data)
|
||||||
{ SRC_PRIVATE *psrc ;
|
{
|
||||||
int error ;
|
int error ;
|
||||||
|
|
||||||
psrc = (SRC_PRIVATE*) state ;
|
if (state == NULL)
|
||||||
|
|
||||||
if (psrc == NULL)
|
|
||||||
return SRC_ERR_BAD_STATE ;
|
return SRC_ERR_BAD_STATE ;
|
||||||
if (psrc->vari_process == NULL || psrc->const_process == NULL)
|
|
||||||
return SRC_ERR_BAD_PROC_PTR ;
|
|
||||||
|
|
||||||
if (psrc->mode != SRC_MODE_PROCESS)
|
if (state->mode != SRC_MODE_PROCESS)
|
||||||
return SRC_ERR_BAD_MODE ;
|
return SRC_ERR_BAD_MODE ;
|
||||||
|
|
||||||
/* Check for valid SRC_DATA first. */
|
/* Check for valid SRC_DATA first. */
|
||||||
|
@ -113,7 +94,8 @@ src_process (SRC_STATE *state, SRC_DATA *data)
|
||||||
return SRC_ERR_BAD_DATA ;
|
return SRC_ERR_BAD_DATA ;
|
||||||
|
|
||||||
/* And that data_in and data_out are valid. */
|
/* And that data_in and data_out are valid. */
|
||||||
if (data->data_in == NULL || data->data_out == NULL)
|
if ((data->data_in == NULL && data->input_frames > 0)
|
||||||
|
|| (data->data_out == NULL && data->output_frames > 0))
|
||||||
return SRC_ERR_BAD_DATA_PTR ;
|
return SRC_ERR_BAD_DATA_PTR ;
|
||||||
|
|
||||||
/* Check src_ratio is in range. */
|
/* Check src_ratio is in range. */
|
||||||
|
@ -126,13 +108,13 @@ src_process (SRC_STATE *state, SRC_DATA *data)
|
||||||
data->output_frames = 0 ;
|
data->output_frames = 0 ;
|
||||||
|
|
||||||
if (data->data_in < data->data_out)
|
if (data->data_in < data->data_out)
|
||||||
{ if (data->data_in + data->input_frames * psrc->channels > data->data_out)
|
{ if (data->data_in + data->input_frames * state->channels > data->data_out)
|
||||||
{ /*-printf ("\n\ndata_in: %p data_out: %p\n",
|
{ /*-printf ("\n\ndata_in: %p data_out: %p\n",
|
||||||
(void*) (data->data_in + data->input_frames * psrc->channels), (void*) data->data_out) ;-*/
|
(void*) (data->data_in + data->input_frames * psrc->channels), (void*) data->data_out) ;-*/
|
||||||
return SRC_ERR_DATA_OVERLAP ;
|
return SRC_ERR_DATA_OVERLAP ;
|
||||||
} ;
|
} ;
|
||||||
}
|
}
|
||||||
else if (data->data_out + data->output_frames * psrc->channels > data->data_in)
|
else if (data->data_out + data->output_frames * state->channels > data->data_in)
|
||||||
{ /*-printf ("\n\ndata_in : %p ouput frames: %ld data_out: %p\n", (void*) data->data_in, data->output_frames, (void*) data->data_out) ;
|
{ /*-printf ("\n\ndata_in : %p ouput frames: %ld data_out: %p\n", (void*) data->data_in, data->output_frames, (void*) data->data_out) ;
|
||||||
|
|
||||||
printf ("data_out: %p (%p) data_in: %p\n", (void*) data->data_out,
|
printf ("data_out: %p (%p) data_in: %p\n", (void*) data->data_out,
|
||||||
|
@ -145,21 +127,21 @@ src_process (SRC_STATE *state, SRC_DATA *data)
|
||||||
data->output_frames_gen = 0 ;
|
data->output_frames_gen = 0 ;
|
||||||
|
|
||||||
/* Special case for when last_ratio has not been set. */
|
/* Special case for when last_ratio has not been set. */
|
||||||
if (psrc->last_ratio < (1.0 / SRC_MAX_RATIO))
|
if (state->last_ratio < (1.0 / SRC_MAX_RATIO))
|
||||||
psrc->last_ratio = data->src_ratio ;
|
state->last_ratio = data->src_ratio ;
|
||||||
|
|
||||||
/* Now process. */
|
/* Now process. */
|
||||||
if (fabs (psrc->last_ratio - data->src_ratio) < 1e-15)
|
if (fabs (state->last_ratio - data->src_ratio) < 1e-15)
|
||||||
error = psrc->const_process (psrc, data) ;
|
error = state->vt->const_process (state, data) ;
|
||||||
else
|
else
|
||||||
error = psrc->vari_process (psrc, data) ;
|
error = state->vt->vari_process (state, data) ;
|
||||||
|
|
||||||
return error ;
|
return error ;
|
||||||
} /* src_process */
|
} /* src_process */
|
||||||
|
|
||||||
long
|
long
|
||||||
src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
|
src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
|
||||||
{ SRC_PRIVATE *psrc ;
|
{
|
||||||
SRC_DATA src_data ;
|
SRC_DATA src_data ;
|
||||||
|
|
||||||
long output_frames_gen ;
|
long output_frames_gen ;
|
||||||
|
@ -171,15 +153,13 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
|
||||||
if (frames <= 0)
|
if (frames <= 0)
|
||||||
return 0 ;
|
return 0 ;
|
||||||
|
|
||||||
psrc = (SRC_PRIVATE*) state ;
|
if (state->mode != SRC_MODE_CALLBACK)
|
||||||
|
{ state->error = SRC_ERR_BAD_MODE ;
|
||||||
if (psrc->mode != SRC_MODE_CALLBACK)
|
|
||||||
{ psrc->error = SRC_ERR_BAD_MODE ;
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
if (psrc->callback_func == NULL)
|
if (state->callback_func == NULL)
|
||||||
{ psrc->error = SRC_ERR_NULL_CALLBACK ;
|
{ state->error = SRC_ERR_NULL_CALLBACK ;
|
||||||
return 0 ;
|
return 0 ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -187,7 +167,7 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
|
||||||
|
|
||||||
/* Check src_ratio is in range. */
|
/* Check src_ratio is in range. */
|
||||||
if (is_bad_src_ratio (src_ratio))
|
if (is_bad_src_ratio (src_ratio))
|
||||||
{ psrc->error = SRC_ERR_BAD_SRC_RATIO ;
|
{ state->error = SRC_ERR_BAD_SRC_RATIO ;
|
||||||
return 0 ;
|
return 0 ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -196,8 +176,8 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
|
||||||
src_data.data_out = data ;
|
src_data.data_out = data ;
|
||||||
src_data.output_frames = frames ;
|
src_data.output_frames = frames ;
|
||||||
|
|
||||||
src_data.data_in = psrc->saved_data ;
|
src_data.data_in = state->saved_data ;
|
||||||
src_data.input_frames = psrc->saved_frames ;
|
src_data.input_frames = state->saved_frames ;
|
||||||
|
|
||||||
output_frames_gen = 0 ;
|
output_frames_gen = 0 ;
|
||||||
while (output_frames_gen < frames)
|
while (output_frames_gen < frames)
|
||||||
|
@ -209,7 +189,7 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
|
||||||
if (src_data.input_frames == 0)
|
if (src_data.input_frames == 0)
|
||||||
{ float *ptr = dummy ;
|
{ float *ptr = dummy ;
|
||||||
|
|
||||||
src_data.input_frames = psrc->callback_func (psrc->user_callback_data, &ptr) ;
|
src_data.input_frames = state->callback_func (state->user_callback_data, &ptr) ;
|
||||||
src_data.data_in = ptr ;
|
src_data.data_in = ptr ;
|
||||||
|
|
||||||
if (src_data.input_frames == 0)
|
if (src_data.input_frames == 0)
|
||||||
|
@ -221,17 +201,17 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
|
||||||
** to SRC_MODE_PROCESS first and when we return set it back to
|
** to SRC_MODE_PROCESS first and when we return set it back to
|
||||||
** SRC_MODE_CALLBACK.
|
** SRC_MODE_CALLBACK.
|
||||||
*/
|
*/
|
||||||
psrc->mode = SRC_MODE_PROCESS ;
|
state->mode = SRC_MODE_PROCESS ;
|
||||||
error = src_process (state, &src_data) ;
|
error = src_process (state, &src_data) ;
|
||||||
psrc->mode = SRC_MODE_CALLBACK ;
|
state->mode = SRC_MODE_CALLBACK ;
|
||||||
|
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
src_data.data_in += src_data.input_frames_used * psrc->channels ;
|
src_data.data_in += src_data.input_frames_used * state->channels ;
|
||||||
src_data.input_frames -= src_data.input_frames_used ;
|
src_data.input_frames -= src_data.input_frames_used ;
|
||||||
|
|
||||||
src_data.data_out += src_data.output_frames_gen * psrc->channels ;
|
src_data.data_out += src_data.output_frames_gen * state->channels ;
|
||||||
src_data.output_frames -= src_data.output_frames_gen ;
|
src_data.output_frames -= src_data.output_frames_gen ;
|
||||||
|
|
||||||
output_frames_gen += src_data.output_frames_gen ;
|
output_frames_gen += src_data.output_frames_gen ;
|
||||||
|
@ -240,11 +220,11 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
|
||||||
break ;
|
break ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
psrc->saved_data = src_data.data_in ;
|
state->saved_data = src_data.data_in ;
|
||||||
psrc->saved_frames = src_data.input_frames ;
|
state->saved_frames = src_data.input_frames ;
|
||||||
|
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
{ psrc->error = error ;
|
{ state->error = (SRC_ERROR) error ;
|
||||||
return 0 ;
|
return 0 ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -256,54 +236,42 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
|
||||||
|
|
||||||
int
|
int
|
||||||
src_set_ratio (SRC_STATE *state, double new_ratio)
|
src_set_ratio (SRC_STATE *state, double new_ratio)
|
||||||
{ SRC_PRIVATE *psrc ;
|
{
|
||||||
|
if (state == NULL)
|
||||||
psrc = (SRC_PRIVATE*) state ;
|
|
||||||
|
|
||||||
if (psrc == NULL)
|
|
||||||
return SRC_ERR_BAD_STATE ;
|
return SRC_ERR_BAD_STATE ;
|
||||||
if (psrc->vari_process == NULL || psrc->const_process == NULL)
|
|
||||||
return SRC_ERR_BAD_PROC_PTR ;
|
|
||||||
|
|
||||||
if (is_bad_src_ratio (new_ratio))
|
if (is_bad_src_ratio (new_ratio))
|
||||||
return SRC_ERR_BAD_SRC_RATIO ;
|
return SRC_ERR_BAD_SRC_RATIO ;
|
||||||
|
|
||||||
psrc->last_ratio = new_ratio ;
|
state->last_ratio = new_ratio ;
|
||||||
|
|
||||||
return SRC_ERR_NO_ERROR ;
|
return SRC_ERR_NO_ERROR ;
|
||||||
} /* src_set_ratio */
|
} /* src_set_ratio */
|
||||||
|
|
||||||
int
|
int
|
||||||
src_get_channels (SRC_STATE *state)
|
src_get_channels (SRC_STATE *state)
|
||||||
{ SRC_PRIVATE *psrc ;
|
{
|
||||||
|
if (state == NULL)
|
||||||
|
return -SRC_ERR_BAD_STATE ;
|
||||||
|
|
||||||
psrc = (SRC_PRIVATE*) state ;
|
return state->channels ;
|
||||||
|
|
||||||
if (psrc == NULL)
|
|
||||||
return SRC_ERR_BAD_STATE ;
|
|
||||||
if (psrc->vari_process == NULL || psrc->const_process == NULL)
|
|
||||||
return SRC_ERR_BAD_PROC_PTR ;
|
|
||||||
|
|
||||||
return psrc->channels ;
|
|
||||||
} /* src_get_channels */
|
} /* src_get_channels */
|
||||||
|
|
||||||
int
|
int
|
||||||
src_reset (SRC_STATE *state)
|
src_reset (SRC_STATE *state)
|
||||||
{ SRC_PRIVATE *psrc ;
|
{
|
||||||
|
if (state == NULL)
|
||||||
if ((psrc = (SRC_PRIVATE*) state) == NULL)
|
|
||||||
return SRC_ERR_BAD_STATE ;
|
return SRC_ERR_BAD_STATE ;
|
||||||
|
|
||||||
if (psrc->reset != NULL)
|
state->vt->reset (state) ;
|
||||||
psrc->reset (psrc) ;
|
|
||||||
|
|
||||||
psrc->last_position = 0.0 ;
|
state->last_position = 0.0 ;
|
||||||
psrc->last_ratio = 0.0 ;
|
state->last_ratio = 0.0 ;
|
||||||
|
|
||||||
psrc->saved_data = NULL ;
|
state->saved_data = NULL ;
|
||||||
psrc->saved_frames = 0 ;
|
state->saved_frames = 0 ;
|
||||||
|
|
||||||
psrc->error = SRC_ERR_NO_ERROR ;
|
state->error = SRC_ERR_NO_ERROR ;
|
||||||
|
|
||||||
return SRC_ERR_NO_ERROR ;
|
return SRC_ERR_NO_ERROR ;
|
||||||
} /* src_reset */
|
} /* src_reset */
|
||||||
|
@ -365,7 +333,7 @@ src_is_valid_ratio (double ratio)
|
||||||
int
|
int
|
||||||
src_error (SRC_STATE *state)
|
src_error (SRC_STATE *state)
|
||||||
{ if (state)
|
{ if (state)
|
||||||
return ((SRC_PRIVATE*) state)->error ;
|
return state->error ;
|
||||||
return SRC_ERR_NO_ERROR ;
|
return SRC_ERR_NO_ERROR ;
|
||||||
} /* src_error */
|
} /* src_error */
|
||||||
|
|
||||||
|
@ -466,24 +434,18 @@ src_short_to_float_array (const short *in, float *out, int len)
|
||||||
|
|
||||||
void
|
void
|
||||||
src_float_to_short_array (const float *in, short *out, int len)
|
src_float_to_short_array (const float *in, short *out, int len)
|
||||||
{ double scaled_value ;
|
{
|
||||||
|
|
||||||
while (len)
|
while (len)
|
||||||
{ len -- ;
|
{ float scaled_value ;
|
||||||
|
len -- ;
|
||||||
scaled_value = in [len] * (8.0 * 0x10000000) ;
|
scaled_value = in [len] * 32768.f ;
|
||||||
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
|
if (scaled_value >= 32767.f)
|
||||||
{ out [len] = 32767 ;
|
out [len] = 32767 ;
|
||||||
continue ;
|
else if (scaled_value <= -32768.f)
|
||||||
} ;
|
out [len] = -32768 ;
|
||||||
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
|
else
|
||||||
{ out [len] = -32768 ;
|
out [len] = (short) (lrintf (scaled_value)) ;
|
||||||
continue ;
|
}
|
||||||
} ;
|
|
||||||
|
|
||||||
out [len] = (short) (lrint (scaled_value) >> 16) ;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
} /* src_float_to_short_array */
|
} /* src_float_to_short_array */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -505,16 +467,19 @@ src_float_to_int_array (const float *in, int *out, int len)
|
||||||
{ len -- ;
|
{ len -- ;
|
||||||
|
|
||||||
scaled_value = in [len] * (8.0 * 0x10000000) ;
|
scaled_value = in [len] * (8.0 * 0x10000000) ;
|
||||||
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
|
#if CPU_CLIPS_POSITIVE == 0
|
||||||
|
if (scaled_value >= (1.0 * 0x7FFFFFFF))
|
||||||
{ out [len] = 0x7fffffff ;
|
{ out [len] = 0x7fffffff ;
|
||||||
continue ;
|
continue ;
|
||||||
} ;
|
} ;
|
||||||
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
|
#endif
|
||||||
|
#if CPU_CLIPS_NEGATIVE == 0
|
||||||
|
if (scaled_value <= (-8.0 * 0x10000000))
|
||||||
{ out [len] = -1 - 0x7fffffff ;
|
{ out [len] = -1 - 0x7fffffff ;
|
||||||
continue ;
|
continue ;
|
||||||
} ;
|
} ;
|
||||||
|
#endif
|
||||||
out [len] = lrint (scaled_value) ;
|
out [len] = (int) lrint (scaled_value) ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
} /* src_float_to_int_array */
|
} /* src_float_to_int_array */
|
||||||
|
@ -523,18 +488,43 @@ src_float_to_int_array (const float *in, int *out, int len)
|
||||||
** Private functions.
|
** Private functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static SRC_STATE *
|
||||||
psrc_set_converter (SRC_PRIVATE *psrc, int converter_type)
|
psrc_set_converter (int converter_type, int channels, int *error)
|
||||||
{
|
{
|
||||||
if (sinc_set_converter (psrc, converter_type) == SRC_ERR_NO_ERROR)
|
SRC_ERROR temp_error;
|
||||||
return SRC_ERR_NO_ERROR ;
|
SRC_STATE *state ;
|
||||||
|
switch (converter_type)
|
||||||
|
{
|
||||||
|
#ifdef ENABLE_SINC_BEST_CONVERTER
|
||||||
|
case SRC_SINC_BEST_QUALITY :
|
||||||
|
state = sinc_state_new (converter_type, channels, &temp_error) ;
|
||||||
|
break ;
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_SINC_MEDIUM_CONVERTER
|
||||||
|
case SRC_SINC_MEDIUM_QUALITY :
|
||||||
|
state = sinc_state_new (converter_type, channels, &temp_error) ;
|
||||||
|
break ;
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_SINC_FAST_CONVERTER
|
||||||
|
case SRC_SINC_FASTEST :
|
||||||
|
state = sinc_state_new (converter_type, channels, &temp_error) ;
|
||||||
|
break ;
|
||||||
|
#endif
|
||||||
|
case SRC_ZERO_ORDER_HOLD :
|
||||||
|
state = zoh_state_new (channels, &temp_error) ;
|
||||||
|
break ;
|
||||||
|
case SRC_LINEAR :
|
||||||
|
state = linear_state_new (channels, &temp_error) ;
|
||||||
|
break ;
|
||||||
|
default :
|
||||||
|
temp_error = SRC_ERR_BAD_CONVERTER ;
|
||||||
|
state = NULL ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
|
||||||
if (zoh_set_converter (psrc, converter_type) == SRC_ERR_NO_ERROR)
|
if (error)
|
||||||
return SRC_ERR_NO_ERROR ;
|
*error = (int) temp_error ;
|
||||||
|
|
||||||
if (linear_set_converter (psrc, converter_type) == SRC_ERR_NO_ERROR)
|
return state ;
|
||||||
return SRC_ERR_NO_ERROR ;
|
|
||||||
|
|
||||||
return SRC_ERR_BAD_CONVERTER ;
|
|
||||||
} /* psrc_set_converter */
|
} /* psrc_set_converter */
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
** All rights reserved.
|
** All rights reserved.
|
||||||
**
|
**
|
||||||
** This code is released under 2-clause BSD license. Please see the
|
** This code is released under 2-clause BSD license. Please see the
|
||||||
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
|
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** API documentation is available here:
|
** API documentation is available here:
|
||||||
** http://www.mega-nerd.com/SRC/api.html
|
** http://libsndfile.github.io/libsamplerate/api.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SAMPLERATE_H
|
#ifndef SAMPLERATE_H
|
||||||
|
@ -54,6 +54,12 @@ typedef long (*src_callback_t) (void *cb_data, float **data) ;
|
||||||
|
|
||||||
SRC_STATE* src_new (int converter_type, int channels, int *error) ;
|
SRC_STATE* src_new (int converter_type, int channels, int *error) ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Clone a handle : return an anonymous pointer to a new converter
|
||||||
|
** containing the same internal state as orig. Error returned in *error.
|
||||||
|
*/
|
||||||
|
SRC_STATE* src_clone (SRC_STATE* orig, int *error) ;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Initilisation for callback based API : return an anonymous pointer to the
|
** Initilisation for callback based API : return an anonymous pointer to the
|
||||||
** internal state of the converter. Choose a converter from the enums below.
|
** internal state of the converter. Choose a converter from the enums below.
|
||||||
|
|
|
@ -1,21 +1,27 @@
|
||||||
/*
|
/*
|
||||||
** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
|
** Copyright (c) 2002-2021, Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||||
** All rights reserved.
|
** All rights reserved.
|
||||||
**
|
**
|
||||||
** This code is released under 2-clause BSD license. Please see the
|
** This code is released under 2-clause BSD license. Please see the
|
||||||
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
|
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "float_cast.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
static int linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
|
|
||||||
static void linear_reset (SRC_PRIVATE *psrc) ;
|
static SRC_ERROR linear_vari_process (SRC_STATE *state, SRC_DATA *data) ;
|
||||||
|
static void linear_reset (SRC_STATE *state) ;
|
||||||
|
static SRC_STATE *linear_copy (SRC_STATE *state) ;
|
||||||
|
static void linear_close (SRC_STATE *state) ;
|
||||||
|
|
||||||
/*========================================================================================
|
/*========================================================================================
|
||||||
*/
|
*/
|
||||||
|
@ -26,18 +32,26 @@ static void linear_reset (SRC_PRIVATE *psrc) ;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{ int linear_magic_marker ;
|
{ int linear_magic_marker ;
|
||||||
int channels ;
|
bool dirty ;
|
||||||
int reset ;
|
|
||||||
long in_count, in_used ;
|
long in_count, in_used ;
|
||||||
long out_count, out_gen ;
|
long out_count, out_gen ;
|
||||||
float last_value [1] ;
|
float *last_value ;
|
||||||
} LINEAR_DATA ;
|
} LINEAR_DATA ;
|
||||||
|
|
||||||
|
static SRC_STATE_VT linear_state_vt =
|
||||||
|
{
|
||||||
|
linear_vari_process,
|
||||||
|
linear_vari_process,
|
||||||
|
linear_reset,
|
||||||
|
linear_copy,
|
||||||
|
linear_close
|
||||||
|
} ;
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static SRC_ERROR
|
||||||
linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
|
linear_vari_process (SRC_STATE *state, SRC_DATA *data)
|
||||||
{ LINEAR_DATA *priv ;
|
{ LINEAR_DATA *priv ;
|
||||||
double src_ratio, input_index, rem ;
|
double src_ratio, input_index, rem ;
|
||||||
int ch ;
|
int ch ;
|
||||||
|
@ -45,41 +59,41 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
|
||||||
if (data->input_frames <= 0)
|
if (data->input_frames <= 0)
|
||||||
return SRC_ERR_NO_ERROR ;
|
return SRC_ERR_NO_ERROR ;
|
||||||
|
|
||||||
if (psrc->private_data == NULL)
|
if (state->private_data == NULL)
|
||||||
return SRC_ERR_NO_PRIVATE ;
|
return SRC_ERR_NO_PRIVATE ;
|
||||||
|
|
||||||
priv = (LINEAR_DATA*) psrc->private_data ;
|
priv = (LINEAR_DATA*) state->private_data ;
|
||||||
|
|
||||||
if (priv->reset)
|
if (!priv->dirty)
|
||||||
{ /* If we have just been reset, set the last_value data. */
|
{ /* If we have just been reset, set the last_value data. */
|
||||||
for (ch = 0 ; ch < priv->channels ; ch++)
|
for (ch = 0 ; ch < state->channels ; ch++)
|
||||||
priv->last_value [ch] = data->data_in [ch] ;
|
priv->last_value [ch] = data->data_in [ch] ;
|
||||||
priv->reset = 0 ;
|
priv->dirty = true ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
priv->in_count = data->input_frames * priv->channels ;
|
priv->in_count = data->input_frames * state->channels ;
|
||||||
priv->out_count = data->output_frames * priv->channels ;
|
priv->out_count = data->output_frames * state->channels ;
|
||||||
priv->in_used = priv->out_gen = 0 ;
|
priv->in_used = priv->out_gen = 0 ;
|
||||||
|
|
||||||
src_ratio = psrc->last_ratio ;
|
src_ratio = state->last_ratio ;
|
||||||
|
|
||||||
if (is_bad_src_ratio (src_ratio))
|
if (is_bad_src_ratio (src_ratio))
|
||||||
return SRC_ERR_BAD_INTERNAL_STATE ;
|
return SRC_ERR_BAD_INTERNAL_STATE ;
|
||||||
|
|
||||||
input_index = psrc->last_position ;
|
input_index = state->last_position ;
|
||||||
|
|
||||||
/* Calculate samples before first sample in input array. */
|
/* Calculate samples before first sample in input array. */
|
||||||
while (input_index < 1.0 && priv->out_gen < priv->out_count)
|
while (input_index < 1.0 && priv->out_gen < priv->out_count)
|
||||||
{
|
{
|
||||||
if (priv->in_used + priv->channels * (1.0 + input_index) >= priv->in_count)
|
if (priv->in_used + state->channels * (1.0 + input_index) >= priv->in_count)
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
|
if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
|
||||||
src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
|
src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
|
||||||
|
|
||||||
for (ch = 0 ; ch < priv->channels ; ch++)
|
for (ch = 0 ; ch < state->channels ; ch++)
|
||||||
{ data->data_out [priv->out_gen] = (float) (priv->last_value [ch] + input_index *
|
{ data->data_out [priv->out_gen] = (float) (priv->last_value [ch] + input_index *
|
||||||
(data->data_in [ch] - priv->last_value [ch])) ;
|
((double) data->data_in [ch] - priv->last_value [ch])) ;
|
||||||
priv->out_gen ++ ;
|
priv->out_gen ++ ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -88,23 +102,25 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
rem = fmod_one (input_index) ;
|
rem = fmod_one (input_index) ;
|
||||||
priv->in_used += priv->channels * lrint (input_index - rem) ;
|
priv->in_used += state->channels * lrint (input_index - rem) ;
|
||||||
input_index = rem ;
|
input_index = rem ;
|
||||||
|
|
||||||
/* Main processing loop. */
|
/* Main processing loop. */
|
||||||
while (priv->out_gen < priv->out_count && priv->in_used + priv->channels * input_index < priv->in_count)
|
while (priv->out_gen < priv->out_count && priv->in_used + state->channels * input_index < priv->in_count)
|
||||||
{
|
{
|
||||||
if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
|
if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
|
||||||
src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
|
src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
|
||||||
|
|
||||||
if (SRC_DEBUG && priv->in_used < priv->channels && input_index < 1.0)
|
#if SRC_DEBUG
|
||||||
{ printf ("Whoops!!!! in_used : %ld channels : %d input_index : %f\n", priv->in_used, priv->channels, input_index) ;
|
if (priv->in_used < state->channels && input_index < 1.0)
|
||||||
|
{ printf ("Whoops!!!! in_used : %ld channels : %d input_index : %f\n", priv->in_used, state->channels, input_index) ;
|
||||||
exit (1) ;
|
exit (1) ;
|
||||||
} ;
|
} ;
|
||||||
|
#endif
|
||||||
|
|
||||||
for (ch = 0 ; ch < priv->channels ; ch++)
|
for (ch = 0 ; ch < state->channels ; ch++)
|
||||||
{ data->data_out [priv->out_gen] = (float) (data->data_in [priv->in_used - priv->channels + ch] + input_index *
|
{ data->data_out [priv->out_gen] = (float) (data->data_in [priv->in_used - state->channels + ch] + input_index *
|
||||||
(data->data_in [priv->in_used + ch] - data->data_in [priv->in_used - priv->channels + ch])) ;
|
((double) data->data_in [priv->in_used + ch] - data->data_in [priv->in_used - state->channels + ch])) ;
|
||||||
priv->out_gen ++ ;
|
priv->out_gen ++ ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -112,26 +128,26 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
|
||||||
input_index += 1.0 / src_ratio ;
|
input_index += 1.0 / src_ratio ;
|
||||||
rem = fmod_one (input_index) ;
|
rem = fmod_one (input_index) ;
|
||||||
|
|
||||||
priv->in_used += priv->channels * lrint (input_index - rem) ;
|
priv->in_used += state->channels * lrint (input_index - rem) ;
|
||||||
input_index = rem ;
|
input_index = rem ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
if (priv->in_used > priv->in_count)
|
if (priv->in_used > priv->in_count)
|
||||||
{ input_index += (priv->in_used - priv->in_count) / priv->channels ;
|
{ input_index += (priv->in_used - priv->in_count) / state->channels ;
|
||||||
priv->in_used = priv->in_count ;
|
priv->in_used = priv->in_count ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
psrc->last_position = input_index ;
|
state->last_position = input_index ;
|
||||||
|
|
||||||
if (priv->in_used > 0)
|
if (priv->in_used > 0)
|
||||||
for (ch = 0 ; ch < priv->channels ; ch++)
|
for (ch = 0 ; ch < state->channels ; ch++)
|
||||||
priv->last_value [ch] = data->data_in [priv->in_used - priv->channels + ch] ;
|
priv->last_value [ch] = data->data_in [priv->in_used - state->channels + ch] ;
|
||||||
|
|
||||||
/* Save current ratio rather then target ratio. */
|
/* Save current ratio rather then target ratio. */
|
||||||
psrc->last_ratio = src_ratio ;
|
state->last_ratio = src_ratio ;
|
||||||
|
|
||||||
data->input_frames_used = priv->in_used / priv->channels ;
|
data->input_frames_used = priv->in_used / state->channels ;
|
||||||
data->output_frames_gen = priv->out_gen / priv->channels ;
|
data->output_frames_gen = priv->out_gen / state->channels ;
|
||||||
|
|
||||||
return SRC_ERR_NO_ERROR ;
|
return SRC_ERR_NO_ERROR ;
|
||||||
} /* linear_vari_process */
|
} /* linear_vari_process */
|
||||||
|
@ -139,7 +155,7 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char*
|
LIBSAMPLERATE_DLL_PRIVATE const char*
|
||||||
linear_get_name (int src_enum)
|
linear_get_name (int src_enum)
|
||||||
{
|
{
|
||||||
if (src_enum == SRC_LINEAR)
|
if (src_enum == SRC_LINEAR)
|
||||||
|
@ -148,7 +164,7 @@ linear_get_name (int src_enum)
|
||||||
return NULL ;
|
return NULL ;
|
||||||
} /* linear_get_name */
|
} /* linear_get_name */
|
||||||
|
|
||||||
const char*
|
LIBSAMPLERATE_DLL_PRIVATE const char*
|
||||||
linear_get_description (int src_enum)
|
linear_get_description (int src_enum)
|
||||||
{
|
{
|
||||||
if (src_enum == SRC_LINEAR)
|
if (src_enum == SRC_LINEAR)
|
||||||
|
@ -157,53 +173,129 @@ linear_get_description (int src_enum)
|
||||||
return NULL ;
|
return NULL ;
|
||||||
} /* linear_get_descrition */
|
} /* linear_get_descrition */
|
||||||
|
|
||||||
int
|
static LINEAR_DATA *
|
||||||
linear_set_converter (SRC_PRIVATE *psrc, int src_enum)
|
linear_data_new (int channels)
|
||||||
{ LINEAR_DATA *priv = NULL ;
|
{
|
||||||
|
assert (channels > 0) ;
|
||||||
if (src_enum != SRC_LINEAR)
|
|
||||||
return SRC_ERR_BAD_CONVERTER ;
|
|
||||||
|
|
||||||
if (psrc->private_data != NULL)
|
|
||||||
{ free (psrc->private_data) ;
|
|
||||||
psrc->private_data = NULL ;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
if (psrc->private_data == NULL)
|
|
||||||
{ priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
|
|
||||||
psrc->private_data = priv ;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
if (priv == NULL)
|
|
||||||
return SRC_ERR_MALLOC_FAILED ;
|
|
||||||
|
|
||||||
|
LINEAR_DATA *priv = (LINEAR_DATA *) calloc (1, sizeof (LINEAR_DATA)) ;
|
||||||
|
if (priv)
|
||||||
|
{
|
||||||
priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;
|
priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;
|
||||||
priv->channels = psrc->channels ;
|
priv->last_value = (float *) calloc (channels, sizeof (float)) ;
|
||||||
|
if (!priv->last_value)
|
||||||
|
{
|
||||||
|
free (priv) ;
|
||||||
|
priv = NULL ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
psrc->const_process = linear_vari_process ;
|
return priv ;
|
||||||
psrc->vari_process = linear_vari_process ;
|
}
|
||||||
psrc->reset = linear_reset ;
|
|
||||||
|
|
||||||
linear_reset (psrc) ;
|
LIBSAMPLERATE_DLL_PRIVATE SRC_STATE *
|
||||||
|
linear_state_new (int channels, SRC_ERROR *error)
|
||||||
|
{
|
||||||
|
assert (channels > 0) ;
|
||||||
|
assert (error != NULL) ;
|
||||||
|
|
||||||
return SRC_ERR_NO_ERROR ;
|
SRC_STATE *state = (SRC_STATE *) calloc (1, sizeof (SRC_STATE)) ;
|
||||||
} /* linear_set_converter */
|
if (!state)
|
||||||
|
{
|
||||||
|
*error = SRC_ERR_MALLOC_FAILED ;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
state->channels = channels ;
|
||||||
|
state->mode = SRC_MODE_PROCESS ;
|
||||||
|
|
||||||
|
state->private_data = linear_data_new (state->channels) ;
|
||||||
|
if (!state->private_data)
|
||||||
|
{
|
||||||
|
free (state) ;
|
||||||
|
*error = SRC_ERR_MALLOC_FAILED ;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
state->vt = &linear_state_vt ;
|
||||||
|
|
||||||
|
linear_reset (state) ;
|
||||||
|
|
||||||
|
*error = SRC_ERR_NO_ERROR ;
|
||||||
|
|
||||||
|
return state ;
|
||||||
|
}
|
||||||
|
|
||||||
/*===================================================================================
|
/*===================================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
linear_reset (SRC_PRIVATE *psrc)
|
linear_reset (SRC_STATE *state)
|
||||||
{ LINEAR_DATA *priv = NULL ;
|
{ LINEAR_DATA *priv = NULL ;
|
||||||
|
|
||||||
priv = (LINEAR_DATA*) psrc->private_data ;
|
priv = (LINEAR_DATA*) state->private_data ;
|
||||||
if (priv == NULL)
|
if (priv == NULL)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
priv->channels = psrc->channels ;
|
priv->dirty = false ;
|
||||||
priv->reset = 1 ;
|
memset (priv->last_value, 0, sizeof (priv->last_value [0]) * state->channels) ;
|
||||||
memset (priv->last_value, 0, sizeof (priv->last_value [0]) * priv->channels) ;
|
|
||||||
|
|
||||||
return ;
|
return ;
|
||||||
} /* linear_reset */
|
} /* linear_reset */
|
||||||
|
|
||||||
|
SRC_STATE *
|
||||||
|
linear_copy (SRC_STATE *state)
|
||||||
|
{
|
||||||
|
assert (state != NULL) ;
|
||||||
|
|
||||||
|
if (state->private_data == NULL)
|
||||||
|
return NULL ;
|
||||||
|
|
||||||
|
SRC_STATE *to = (SRC_STATE *) calloc (1, sizeof (SRC_STATE)) ;
|
||||||
|
if (!to)
|
||||||
|
return NULL ;
|
||||||
|
memcpy (to, state, sizeof (SRC_STATE)) ;
|
||||||
|
|
||||||
|
LINEAR_DATA* from_priv = (LINEAR_DATA*) state->private_data ;
|
||||||
|
LINEAR_DATA *to_priv = (LINEAR_DATA *) calloc (1, sizeof (LINEAR_DATA)) ;
|
||||||
|
if (!to_priv)
|
||||||
|
{
|
||||||
|
free (to) ;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy (to_priv, from_priv, sizeof (LINEAR_DATA)) ;
|
||||||
|
to_priv->last_value = (float *) malloc (sizeof (float) * state->channels) ;
|
||||||
|
if (!to_priv->last_value)
|
||||||
|
{
|
||||||
|
free (to) ;
|
||||||
|
free (to_priv) ;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
memcpy (to_priv->last_value, from_priv->last_value, sizeof (float) * state->channels) ;
|
||||||
|
|
||||||
|
to->private_data = to_priv ;
|
||||||
|
|
||||||
|
return to ;
|
||||||
|
} /* linear_copy */
|
||||||
|
|
||||||
|
static void
|
||||||
|
linear_close (SRC_STATE *state)
|
||||||
|
{
|
||||||
|
if (state)
|
||||||
|
{
|
||||||
|
LINEAR_DATA *linear = (LINEAR_DATA *) state->private_data ;
|
||||||
|
if (linear)
|
||||||
|
{
|
||||||
|
if (linear->last_value)
|
||||||
|
{
|
||||||
|
free (linear->last_value) ;
|
||||||
|
linear->last_value = NULL ;
|
||||||
|
}
|
||||||
|
free (linear) ;
|
||||||
|
linear = NULL ;
|
||||||
|
}
|
||||||
|
free (state) ;
|
||||||
|
state = NULL ;
|
||||||
|
}
|
||||||
|
} /* linear_close */
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,21 +1,24 @@
|
||||||
/*
|
/*
|
||||||
** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
|
** Copyright (c) 2002-2021, Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||||
** All rights reserved.
|
** All rights reserved.
|
||||||
**
|
**
|
||||||
** This code is released under 2-clause BSD license. Please see the
|
** This code is released under 2-clause BSD license. Please see the
|
||||||
** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
|
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "float_cast.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
static int zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
|
static SRC_ERROR zoh_vari_process (SRC_STATE *state, SRC_DATA *data) ;
|
||||||
static void zoh_reset (SRC_PRIVATE *psrc) ;
|
static void zoh_reset (SRC_STATE *state) ;
|
||||||
|
static SRC_STATE *zoh_copy (SRC_STATE *state) ;
|
||||||
|
static void zoh_close (SRC_STATE *state) ;
|
||||||
|
|
||||||
/*========================================================================================
|
/*========================================================================================
|
||||||
*/
|
*/
|
||||||
|
@ -24,18 +27,26 @@ static void zoh_reset (SRC_PRIVATE *psrc) ;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{ int zoh_magic_marker ;
|
{ int zoh_magic_marker ;
|
||||||
int channels ;
|
bool dirty ;
|
||||||
int reset ;
|
|
||||||
long in_count, in_used ;
|
long in_count, in_used ;
|
||||||
long out_count, out_gen ;
|
long out_count, out_gen ;
|
||||||
float last_value [1] ;
|
float *last_value ;
|
||||||
} ZOH_DATA ;
|
} ZOH_DATA ;
|
||||||
|
|
||||||
|
static SRC_STATE_VT zoh_state_vt =
|
||||||
|
{
|
||||||
|
zoh_vari_process,
|
||||||
|
zoh_vari_process,
|
||||||
|
zoh_reset,
|
||||||
|
zoh_copy,
|
||||||
|
zoh_close
|
||||||
|
} ;
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static SRC_ERROR
|
||||||
zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
|
zoh_vari_process (SRC_STATE *state, SRC_DATA *data)
|
||||||
{ ZOH_DATA *priv ;
|
{ ZOH_DATA *priv ;
|
||||||
double src_ratio, input_index, rem ;
|
double src_ratio, input_index, rem ;
|
||||||
int ch ;
|
int ch ;
|
||||||
|
@ -43,39 +54,39 @@ zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
|
||||||
if (data->input_frames <= 0)
|
if (data->input_frames <= 0)
|
||||||
return SRC_ERR_NO_ERROR ;
|
return SRC_ERR_NO_ERROR ;
|
||||||
|
|
||||||
if (psrc->private_data == NULL)
|
if (state->private_data == NULL)
|
||||||
return SRC_ERR_NO_PRIVATE ;
|
return SRC_ERR_NO_PRIVATE ;
|
||||||
|
|
||||||
priv = (ZOH_DATA*) psrc->private_data ;
|
priv = (ZOH_DATA*) state->private_data ;
|
||||||
|
|
||||||
if (priv->reset)
|
if (!priv->dirty)
|
||||||
{ /* If we have just been reset, set the last_value data. */
|
{ /* If we have just been reset, set the last_value data. */
|
||||||
for (ch = 0 ; ch < priv->channels ; ch++)
|
for (ch = 0 ; ch < state->channels ; ch++)
|
||||||
priv->last_value [ch] = data->data_in [ch] ;
|
priv->last_value [ch] = data->data_in [ch] ;
|
||||||
priv->reset = 0 ;
|
priv->dirty = true ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
priv->in_count = data->input_frames * priv->channels ;
|
priv->in_count = data->input_frames * state->channels ;
|
||||||
priv->out_count = data->output_frames * priv->channels ;
|
priv->out_count = data->output_frames * state->channels ;
|
||||||
priv->in_used = priv->out_gen = 0 ;
|
priv->in_used = priv->out_gen = 0 ;
|
||||||
|
|
||||||
src_ratio = psrc->last_ratio ;
|
src_ratio = state->last_ratio ;
|
||||||
|
|
||||||
if (is_bad_src_ratio (src_ratio))
|
if (is_bad_src_ratio (src_ratio))
|
||||||
return SRC_ERR_BAD_INTERNAL_STATE ;
|
return SRC_ERR_BAD_INTERNAL_STATE ;
|
||||||
|
|
||||||
input_index = psrc->last_position ;
|
input_index = state->last_position ;
|
||||||
|
|
||||||
/* Calculate samples before first sample in input array. */
|
/* Calculate samples before first sample in input array. */
|
||||||
while (input_index < 1.0 && priv->out_gen < priv->out_count)
|
while (input_index < 1.0 && priv->out_gen < priv->out_count)
|
||||||
{
|
{
|
||||||
if (priv->in_used + priv->channels * input_index >= priv->in_count)
|
if (priv->in_used + state->channels * input_index >= priv->in_count)
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
|
if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
|
||||||
src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
|
src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
|
||||||
|
|
||||||
for (ch = 0 ; ch < priv->channels ; ch++)
|
for (ch = 0 ; ch < state->channels ; ch++)
|
||||||
{ data->data_out [priv->out_gen] = priv->last_value [ch] ;
|
{ data->data_out [priv->out_gen] = priv->last_value [ch] ;
|
||||||
priv->out_gen ++ ;
|
priv->out_gen ++ ;
|
||||||
} ;
|
} ;
|
||||||
|
@ -85,17 +96,17 @@ zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
rem = fmod_one (input_index) ;
|
rem = fmod_one (input_index) ;
|
||||||
priv->in_used += priv->channels * lrint (input_index - rem) ;
|
priv->in_used += state->channels * lrint (input_index - rem) ;
|
||||||
input_index = rem ;
|
input_index = rem ;
|
||||||
|
|
||||||
/* Main processing loop. */
|
/* Main processing loop. */
|
||||||
while (priv->out_gen < priv->out_count && priv->in_used + priv->channels * input_index <= priv->in_count)
|
while (priv->out_gen < priv->out_count && priv->in_used + state->channels * input_index <= priv->in_count)
|
||||||
{
|
{
|
||||||
if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
|
if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
|
||||||
src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
|
src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
|
||||||
|
|
||||||
for (ch = 0 ; ch < priv->channels ; ch++)
|
for (ch = 0 ; ch < state->channels ; ch++)
|
||||||
{ data->data_out [priv->out_gen] = data->data_in [priv->in_used - priv->channels + ch] ;
|
{ data->data_out [priv->out_gen] = data->data_in [priv->in_used - state->channels + ch] ;
|
||||||
priv->out_gen ++ ;
|
priv->out_gen ++ ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -103,26 +114,26 @@ zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
|
||||||
input_index += 1.0 / src_ratio ;
|
input_index += 1.0 / src_ratio ;
|
||||||
rem = fmod_one (input_index) ;
|
rem = fmod_one (input_index) ;
|
||||||
|
|
||||||
priv->in_used += priv->channels * lrint (input_index - rem) ;
|
priv->in_used += state->channels * lrint (input_index - rem) ;
|
||||||
input_index = rem ;
|
input_index = rem ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
if (priv->in_used > priv->in_count)
|
if (priv->in_used > priv->in_count)
|
||||||
{ input_index += (priv->in_used - priv->in_count) / priv->channels ;
|
{ input_index += (priv->in_used - priv->in_count) / state->channels ;
|
||||||
priv->in_used = priv->in_count ;
|
priv->in_used = priv->in_count ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
psrc->last_position = input_index ;
|
state->last_position = input_index ;
|
||||||
|
|
||||||
if (priv->in_used > 0)
|
if (priv->in_used > 0)
|
||||||
for (ch = 0 ; ch < priv->channels ; ch++)
|
for (ch = 0 ; ch < state->channels ; ch++)
|
||||||
priv->last_value [ch] = data->data_in [priv->in_used - priv->channels + ch] ;
|
priv->last_value [ch] = data->data_in [priv->in_used - state->channels + ch] ;
|
||||||
|
|
||||||
/* Save current ratio rather then target ratio. */
|
/* Save current ratio rather then target ratio. */
|
||||||
psrc->last_ratio = src_ratio ;
|
state->last_ratio = src_ratio ;
|
||||||
|
|
||||||
data->input_frames_used = priv->in_used / priv->channels ;
|
data->input_frames_used = priv->in_used / state->channels ;
|
||||||
data->output_frames_gen = priv->out_gen / priv->channels ;
|
data->output_frames_gen = priv->out_gen / state->channels ;
|
||||||
|
|
||||||
return SRC_ERR_NO_ERROR ;
|
return SRC_ERR_NO_ERROR ;
|
||||||
} /* zoh_vari_process */
|
} /* zoh_vari_process */
|
||||||
|
@ -130,7 +141,7 @@ zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char*
|
LIBSAMPLERATE_DLL_PRIVATE const char*
|
||||||
zoh_get_name (int src_enum)
|
zoh_get_name (int src_enum)
|
||||||
{
|
{
|
||||||
if (src_enum == SRC_ZERO_ORDER_HOLD)
|
if (src_enum == SRC_ZERO_ORDER_HOLD)
|
||||||
|
@ -139,7 +150,7 @@ zoh_get_name (int src_enum)
|
||||||
return NULL ;
|
return NULL ;
|
||||||
} /* zoh_get_name */
|
} /* zoh_get_name */
|
||||||
|
|
||||||
const char*
|
LIBSAMPLERATE_DLL_PRIVATE const char*
|
||||||
zoh_get_description (int src_enum)
|
zoh_get_description (int src_enum)
|
||||||
{
|
{
|
||||||
if (src_enum == SRC_ZERO_ORDER_HOLD)
|
if (src_enum == SRC_ZERO_ORDER_HOLD)
|
||||||
|
@ -148,53 +159,129 @@ zoh_get_description (int src_enum)
|
||||||
return NULL ;
|
return NULL ;
|
||||||
} /* zoh_get_descrition */
|
} /* zoh_get_descrition */
|
||||||
|
|
||||||
int
|
static ZOH_DATA *
|
||||||
zoh_set_converter (SRC_PRIVATE *psrc, int src_enum)
|
zoh_data_new (int channels)
|
||||||
{ ZOH_DATA *priv = NULL ;
|
{
|
||||||
|
assert (channels > 0) ;
|
||||||
if (src_enum != SRC_ZERO_ORDER_HOLD)
|
|
||||||
return SRC_ERR_BAD_CONVERTER ;
|
|
||||||
|
|
||||||
if (psrc->private_data != NULL)
|
|
||||||
{ free (psrc->private_data) ;
|
|
||||||
psrc->private_data = NULL ;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
if (psrc->private_data == NULL)
|
|
||||||
{ priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
|
|
||||||
psrc->private_data = priv ;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
if (priv == NULL)
|
|
||||||
return SRC_ERR_MALLOC_FAILED ;
|
|
||||||
|
|
||||||
|
ZOH_DATA *priv = (ZOH_DATA *) calloc (1, sizeof (ZOH_DATA)) ;
|
||||||
|
if (priv)
|
||||||
|
{
|
||||||
priv->zoh_magic_marker = ZOH_MAGIC_MARKER ;
|
priv->zoh_magic_marker = ZOH_MAGIC_MARKER ;
|
||||||
priv->channels = psrc->channels ;
|
priv->last_value = (float *) calloc (channels, sizeof (float)) ;
|
||||||
|
if (!priv->last_value)
|
||||||
|
{
|
||||||
|
free (priv) ;
|
||||||
|
priv = NULL ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
psrc->const_process = zoh_vari_process ;
|
return priv ;
|
||||||
psrc->vari_process = zoh_vari_process ;
|
}
|
||||||
psrc->reset = zoh_reset ;
|
|
||||||
|
|
||||||
zoh_reset (psrc) ;
|
LIBSAMPLERATE_DLL_PRIVATE SRC_STATE *
|
||||||
|
zoh_state_new (int channels, SRC_ERROR *error)
|
||||||
|
{
|
||||||
|
assert (channels > 0) ;
|
||||||
|
assert (error != NULL) ;
|
||||||
|
|
||||||
return SRC_ERR_NO_ERROR ;
|
SRC_STATE *state = (SRC_STATE *) calloc (1, sizeof (SRC_STATE)) ;
|
||||||
} /* zoh_set_converter */
|
if (!state)
|
||||||
|
{
|
||||||
|
*error = SRC_ERR_MALLOC_FAILED ;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
state->channels = channels ;
|
||||||
|
state->mode = SRC_MODE_PROCESS ;
|
||||||
|
|
||||||
|
state->private_data = zoh_data_new (state->channels) ;
|
||||||
|
if (!state->private_data)
|
||||||
|
{
|
||||||
|
free (state) ;
|
||||||
|
*error = SRC_ERR_MALLOC_FAILED ;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
state->vt = &zoh_state_vt ;
|
||||||
|
|
||||||
|
zoh_reset (state) ;
|
||||||
|
|
||||||
|
*error = SRC_ERR_NO_ERROR ;
|
||||||
|
|
||||||
|
return state ;
|
||||||
|
}
|
||||||
|
|
||||||
/*===================================================================================
|
/*===================================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zoh_reset (SRC_PRIVATE *psrc)
|
zoh_reset (SRC_STATE *state)
|
||||||
{ ZOH_DATA *priv ;
|
{ ZOH_DATA *priv ;
|
||||||
|
|
||||||
priv = (ZOH_DATA*) psrc->private_data ;
|
priv = (ZOH_DATA*) state->private_data ;
|
||||||
if (priv == NULL)
|
if (priv == NULL)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
priv->channels = psrc->channels ;
|
priv->dirty = false ;
|
||||||
priv->reset = 1 ;
|
memset (priv->last_value, 0, sizeof (float) * state->channels) ;
|
||||||
memset (priv->last_value, 0, sizeof (priv->last_value [0]) * priv->channels) ;
|
|
||||||
|
|
||||||
return ;
|
return ;
|
||||||
} /* zoh_reset */
|
} /* zoh_reset */
|
||||||
|
|
||||||
|
static SRC_STATE *
|
||||||
|
zoh_copy (SRC_STATE *state)
|
||||||
|
{
|
||||||
|
assert (state != NULL) ;
|
||||||
|
|
||||||
|
if (state->private_data == NULL)
|
||||||
|
return NULL ;
|
||||||
|
|
||||||
|
SRC_STATE *to = (SRC_STATE *) calloc (1, sizeof (SRC_STATE)) ;
|
||||||
|
if (!to)
|
||||||
|
return NULL ;
|
||||||
|
memcpy (to, state, sizeof (SRC_STATE)) ;
|
||||||
|
|
||||||
|
ZOH_DATA* from_priv = (ZOH_DATA*) state->private_data ;
|
||||||
|
ZOH_DATA *to_priv = (ZOH_DATA *) calloc (1, sizeof (ZOH_DATA)) ;
|
||||||
|
if (!to_priv)
|
||||||
|
{
|
||||||
|
free (to) ;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy (to_priv, from_priv, sizeof (ZOH_DATA)) ;
|
||||||
|
to_priv->last_value = (float *) malloc (sizeof (float) * state->channels) ;
|
||||||
|
if (!to_priv->last_value)
|
||||||
|
{
|
||||||
|
free (to) ;
|
||||||
|
free (to_priv) ;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
memcpy (to_priv->last_value, from_priv->last_value, sizeof (float) * state->channels) ;
|
||||||
|
|
||||||
|
to->private_data = to_priv ;
|
||||||
|
|
||||||
|
return to ;
|
||||||
|
} /* zoh_copy */
|
||||||
|
|
||||||
|
static void
|
||||||
|
zoh_close (SRC_STATE *state)
|
||||||
|
{
|
||||||
|
if (state)
|
||||||
|
{
|
||||||
|
ZOH_DATA *zoh = (ZOH_DATA *) state->private_data ;
|
||||||
|
if (zoh)
|
||||||
|
{
|
||||||
|
if (zoh->last_value)
|
||||||
|
{
|
||||||
|
free (zoh->last_value) ;
|
||||||
|
zoh->last_value = NULL ;
|
||||||
|
}
|
||||||
|
free (zoh) ;
|
||||||
|
zoh = NULL ;
|
||||||
|
}
|
||||||
|
free (state) ;
|
||||||
|
state = NULL ;
|
||||||
|
}
|
||||||
|
} /* zoh_close */
|
||||||
|
|
Loading…
Reference in New Issue