Add ability to reverse global stereo output

Closes #307.
This commit is contained in:
Dale Whinham committed 2022-12-01 14:26:38 +00:00
1 parent 3202586c61
commit b0db927221
4 files changed
+27

No files matched your search

+4
View File
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Ability to reverse global left and right audio channels (new configuration file option) to work around broken hardware (issue #307).
### Changed
- Update to libmt32emu v2.7.0.
+1
View File
@@ -53,6 +53,7 @@ BEGIN_SECTION(audio)
CFG(output_device, TAudioOutputDevice, AudioOutputDevice, TAudioOutputDevice::PWM )
CFG(sample_rate, int, AudioSampleRate, 48000 )
CFG(chunk_size, int, AudioChunkSize, 256 )
CFG(reversed_stereo, bool, AudioReversedStereo, false )
END_SECTION
BEGIN_SECTION(control)
+7
View File
@@ -147,6 +147,13 @@ sample_rate = 48000
# Values: 2-2048 (256*)
chunk_size = 256
# Set whether the stereo channels should be swapped or not.
#
# Use this option to work around wrongly-wired audio hardware.
#
# Values: on, off*
reversed_stereo = off
# -----------------------------------------------------------------------------
# Control options
# -----------------------------------------------------------------------------
+15
View File
@@ -562,6 +562,7 @@ void CMT32Pi::AudioTask()
// Circle's "fast path" for I2S 24-bit really expects 32-bit samples
const bool bI2S = m_pConfig->AudioOutputDevice == CConfig::TAudioOutputDevice::I2S;
const bool bReversedStereo = m_pConfig->AudioReversedStereo;
const u8 nBytesPerSample = bI2S ? sizeof(s32) : (sizeof(s8) * 3);
const u8 nBytesPerFrame = 2 * nBytesPerSample;
@@ -578,12 +579,26 @@ void CMT32Pi::AudioTask()
m_pCurrentSynth->Render(FloatBuffer, nFrames);
if (bReversedStereo)
{
// Convert to signed 24-bit integers with channel swap
for (size_t i = 0; i < nFrames * nChannels; i += nChannels)
{
s32* const pLeftSample = reinterpret_cast<s32*>(IntBuffer + i * nBytesPerSample);
s32* const pRightSample = reinterpret_cast<s32*>(IntBuffer + (i + 1) * nBytesPerSample);
*pLeftSample = FloatBuffer[i + 1] * Sample24BitMax;
*pRightSample = FloatBuffer[i] * Sample24BitMax;
}
}
else
{
// Convert to signed 24-bit integers
for (size_t i = 0; i < nFrames * nChannels; ++i)
{
s32* const pSample = reinterpret_cast<s32*>(IntBuffer + i * nBytesPerSample);
*pSample = FloatBuffer[i] * Sample24BitMax;
}
}
const int nResult = m_pSound->Write(IntBuffer, nWriteBytes);
if (nResult != static_cast<int>(nWriteBytes))