mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-18 06:30:55 +00:00
Fix surround sound channel mapping on ALSA
This commit is contained in:
@@ -194,6 +194,42 @@ int PortAudioRenderer::detectAudioConfiguration() const
|
||||
}
|
||||
}
|
||||
|
||||
void PortAudioRenderer::adjustOpusChannelMapping(OPUS_MULTISTREAM_CONFIGURATION* opusConfig) const
|
||||
{
|
||||
const OPUS_MULTISTREAM_CONFIGURATION origConfig = *opusConfig;
|
||||
|
||||
const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice());
|
||||
if (deviceInfo == nullptr) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Pa_GetDeviceInfo() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
const PaHostApiInfo* hostApiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
|
||||
if (hostApiInfo == nullptr) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Pa_GetHostApiInfo() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"PortAudio host API: %s",
|
||||
hostApiInfo->name);
|
||||
|
||||
if (hostApiInfo->type == paALSA) {
|
||||
// The default mapping array has is: FL-FR-C-LFE-RL-RR
|
||||
// ALSA expects: FL-FR-RL-RR-C-LFE
|
||||
opusConfig->mapping[0] = origConfig.mapping[0];
|
||||
opusConfig->mapping[1] = origConfig.mapping[1];
|
||||
if (opusConfig->channelCount == 6) {
|
||||
opusConfig->mapping[2] = origConfig.mapping[4];
|
||||
opusConfig->mapping[3] = origConfig.mapping[5];
|
||||
opusConfig->mapping[4] = origConfig.mapping[2];
|
||||
opusConfig->mapping[5] = origConfig.mapping[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int PortAudioRenderer::paStreamCallback(const void*, void* output, unsigned long frameCount, const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags, void* userData)
|
||||
{
|
||||
auto me = reinterpret_cast<PortAudioRenderer*>(userData);
|
||||
|
||||
@@ -24,6 +24,8 @@ public:
|
||||
|
||||
virtual int detectAudioConfiguration() const;
|
||||
|
||||
virtual void adjustOpusChannelMapping(OPUS_MULTISTREAM_CONFIGURATION* opusConfig) const;
|
||||
|
||||
static int paStreamCallback(const void *input,
|
||||
void *output,
|
||||
unsigned long frameCount,
|
||||
|
||||
@@ -10,6 +10,8 @@ class IAudioRenderer
|
||||
public:
|
||||
virtual ~IAudioRenderer() {}
|
||||
|
||||
virtual void adjustOpusChannelMapping(OPUS_MULTISTREAM_CONFIGURATION* opusConfig) const = 0;
|
||||
|
||||
virtual bool prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* opusConfig) = 0;
|
||||
|
||||
virtual void submitAudio(short* audioBuffer, int audioSize) = 0;
|
||||
|
||||
@@ -23,6 +23,8 @@ public:
|
||||
|
||||
virtual int detectAudioConfiguration() const;
|
||||
|
||||
virtual void adjustOpusChannelMapping(OPUS_MULTISTREAM_CONFIGURATION* opusConfig) const;
|
||||
|
||||
private:
|
||||
SDL_AudioDeviceID m_AudioDevice;
|
||||
Uint32 m_ChannelCount;
|
||||
|
||||
@@ -51,6 +51,11 @@ int SdlAudioRenderer::detectAudioConfiguration() const
|
||||
}
|
||||
}
|
||||
|
||||
void SdlAudioRenderer::adjustOpusChannelMapping(OPUS_MULTISTREAM_CONFIGURATION*) const
|
||||
{
|
||||
// The default mapping is fine for SDL
|
||||
}
|
||||
|
||||
bool SdlAudioRenderer::testAudio(int audioConfiguration) const
|
||||
{
|
||||
SDL_AudioSpec want, have;
|
||||
|
||||
Reference in New Issue
Block a user