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.

This commit is contained in:
Alex Szpakowski
2019-05-26 14:46:52 -03:00
parent 3c77edb68b
commit 38cb56f168
22 changed files with 39 additions and 37 deletions
+11 -9
View File
@@ -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
View File
@@ -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;