Index: /dsfilters/temp/libmpcenc/src/bitstream.h
===================================================================
--- /dsfilters/temp/libmpcenc/src/bitstream.h	(revision 398)
+++ /dsfilters/temp/libmpcenc/src/bitstream.h	(revision 399)
@@ -20,4 +20,8 @@
 #pragma once
 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 
@@ -79,2 +83,6 @@
 
 
+
+#ifdef __cplusplus
+};
+#endif
Index: /dsfilters/temp/libmpcenc/src/enc_interface.c
===================================================================
--- /dsfilters/temp/libmpcenc/src/enc_interface.c	(revision 398)
+++ /dsfilters/temp/libmpcenc/src/enc_interface.c	(revision 399)
@@ -180,16 +180,102 @@
 
 // encoding PCM samples
-int mpc_encoder_encode_pcm(mpc_encoder_t instance, float *samples, int count, mpc_uint8_t *buf, int *bytes_written)
-{
-	return 0;
-}
-
-int mpc_encoder_encode_tail(mpc_encoder_t instance, mpc_uint8_t *buf, int *bytes_written)
-{
-	return 0;
-}
-
-
-int mpc_encoder_get_hdr_packet(mpc_encoder_t instance, int type, mpc_uint8_t *buf, int *bytes_written)
+int mpc_encoder_encode_pcm(mpc_encoder_t instance, float *samples, int count, unsigned char *buf, int *bytes_written)
+{
+	mpc_enc_t		*encoder = (mpc_enc_t*)instance;
+
+	// load data into the buffer
+	int				time_samples, left, i, written;
+	unsigned char	*dst = buf;
+	float			*cur = samples;
+	PCMDataTyp		*s;
+
+	// check
+	if (!encoder || !buf || !bytes_written) return -1;
+
+	time_samples = count / encoder->config.channels;
+	left         = time_samples;
+	written      = 0;
+	s = &encoder->Main;
+
+	// loop through all the samples
+	while (left > 0) {
+
+		int		ts    = encoder->time_samples;
+		int		to_do = min( BLOCK - ts, left );
+
+		// append samples to the buffer
+		switch (encoder->config.channels) {
+		case 1:
+			{
+				for (i=0; i<to_do; i++) {
+					s->L[CENTER + ts + i] = *cur;
+					s->R[CENTER + ts + i] = *cur++;
+					s->M[CENTER + ts + i] = (s->L[CENTER + ts + i] + s->R[CENTER + ts + i]) * 0.5;
+					s->S[CENTER + ts + i] = (s->L[CENTER + ts + i] - s->R[CENTER + ts + i]) * 0.5;
+				}
+			}
+			break;
+		case 2:
+			{
+				for (i=0; i<to_do; i++) {
+					s->L[CENTER + ts + i] = *cur++;
+					s->R[CENTER + ts + i] = *cur++;
+					s->M[CENTER + ts + i] = (s->L[CENTER + ts + i] + s->R[CENTER + ts + i]) * 0.5;
+					s->S[CENTER + ts + i] = (s->L[CENTER + ts + i] - s->R[CENTER + ts + i]) * 0.5;
+				}
+			}
+			break;
+		}
+		encoder->time_samples += to_do;
+		left                  -= to_do;
+
+		// if the buffer is full, do some encoding..
+		if (encoder->time_samples == BLOCK) {
+
+			// if these are REALLY the first samples we're encoding
+			// we might need to adjust the start of our samples buffer
+			if (encoder->samples_encoded == 0) {
+				mpc_encoder_prepare_first_block(encoder);
+			}
+
+			// process one block
+			mpc_encoder_encode_block(encoder);
+
+			// is there any output ?
+			if (encoder->framesInBlock == (1 << encoder->frames_per_block_pwr)) {
+				int	payload_len, len;
+
+				// bytealign and flush the bitstream
+				mpc_bs_bytealign(&encoder->bs, 0);
+				mpc_bs_writebits(&encoder->bs);
+
+				// flush the data as a new 'AP' packet
+				payload_len = encoder->bs.buf - encoder->buffer;
+				len = writePacket(dst, PACKET_TYPE('A','P'), encoder->buffer, payload_len, MPC_TRUE);
+				dst += len;
+
+				// reset bitstream & frame counter
+				mpc_bs_init(&encoder->bs, encoder->buffer);
+				encoder->framesInBlock = 0;
+			}
+
+			// flush audio samples from the buffer
+			mpc_encoder_flush_block(encoder);
+		}
+
+	}
+
+	// the number of bytes written
+	*bytes_written = (dst - buf);
+	return 0;
+}
+
+int mpc_encoder_encode_tail(mpc_encoder_t instance, unsigned char *buf, int *bytes_written)
+{
+	return 0;
+}
+
+
+int mpc_encoder_get_hdr_packet(mpc_encoder_t instance, int type, unsigned char *buf, int *bytes_written)
 {
 	mpc_enc_t		*encoder = (mpc_enc_t*)instance;
@@ -209,5 +295,5 @@
 			mpc_bs_init(&bs, buf);
 			writeMagic(&bs);
-			*bytes_written = (bs.buf - temp);
+			*bytes_written = (bs.buf - buf);
 		}
 		break;
