﻿Index: src/Tools/AudioFileIO/MpegAudioStream.cxx
===================================================================
--- src/Tools/AudioFileIO/MpegAudioStream.cxx	(révision 10864)
+++ src/Tools/AudioFileIO/MpegAudioStream.cxx	(copie de travail)
@@ -69,6 +69,7 @@
 		mName = file.GetLocation();
 		mEncodedSampleRate = (int)file.GetHeader().GetSampleRate();
 		mEncodedChannels = (int)file.GetHeader().GetChannels();
+		mDuration = file.GetHeader().GetLength();
 
 		mDecodeBuffer.resize( mEncodedChannels );
 	}
@@ -111,6 +112,14 @@
 		mBitstream.Finish();
 	}
 
+        void MpegAudioStream::SeekTime(const int msec)
+	{
+	  int frame = (int)(msec * ( mEncodedSampleRate / 1000 ));
+	  //use libmad here with MpegBitstream
+          //SeekFrame((const int)frame);
+	  mBitstream.SeekTime(msec, (unsigned int)mEncodedSampleRate);
+	}
+
 	void MpegAudioStream::DiskToMemoryTransfer()
 	{
 		unsigned samplesToRead = mInterleavedData.Size()/mEncodedChannels;
Index: src/Tools/AudioFileIO/MpegAudioStream.hxx
===================================================================
--- src/Tools/AudioFileIO/MpegAudioStream.hxx	(révision 10864)
+++ src/Tools/AudioFileIO/MpegAudioStream.hxx	(copie de travail)
@@ -49,6 +49,7 @@
 		void PrepareWriting();
 		void PrepareReadWrite();
 		void Dispose();
+	        void SeekTime(const int);
 
 	protected:
 
@@ -65,6 +66,7 @@
 		MpegBitstream mBitstream;
 		int           mEncodedSampleRate;
 		int           mEncodedChannels;
+	        long          mDuration;
 
 		static const TSize                    mMaxDecodedBlockSize;
 		std::vector<std::deque<mad_fixed_t> > mDecodeBuffer;
Index: src/Tools/AudioFileIO/PCMAudioStream.cxx
===================================================================
--- src/Tools/AudioFileIO/PCMAudioStream.cxx	(révision 10864)
+++ src/Tools/AudioFileIO/PCMAudioStream.cxx	(copie de travail)
@@ -120,6 +120,16 @@
 		}
 	}
 
+        void PCMAudioStream::SeekFrame(const int frame)
+	{
+	  sf_seek(mFileHandle, frame, SEEK_SET);
+	}
+
+        void PCMAudioStream::SeekTime(const int msec)
+	{
+	  SeekFrame((const int)(msec*(mNativeFileParams.samplerate/1000)));
+	}
+
 	void PCMAudioStream::DiskToMemoryTransfer()
 	{
 		int channelCount = mNativeFileParams.channels;			
Index: src/Tools/AudioFileIO/PCMAudioStream.hxx
===================================================================
--- src/Tools/AudioFileIO/PCMAudioStream.hxx	(révision 10864)
+++ src/Tools/AudioFileIO/PCMAudioStream.hxx	(copie de travail)
@@ -50,6 +50,8 @@
 		void PrepareWriting();
 		void PrepareReadWrite();
 		void Dispose();
+	        void SeekFrame(const int);
+	        void SeekTime(const int);
 
 	protected:
 		
Index: src/Tools/AudioFileIO/OggVorbisAudioStream.cxx
===================================================================
--- src/Tools/AudioFileIO/OggVorbisAudioStream.cxx	(révision 10864)
+++ src/Tools/AudioFileIO/OggVorbisAudioStream.cxx	(copie de travail)
@@ -242,6 +242,11 @@
 		}
 	}
 
