Index: libmpc/trunk/mpcdec/mpcdec.c
===================================================================
--- libmpc/trunk/mpcdec/mpcdec.c	(revision 444)
+++ libmpc/trunk/mpcdec/mpcdec.c	(revision 480)
@@ -40,4 +40,6 @@
 #include <libwaveformat.h>
 #include <getopt.h>
+#include <math.h>
+#include <byteswap.h>
 
 #ifdef _MSC_VER
@@ -75,4 +77,42 @@
     return (t_wav_uint32) !fseek(p_handle, p_position, SEEK_SET);
 }
+
+#ifdef MPC_FIXED_POINT
+
+static int raw_output_int16(FILE * file, short * buff, int cnt, mpc_bool_t reverse_endian)
+{
+	int i;
+	for (i = 0; i < cnt; i++) {
+		short out = buff[i];
+		if (reverse_endian)
+			out = bswap_16(out);
+		if (fwrite(&out, sizeof(out), 1, file) != 1)
+			return -1;
+	}
+	return 0;
+}
+
+#else
+
+static int raw_output_float32(FILE * file, float * buff, int cnt, mpc_bool_t reverse_endian)
+{
+	int i;
+	for (i = 0; i < cnt; i++) {
+		int tmp = nearbyintf(buff[i] * (1 << 15));
+		short out;
+		if (tmp > ((1 << 15) - 1))
+			tmp = ((1 << 15) - 1);
+		if (tmp < -(1 << 15))
+			tmp = -(1 << 15);
+		if (reverse_endian)
+			tmp = bswap_16((short) tmp);
+		out = (short)tmp;
+		if (fwrite(&out, sizeof(out), 1, file) != 1)
+			return -1;
+	}
+	return 0;
+}
+
+#endif
 
 static void print_info(mpc_streaminfo * info, char * filename)
@@ -109,4 +149,6 @@
 			"-c : check the file for stream errors\n"
 			"     (doesn't fully decode, outfile will be ignored)\n"
+			"-r : output raw data (left/right) in machine native endian\n"
+			"-e : reverse raw data endianness\n"
 			"-h : print this help\n"
             "you can use stdin and stdout as resp. <infile.mpc> and\n"
@@ -122,11 +164,14 @@
 	mpc_status err;
 	mpc_bool_t info = MPC_FALSE, is_wav_output = MPC_FALSE, check = MPC_FALSE;
+	mpc_bool_t is_raw_output = MPC_FALSE, reverse_endian = MPC_FALSE;
     MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH];
-    clock_t begin, end, sum; int total_samples; t_wav_output_file wav_output;
+    clock_t begin, end, sum; int total_samples;
+	t_wav_output_file wav_output;
+	t_wav_output_file_callback wavo_fc;
 	int c;
 
     fprintf(stderr, About);
 
-	while ((c = getopt(argc , argv, "ihc")) != -1) {
+	while ((c = getopt(argc , argv, "ihcre")) != -1) {
 		switch (c) {
 			case 'i':
@@ -136,4 +181,10 @@
 				check = MPC_TRUE;
 				break;
+			case 'r':
+				is_raw_output = MPC_TRUE;
+				break;
+			case 'e':
+				reverse_endian = MPC_TRUE;
+				break;
 			case 'h':
 				usage(argv[0]);
@@ -166,20 +217,27 @@
 	}
 
-	if (!check)
-		is_wav_output = argc - optind > 1;
-    if(is_wav_output)
+	if (check) {
+		is_raw_output = MPC_FALSE;
+	} else if (argc - optind > 1 && is_raw_output == MPC_FALSE) {
+		is_wav_output = MPC_TRUE;
+	};
+	
+    if (is_wav_output || is_raw_output)
     {
-        t_wav_output_file_callback wavo_fc;
         memset(&wav_output, 0, sizeof wav_output);
         wavo_fc.m_seek      = mpc_wav_output_seek;
         wavo_fc.m_write     = mpc_wav_output_write;
-		if (strcmp(argv[optind + 1], "-") == 0) {
+		if (strcmp(argv[optind + 1], "-") == 0 || (is_raw_output && argc - optind <= 1)) {
 			SET_BINARY_MODE(stdout);
 		    wavo_fc.m_user_data = stdout;
 		} else
 			wavo_fc.m_user_data = fopen(argv[optind + 1], "wb");
-        if(!wavo_fc.m_user_data) return !MPC_STATUS_OK;
-        err = waveformat_output_open(&wav_output, wavo_fc, si.channels, 16, 0, si.sample_freq, (t_wav_uint32) si.samples * si.channels);
-        if(!err) return !MPC_STATUS_OK;
+        if(!wavo_fc.m_user_data)
+			return !MPC_STATUS_OK;
+		
+		if (is_wav_output) {
+			if (!waveformat_output_open(&wav_output, wavo_fc, si.channels, 16, 0, si.sample_freq, (t_wav_uint32) si.samples * si.channels))
+				return !MPC_STATUS_OK;
+		}
     }
 
@@ -200,5 +258,5 @@
         sum           += end - begin;
 
-		if(is_wav_output) {
+		if (is_wav_output || is_raw_output) {
 #ifdef MPC_FIXED_POINT
 			mpc_int16_t tmp_buff[MPC_DECODER_BUFFER_LENGTH];
@@ -210,9 +268,21 @@
 				tmp_buff[i] = tmp;
 			}
-			if(waveformat_output_process_int16(&wav_output, tmp_buff, frame.samples * si.channels) < 0)
+#endif
+			if (is_wav_output) {
+#ifdef MPC_FIXED_POINT
+				if(waveformat_output_process_int16(&wav_output, tmp_buff, frame.samples * si.channels) < 0)
 #else
-			if(waveformat_output_process_float32(&wav_output, sample_buffer, frame.samples * si.channels) < 0)
-#endif
-                break;
+				if(waveformat_output_process_float32(&wav_output, sample_buffer, frame.samples * si.channels) < 0)
+#endif
+					break;
+			}
+			if (is_raw_output) {
+#ifdef MPC_FIXED_POINT
+				if (raw_output_int16(wavo_fc.m_user_data, tmp_buff, frame.samples * si.channels, reverse_endian) < 0)
+#else
+				if (raw_output_float32(wavo_fc.m_user_data, sample_buffer, frame.samples * si.channels, reverse_endian) < 0)
+#endif
+					break;
+			}
 		}
     }