@@ -234,4 +320,10 @@
 		break;
 
+	case PACKET_TYPE('S','E'):
+		{
+			*bytes_written = writePacket(buf, type, NULL, 0, MPC_FALSE);
+		}
+		break;
+
 	// no other packet types
 	default:	return -1;
Index: /dsfilters/temp/libmpcenc/src/encoder.h
===================================================================
--- /dsfilters/temp/libmpcenc/src/encoder.h	(revision 398)
+++ /dsfilters/temp/libmpcenc/src/encoder.h	(revision 399)
@@ -79,9 +79,18 @@
 
 	// psy model in use
-	PsyModel				psy_model;
+	PsyModel			psy_model;
+
+	// encoding stuff
+	SMRTyp				SMR;
+	PCMDataTyp			Main;
+	SubbandFloatTyp		X[32];
+	int					time_samples;			// the number of samples already in the buffer
 
 } mpc_enc_t;
 
 
+int mpc_encoder_encode_block(mpc_enc_t *e);
+void mpc_encoder_flush_block(mpc_enc_t *e);
 
-
+void mpc_encoder_prepare_first_block(mpc_enc_t *e);
+void mpc_encoder_prepare_last_block(mpc_enc_t *e);
Index: /dsfilters/temp/libmpcenc/src/syntax_sv8.c
===================================================================
--- /dsfilters/temp/libmpcenc/src/syntax_sv8.c	(revision 398)
+++ /dsfilters/temp/libmpcenc/src/syntax_sv8.c	(revision 399)
@@ -60,5 +60,5 @@
 
 	if (add_crc) {
-		mpc_bs_encode_size(&bs, payload_len+4, MPC_TRUE);
+		mpc_bs_encode_size(&bs, payload_len+4+2, MPC_TRUE);
 
 		crc = crc32((unsigned char *)payload, payload_len);
@@ -66,5 +66,5 @@
 
 	} else {
-		mpc_bs_encode_size(&bs, payload_len, MPC_TRUE);
+		mpc_bs_encode_size(&bs, payload_len+2, MPC_TRUE);
 	}
 
Index: /dsfilters/temp/libmpcenc/vcproj/libmpcenc.sln
===================================================================
--- /dsfilters/temp/libmpcenc/vcproj/libmpcenc.sln	(revision 398)
+++ /dsfilters/temp/libmpcenc/vcproj/libmpcenc.sln	(revision 399)
@@ -3,4 +3,9 @@
 # Visual Studio 2005
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmpcenc", "libmpcenc.vcproj", "{182795A1-4E07-4CFF-99B9-A14BA2DA37EA}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mpcenc2", "..\..\mpcenc2\mpcenc2.vcproj", "{C9188201-4C57-4F5F-B9DD-147D331B23AE}"
+	ProjectSection(ProjectDependencies) = postProject
+		{182795A1-4E07-4CFF-99B9-A14BA2DA37EA} = {182795A1-4E07-4CFF-99B9-A14BA2DA37EA}
+	EndProjectSection
 EndProject
 Global
