Skip to content

Commit

Permalink
Fix Stereo channel swap with HDMI (#52)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rsta2 committed Mar 21, 2022
1 parent 9d81a69 commit 7519da5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CConfig // Configuration for MiniDexed
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;
Expand Down Expand Up @@ -100,6 +101,7 @@ class CConfig // Configuration for MiniDexed
unsigned m_nSampleRate;
unsigned m_nChunkSize;
unsigned m_nDACI2CAddress;
bool m_bChannelsSwapped;

unsigned m_nMIDIBaudRate;

Expand Down
17 changes: 15 additions & 2 deletions src/minidexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/minidexed.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class CMiniDexed
bool m_bUseSerial;

CSoundBaseDevice *m_pSoundDevice;
bool m_bChannelsSwapped;
unsigned m_nQueueSizeFrames;

#ifdef ARM_ALLOW_MULTI_CORE
Expand Down
1 change: 1 addition & 0 deletions src/minidexed.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SoundDevice=pwm
SampleRate=48000
#ChunkSize=256
DACI2CAddress=0
ChannelsSwapped=0

# MIDI
MIDIBaudRate=31250
Expand Down

0 comments on commit 7519da5

Please sign in to comment.