Skip to content

Commit

Permalink
dosbox generateSamples improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Nov 12, 2023
1 parent a133242 commit f4371e8
Showing 1 changed file with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,37 +214,42 @@ namespace HyperSonicDrivers::hardware::opl::scummvm::dosbox

if(isStereo())
{
while (length_ > 0)
if (m_emulator->opl3Active) // DUAL_OPL2 or OPL3 in OPL3 mode
{
const unsigned int readSamples = std::min<unsigned int>(length_, bufferLength);
const unsigned int readSamples2 = (readSamples << 1);
if (m_emulator->opl3Active)
while (length_ > 0)
{
const unsigned int readSamples = std::min<unsigned int>(length_, bufferLength);
const unsigned int readSamples2 = (readSamples << 1);
m_emulator->GenerateBlock3(readSamples, tempBuffer.data());
for (unsigned int i = 0; i < readSamples2; ++i)
buffer[i] = static_cast<int16_t>(tempBuffer[i]);

buffer += static_cast<int16_t>(readSamples2);
length_ -= readSamples;
}
else
}
else // OPL3 in OPL2 compatibility mode
{
while (length_ > 0)
{
const unsigned int readSamples = std::min<unsigned int>(length_, bufferLength);
const unsigned int readSamples2 = (readSamples << 1);
m_emulator->GenerateBlock2(readSamples, tempBuffer.data());
for (unsigned int i = 0, j =0; i < readSamples; ++i, j+=2)
{
buffer[j] = buffer[j+1] = static_cast<int16_t>(tempBuffer[i]);
}
}
for (unsigned int i = 0, j = 0; i < readSamples; ++i, j += 2)
buffer[j] = buffer[j + 1] = static_cast<int16_t>(tempBuffer[i]);

buffer += static_cast<int16_t>(readSamples2);
length_ -= readSamples;

buffer += static_cast<int16_t>(readSamples2);
length_ -= readSamples;
}
}
}
else
else // OPL2
{
while (length_ > 0)
{
const unsigned int readSamples = std::min<unsigned int>(length_, bufferLength << 1);

m_emulator->GenerateBlock2(readSamples, tempBuffer.data());

for (unsigned int i = 0; i < readSamples; ++i)
buffer[i] = static_cast<int16_t>(tempBuffer[i]);

Expand Down

0 comments on commit f4371e8

Please sign in to comment.