@@ -14,4 +19,8 @@
 		{182795A1-4E07-4CFF-99B9-A14BA2DA37EA}.Release|Win32.ActiveCfg = Release|Win32
 		{182795A1-4E07-4CFF-99B9-A14BA2DA37EA}.Release|Win32.Build.0 = Release|Win32
+		{C9188201-4C57-4F5F-B9DD-147D331B23AE}.Debug|Win32.ActiveCfg = Debug|Win32
+		{C9188201-4C57-4F5F-B9DD-147D331B23AE}.Debug|Win32.Build.0 = Debug|Win32
+		{C9188201-4C57-4F5F-B9DD-147D331B23AE}.Release|Win32.ActiveCfg = Release|Win32
+		{C9188201-4C57-4F5F-B9DD-147D331B23AE}.Release|Win32.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
Index: /dsfilters/temp/libmpcenc/vcproj/libmpcenc.vcproj
===================================================================
--- /dsfilters/temp/libmpcenc/vcproj/libmpcenc.vcproj	(revision 398)
+++ /dsfilters/temp/libmpcenc/vcproj/libmpcenc.vcproj	(revision 399)
@@ -207,30 +207,30 @@
 				>
 			</File>
+		</Filter>
+		<Filter
+			Name="Encoder"
+			>
+			<File
+				RelativePath="..\src\bitstream.c"
+				>
+			</File>
+			<File
+				RelativePath="..\src\bitstream.h"
+				>
+			</File>
+			<File
+				RelativePath="..\src\enc_interface.c"
+				>
+			</File>
+			<File
+				RelativePath="..\src\encoder.c"
+				>
+			</File>
+			<File
+				RelativePath="..\src\encoder.h"
+				>
+			</File>
 			<File
 				RelativePath="..\src\syntax_sv8.c"
-				>
-			</File>
-		</Filter>
-		<Filter
-			Name="Encoder"
-			>
-			<File
-				RelativePath="..\src\bitstream.c"
-				>
-			</File>
-			<File
-				RelativePath="..\src\bitstream.h"
-				>
-			</File>
-			<File
-				RelativePath="..\src\enc_interface.c"
-				>
-			</File>
-			<File
-				RelativePath="..\src\encoder.c"
-				>
-			</File>
-			<File
-				RelativePath="..\src\encoder.h"
 				>
 			</File>
