Browse Source

Use doubles instead of floats for the time argument in Source:seek. This probably won't affect anything meaningfully, but in theory it's more precise.

Alex Szpakowski 6 years ago
parent
commit
38cb56f168

+ 2 - 2
src/modules/audio/Source.h

@@ -72,8 +72,8 @@ public:
 	virtual void setVolume(float volume) = 0;
 	virtual float getVolume() const = 0;
 
-	virtual void seek(float offset, Unit unit) = 0;
-	virtual float tell(Unit unit) = 0;
+	virtual void seek(double offset, Unit unit) = 0;
+	virtual double tell(Unit unit) = 0;
 	virtual double getDuration(Unit unit) = 0;
 
 	// all float * v must be of size 3

+ 2 - 2
src/modules/audio/null/Source.cpp

@@ -90,11 +90,11 @@ float Source::getVolume() const
 	return volume;
 }
 
-void Source::seek(float, Source::Unit)
+void Source::seek(double, Source::Unit)
 {
 }
 
-float Source::tell(Source::Unit)
+double Source::tell(Source::Unit)
 {
 	return 0.0f;
 }

+ 2 - 2
src/modules/audio/null/Source.h

@@ -50,8 +50,8 @@ public:
 	virtual float getPitch() const;
 	virtual void setVolume(float volume);
 	virtual float getVolume() const;
-	virtual void seek(float offset, Unit unit);
-	virtual float tell(Unit unit);
+	virtual void seek(double offset, Unit unit);
+	virtual double tell(Unit unit);
 	virtual double getDuration(Unit unit);
 	virtual void setPosition(float *v);
 	virtual void getPosition(float *v) const;

+ 11 - 9
src/modules/audio/openal/Source.cpp

@@ -506,23 +506,23 @@ float Source::getVolume() const
 	return volume;
 }
 
-void Source::seek(float offset, Source::Unit unit)
+void Source::seek(double offset, Source::Unit unit)
 {
 	Lock l = pool->lock();
 
 	int offsetSamples = 0;
-	float offsetSeconds = 0.0f;
+	double offsetSeconds = 0.0f;
 
 	switch (unit)
 	{
 	case Source::UNIT_SAMPLES:
-		offsetSamples = offset;
-		offsetSeconds = offset / sampleRate;
+		offsetSamples = (int) offset;
+		offsetSeconds = offset / (double) sampleRate;
 		break;
 	case Source::UNIT_SECONDS:
 	default:
 		offsetSeconds = offset;
-		offsetSamples = offset * sampleRate;
+		offsetSamples = (int) (offset * sampleRate);
 		break;
 	}
 
@@ -573,12 +573,13 @@ void Source::seek(float offset, Source::Unit unit)
 				}
 				if (unusedBuffers.empty())
 					offsetSamples = 0;
-				offsetSeconds = offsetSamples / sampleRate;
+				offsetSeconds = offsetSamples / (double) sampleRate;
 			}
 			break;
 		case TYPE_MAX_ENUM:
 			break;
 	}
+
 	if (wasPlaying && (alGetError() == AL_INVALID_VALUE || (sourceType == TYPE_STREAM && !isPlaying())))
 	{
 		stop();
@@ -586,10 +587,11 @@ void Source::seek(float offset, Source::Unit unit)
 			play();
 		return;
 	}
+
 	this->offsetSamples = offsetSamples;
 }
 
-float Source::tell(Source::Unit unit)
+double Source::tell(Source::Unit unit)
 {
 	Lock l = pool->lock();
 
@@ -601,7 +603,7 @@ float Source::tell(Source::Unit unit)
 	offset += offsetSamples;
 
 	if (unit == UNIT_SECONDS)
-		return offset / (float)sampleRate;
+		return offset / (double) sampleRate;
 	else
 		return offset;
 }
@@ -867,7 +869,7 @@ void Source::prepareAtomic()
 	}
 
 	// Seek to the current/pending offset.
-	alSourcef(source, AL_SAMPLE_OFFSET, offsetSamples);
+	alSourcei(source, AL_SAMPLE_OFFSET, offsetSamples);
 }
 
 void Source::teardownAtomic()

+ 2 - 2
src/modules/audio/openal/Source.h

@@ -115,8 +115,8 @@ public:
 	virtual float getPitch() const;
 	virtual void setVolume(float volume);
 	virtual float getVolume() const;
-	virtual void seek(float offset, Unit unit);
-	virtual float tell(Unit unit);
+	virtual void seek(double offset, Unit unit);
+	virtual double tell(Unit unit);
 	virtual double getDuration(Unit unit);
 	virtual void setPosition(float *v);
 	virtual void getPosition(float *v) const;

+ 1 - 1
src/modules/audio/wrap_Source.cpp

