[Mplayer-cvslog] CVS: main/libmpflac FLAC_export.h, 1.1, 1.2 FLAC_ordinals.h, 1.1, 1.2 FLAC_stream_decoder.h, 1.1, 1.2 dither.c, 1.1, 1.2 dither.h, 1.1, 1.2 format.c, 1.1, 1.2 replaygain_synthesis.c, 1.1, 1.2 replaygain_synthesis.h, 1.1, 1.2 stream_decoder.c, 1.1, 1.2

Dmitry Baryshkov CVS lumag at mplayerhq.hu
Mon Dec 29 19:10:51 CET 2003


Update of /cvsroot/mplayer/main/libmpflac
In directory mail:/tmp/cvs-serv463/libmpflac

Modified Files:
	FLAC_export.h FLAC_ordinals.h FLAC_stream_decoder.h dither.c 
	dither.h format.c replaygain_synthesis.c 
	replaygain_synthesis.h stream_decoder.c 
Log Message:
Sync to original FLAC.
Main reason from their CVS log: add support for synthesis to big-endian in plugins.



Index: FLAC_export.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpflac/FLAC_export.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FLAC_export.h	4 Oct 2003 22:00:27 -0000	1.1
+++ FLAC_export.h	29 Dec 2003 18:10:49 -0000	1.2
@@ -41,7 +41,7 @@
 #define	FLAC_API	_declspec(dllexport)
 #else
 #define FLAC_API	_declspec(dllimport)
-#define __LIBNAME__ "libFLAC.lib"
+#define __LIBNAME__ "libFLAC_static.lib"
 #pragma comment(lib, __LIBNAME__)
 #undef __LIBNAME__
 

Index: FLAC_ordinals.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpflac/FLAC_ordinals.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FLAC_ordinals.h	4 Oct 2003 22:00:27 -0000	1.1
+++ FLAC_ordinals.h	29 Dec 2003 18:10:49 -0000	1.2
@@ -32,19 +32,25 @@
 #ifndef FLAC__ORDINALS_H
 #define FLAC__ORDINALS_H
 
-#ifdef true
-#undef true
+#ifdef HAVE_CONFIG_H
+#include <config.h>
 #endif
-#ifdef false
-#undef false
+
+#define HAVE_INTTYPES_H /* If we passed configure, we have inttypes.h */
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#elif defined(HAVE_U_INT)
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
 #endif
-#ifndef __cplusplus
-#define true 1
-#define false 0
+#define uint8_t u_int8_t
+#define uint16_t u_int16_t
+#define uint32_t u_int32_t
+#define uint64_t u_int64_t
+#elif !defined(_MSC_VER)
+#error Unable to find fixed-size data types
 #endif
 
-typedef int FLAC__bool;
-
 typedef signed char FLAC__int8;
 typedef unsigned char FLAC__uint8;
 
@@ -56,15 +62,28 @@
 typedef unsigned __int32 FLAC__uint32;
 typedef unsigned __int64 FLAC__uint64;
 #else
-typedef short FLAC__int16;
-typedef int FLAC__int32;
-typedef long long FLAC__int64;
-typedef unsigned short FLAC__uint16;
-typedef unsigned int FLAC__uint32;
-typedef unsigned long long FLAC__uint64;
+typedef int16_t FLAC__int16;
+typedef int32_t FLAC__int32;
+typedef int64_t FLAC__int64;
+typedef uint16_t FLAC__uint16;
+typedef uint32_t FLAC__uint32;
+typedef uint64_t FLAC__uint64;
 #endif
 
+typedef int FLAC__bool;
+
 typedef FLAC__uint8 FLAC__byte;
 typedef float FLAC__real;
 
+#ifdef true
+#undef true
+#endif
+#ifdef false
+#undef false
+#endif
+#ifndef __cplusplus
+#define true 1
+#define false 0
+#endif
+
 #endif

Index: FLAC_stream_decoder.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpflac/FLAC_stream_decoder.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FLAC_stream_decoder.h	4 Oct 2003 22:00:27 -0000	1.1
+++ FLAC_stream_decoder.h	29 Dec 2003 18:10:49 -0000	1.2
@@ -606,6 +606,16 @@
  */
 FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
 