Index: /dsfilters/temp/mpcenc2/mpcenc2.cpp
===================================================================
--- /dsfilters/temp/mpcenc2/mpcenc2.cpp	(revision 399)
+++ /dsfilters/temp/mpcenc2/mpcenc2.cpp	(revision 399)
@@ -0,0 +1,100 @@
+// mpcenc2.cpp : Defines the entry point for the console application.
+//
+
+#include "stdafx.h"
+#include <stdlib.h>
+#include "libmpcenc.h"
+
+
+#define	DUMP(fn, buf, len)		{ FILE *f = fopen(fn, "wb"); fwrite(buf, 1, len, f); fclose(f); }
+#define WRITE_PACKET(type)		{ mpc_encoder_get_hdr_packet(encoder, type, buf, &len);	fwrite(buf, 1, len, outfile); }
+
+// Globals
+mpc_encoder_t			encoder;
+mpc_encoder_config_t	*config;
+FILE					*outfile;
+unsigned char			*buf = NULL;
+
+
+void write_head()
+{
+	int	len;
+
+	WRITE_PACKET(PACKET_MAGIC)
+	WRITE_PACKET(PACKET_TYPE('S','H'))
+	WRITE_PACKET(PACKET_TYPE('R','G'))
+	WRITE_PACKET(PACKET_TYPE('E','I'))
+}
+
+void write_tail()
+{
+	int	len;
+
+	// STREAM END
+	WRITE_PACKET(PACKET_TYPE('S','E'))
+}
+
+void encode_noise_frame()
+{
+	// generate random data
+	float		pcm[1152 * 2];
+	int			len = 0;
+
+	for (int i=0; i<1152*2; i++) {
+		pcm[i] = ((rand()%65536) - 32768) / 70000.0;
+	}
+
+	mpc_encoder_encode_pcm(encoder, pcm, 1152*2, buf, &len);
+	if (len > 0) {
+		fwrite(buf, 1, len, outfile);
+	}
+}
+
+
+int test_enc()
+{
+	int						ret;
+
+	mpc_encoder_config(encoder, 44100, 2, 5);
+	mpc_encoder_get_config(encoder, &config);
+	mpc_encoder_init(encoder);
+
+	buf = (unsigned char*)malloc(config->buffer_size);
+
+	write_head();
+	
+	// let's encode several dummy frames
+	for (int i=0; i<150; i++) {
+		encode_noise_frame();
+	}
+
+	write_tail();
+	return 0;
+}
+
+int _tmain(int argc, _TCHAR* argv[])
+{
+	int		ret;
+
+	// create encoder instance
+	ret = mpc_encoder_open(&encoder);
+	if (ret < 0) {
+		printf("failed to create instance\n");
+		return -1;
+	}
+
+	outfile = fopen("output.mpc", "wb");
+	if (!outfile) {
+		mpc_encoder_close(encoder);
+		printf("Cannot open file\n");
+		return -1;
+	}
+
+	ret = test_enc();
+
+	mpc_encoder_close(encoder);
+	if (buf) free(buf);
+	fclose(outfile);
+	return ret;	
+}
+
Index: /dsfilters/temp/mpcenc2/mpcenc2.vcproj
===================================================================
--- /dsfilters/temp/mpcenc2/mpcenc2.vcproj	(revision 399)
+++ /dsfilters/temp/mpcenc2/mpcenc2.vcproj	(revision 399)
@@ -0,0 +1,210 @@
+<?xml version="1.0" encoding="windows-1250"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="8,00"
+	Name="mpcenc2"
+	ProjectGUID="{C9188201-4C57-4F5F-B9DD-147D331B23AE}"
+	RootNamespace="mpcenc2"
+	Keyword="Win32Proj"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="..\libmpcenc\include"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="libmpcenc_d.lib"
+				LinkIncremental="2"
+				AdditionalLibraryDirectories="..\libmpcenc\lib"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories="..\libmpcenc\include"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="..\libmpcenc\lib"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath=".\mpcenc2.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\stdafx.cpp"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+			<File
+				RelativePath=".\stdafx.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+			>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
Index: /dsfilters/temp/mpcenc2/stdafx.cpp
===================================================================
--- /dsfilters/temp/mpcenc2/stdafx.cpp	(revision 399)
+++ /dsfilters/temp/mpcenc2/stdafx.cpp	(revision 399)
@@ -0,0 +1,8 @@
+// stdafx.cpp : source file that includes just the standard includes
+// mpcenc2.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file
Index: /dsfilters/temp/mpcenc2/stdafx.h
===================================================================
--- /dsfilters/temp/mpcenc2/stdafx.h	(revision 399)
+++ /dsfilters/temp/mpcenc2/stdafx.h	(revision 399)
@@ -0,0 +1,17 @@
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+#ifndef _WIN32_WINNT		// Allow use of features specific to Windows XP or later.                   
+#define _WIN32_WINNT 0x0501	// Change this to the appropriate value to target other versions of Windows.
+#endif						
+
+#include <stdio.h>
+#include <tchar.h>
+
+
+
+// TODO: reference additional headers your program requires here
