From 7519da5e13ff72a43d05a8a1632d0becb33d457b Mon Sep 17 00:00:00 2001 From: Rene Stange Date: Mon, 21 Mar 2022 19:02:29 +0100 Subject: [PATCH] Fix Stereo channel swap with HDMI (#52) There has been a swap of the Stereo channels with HDMI. With the new option "ChannelsSwapped=0|1" in minidexed.ini one can swap the channels again, in case it is needed. --- src/config.cpp | 6 ++++++ src/config.h | 2 ++ src/minidexed.cpp | 17 +++++++++++++++-- src/minidexed.h | 1 + src/minidexed.ini | 1 + 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 0242548..d8ba0cf 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -44,6 +44,7 @@ void CConfig::Load (void) m_nChunkSize = m_Properties.GetNumber ("ChunkSize", m_SoundDevice == "hdmi" ? 384*6 : 1024); #endif m_nDACI2CAddress = m_Properties.GetNumber ("DACI2CAddress", 0); + m_bChannelsSwapped = m_Properties.GetNumber ("ChannelsSwapped", 0) != 0; m_nMIDIBaudRate = m_Properties.GetNumber ("MIDIBaudRate", 31250); @@ -85,6 +86,11 @@ unsigned CConfig::GetDACI2CAddress (void) const return m_nDACI2CAddress; } +bool CConfig::GetChannelsSwapped (void) const +{ + return m_bChannelsSwapped; +} + unsigned CConfig::GetMIDIBaudRate (void) const { return m_nMIDIBaudRate; diff --git a/src/config.h b/src/config.h index f94e62e..2b24ffc 100644 --- a/src/config.h +++ b/src/config.h @@ -67,6 +67,7 @@ public: unsigned GetSampleRate (void) const; unsigned GetChunkSize (void) const; unsigned GetDACI2CAddress (void) const; // 0 for auto probing + bool GetChannelsSwapped (void) const; // MIDI unsigned GetMIDIBaudRate (void) const; @@ -100,6 +101,7 @@ private: unsigned m_nSampleRate; unsigned m_nChunkSize; unsigned m_nDACI2CAddress; + bool m_bChannelsSwapped; unsigned m_nMIDIBaudRate; diff --git a/src/minidexed.cpp b/src/minidexed.cpp index df37609..a8284d1 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -41,6 +41,7 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt, m_SerialMIDI (this, pInterrupt, pConfig), m_bUseSerial (false), m_pSoundDevice (0), + m_bChannelsSwapped (pConfig->GetChannelsSwapped ()), #ifdef ARM_ALLOW_MULTI_CORE m_nActiveTGsLog2 (0), #endif @@ -83,6 +84,10 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt, m_pSoundDevice = new CHDMISoundBaseDevice (pInterrupt, pConfig->GetSampleRate (), pConfig->GetChunkSize ()); + + // The channels are swapped by default in the HDMI sound driver. + // TODO: Remove this line, when this has been fixed in the driver. + m_bChannelsSwapped = !m_bChannelsSwapped; } else { @@ -512,8 +517,16 @@ void CMiniDexed::ProcessSound (void) + m_OutputLevel[7][i] * m_nPan[7]; nRight >>= m_nActiveTGsLog2 + 7; - SampleBuffer[i][0] = (int16_t) nLeft; - SampleBuffer[i][1] = (int16_t) nRight; + if (!m_bChannelsSwapped) + { + SampleBuffer[i][0] = (int16_t) nLeft; + SampleBuffer[i][1] = (int16_t) nRight; + } + else + { + SampleBuffer[i][0] = (int16_t) nRight; + SampleBuffer[i][1] = (int16_t) nLeft; + } } if ( m_pSoundDevice->Write (SampleBuffer, sizeof SampleBuffer) diff --git a/src/minidexed.h b/src/minidexed.h index b592af7..daf9acb 100644 --- a/src/minidexed.h +++ b/src/minidexed.h @@ -103,6 +103,7 @@ private: bool m_bUseSerial; CSoundBaseDevice *m_pSoundDevice; + bool m_bChannelsSwapped; unsigned m_nQueueSizeFrames; #ifdef ARM_ALLOW_MULTI_CORE diff --git a/src/minidexed.ini b/src/minidexed.ini index 9b5b10e..cd2123a 100644 --- a/src/minidexed.ini +++ b/src/minidexed.ini @@ -7,6 +7,7 @@ SoundDevice=pwm SampleRate=48000 #ChunkSize=256 DACI2CAddress=0 +ChannelsSwapped=0 # MIDI MIDIBaudRate=31250