+/** Get the current decoder state as a C string.
+ *
+ * \param  decoder  A decoder instance to query.
+ * \assert
+ *    \code decoder != NULL \endcode
+ * \retval const char *
+ *    The decoder state as a C string.  Do not modify the contents.
+ */
+FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
+
 /** Get the current number of channels in the stream being decoded.
  *  Will only be valid after decoding has started and will contain the
  *  value from the most recently decoded frame header.
@@ -677,7 +687,7 @@
  * \assert
  *    \code decoder != NULL \endcode
  * \retval FLAC__StreamDecoderState
- *    \c FLAC__STREAM_DECODER_SEARCH_FOR_MEATADATA if initialization was
+ *    \c FLAC__STREAM_DECODER_SEARCH_FOR_METADATA if initialization was
  *    successful; see FLAC__StreamDecoderState for the meanings of other
  *    return values.
  */

Index: dither.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpflac/dither.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- dither.c	4 Oct 2003 22:00:27 -0000	1.1
+++ dither.c	29 Dec 2003 18:10:49 -0000	1.2
@@ -107,7 +107,7 @@
 	return output >> scalebits;
 }
 
-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_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;
@@ -115,7 +115,88 @@
 	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);
+	FLAC__ASSERT(target_bps <= 24);
+	FLAC__ASSERT(target_bps <= source_bps);
+	FLAC__ASSERT((source_bps & 7) == 0);
+	FLAC__ASSERT((target_bps & 7) == 0);
+
+	if(source_bps != target_bps) {
+		const FLAC__int32 MIN = -(1L << (source_bps - 1));
+		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];
+
+			while(samples--) {
+				sample = linear_dither(source_bps, target_bps, *input_++, &dither[channel], MIN, MAX);
+
+				switch(target_bps) {
+					case 8:
+						data[0] = sample ^ 0x80;
+						break;
+					case 16:
+						data[0] = (FLAC__byte)(sample >> 8);
+						data[1] = (FLAC__byte)sample;
+						break;
+					case 24:
+						data[0] = (FLAC__byte)(sample >> 16);
+						data[1] = (FLAC__byte)(sample >> 8);
+						data[2] = (FLAC__byte)sample;
+						break;
+				}
+
+				data += incr;
+			}
+		}
+	}
+	else {
+		for(channel = 0; channel < channels; channel++) {
+			samples = wide_samples;
+			data = start + bytes_per_sample * channel;
+			input_ = input[channel];
+
+			while(samples--) {
+				sample = *input_++;
+
+				switch(target_bps) {
+					case 8:
+						data[0] = sample ^ 0x80;
+						break;
+					case 16:
+						data[0] = (FLAC__byte)(sample >> 8);
+						data[1] = (FLAC__byte)sample;
+						break;
+					case 24:
+						data[0] = (FLAC__byte)(sample >> 16);
+						data[1] = (FLAC__byte)(sample >> 8);
+						data[2] = (FLAC__byte)sample;
+						break;
+				}
+
+				data += incr;
+			}
+		}
+	}
+
+	return wide_samples * channels * (target_bps/8);
+}
+
+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;
+	FLAC__int32 sample;
+	const FLAC__int32 *input_;
+	unsigned samples, channel;
+	const unsigned bytes_per_sample = target_bps / 8;
+	const unsigned incr = bytes_per_sample * channels;
 
 	FLAC__ASSERT(channels > 0 && channels <= FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS);
 	FLAC__ASSERT(source_bps < 32);
@@ -149,7 +230,7 @@
 						data[0] = (FLAC__byte)sample;
 				}
 
-				data += inc;
+				data += incr;
 			}
 		}
 	}
@@ -174,10 +255,10 @@
 						data[0] = (FLAC__byte)sample;
 				}
 
-				data += inc;
+				data += incr;
 			}
 		}
 	}
 
-	return data - start;
+	return wide_samples * channels * (target_bps/8);
 }

Index: dither.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpflac/dither.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- dither.h	4 Oct 2003 22:00:27 -0000	1.1
+++ dither.h	29 Dec 2003 18:10:49 -0000	1.2
@@ -19,6 +19,7 @@
 #ifndef FLAC__PLUGIN_COMMON__DITHER_H
 #define FLAC__PLUGIN_COMMON__DITHER_H
 
+#include <stdlib.h> /* for size_t */
 #include "defs.h" /* buy FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS for the caller */
 #ifdef USE_MPFLAC_DECODER
 #include "FLAC_ordinals.h"
@@ -26,6 +27,7 @@
 #include <FLAC/ordinals.h>
 #endif
 
-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_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_little_endian(FLAC__byte *data, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps);
 
 #endif

Index: format.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpflac/format.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- format.c	4 Oct 2003 22:00:27 -0000	1.1
+++ format.c	29 Dec 2003 18:10:49 -0000	1.2
@@ -50,9 +50,9 @@
 
 #if defined _MSC_VER || defined __MINW32__
 /* yet one more hack because of MSVC6: */
-FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.1.0 20030126";
+FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC CVS 20031217";
 #else
-FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20030126";
+FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20031217";
 #endif
 
 FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };

Index: replaygain_synthesis.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpflac/replaygain_synthesis.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- replaygain_synthesis.c	4 Oct 2003 22:00:27 -0000	1.1
+++ replaygain_synthesis.c	29 Dec 2003 18:10:49 -0000	1.2
@@ -1,4 +1,4 @@
-/* plugin_common - Routines common to several plugins
+/* replaygain_synthesis - Routines for applying ReplayGain to a signal
  * Copyright (C) 2002,2003  Josh Coalson
  *
  * This program is free software; you can redistribute it and/or
@@ -203,7 +203,7 @@
 }
 
 
-void FLAC__plugin_common__init_dither_context(DitherContext *d, int bits, int shapingtype)
+void FLAC__replaygain_synthesis__init_dither_context(DitherContext *d, int bits, int shapingtype)
 {
 	static unsigned char default_dither [] = { 92, 92, 88, 84, 81, 78, 74, 67,  0,  0 };
 	static const float*               F [] = { F44_0, F44_1, F44_2, F44_3 };
@@ -292,7 +292,7 @@
 #endif
 
 
-int FLAC__plugin_common__apply_gain(FLAC__byte *data_out, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, const unsigned source_bps, const unsigned target_bps, const float scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context)
+size_t FLAC__replaygain_synthesis__apply_gain(FLAC__byte *data_out, FLAC__bool little_endian_data_out, FLAC__bool unsigned_data_out, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, const unsigned source_bps, const unsigned target_bps, const double scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context)
 {
 	static const FLAC__int32 conv_factors_[33] = {
 		-1, /* 0 bits-per-sample (not supported) */
@@ -379,12 +379,14 @@
 	const FLAC__int32 *input_;
 	double sample;
 	const unsigned bytes_per_sample = target_bps / 8;
-	unsigned inc = bytes_per_sample * channels, last_history_index = dither_context->LastHistoryIndex;
+	const unsigned last_history_index = dither_context->LastHistoryIndex;
 	NoiseShaping noise_shaping = dither_context->ShapingType;
 	FLAC__int64 val64;
 	FLAC__int32 val32;
+	FLAC__int32 uval32;
+	const FLAC__uint32 twiggle = 1u << (target_bps - 1);
 
-	FLAC__ASSERT(channels > 0 && channels <= FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS);
+	FLAC__ASSERT(channels > 0 && channels <= FLAC_SHARE__MAX_SUPPORTED_CHANNELS);
 	FLAC__ASSERT(source_bps >= 4);
 	FLAC__ASSERT(target_bps >= 4);
 	FLAC__ASSERT(source_bps <= 32);
