[LIBSAMPLERATE]
authorThomas Faber <thomas.faber@reactos.org>
Sun, 18 Jun 2017 11:41:14 +0000 (11:41 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Sun, 18 Jun 2017 11:41:14 +0000 (11:41 +0000)
- Update to version 1.0.9
CORE-13451

svn path=/trunk/; revision=75088

13 files changed:
reactos/sdk/lib/3rdparty/libsamplerate/COPYING [new file with mode: 0644]
reactos/sdk/lib/3rdparty/libsamplerate/common.h
reactos/sdk/lib/3rdparty/libsamplerate/config.h
reactos/sdk/lib/3rdparty/libsamplerate/fastest_coeffs.h
reactos/sdk/lib/3rdparty/libsamplerate/float_cast.h
reactos/sdk/lib/3rdparty/libsamplerate/high_qual_coeffs.h
reactos/sdk/lib/3rdparty/libsamplerate/mid_qual_coeffs.h
reactos/sdk/lib/3rdparty/libsamplerate/samplerate.c
reactos/sdk/lib/3rdparty/libsamplerate/samplerate.h
reactos/sdk/lib/3rdparty/libsamplerate/src_linear.c
reactos/sdk/lib/3rdparty/libsamplerate/src_sinc.c
reactos/sdk/lib/3rdparty/libsamplerate/src_zoh.c
reactos/sdk/lib/3rdparty/libsamplerate/unistd.h

diff --git a/reactos/sdk/lib/3rdparty/libsamplerate/COPYING b/reactos/sdk/lib/3rdparty/libsamplerate/COPYING
new file mode 100644 (file)
index 0000000..9f82626
--- /dev/null
@@ -0,0 +1,25 @@
+Copyright (c) 2012-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
index a8d4e98..10b3536 100644 (file)
@@ -1,25 +1,9 @@
 /*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-/*
-** This code is part of Secret Rabbit Code aka libsamplerate. A commercial
-** use license for this code is available, please see:
-**             http://www.mega-nerd.com/SRC/procedure.html
+** This code is released under 2-clause BSD license. Please see the
+** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
 */
 
 #ifndef COMMON_H_INCLUDED
@@ -99,6 +83,7 @@ enum
        SRC_ERR_NULL_CALLBACK,
        SRC_ERR_NO_VARIABLE_RATIO,
        SRC_ERR_SINC_PREPARE_DATA_BAD_LEN,
+       SRC_ERR_BAD_INTERNAL_STATE,
 
        /* This must be the last error number. */
        SRC_ERR_MAX_ERROR
@@ -129,7 +114,7 @@ typedef struct SRC_PRIVATE_tag
        src_callback_t  callback_func ;
        void                    *user_callback_data ;
        long                    saved_frames ;
-       float                   *saved_data ;
+       const float             *saved_data ;
 } SRC_PRIVATE ;
 
 /* In src_sinc.c */
@@ -165,5 +150,11 @@ fmod_one (double x)
        return res ;
 } /* fmod_one */
 
+static inline int
+is_bad_src_ratio (double ratio)
+{      return (ratio < (1.0 / SRC_MAX_RATIO) || ratio > (1.0 * SRC_MAX_RATIO)) ;
+} /* is_bad_src_ratio */
+
+
 #endif /* COMMON_H_INCLUDED */
 
index 8f7fd4f..c360c2b 100644 (file)
@@ -1,19 +1,9 @@
 /*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+** This code is released under 2-clause BSD license. Please see the
+** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
 */
 
 /*
index 49b8399..ed009ef 100644 (file)
@@ -1,25 +1,9 @@
 /*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-/*
-** This code is part of Secret Rabbit Code aka libsamplerate. A commercial
-** use license for this code is available, please see:
-**             http://www.mega-nerd.com/SRC/procedure.html
+** This code is released under 2-clause BSD license. Please see the
+** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
 */
 
 /*
index 17e9331..b93aa32 100644 (file)
@@ -1,19 +1,9 @@
 /*
-** Copyright (C) 2001-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2001-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU Lesser General Public License as published by
-** the Free Software Foundation; either version 2.1 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU Lesser General Public License for more details.
-**
-** You should have received a copy of the GNU Lesser General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+** 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 */
index bc7302c..f0f2fb4 100644 (file)
@@ -1,25 +1,9 @@
 /*
-** Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2007-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-/*
-** This code is part of Secret Rabbit Code aka libsamplerate. A commercial
-** use license for this code is available, please see:
-**             http://www.mega-nerd.com/SRC/procedure.html
+** This code is released under 2-clause BSD license. Please see the
+** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
 */
 
 /*
index e54ec75..95f1ae8 100644 (file)
@@ -1,25 +1,9 @@
 /*
-** Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2007-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-/*
-** This code is part of Secret Rabbit Code aka libsamplerate. A commercial
-** use license for this code is available, please see:
-**             http://www.mega-nerd.com/SRC/procedure.html
+** This code is released under 2-clause BSD license. Please see the
+** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
 */
 
 /*
index ee36db0..e5184cb 100644 (file)
@@ -1,25 +1,9 @@
 /*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-/*
-** This code is part of Secret Rabbit Code aka libsamplerate. A commercial
-** use license for this code is available, please see:
-**             http://www.mega-nerd.com/SRC/procedure.html
+** This code is released under 2-clause BSD license. Please see the
+** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
 */
 
 #include "precomp.h"
 static int psrc_set_converter (SRC_PRIVATE     *psrc, int converter_type) ;
 
 
