Audio/Music: Fix Seek method
This commit is contained in:
parent
5bc3cd8d8c
commit
f0b26efcd3
|
|
@ -250,7 +250,7 @@ namespace Nz
|
|||
else
|
||||
{
|
||||
UInt64 readSample = drwav_read_pcm_frames_s16(&m_decoder, sampleCount / m_decoder.channels, static_cast<Int16*>(buffer));
|
||||
m_readSampleCount += readSample;
|
||||
m_readSampleCount += readSample * m_decoder.channels;
|
||||
|
||||
return readSample * m_decoder.channels;
|
||||
}
|
||||
|
|
@ -258,7 +258,7 @@ namespace Nz
|
|||
|
||||
void Seek(UInt64 offset) override
|
||||
{
|
||||
drwav_seek_to_pcm_frame(&m_decoder, offset);
|
||||
drwav_seek_to_pcm_frame(&m_decoder, (m_mixToMono) ? offset : offset / m_decoder.channels);
|
||||
m_readSampleCount = offset;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -338,8 +338,8 @@ namespace Nz
|
|||
|
||||
void Seek(UInt64 offset) override
|
||||
{
|
||||
if (m_mixToMono)
|
||||
offset *= m_channelCount;
|
||||
if (!m_mixToMono)
|
||||
offset /= m_channelCount;
|
||||
|
||||
ov_pcm_seek(&m_decoder, Int64(offset));
|
||||
}
|
||||
|
|
@ -347,8 +347,8 @@ namespace Nz
|
|||
UInt64 Tell() override
|
||||
{
|
||||
UInt64 offset = UInt64(ov_pcm_tell(&m_decoder));
|
||||
if (m_mixToMono)
|
||||
offset /= m_channelCount;
|
||||
if (!m_mixToMono)
|
||||
offset *= m_channelCount;
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace Nz
|
|||
std::mutex bufferLock;
|
||||
std::shared_ptr<SoundStream> stream;
|
||||
std::thread thread;
|
||||
UInt64 playingOffset;
|
||||
UInt64 streamOffset;
|
||||
bool loop = false;
|
||||
unsigned int sampleRate;
|
||||
};
|
||||
|
|
@ -342,8 +342,10 @@ namespace Nz
|
|||
if (isPlaying)
|
||||
Stop();
|
||||
|
||||
m_impl->playingOffset = offset;
|
||||
m_impl->processedSamples = UInt64(offset) * m_impl->sampleRate * GetChannelCount(m_impl->stream->GetFormat()) / 1000ULL;
|
||||
UInt64 sampleOffset = UInt64(offset) * m_impl->sampleRate * GetChannelCount(m_impl->stream->GetFormat()) / 1000ULL;
|
||||
|
||||
m_impl->processedSamples = sampleOffset;
|
||||
m_impl->streamOffset = sampleOffset;
|
||||
|
||||
if (isPlaying)
|
||||
Play();
|
||||
|
|
@ -371,7 +373,7 @@ namespace Nz
|
|||
{
|
||||
std::lock_guard<std::mutex> lock(m_impl->stream->GetMutex());
|
||||
|
||||
m_impl->stream->Seek(m_impl->playingOffset);
|
||||
m_impl->stream->Seek(m_impl->streamOffset);
|
||||
|
||||
// Fill the buffer by reading from the stream
|
||||
for (;;)
|
||||
|
|
@ -388,7 +390,7 @@ namespace Nz
|
|||
break;
|
||||
}
|
||||
|
||||
m_impl->playingOffset = m_impl->stream->Tell();
|
||||
m_impl->streamOffset = m_impl->stream->Tell();
|
||||
}
|
||||
|
||||
// Update the buffer (send it to OpenAL) and queue it if we got any data
|
||||
|
|
|
|||
Loading…
Reference in New Issue