@@ -392,9 +394,10 @@
 	FLAC__ASSERT((target_bps & 7) == 0);
 
 	for(channel = 0; channel < channels; channel++) {
+		const unsigned incr = bytes_per_sample * channels;
 		data_out = start + bytes_per_sample * channel;
 		input_ = input[channel];
-		for(i = 0; i < wide_samples; i++, data_out += inc) {
+		for(i = 0; i < wide_samples; i++, data_out += incr) {
 			sample = (double)input_[i] * multi_scale;
 
 			if(hard_limit) {
@@ -414,20 +417,42 @@
 			else if(val64 < hard_clip_factor)
 				val32 = (FLAC__int32)hard_clip_factor;
 
-			switch(target_bps) {
-				case 8:
-					data_out[0] = val32 ^ 0x80;
-					break;
-				case 24:
-					data_out[2] = (FLAC__byte)(val32 >> 16);
-					/* fall through */
-				case 16:
-					data_out[1] = (FLAC__byte)(val32 >> 8);
-					data_out[0] = (FLAC__byte)val32;
+			uval32 = (FLAC__uint32)val32;
+			if (unsigned_data_out)
+				uval32 ^= twiggle;
+
+			if (little_endian_data_out) {
+				switch(target_bps) {
+					case 24:
+						data_out[2] = (FLAC__byte)(uval32 >> 16);
+						/* fall through */
+					case 16:
+						data_out[1] = (FLAC__byte)(uval32 >> 8);
+						/* fall through */
+					case 8:
+						data_out[0] = (FLAC__byte)uval32;
+						break;
+				}
+			}
+			else {
+				switch(target_bps) {
+					case 24:
+						data_out[0] = (FLAC__byte)(uval32 >> 16);
+						data_out[1] = (FLAC__byte)(uval32 >> 8);
+						data_out[2] = (FLAC__byte)uval32;
+						break;
+					case 16:
+						data_out[0] = (FLAC__byte)(uval32 >> 8);
+						data_out[1] = (FLAC__byte)uval32;
+						break;
+					case 8:
+						data_out[0] = (FLAC__byte)uval32;
+						break;
+				}
 			}
 		}
 	}
 	dither_context->LastHistoryIndex = (last_history_index + wide_samples) % 32;
 
-	return data_out - start;
+	return wide_samples * channels * (target_bps/8);
 }

Index: replaygain_synthesis.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpflac/replaygain_synthesis.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- replaygain_synthesis.h	4 Oct 2003 22:00:27 -0000	1.1
+++ replaygain_synthesis.h	29 Dec 2003 18:10:49 -0000	1.2
@@ -16,20 +16,22 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
-#ifndef FLAC__PLUGIN_COMMON__REPLAYGAIN_SYNTHESIS_H
-#define FLAC__PLUGIN_COMMON__REPLAYGAIN_SYNTHESIS_H
+#ifndef FLAC__SHARE__REPLAYGAIN_SYNTHESIS_H
+#define FLAC__SHARE__REPLAYGAIN_SYNTHESIS_H
 
-#include "defs.h"
+#include <stdlib.h> /* for size_t */
 #ifdef USE_MPFLAC_DECODER
 #include "FLAC_ordinals.h"
 #else
 #include <FLAC/ordinals.h>
 #endif
 
+#define FLAC_SHARE__MAX_SUPPORTED_CHANNELS 2
+
 typedef enum {
 	NOISE_SHAPING_NONE = 0,
 	NOISE_SHAPING_LOW = 1,
-	NOISE_SHAPING_MEDUIM = 2,
+	NOISE_SHAPING_MEDIUM = 2,
 	NOISE_SHAPING_HIGH = 3
 } NoiseShaping;
 
@@ -38,16 +40,16 @@
 	FLAC__uint64  Mask;
 	double        Add;
 	float         Dither;
-	float         ErrorHistory     [FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS] [16];  /* 16th order Noise shaping */
-	float         DitherHistory    [FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS] [16];
-	int           LastRandomNumber [FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS];
+	float         ErrorHistory     [FLAC_SHARE__MAX_SUPPORTED_CHANNELS] [16];  /* 16th order Noise shaping */
+	float         DitherHistory    [FLAC_SHARE__MAX_SUPPORTED_CHANNELS] [16];
+	int           LastRandomNumber [FLAC_SHARE__MAX_SUPPORTED_CHANNELS];
 	unsigned      LastHistoryIndex;
 	NoiseShaping  ShapingType;
 } DitherContext;
 
-void FLAC__plugin_common__init_dither_context(DitherContext *dither, int bits, int shapingtype);
+void FLAC__replaygain_synthesis__init_dither_context(DitherContext *dither, int bits, int shapingtype);
 
 /* scale = (float) pow(10., (double)replaygain * 0.05); */
-int FLAC__plugin_common__apply_gain(FLAC__byte *data_out, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, const unsigned source_bps, const unsigned target_bps, const float scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context);
+size_t FLAC__replaygain_synthesis__apply_gain(FLAC__byte *data_out, FLAC__bool little_endian_data_out, FLAC__bool unsigned_data_out, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, const unsigned source_bps, const unsigned target_bps, const double scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context);
 
 #endif

Index: stream_decoder.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpflac/stream_decoder.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- stream_decoder.c	4 Oct 2003 22:00:27 -0000	1.1
+++ stream_decoder.c	29 Dec 2003 18:10:49 -0000	1.2
@@ -516,6 +516,11 @@
 	return decoder->protected_->state;
 }
 
+FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
+{
+	return FLAC__StreamDecoderStateString[decoder->protected_->state];
+}
+
 FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
 {
 	FLAC__ASSERT(0 != decoder);
@@ -1657,13 +1662,15 @@
 			return true;
 		}
 		decoder->private_->last_frame_number = x;
-		if(decoder->private_->has_stream_info) {
-			decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
-			decoder->private_->frame.header.number.sample_number = (FLAC__int64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__int64)x;
-		}
-		else {
-			is_unparseable = true;
+		decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
+		if(blocksize_hint) {
+			if(decoder->private_->has_stream_info)
+				decoder->private_->frame.header.number.sample_number = (FLAC__int64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__int64)x;
+			else
+				is_unparseable = true;
 		}
+		else	
+			decoder->private_->frame.header.number.sample_number = (FLAC__int64)decoder->private_->frame.header.blocksize * (FLAC__int64)x;
 	}
 
 	if(blocksize_hint) {




More information about the MPlayer-cvslog mailing list