Index: libmpcdec/branches/zorg/include/mpcdec/mpcdec.h
===================================================================
--- libmpcdec/branches/zorg/include/mpcdec/mpcdec.h	(revision 69)
+++ libmpcdec/branches/zorg/include/mpcdec/mpcdec.h	(revision 70)
@@ -46,18 +46,20 @@
 #endif
 
+enum {
+    MPC_FRAME_LENGTH          = (36 * 32),              ///< Samples per mpc frame
+    MPC_DECODER_BUFFER_LENGTH = (MPC_FRAME_LENGTH * 4), ///< Required buffer size for decoder
+    MPC_DECODER_SYNTH_DELAY   = 481
+};
+
 typedef struct mpc_decoder_t mpc_decoder;
 
-/// Sets up decoder library.
-/// Call this first when preparing to decode an mpc stream.
+/// Initializes mpc decoder with the supplied stream info parameters.
 /// \param p_reader reader that will supply raw data to the decoder
-void mpc_decoder_setup(mpc_decoder *p_dec, mpc_reader *p_reader);
-
-/// Initializes mpc decoder with the supplied stream info parameters.
 /// \param si streaminfo structure indicating format of source stream
 /// \return TRUE if decoder was initalized successfully, FALSE otherwise    
-mpc_status mpc_init_decoder(mpc_decoder **p_dec, mpc_streaminfo *si);
+mpc_status mpc_decoder_init(mpc_decoder **p_dec, mpc_reader *p_reader, mpc_streaminfo *si);
 
 /// Releases input mpc decoder 
-void mpc_exit_decoder(mpc_decoder *p_dec);
+void mpc_decoder_exit(mpc_decoder *p_dec);
 
 /// Call this next after calling mpc_decoder_setup.
Index: libmpcdec/branches/zorg/include/mpcdec/reader.h
===================================================================
--- libmpcdec/branches/zorg/include/mpcdec/reader.h	(revision 69)
+++ libmpcdec/branches/zorg/include/mpcdec/reader.h	(revision 70)
@@ -78,10 +78,10 @@
 /// \param r p_reader handle to initialize
 /// \param filename input filename to attach to the reader
-mpc_status mpc_init_stdio_reader(mpc_reader *p_reader, char *filename);
+mpc_status mpc_reader_init_stdio(mpc_reader *p_reader, char *filename);
 
 /// Release reader with default stdio file reader implementation.
 ///
 /// \param r reader handle to release
-void mpc_exit_stdio_reader(mpc_reader *p_reader);
+void mpc_reader_exit_stdio(mpc_reader *p_reader);
 
 #ifdef __cplusplus
Index: libmpcdec/branches/zorg/include/mpcdec/streaminfo.h
===================================================================
--- libmpcdec/branches/zorg/include/mpcdec/streaminfo.h	(revision 69)
+++ libmpcdec/branches/zorg/include/mpcdec/streaminfo.h	(revision 70)
@@ -94,13 +94,9 @@
 } mpc_streaminfo;
 
-/// Initializes a streaminfo structure.
-/// \param si streaminfo structure to initialize
-void mpc_streaminfo_init(mpc_streaminfo *si);
-
 /// Reads streaminfo header from the mpc stream supplied by r.
 /// \param si si pointer to which info will be written
 /// \param p_reader stream reader to supply raw data
 /// \return error code
-mpc_status mpc_streaminfo_read(mpc_streaminfo *si, mpc_reader *p_reader);
+mpc_status mpc_streaminfo_init(mpc_streaminfo *si, mpc_reader *p_reader);
 
 /// Gets length of stream si, in seconds.
Index: libmpcdec/branches/zorg/mpcdec/mpcdec.c
===================================================================
--- libmpcdec/branches/zorg/mpcdec/mpcdec.c	(revision 69)
+++ libmpcdec/branches/zorg/mpcdec/mpcdec.c	(revision 70)
@@ -35,14 +35,14 @@
 #include <assert.h>
 #include <time.h>
+#include <mpcdec/mpcdec.h>
 
-#include <mpcdec/mpcdec.h>
-#include <libwaveformat.h>
+#ifdef WIN32
+#include <crtdbg.h>
+#endif
 
 static void
 usage(const char *exename)
 {
-    printf
-        ("Usage: %s <infile.mpc> [<outfile.wav>]\nIf <outfile.wav> is not specified, decoder will run in benchmark mode.\n",
-         exename);
+    printf("Usage: %s <infile.mpc>\n", exename);
 }
 
