Bulk update copyright dates
[flac.git] / src / plugin_common / dither.c
index eb379be..b20ab51 100644 (file)
@@ -1,5 +1,6 @@
 /* plugin_common - Routines common to several plugins
- * Copyright (C) 2002,2003  Josh Coalson
+ * Copyright (C) 2002-2009  Josh Coalson
+ * Copyright (C) 2011-2016  Xiph.Org Foundation
  *
  * dithering routine derived from (other GPLed source):
  * mad - MPEG audio decoder
  * 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.
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include "dither.h"
 #include "FLAC/assert.h"
 
 #endif
 #define max(a,b) ((a)>(b)?(a):(b))
 
-
-#if defined _MSC_VER
-#define FLAC__INLINE __inline
-#else
-#define FLAC__INLINE
+#ifndef FLaC__INLINE
+#define FLaC__INLINE
 #endif
 
+
 /* 32-bit pseudo-random number generator
  *
  * @@@ According to Miroslav, this one is poor quality, the one from the
  * @@@ original replaygain code is much better
  */
-static FLAC__INLINE FLAC__uint32 prng(FLAC__uint32 state)
+static FLaC__INLINE FLAC__uint32 prng(FLAC__uint32 state)
 {
        return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL;
 }
@@ -52,7 +55,7 @@ typedef struct {
        FLAC__int32 random;
 } dither_state;
 
-static FLAC__INLINE FLAC__int32 linear_dither(unsigned source_bps, unsigned target_bps, FLAC__int32 sample, dither_state *dither, const FLAC__int32 MIN, const FLAC__int32 MAX)
+static FLAC__int32 linear_dither(unsigned source_bps, unsigned target_bps, FLAC__int32 sample, dither_state *dither, const FLAC__int32 MIN, const FLAC__int32 MAX)
 {
        unsigned scalebits;
        FLAC__int32 output, mask, random;
@@ -103,7 +106,7 @@ static FLAC__INLINE FLAC__int32 linear_dither(unsigned source_bps, unsigned targ
        return output >> scalebits;
 }
 
-unsigned FLAC__plugin_common__pack_pcm_signed_big_endian(FLAC__byte *data, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps)
+size_t FLAC__plugin_common__pack_pcm_signed_big_endian(FLAC__byte *data, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps)
 {
        static dither_state dither[FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS];
        FLAC__byte * const start = data;
@@ -111,7 +114,7 @@ unsigned FLAC__plugin_common__pack_pcm_signed_big_endian(FLAC__byte *data, const
        const FLAC__int32 *input_;
        unsigned samples, channel;
        const unsigned bytes_per_sample = target_bps / 8;
-       unsigned inc = bytes_per_sample * channels;
+       const unsigned incr = bytes_per_sample * channels;
 
        FLAC__ASSERT(channels > 0 && channels <= FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS);
        FLAC__ASSERT(source_bps < 32);
@@ -125,7 +128,7 @@ unsigned FLAC__plugin_common__pack_pcm_signed_big_endian(FLAC__byte *data, const
                const FLAC__int32 MAX = ~MIN; /*(1L << (source_bps-1)) - 1 */
 
                for(channel = 0; channel < channels; channel++) {
-                       
+
                        samples = wide_samples;
                        data = start + bytes_per_sample * channel;
                        input_ = input[channel];
@@ -148,7 +151,7 @@ unsigned FLAC__plugin_common__pack_pcm_signed_big_endian(FLAC__byte *data, const
                                                break;
                                }
 
-                               data += inc;
+                               data += incr;
                        }
                }
        }
@@ -176,15 +179,15 @@ unsigned FLAC__plugin_common__pack_pcm_signed_big_endian(FLAC__byte *data, const
                                                break;
                                }
 
-                               data += inc;
+                               data += incr;
                        }
                }
        }
 
-       return data - start;
+       return wide_samples * channels * (target_bps/8);
 }
 
-unsigned FLAC__plugin_common__pack_pcm_signed_little_endian(FLAC__byte *data, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps)
+size_t FLAC__plugin_common__pack_pcm_signed_little_endian(FLAC__byte *data, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps)
 {
        static dither_state dither[FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS];
        FLAC__byte * const start = data;
@@ -192,7 +195,7 @@ unsigned FLAC__plugin_common__pack_pcm_signed_little_endian(FLAC__byte *data, co
        const FLAC__int32 *input_;
        unsigned samples, channel;
        const unsigned bytes_per_sample = target_bps / 8;
-       unsigned inc = bytes_per_sample * channels;
+       const unsigned incr = bytes_per_sample * channels;
 
        FLAC__ASSERT(channels > 0 && channels <= FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS);
        FLAC__ASSERT(source_bps < 32);
@@ -206,7 +209,7 @@ unsigned FLAC__plugin_common__pack_pcm_signed_little_endian(FLAC__byte *data, co
                const FLAC__int32 MAX = ~MIN; /*(1L << (source_bps-1)) - 1 */
 
                for(channel = 0; channel < channels; channel++) {
-                       
+
                        samples = wide_samples;
                        data = start + bytes_per_sample * channel;
                        input_ = input[channel];
@@ -226,7 +229,7 @@ unsigned FLAC__plugin_common__pack_pcm_signed_little_endian(FLAC__byte *data, co
                                                data[0] = (FLAC__byte)sample;
                                }
 
-                               data += inc;
+                               data += incr;
                        }
                }
        }
@@ -251,10 +254,10 @@ unsigned FLAC__plugin_common__pack_pcm_signed_little_endian(FLAC__byte *data, co
                                                data[0] = (FLAC__byte)sample;
                                }
 
-                               data += inc;
+                               data += incr;
                        }
                }
        }
 
-       return data - start;
+       return wide_samples * channels * (target_bps/8);
 }