Browse Source

Fixed file not closing after require(). Changed seek() to use seconds.

rude 16 years ago
parent
commit
92c678ce02

+ 0 - 1
src/modules/filesystem/physfs/Filesystem.cpp

@@ -481,7 +481,6 @@ namespace physfs
 
 		// Create the file.
 		File * file = newFile(filename);
-		file->open(File::READ);
 
 		// Get the data from the file.
 		Data * data = file->read();

+ 2 - 2
src/modules/sound/Decoder.h

@@ -92,10 +92,10 @@ namespace sound
 
 		/**
 		* Seeks to the specified position, if possible.
-		* @param ms The position in the stream in milliseconds.
+		* @param s The position in the stream in seconds.
 		* @return True if success, false on fail/unsupported.
 		**/
-		virtual bool seek(int ms) = 0;
+		virtual bool seek(float s) = 0;
 
 		/**
 		* Rewinds the stream to the start.

+ 2 - 2
src/modules/sound/lullaby/FLACDecoder.cpp

@@ -73,9 +73,9 @@ namespace lullaby
 		return bufferSize;
 	}
 
-	bool FLACDecoder::seek(int ms)
+	bool FLACDecoder::seek(float s)
 	{
-		return seek_absolute(ms);
+		return seek_absolute((int)(s*1000.0f));
 	}
 
 	bool FLACDecoder::rewind()

+ 1 - 1
src/modules/sound/lullaby/FLACDecoder.h

@@ -46,7 +46,7 @@ namespace lullaby
 			static bool accepts(const std::string &ext);
 			love::sound::Decoder *clone();
 			int decode();
-			bool seek(int ms);
+			bool seek(float s);
 			bool rewind();
 			bool isSeekable();
 			int getChannels() const;

+ 2 - 2
src/modules/sound/lullaby/ModPlugDecoder.cpp

@@ -85,9 +85,9 @@ namespace lullaby
 		return r;
 	}
 
-	bool ModPlugDecoder::seek(int ms)
+	bool ModPlugDecoder::seek(float s)
 	{
-		ModPlug_Seek(plug, ms);
+		ModPlug_Seek(plug, (int)(s*1000.0f));
 		return true;
 	}
 

+ 1 - 1
src/modules/sound/lullaby/ModPlugDecoder.h

@@ -50,7 +50,7 @@ namespace lullaby
 
 		love::sound::Decoder * clone();
 		int decode();
-		bool seek(int ms);
+		bool seek(float s);
 		bool rewind();
 		bool isSeekable();
 		int getChannels() const;

+ 38 - 8
src/modules/sound/lullaby/Mpg123Decoder.cpp

@@ -58,9 +58,20 @@ namespace lullaby
 		if (ret != MPG123_OK)
 			throw love::Exception("Could not set output format.");
 		size_t numbytes = 0;
-		ret = mpg123_decode(handle, (unsigned char*) data->getData(), data->getSize(), NULL, 0, &numbytes);
-		if (ret != MPG123_DONE && ret != MPG123_NEW_FORMAT)
-			throw love::Exception("Could not decode feed.");
+		ret = mpg123_feed(handle, (unsigned char*)data->getData(), data->getSize());
+		
+		if(ret == MPG123_NEW_FORMAT)
+		{
+			long rate;
+			int channels;
+			int encoding;
+			mpg123_getformat(handle, &rate, &channels, &encoding);
+		}
+		else if(ret != 0)
+		{
+			throw love::Exception(mpg123_strerror(handle));
+		}
+
 	}
 
 	Mpg123Decoder::~Mpg123Decoder()
@@ -98,9 +109,26 @@ namespace lullaby
 	int Mpg123Decoder::decode()
 	{
 		size_t numbytes;
-		int r =  mpg123_read(handle, (unsigned char*) buffer, bufferSize, &numbytes);
+		
+		for(int i = 0; i < 2; ++i)
+		{
+			int r = mpg123_read(handle, (unsigned char*) buffer, bufferSize, &numbytes);
+
+			switch(r)
+			{
+			case MPG123_NEW_FORMAT:
+				continue;
+			case MPG123_DONE:
+				eof = false;
+			case MPG123_OK:
+			default:
+				return numbytes;
+			}
+		}
+
 
 		// If we're done, then EOF. If some error occurred, pretend we EOF'd.
+		/*
 		if (r == MPG123_DONE || r != MPG123_OK)
 		{
 			if ( r == MPG123_NEED_MORE )
@@ -114,19 +142,21 @@ namespace lullaby
 				numbytes = 0;
 			}
 		}
+		*/
 
 		return numbytes;
 	}
 
-	bool Mpg123Decoder::seek(int ms)
+	bool Mpg123Decoder::seek(float s)
 	{
-		mpg123_seek(handle, ms, SEEK_SET);
-		return true;
+		off_t r = mpg123_seek(handle, (off_t)(s*1000.0f), SEEK_SET);
+
+		return (r >= 0);
 	}
 
 	bool Mpg123Decoder::rewind()
 	{
-		if(mpg123_seek(handle, 0, SEEK_SET) < 0)
+		if(mpg123_seek(handle, 0, SEEK_SET) >= 0)
 			return false;
 		return true;
 	}

+ 1 - 1
src/modules/sound/lullaby/Mpg123Decoder.h

@@ -52,7 +52,7 @@ namespace lullaby
 
 		love::sound::Decoder * clone();
 		int decode();
-		bool seek(int ms);
+		bool seek(float s);
 		bool rewind();
 		bool isSeekable();
 		int getChannels() const;

+ 2 - 2
src/modules/sound/lullaby/VorbisDecoder.cpp

@@ -218,10 +218,10 @@ namespace lullaby
 		return size;
 	}
 
-	bool VorbisDecoder::seek(int ms)
+	bool VorbisDecoder::seek(float s)
 	{
 		eof = false;
-		int result = ov_time_seek(&handle, ms / 100);
+		int result = ov_time_seek(&handle, (int)(s*1000.0f) / 100);
 
 		if(result == 0)
 			return true;

+ 1 - 1
src/modules/sound/lullaby/VorbisDecoder.h

@@ -61,7 +61,7 @@ namespace lullaby
 
 		love::sound::Decoder * clone();
 		int decode();
-		bool seek(int ms);
+		bool seek(float s);
 		bool rewind();
 		bool isSeekable();
 		int getChannels() const;