+        void OggVorbisAudioStream::SeekTime(const int msec)
+	{
+	  // TODO : some code should be here
+	}
+
 	void OggVorbisAudioStream::ConsumeDecodedSamples()
 	{
 		CLAM_ASSERT( mDecodeBuffer.size() >= unsigned(mInterleavedData.Size()),
Index: src/Tools/AudioFileIO/AudioCodecs_Stream.hxx
===================================================================
--- src/Tools/AudioFileIO/AudioCodecs_Stream.hxx	(révision 10864)
+++ src/Tools/AudioFileIO/AudioCodecs_Stream.hxx	(copie de travail)
@@ -52,6 +52,7 @@
 		virtual void PrepareWriting()   = 0;
 		virtual void PrepareReadWrite() = 0;
 		virtual void Dispose()          = 0;
+	        virtual void SeekTime(const int)= 0;
 		
 		void DeactivateStrictStreaming();
 		void ActivateStrictStreaming();
Index: src/Tools/AudioFileIO/MpegBitstream.cxx
===================================================================
--- src/Tools/AudioFileIO/MpegBitstream.cxx	(révision 10864)
+++ src/Tools/AudioFileIO/MpegBitstream.cxx	(copie de travail)
@@ -175,8 +175,17 @@
 		return true;
 	}
 
-	struct mad_frame& MpegBitstream::CurrentFrame()
+        void MpegBitstream::SeekTime(int msec, unsigned int sampleRate)
 	{
+	  /*
+	  ** TODO : read the good buffer according to mInputBufferSize
+	  ** go to the good frame (frame = (msec * ( mEncodedSampleRate / 1000 )))
+	  **
+	  */
+	}
+  
+        struct mad_frame& MpegBitstream::CurrentFrame()
+	{
 		return mCurrentFrame;
 	}
 
Index: src/Tools/AudioFileIO/OggVorbisAudioStream.hxx
===================================================================
--- src/Tools/AudioFileIO/OggVorbisAudioStream.hxx	(révision 10864)
+++ src/Tools/AudioFileIO/OggVorbisAudioStream.hxx	(copie de travail)
@@ -55,6 +55,7 @@
 		void PrepareWriting();
 		void PrepareReadWrite();
 		void Dispose();
+	        void SeekTime(const int);
 
 	protected:
 		void AudioFileToNative( const AudioFile& file );
Index: src/Tools/AudioFileIO/AudioFile.hxx
===================================================================
--- src/Tools/AudioFileIO/AudioFile.hxx	(révision 10864)
+++ src/Tools/AudioFileIO/AudioFile.hxx	(copie de travail)
@@ -33,7 +33,7 @@
 	namespace AudioCodecs
 	{
 		class Codec;       // forward declaration
-		class Stream; // forward declaration
+	        class Stream;      // forward declaration
 	}
 
 	/** @ingroup AudioFileIO */
@@ -59,8 +59,8 @@
 		bool                          IsReadable() const;
 		bool                          IsWritable() const;
 
-		AudioCodecs::Stream*   GetStream();
-
+	        AudioCodecs::Stream*   GetStream();
+	        
 	protected:
 		//! Usually the header is set into the file using CreateNew or OpenExistig (public) methods 
 		bool SetHeader( const AudioFileHeader& );
Index: src/Tools/AudioFileIO/MpegBitstream.hxx
===================================================================
--- src/Tools/AudioFileIO/MpegBitstream.hxx	(révision 10864)
+++ src/Tools/AudioFileIO/MpegBitstream.hxx	(copie de travail)
@@ -62,6 +62,7 @@
 		bool   FatalError();
 		bool   NextFrame();
 		bool   SynthesizeCurrent();
+	        void   SeekTime(int msec, unsigned int sampleRate);
 		struct mad_frame& CurrentFrame();
 		struct mad_synth&  CurrentSynthesis();
 		struct mad_stream& StreamState();
Index: src/Processing/AudioFileIO/MonoAudioFileReader.hxx
===================================================================
--- src/Processing/AudioFileIO/MonoAudioFileReader.hxx	(révision 10864)
+++ src/Processing/AudioFileIO/MonoAudioFileReader.hxx	(copie de travail)
@@ -27,6 +27,7 @@
 #include "AudioOutPort.hxx"
 #include "AudioFile.hxx"
 #include "OutControl.hxx"
+#include "AudioCodecs_Stream.hxx"
 
 namespace CLAM
 {
@@ -46,6 +47,7 @@
 		const AudioTextDescriptors & GetTextDescriptors () const { return mAudioFile.GetTextDescriptors(); }
 		const EAudioFileCodec GetCodec() const { return mAudioFile.GetCodec(); }
 
+	        void SeekTime(int msec) { mNativeStream->SeekTime(msec); }
 
 	protected: // methods
 
Index: src/Processing/AudioFileIO/MultiChannelAudioFileReader.hxx
===================================================================
--- src/Processing/AudioFileIO/MultiChannelAudioFileReader.hxx	(révision 10864)
+++ src/Processing/AudioFileIO/MultiChannelAudioFileReader.hxx	(copie de travail)
@@ -28,6 +28,7 @@
 #include "Audio.hxx"
 #include "OutControl.hxx"
 #include <vector>
+#include "AudioCodecs_Stream.hxx"
 
 namespace CLAM
 {
@@ -51,6 +52,8 @@
 		const AudioFileHeader & GetHeader() const { return mAudioFile.GetHeader(); }
 		const AudioTextDescriptors & GetTextDescriptors () const { return mAudioFile.GetTextDescriptors(); }
 		const EAudioFileCodec GetCodec() const { return mAudioFile.GetCodec(); }
+
+	        void SeekTime(int msec) { mNativeStream->SeekTime(msec); }
 	
 	protected: // methods
 		