@@ -50,114 +50,51 @@
 main(int argc, char **argv)
 {
-    mpc_reader reader; mpc_streaminfo si; mpc_decoder decoder; wavwriter
+    mpc_reader reader; mpc_streaminfo si; mpc_decoder* decoder; mpc_status err;
+    MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH];
+    clock_t begin, end, sum; int total_samples;
 
-    if (argc != 2 && argc != 3) {
-        if (argc > 0)
-            usage(argv[0]);
+    if(argc != 2)
+    {
+        usage(argv[0]);
         return 0;
     }
 
+    err = mpc_reader_init_stdio(&reader, argv[1]);
+    if(err < 0) return !MPC_STATUS_OK;
 
-    FILE *input = fopen(argv[1], "rb");
-    FILE *output = 0;
-    if (input == 0) {
-        usage(argv[0]);
-        printf("Error opening input file: \"%s\"\n", argv[1]);
-        return 1;
+    err = mpc_streaminfo_init(&si, &reader);
+    if(err < 0) return !MPC_STATUS_OK;
+
+    err = mpc_decoder_init(&decoder, &reader, &si);
+    if(err < 0) return !MPC_STATUS_OK;
+
+    sum = total_samples = 0;
+    while(TRUE)
+    {
+        mpc_uint32_t samples;
+        begin = clock();
+        samples = mpc_decoder_decode(decoder, sample_buffer, 0, 0);
+        end = clock();
+        if(samples <= 0) break;
+        if(!samples) break;
+        total_samples += samples;
+        sum           += end - begin;
     }
 
-    if (argc == 3) {
-        output = fopen(argv[2], "wb");
-        if (output == 0) {
-            fclose(input);
-            usage(argv[0]);
-            printf("Error opening output file: \"%s\"\n", argv[2]);
-            return 1;
-        }
-    }
+    printf("%u samples ", total_samples);
+    total_samples = (mpc_uint32_t) ((double) total_samples * CLOCKS_PER_SEC * 100 / (si.sample_freq * sum));
+    printf("decoded in %u ms (%u.%02ux)\n",
+           sum * 1000 / CLOCKS_PER_SEC,
+           total_samples / 100,
+           total_samples % 100
+           );
 
-    /* initialize our reader_data tag the reader will carry around with it */
-    reader_data data;
-    data.file = input;
-    data.seekable = true;
-    fseek(data.file, 0, SEEK_END);
-    data.size = ftell(data.file);
-    fseek(data.file, 0, SEEK_SET);
+    mpc_decoder_exit(decoder);
+    mpc_reader_exit_stdio(&reader);
 
-    /* set up an mpc_reader linked to our function implementations */
-    mpc_decoder decoder;
-    mpc_reader reader;
-    reader.read = read_impl;
-    reader.seek = seek_impl;
-    reader.tell = tell_impl;
-    reader.get_size = get_size_impl;
-    reader.canseek = canseek_impl;
-    reader.data = &data;
-
-    /* read file's streaminfo data */
-    mpc_streaminfo info;
-    mpc_streaminfo_init(&info);
-    if (mpc_streaminfo_read(&info, &reader) != ERROR_CODE_OK) {
-        printf("Not a valid musepack file: \"%s\"\n", argv[1]);
-        return 1;
-    }
-
-    /* instantiate a decoder with our file reader */
-    mpc_decoder_setup(&decoder, &reader);
-    if (!mpc_decoder_initialize(&decoder, &info)) {
-        printf("Error initializing decoder.\n", argv[1]);
-        return 1;
-    }
-
-    /* decode the file */
-    printf("Decoding from:\n%s\nTo:\n%s\n", argv[1],
-           output ? argv[2] : "N/A");
-    WavWriter *wavwriter =
-        output ? new WavWriter(output, 2, 16, info.sample_freq) : 0;
-    MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH];
-    clock_t begin, end;
-    begin = clock();
-    unsigned total_samples = 0;
-    mpc_bool_t successful = FALSE;
-    for (;;) {
-        unsigned status = mpc_decoder_decode(&decoder, sample_buffer, 0, 0);
-        if (status == (unsigned)(-1)) {
-            //decode error
-            printf("Error decoding file.\n");
-            break;
-        }
-        else if (status == 0)   //EOF
-        {
-            successful = true;
-            break;
-        }
-        else                    //status>0
-        {
-            total_samples += status;
-            if (wavwriter) {
-                if (!wavwriter->
-                    WriteSamples(sample_buffer, status * /* stereo */ 2)) {
-                    printf("Write error.\n");
-                    break;
-                }
-            }
-        }
-    }
-
-    end = clock();
-
-    if (wavwriter) {
-        delete wavwriter;
-    }
-
-    if (successful) {
-        printf("\nFinished.\nTotal samples decoded: %u.\n", total_samples);
-        unsigned ms = (end - begin) * 1000 / CLOCKS_PER_SEC;
-        unsigned ratio =
-            (unsigned)((double)total_samples / (double)info.sample_freq /
-                       ((double)ms / 1000.0) * 100.0);
-        printf("Time: %u ms (%u.%02ux).\n", ms, ratio / 100, ratio % 100);
-    }
-
+#ifdef WIN32
+    assert(_CrtCheckMemory());
+    _CrtDumpMemoryLeaks();
+#endif
     return 0;
 }
