Index: libmpc/branches/r2d/libmpcenc/encode_sv7.c
===================================================================
--- libmpc/branches/r2d/libmpcenc/encode_sv7.c	(revision 225)
+++ libmpc/branches/r2d/libmpcenc/encode_sv7.c	(revision 226)
@@ -50,5 +50,8 @@
 // initialize SV8
 void
-Init_SV8 ( mpc_encoder_t * e )
+mpc_encoder_init ( mpc_encoder_t * e,
+				   mpc_uint64_t SamplesInWAVE,
+				   unsigned int FramesBlockPwr,
+				   unsigned int SeekDistance )
 {
 	Init_Skalenfaktoren ();
@@ -56,5 +59,26 @@
 
 	memset(e, 0, sizeof(*e));
-	e->seek_pwr = 1;
+
+	if (SeekDistance > 15)
+		SeekDistance = 1;
+	if (FramesBlockPwr > 14)
+		FramesBlockPwr = 6;
+
+	e->seek_pwr = SeekDistance;
+	e->frames_per_block_pwr = FramesBlockPwr;
+
+	if (SamplesInWAVE == 0)
+		e->seek_table = malloc((1 << 16) * sizeof(mpc_uint32_t));
+	else
+		e->seek_table = malloc((size_t)(2 + SamplesInWAVE / (MPC_FRAME_LENGTH << (e->seek_pwr + e->frames_per_block_pwr))) * sizeof(mpc_uint32_t));
+
+	e->buffer = malloc(MAX_FRAME_SIZE * (1 << e->frames_per_block_pwr) * sizeof(mpc_uint8_t));
+}
+
+void
+mpc_encoder_exit ( mpc_encoder_t * e )
+{
+	free(e->seek_table);
+	free(e->buffer);
 }
 
@@ -105,5 +129,5 @@
 	writeBits ( e, ChannelCount - 1  ,  4 );    // Channels
 	writeBits ( e, MS_on        ,  1 );    // MS-Coding Flag
-	writeBits ( e, FRAMES_PER_BLOCK_PWR >> 1,  3 );    // frames per block (log4 unit)
+	writeBits ( e, e->frames_per_block_pwr >> 1,  3 );    // frames per block (log4 unit)
 }
 
@@ -350,5 +374,5 @@
 
 	e->framesInBlock++;
-	if (e->framesInBlock == FRAMES_PER_BLOCK) {
+	if (e->framesInBlock == (1 << e->frames_per_block_pwr)) {
 		if ((e->block_cnt & ((1 << e->seek_pwr) - 1)) == 0) {
 			e->seek_table[e->seek_pos] = ftell(e->outputFile);
Index: libmpc/branches/r2d/libmpcenc/libmpcenc.h
===================================================================
--- libmpc/branches/r2d/libmpcenc/libmpcenc.h	(revision 225)
+++ libmpc/branches/r2d/libmpcenc/libmpcenc.h	(revision 226)
@@ -27,11 +27,6 @@
 #endif
 
-// bitstream.c
-#define FRAMES_PER_BLOCK_PWR 6 // MUST be even
-#define FRAMES_PER_BLOCK (1 << FRAMES_PER_BLOCK_PWR)
-#define BUFFER_FULL         (4352 * FRAMES_PER_BLOCK)         // 34490 bit/frame  1320.3 kbps
-
-// FIXME : make this size dependent of the input file
-#define SEEK_SIZE (1 << 16) // number of seek entries
+#define MPC_FRAME_LENGTH (36 * 32)
+#define MAX_FRAME_SIZE 4352
 
 typedef struct {
@@ -45,9 +40,10 @@
 	mpc_uint64_t outputBits; // Counter for the number of written bits in the bitstream
 	mpc_uint32_t bitsBuff; // bits buffer
-	mpc_uint8_t buffer [BUFFER_FULL]; // Buffer for bitstream-file
-	mpc_uint_t framesInBlock;
+	mpc_uint8_t * buffer; // Buffer for bitstream-file
+	mpc_uint_t framesInBlock; // Number of frames in current block
+	mpc_uint_t frames_per_block_pwr; // Number of frame in a block = 1 << frames_per_block_pwr
 
 	// seeking
-	mpc_uint32_t seek_table[SEEK_SIZE];
+	mpc_uint32_t * seek_table;
 	mpc_uint32_t seek_pos; /// current position in the seek table
 	mpc_uint32_t seek_ref; /// reference position for the seek information
@@ -74,5 +70,9 @@
  } mpc_encoder_t;
 
- void         Init_SV8             ( mpc_encoder_t* );
+ void mpc_encoder_init ( mpc_encoder_t * e,
+						 mpc_uint64_t SamplesInWAVE,
+						 unsigned int FramesBlockPwr,
+						 unsigned int SeekDistance );
+ void mpc_encoder_exit ( mpc_encoder_t * e );
  void writeStreamInfo ( mpc_encoder_t*e,
 						const unsigned int  MaxBand,