@@ -105,7 +105,7 @@ int w_Source_getVolume(lua_State *L)
 int w_Source_seek(lua_State *L)
 {
 	Source *t = luax_checksource(L, 1);
-	float offset = (float)luaL_checknumber(L, 2);
+	double offset = luaL_checknumber(L, 2);
 	if (offset < 0)
 		return luaL_argerror(L, 2, "can't seek to a negative position");
 

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

@@ -98,7 +98,7 @@ public:
 	 * @param s The position in the stream in seconds.
 	 * @return True if success, false on fail/unsupported.
 	 **/
-	virtual bool seek(float s) = 0;
+	virtual bool seek(double s) = 0;
 
 	/**
 	 * Rewinds the stream to the start.

+ 1 - 1
src/modules/sound/lullaby/CoreAudioDecoder.cpp

@@ -227,7 +227,7 @@ int CoreAudioDecoder::decode()
 	return size;
 }
 
-bool CoreAudioDecoder::seek(float s)
+bool CoreAudioDecoder::seek(double s)
 {
 	OSStatus err = ExtAudioFileSeek(extAudioFile, (SInt64) (s * inputInfo.mSampleRate));
 

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

@@ -54,7 +54,7 @@ public:
 
 	love::sound::Decoder *clone();
 	int decode();
-	bool seek(float s);
+	bool seek(double s);
 	bool rewind();
 	bool isSeekable();
 	int getChannelCount() const;

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

@@ -78,9 +78,9 @@ int FLACDecoder::decode()
 	return bufferSize;
 }
 
-bool FLACDecoder::seek(float s)
+bool FLACDecoder::seek(double s)
 {
-	return seek_absolute((int)(s*1000.0f));
+	return seek_absolute((int)(s*1000.0));
 }
 
 bool FLACDecoder::rewind()

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

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

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

@@ -109,9 +109,9 @@ int GmeDecoder::decode()
 	return bufferSize;
 }
 
-bool GmeDecoder::seek(float s)
+bool GmeDecoder::seek(double s)
 {
-	return gme_seek(emu, static_cast<long>(s * 1000.f)) != 0;
+	return gme_seek(emu, static_cast<long>(s * 1000.0)) != 0;
 }
 
 bool GmeDecoder::rewind()

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

@@ -51,7 +51,7 @@ public:
 
 	love::sound::Decoder *clone();
 	int decode();
-	bool seek(float s);
+	bool seek(double s);
 	bool rewind();
 	bool isSeekable();
 	int getChannelCount() const;

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

@@ -111,9 +111,9 @@ int ModPlugDecoder::decode()
 	return r;
 }
 
-bool ModPlugDecoder::seek(float s)
+bool ModPlugDecoder::seek(double s)
 {
-	ModPlug_Seek(plug, (int)(s*1000.0f));
+	ModPlug_Seek(plug, (int)(s*1000.0));
 	return true;
 }
 

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

@@ -54,7 +54,7 @@ public:
 
 	love::sound::Decoder *clone();
 	int decode();
-	bool seek(float s);
+	bool seek(double s);
 	bool rewind();
 	bool isSeekable();
 	int getChannelCount() const;

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

@@ -232,7 +232,7 @@ int Mpg123Decoder::decode()
 	return size;
 }
 
-bool Mpg123Decoder::seek(float s)
+bool Mpg123Decoder::seek(double s)
 {
 	off_t offset = (off_t) (s * (double) sampleRate);
 

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

@@ -66,7 +66,7 @@ public:
 
 	love::sound::Decoder *clone();
 	int decode();
-	bool seek(float s);
+	bool seek(double s);
 	bool rewind();
 	bool isSeekable();
 	int getChannelCount() const;

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

@@ -209,7 +209,7 @@ int VorbisDecoder::decode()
 	return size;
 }
 
-bool VorbisDecoder::seek(float s)
+bool VorbisDecoder::seek(double s)
 {
 	int result = 0;
 

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

@@ -57,7 +57,7 @@ public:
 
 	love::sound::Decoder *clone();
 	int decode();
-	bool seek(float s);
+	bool seek(double s);
 	bool rewind();
 	bool isSeekable();
 	int getChannelCount() const;

+ 1 - 1
src/modules/sound/lullaby/WaveDecoder.cpp

@@ -143,7 +143,7 @@ int WaveDecoder::decode()
 	return (int) size;
 }
 
-bool WaveDecoder::seek(float s)
+bool WaveDecoder::seek(double s)
 {
 	int wuff_status = wuff_seek(handle, (wuff_uint64) (s * info.sample_rate));
 

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

@@ -53,7 +53,7 @@ public:
 
 	love::sound::Decoder *clone();
 	int decode();
-	bool seek(float s);
+	bool seek(double s);
 	bool rewind();
 	bool isSeekable();
 	int getChannelCount() const;

+ 1 - 1
src/modules/sound/wrap_Decoder.cpp

@@ -96,7 +96,7 @@ int w_Decoder_decode(lua_State *L)
 int w_Decoder_seek(lua_State *L)
 {
 	Decoder *t = luax_checkdecoder(L, 1);
-	float offset = luaL_checknumber(L, 2);
+	double offset = luaL_checknumber(L, 2);
 	if (offset < 0)
 		return luaL_argerror(L, 2, "can't seek to a negative position");
 	else if (offset == 0)