Index: libmpcdec/branches/zorg/src/internal.h
===================================================================
--- libmpcdec/branches/zorg/src/internal.h	(revision 69)
+++ libmpcdec/branches/zorg/src/internal.h	(revision 70)
@@ -45,10 +45,4 @@
 #include <mpcdec/mpcdec.h>
 
-enum {
-    MPC_FRAME_LENGTH          = (36 * 32),              ///< Samples per mpc frame
-    MPC_DECODER_BUFFER_LENGTH = (MPC_FRAME_LENGTH * 4), ///< Required buffer size for decoder
-    MPC_DECODER_SYNTH_DELAY   = 481
-};
-
 /// Big/little endian 32 bit byte swapping routine.
 static mpc_inline
Index: libmpcdec/branches/zorg/src/mpc_decoder.c
===================================================================
--- libmpcdec/branches/zorg/src/mpc_decoder.c	(revision 69)
+++ libmpcdec/branches/zorg/src/mpc_decoder.c	(revision 70)
@@ -79,10 +79,10 @@
 static mpc_int32_t f_read(mpc_decoder *d, void *ptr, mpc_int32_t size) 
 { 
-    return d->r->read(d->r->data, ptr, size); 
+    return d->r->read(d->r, ptr, size); 
 }
 
 static mpc_bool_t f_seek(mpc_decoder *d, mpc_int32_t offset) 
 { 
-    return d->r->seek(d->r->data, offset); 
+    return d->r->seek(d->r, offset); 
 }
 
@@ -861,8 +861,4 @@
   mpc_decoder_reset_bitstream_decode(d);
   mpc_decoder_initialisiere_quantisierungstabellen(d, 1.0f);
-#if 0
-  mpc_decoder_init_huffman_sv6(d);
-  mpc_decoder_init_huffman_sv7(d);
-#endif
 }
 
@@ -896,18 +892,30 @@
 }
 
-mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si) 
-{
-    mpc_decoder_set_streaminfo(d, si);
+mpc_status mpc_decoder_init(mpc_decoder **d, mpc_reader *r, mpc_streaminfo *si) 
+{
+    mpc_decoder* p_tmp;
+    
+    p_tmp = malloc(sizeof *p_tmp);
+    memset(p_tmp, 0, sizeof *p_tmp);
+    mpc_decoder_setup(p_tmp, r);
+
+    mpc_decoder_set_streaminfo(p_tmp, si);
 
     // AB: setting position to the beginning of the data-bitstream
-    mpc_decoder_seek(d, get_initial_fpos(d));
-
-    d->seeking_pwr = 0;
-    while (d->OverallFrames > (SEEKING_TABLE_SIZE << d->seeking_pwr))
-        d->seeking_pwr++;
-    d->seeking_table_frames = 0;
-    d->seeking_table[0] = get_initial_fpos(d);
-
-    return TRUE;
+    mpc_decoder_seek(p_tmp, get_initial_fpos(p_tmp));
+
+    p_tmp->seeking_pwr = 0;
+    while (p_tmp->OverallFrames > (SEEKING_TABLE_SIZE << p_tmp->seeking_pwr))
+        p_tmp->seeking_pwr++;
+    p_tmp->seeking_table_frames = 0;
+    p_tmp->seeking_table[0] = get_initial_fpos(p_tmp);
+
+    *d = p_tmp;
+    return MPC_STATUS_OK;
+}
+
+void mpc_decoder_exit(mpc_decoder *d)
+{
+    free(d);
 }
 
Index: libmpcdec/branches/zorg/src/mpc_reader.c
===================================================================
--- libmpcdec/branches/zorg/src/mpc_reader.c	(revision 69)
+++ libmpcdec/branches/zorg/src/mpc_reader.c	(revision 70)
@@ -88,5 +88,5 @@
 
 mpc_status
-mpc_reader_setup_file_reader(mpc_reader *p_reader, char *filename)
+mpc_reader_init_stdio(mpc_reader *p_reader, char *filename)
 {
     mpc_reader tmp_reader; mpc_reader_stdio *p_stdio; int err;
@@ -127,5 +127,5 @@
 
 void
-mpc_exit_stdio_reader(mpc_reader *p_reader)
+mpc_reader_exit_stdio(mpc_reader *p_reader)
 {
     mpc_reader_stdio *p_stdio = (mpc_reader_stdio*) p_reader->data;
Index: libmpcdec/branches/zorg/src/streaminfo.c
===================================================================
--- libmpcdec/branches/zorg/src/streaminfo.c	(revision 69)
+++ libmpcdec/branches/zorg/src/streaminfo.c	(revision 70)
@@ -51,10 +51,4 @@
 {
     return profile >= sizeof versionNames / sizeof *versionNames ? na : versionNames[profile];
-}
-
-void
-mpc_streaminfo_init(mpc_streaminfo* si)
-{
-    memset(si, 0, sizeof *si);
 }
 
@@ -115,8 +109,9 @@
 // reads file header and tags
 mpc_status
-mpc_streaminfo_read(mpc_streaminfo * si, mpc_reader *p_reader)
+mpc_streaminfo_init(mpc_streaminfo * si, mpc_reader *p_reader)
 {
     mpc_uint32_t headerData[8]; int err;
 
+    memset(si, 0, sizeof *si);
     // get header position
     err = si->header_position = mpc_skip_id3v2(p_reader);
@@ -136,5 +131,5 @@
 
     err = memcmp(headerData, "MP+", 3);
-    if(!err) return MPC_STATUS_INVALIDSV;
+    if(err) return MPC_STATUS_INVALIDSV;
 
 #ifndef MPC_LITTLE_ENDIAN
Index: libmpcdec/branches/zorg/win32/libmpcdec.sln
===================================================================
--- libmpcdec/branches/zorg/win32/libmpcdec.sln	(revision 69)
+++ libmpcdec/branches/zorg/win32/libmpcdec.sln	(revision 70)
@@ -7,4 +7,7 @@
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mpcdec", "mpcdec.vcproj", "{A527175B-22A9-41AB-B2E8-580F573CCAFB}"
+	ProjectSection(ProjectDependencies) = postProject
+		{4C5362CD-0BF2-4B3B-971B-8293EB1A1DC3} = {4C5362CD-0BF2-4B3B-971B-8293EB1A1DC3}
+	EndProjectSection
 EndProject
 Global
Index: libmpcdec/branches/zorg/win32/libmpcdec.vcproj
===================================================================
--- libmpcdec/branches/zorg/win32/libmpcdec.vcproj	(revision 69)
+++ libmpcdec/branches/zorg/win32/libmpcdec.vcproj	(revision 70)
@@ -5,4 +5,5 @@
 	Name="libmpcdec"
 	ProjectGUID="{4C5362CD-0BF2-4B3B-971B-8293EB1A1DC3}"
+	RootNamespace="libmpcdec"
 	>
 	<Platforms>
@@ -41,4 +42,5 @@
 				AdditionalIncludeDirectories="../include"
 				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
+				ExceptionHandling="0"
 				BasicRuntimeChecks="3"
 				SmallerTypeCheck="true"
@@ -61,4 +63,5 @@
 			<Tool
 				Name="VCLibrarianTool"
+				OutputFile="$(OutDir)\$(ProjectName)_d.lib"
 			/>
 			<Tool
@@ -76,4 +79,5 @@
 			<Tool
 				Name="VCPostBuildEventTool"
+				CommandLine="copy $(TargetPath) ..\bin\."
 			/>
 		</Configuration>
@@ -105,4 +109,9 @@
 				AdditionalIncludeDirectories="../include"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
+				StringPooling="true"
+				ExceptionHandling="0"
+				BufferSecurityCheck="false"
+				EnableFunctionLevelLinking="true"
+				WarningLevel="3"
 				CompileAs="1"
 			/>
@@ -133,4 +142,5 @@
 			<Tool
 				Name="VCPostBuildEventTool"
+				CommandLine="copy $(TargetPath) ..\bin\."
 			/>
 		</Configuration>
Index: libmpcdec/branches/zorg/win32/libwavformat.vcproj
===================================================================
--- libmpcdec/branches/zorg/win32/libwavformat.vcproj	(revision 69)
+++ libmpcdec/branches/zorg/win32/libwavformat.vcproj	(revision 70)
@@ -42,11 +42,13 @@
 				Optimization="0"
 				PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
-				MinimalRebuild="true"
+				ExceptionHandling="0"
 				BasicRuntimeChecks="3"
 				RuntimeLibrary="1"
 				UsePrecompiledHeader="0"
+				BrowseInformation="1"
 				WarningLevel="3"
 				Detect64BitPortabilityProblems="true"
-				DebugInformationFormat="4"
+				DebugInformationFormat="1"
+				CompileAs="1"
 			/>
 			<Tool
@@ -61,4 +63,5 @@
 			<Tool
 				Name="VCLibrarianTool"
+				OutputFile="$(OutDir)\$(ProjectName)_d.lib"
 			/>
 			<Tool
@@ -76,4 +79,5 @@
 			<Tool
 				Name="VCPostBuildEventTool"
+				CommandLine="copy $(TargetPath) ..\bin\."
 			/>
 		</Configuration>
@@ -104,9 +108,12 @@
 				Name="VCCLCompilerTool"
 				PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+				ExceptionHandling="0"
 				RuntimeLibrary="0"
+				BufferSecurityCheck="false"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
 				Detect64BitPortabilityProblems="true"
 				DebugInformationFormat="0"
+				CompileAs="1"
 			/>
 			<Tool
@@ -136,4 +143,5 @@
 			<Tool
 				Name="VCPostBuildEventTool"
+				CommandLine="copy $(TargetPath) ..\bin\."
 			/>
 		</Configuration>
Index: libmpcdec/branches/zorg/win32/mpcdec.vcproj
===================================================================
--- libmpcdec/branches/zorg/win32/mpcdec.vcproj	(revision 69)
+++ libmpcdec/branches/zorg/win32/mpcdec.vcproj	(revision 70)
@@ -43,11 +43,12 @@
 				AdditionalIncludeDirectories="../include,../libwavformat"
 				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
-				MinimalRebuild="true"
+				ExceptionHandling="0"
 				BasicRuntimeChecks="3"
-				RuntimeLibrary="3"
+				RuntimeLibrary="1"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
 				Detect64BitPortabilityProblems="true"
-				DebugInformationFormat="4"
+				DebugInformationFormat="1"
+				CompileAs="1"
 			/>
 			<Tool
@@ -62,8 +63,12 @@
 			<Tool
 				Name="VCLinkerTool"
-				LinkIncremental="2"
+				AdditionalDependencies="libmpcdec_d.lib"
+				OutputFile="$(OutDir)\$(ProjectName)_d.exe"
+				AdditionalLibraryDirectories="../bin"
+				GenerateManifest="false"
 				GenerateDebugInformation="true"
 				SubSystem="1"
 				TargetMachine="1"
+				AllowIsolation="false"
 			/>
 			<Tool
@@ -72,4 +77,5 @@
 			<Tool
 				Name="VCManifestTool"
+				EmbedManifest="false"
 			/>
 			<Tool
@@ -90,4 +96,5 @@
 			<Tool
 				Name="VCPostBuildEventTool"
+				CommandLine="copy $(TargetPath) ..\bin\."
 			/>
 		</Configuration>
@@ -117,10 +124,13 @@
 			<Tool
 				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories="../include,../libwavformat"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
-				RuntimeLibrary="2"
+				ExceptionHandling="0"
+				BufferSecurityCheck="false"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
 				Detect64BitPortabilityProblems="true"
-				DebugInformationFormat="3"
+				DebugInformationFormat="0"
+				CompileAs="1"
 			/>
 			<Tool
@@ -135,10 +145,12 @@
 			<Tool
 				Name="VCLinkerTool"
-				LinkIncremental="1"
-				GenerateDebugInformation="true"
+				AdditionalDependencies="libmpcdec.lib"
+				AdditionalLibraryDirectories="../bin"
+				GenerateManifest="false"
 				SubSystem="1"
 				OptimizeReferences="2"
 				EnableCOMDATFolding="2"
 				TargetMachine="1"
+				AllowIsolation="false"
 			/>
 			<Tool
@@ -147,4 +159,5 @@
 			<Tool
 				Name="VCManifestTool"
+				EmbedManifest="false"
 			/>
 			<Tool
@@ -165,4 +178,5 @@
 			<Tool
 				Name="VCPostBuildEventTool"
+				CommandLine="copy $(TargetPath) ..\bin\."
 			/>
 		</Configuration>