-static inline int
-is_bad_src_ratio (double ratio)
-{      return (ratio < (1.0 / SRC_MAX_RATIO) || ratio > (1.0 * SRC_MAX_RATIO)) ;
-} /* is_bad_src_ratio */
-
 SRC_STATE *
 src_new (int converter_type, int channels, int *error)
 {      SRC_PRIVATE     *psrc ;
@@ -286,6 +265,20 @@ src_set_ratio (SRC_STATE *state, double new_ratio)
        return SRC_ERR_NO_ERROR ;
 } /* src_set_ratio */
 
+int
+src_get_channels (SRC_STATE *state)
+{      SRC_PRIVATE *psrc ;
+
+       psrc = (SRC_PRIVATE*) state ;
+
+       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 */
+
 int
 src_reset (SRC_STATE *state)
 {      SRC_PRIVATE *psrc ;
@@ -381,7 +374,7 @@ src_strerror (int error)
                case SRC_ERR_BAD_DATA :
                                return "SRC_DATA pointer is NULL." ;
                case SRC_ERR_BAD_DATA_PTR :
-                               return "SRC_DATA->data_out is NULL." ;
+                               return "SRC_DATA->data_out or SRC_DATA->data_in is NULL." ;
                case SRC_ERR_NO_PRIVATE :
                                return "Internal error. No private data." ;
 
@@ -418,6 +411,8 @@ src_strerror (int error)
                                return "This converter only allows constant conversion ratios." ;
                case SRC_ERR_SINC_PREPARE_DATA_BAD_LEN :
                                return "Internal error : Bad length in prepare_data ()." ;
+               case SRC_ERR_BAD_INTERNAL_STATE :
+                               return "Error : Someone is trampling on my internal state." ;
 
                case SRC_ERR_MAX_ERROR :
                                return "Placeholder. No error defined for this error number." ;
@@ -445,7 +440,7 @@ src_simple (SRC_DATA *src_data, int converter, int channels)
 
        error = src_process (src_state, src_data) ;
 
-       src_state = src_delete (src_state) ;
+       src_delete (src_state) ;
 
        return error ;
 } /* src_simple */
index 044f8d7..ac0f2b0 100644 (file)
@@ -1,25 +1,9 @@
 /*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-/*
-** This code is part of Secret Rabbit Code aka libsamplerate. A commercial
-** use license for this code is available, please see:
-**             http://www.mega-nerd.com/SRC/procedure.html
+** This code is released under 2-clause BSD license. Please see the
+** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
 */
 
 /*
@@ -40,7 +24,8 @@ typedef struct SRC_STATE_tag SRC_STATE ;
 
 /* SRC_DATA is used to pass data to src_simple() and src_process(). */
 typedef struct
-{      float   *data_in, *data_out ;
+{      const float     *data_in ;
+       float    *data_out ;
 
        long    input_frames, output_frames ;
        long    input_frames_used, output_frames_gen ;
@@ -50,12 +35,6 @@ typedef struct
        double  src_ratio ;
 } SRC_DATA ;
 
-/* SRC_CB_DATA is used with callback based API. */
-typedef struct
-{      long    frames ;
-       float   *data_in ;
-} SRC_CB_DATA ;
-
 /*
 ** User supplied callback function type for use with src_callback_new()
 ** and src_callback_read(). First parameter is the same pointer that was
@@ -136,6 +115,13 @@ const char *src_get_version (void) ;
 
 int src_set_ratio (SRC_STATE *state, double new_ratio) ;
 
+/*
+**     Get the current channel count.
+**     Returns negative on error, positive channel count otherwise
+*/
+
+int src_get_channels (SRC_STATE *state) ;
+
 /*
 **     Reset the internal SRC state.
 **     Does not modify the quality settings.
index b6cbc75..80702c4 100644 (file)
@@ -1,25 +1,9 @@
 /*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-/*
-** This code is part of Secret Rabbit Code aka libsamplerate. A commercial
-** use license for this code is available, please see:
-**             http://www.mega-nerd.com/SRC/procedure.html
+** This code is released under 2-clause BSD license. Please see the
+** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
 */
 
 #include "precomp.h"
@@ -72,6 +56,10 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
        priv->in_used = priv->out_gen = 0 ;
 
        src_ratio = psrc->last_ratio ;
+
+       if (is_bad_src_ratio (src_ratio))
+               return SRC_ERR_BAD_INTERNAL_STATE ;
+
        input_index = psrc->last_position ;
 
        /* Calculate samples before first sample in input array. */
@@ -177,11 +165,12 @@ linear_set_converter (SRC_PRIVATE *psrc, int src_enum)
 
        if (psrc->private_data == NULL)
        {       priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
-               if (priv == NULL)
-                       return SRC_ERR_MALLOC_FAILED ;
                psrc->private_data = priv ;
                } ;
 
+       if (priv == NULL)
+               return SRC_ERR_MALLOC_FAILED ;
+
        priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;
        priv->channels = psrc->channels ;
 
index 66ef8bf..d9d9602 100644 (file)
@@ -1,25 +1,9 @@
 /*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-/*
-** This code is part of Secret Rabbit Code aka libsamplerate. A commercial
-** use license for this code is available, please see:
-**             http://www.mega-nerd.com/SRC/procedure.html
+** This code is released under 2-clause BSD license. Please see the
+** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
 */
 
 #include "precomp.h"
@@ -136,7 +120,7 @@ sinc_get_description (int src_enum)
                        return "Band limited sinc interpolation, medium quality, 121dB SNR, 90% BW." ;
 
                case SRC_SINC_BEST_QUALITY :
-                       return "Band limited sinc interpolation, best quality, 145dB SNR, 96% BW." ;
+                       return "Band limited sinc interpolation, best quality, 144dB SNR, 96% BW." ;
 
                default :
                        break ;
@@ -195,19 +179,19 @@ sinc_set_converter (SRC_PRIVATE *psrc, int src_enum)
        switch (src_enum)
        {       case SRC_SINC_FASTEST :
                                temp_filter.coeffs = fastest_coeffs.coeffs ;
-                               temp_filter.coeff_half_len = ARRAY_LEN (fastest_coeffs.coeffs) - 1 ;
+                               temp_filter.coeff_half_len = ARRAY_LEN (fastest_coeffs.coeffs) - 2 ;
                                temp_filter.index_inc = fastest_coeffs.increment ;
                                break ;
 
                case SRC_SINC_MEDIUM_QUALITY :
                                temp_filter.coeffs = slow_mid_qual_coeffs.coeffs ;
-                               temp_filter.coeff_half_len = ARRAY_LEN (slow_mid_qual_coeffs.coeffs) - 1 ;
+                               temp_filter.coeff_half_len = ARRAY_LEN (slow_mid_qual_coeffs.coeffs) - 2 ;
                                temp_filter.index_inc = slow_mid_qual_coeffs.increment ;
                                break ;
 
                case SRC_SINC_BEST_QUALITY :
                                temp_filter.coeffs = slow_high_qual_coeffs.coeffs ;
-                               temp_filter.coeff_half_len = ARRAY_LEN (slow_high_qual_coeffs.coeffs) - 1 ;
+                               temp_filter.coeff_half_len = ARRAY_LEN (slow_high_qual_coeffs.coeffs) - 2 ;
                                temp_filter.index_inc = slow_high_qual_coeffs.increment ;
                                break ;
 
@@ -341,6 +325,9 @@ sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 
        src_ratio = psrc->last_ratio ;
 
+       if (is_bad_src_ratio (src_ratio))
+               return SRC_ERR_BAD_INTERNAL_STATE ;
+
        /* Check the sample rate ratio wrt the buffer len. */
        count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
        if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
@@ -375,17 +362,14 @@ sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 
                /* This is the termination condition. */
                if (filter->b_real_end >= 0)
-               {       if (filter->b_current + input_index + terminate >= filter->b_real_end)
+               {       if (filter->b_current + input_index + terminate > filter->b_real_end)
                                break ;
                        } ;
 
                if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
                        src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
 
-               float_increment = filter->index_inc * 1.0 ;
-               if (src_ratio < 1.0)
-                       float_increment = filter->index_inc * src_ratio ;
-
+               float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
                increment = double_to_fp (float_increment) ;
 
                start_filter_index = double_to_fp (input_index * float_increment) ;
@@ -490,6 +474,9 @@ sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 
        src_ratio = psrc->last_ratio ;
 
+       if (is_bad_src_ratio (src_ratio))
+               return SRC_ERR_BAD_INTERNAL_STATE ;
+
        /* Check the sample rate ratio wrt the buffer len. */
        count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
        if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
@@ -531,10 +518,7 @@ sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
                if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
                        src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
 
-               float_increment = filter->index_inc * 1.0 ;
-               if (src_ratio < 1.0)
-                       float_increment = filter->index_inc * src_ratio ;
-
+               float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
                increment = double_to_fp (float_increment) ;
 
                start_filter_index = double_to_fp (input_index * float_increment) ;
@@ -644,6 +628,9 @@ sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 
        src_ratio = psrc->last_ratio ;
 
+       if (is_bad_src_ratio (src_ratio))
+               return SRC_ERR_BAD_INTERNAL_STATE ;
+
        /* Check the sample rate ratio wrt the buffer len. */
        count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
        if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
@@ -685,10 +672,7 @@ sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
                if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
                        src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
 
-               float_increment = filter->index_inc * 1.0 ;
-               if (src_ratio < 1.0)
-                       float_increment = filter->index_inc * src_ratio ;
-
+               float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
                increment = double_to_fp (float_increment) ;
 
                start_filter_index = double_to_fp (input_index * float_increment) ;
@@ -804,6 +788,9 @@ sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 
        src_ratio = psrc->last_ratio ;
 
+       if (is_bad_src_ratio (src_ratio))
+               return SRC_ERR_BAD_INTERNAL_STATE ;
+
        /* Check the sample rate ratio wrt the buffer len. */
        count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
        if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
@@ -845,10 +832,7 @@ sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
                if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
                        src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
 
-               float_increment = filter->index_inc * 1.0 ;
-               if (src_ratio < 1.0)
-                       float_increment = filter->index_inc * src_ratio ;
-
+               float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
                increment = double_to_fp (float_increment) ;
 
                start_filter_index = double_to_fp (input_index * float_increment) ;
@@ -1051,6 +1035,9 @@ sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 
        src_ratio = psrc->last_ratio ;
 
+       if (is_bad_src_ratio (src_ratio))
+               return SRC_ERR_BAD_INTERNAL_STATE ;
+
        /* Check the sample rate ratio wrt the buffer len. */
        count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
        if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
@@ -1092,10 +1079,7 @@ sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
                if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
                        src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
 
-               float_increment = filter->index_inc * 1.0 ;
-               if (src_ratio < 1.0)
-                       float_increment = filter->index_inc * src_ratio ;
-
+               float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
                increment = double_to_fp (float_increment) ;
 
                start_filter_index = double_to_fp (input_index * float_increment) ;
index 216dfcb..8f93822 100644 (file)
@@ -1,25 +1,9 @@
 /*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-/*
-** This code is part of Secret Rabbit Code aka libsamplerate. A commercial
-** use license for this code is available, please see:
-**             http://www.mega-nerd.com/SRC/procedure.html
+** This code is released under 2-clause BSD license. Please see the
+** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
 */
 
 #include "precomp.h"
@@ -70,6 +54,10 @@ zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
        priv->in_used = priv->out_gen = 0 ;
 
        src_ratio = psrc->last_ratio ;
+
+       if (is_bad_src_ratio (src_ratio))
+               return SRC_ERR_BAD_INTERNAL_STATE ;
+
        input_index = psrc->last_position ;
 
        /* Calculate samples before first sample in input array. */
@@ -168,11 +156,12 @@ zoh_set_converter (SRC_PRIVATE *psrc, int src_enum)
 
        if (psrc->private_data == NULL)
        {       priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
-               if (priv == NULL)
-                       return SRC_ERR_MALLOC_FAILED ;
                psrc->private_data = priv ;
                } ;
 
+       if (priv == NULL)
+               return SRC_ERR_MALLOC_FAILED ;
+
        priv->zoh_magic_marker = ZOH_MAGIC_MARKER ;
        priv->channels = psrc->channels ;
 
index e3e692f..31d076d 100644 (file)
@@ -1,19 +1,9 @@
 /*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
+** All rights reserved.
 **
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU Lesser General Public License as published by
-** the Free Software Foundation; either version 2.1 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU Lesser General Public License for more details.
-**
-** You should have received a copy of the GNU Lesser General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+** This code is released under 2-clause BSD license. Please see the
+** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
 */
 
 /*