mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-04 00:36:36 +00:00
Add 7.1 surround sound support to libsoundio audio renderer
This commit is contained in:
parent
524e92c81a
commit
ea62e33e51
@ -72,11 +72,17 @@ int SoundIoAudioRenderer::scoreChannelLayout(const struct SoundIoChannelLayout*
|
|||||||
score++;
|
score++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Score layouts using the back L/R as higher
|
|
||||||
// value than those using side L/R.
|
|
||||||
case SoundIoChannelIdBackLeft:
|
case SoundIoChannelIdBackLeft:
|
||||||
case SoundIoChannelIdBackRight:
|
case SoundIoChannelIdBackRight:
|
||||||
|
if (opusConfig->channelCount == 6) {
|
||||||
|
// Score back channels higher in 5.1 mode to
|
||||||
|
// discourage selection of side channel layouts.
|
||||||
score += 2;
|
score += 2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Score back channels normally for 7.1 mode
|
||||||
|
score++;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -211,7 +217,8 @@ bool SoundIoAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATI
|
|||||||
|
|
||||||
m_EffectiveLayout = m_OutputStream->layout;
|
m_EffectiveLayout = m_OutputStream->layout;
|
||||||
for (int i = 0; i < m_EffectiveLayout.channel_count; i++) {
|
for (int i = 0; i < m_EffectiveLayout.channel_count; i++) {
|
||||||
// Fixup the layout to use back L/R so our channel position
|
if (opusConfig->channelCount == 6) {
|
||||||
|
// For 5.1, replace side L/R with back L/R so our channel position
|
||||||
// logic in sioWriteCallback() works.
|
// logic in sioWriteCallback() works.
|
||||||
if (m_EffectiveLayout.channels[i] == SoundIoChannelIdSideLeft) {
|
if (m_EffectiveLayout.channels[i] == SoundIoChannelIdSideLeft) {
|
||||||
m_EffectiveLayout.channels[i] = SoundIoChannelIdBackLeft;
|
m_EffectiveLayout.channels[i] = SoundIoChannelIdBackLeft;
|
||||||
@ -220,6 +227,17 @@ bool SoundIoAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATI
|
|||||||
m_EffectiveLayout.channels[i] = SoundIoChannelIdBackRight;
|
m_EffectiveLayout.channels[i] = SoundIoChannelIdBackRight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (opusConfig->channelCount == 8) {
|
||||||
|
// For 5.1, replace side L/R with LOC/ROC so our channel position
|
||||||
|
// logic in sioWriteCallback() works.
|
||||||
|
if (m_EffectiveLayout.channels[i] == SoundIoChannelIdSideLeft) {
|
||||||
|
m_EffectiveLayout.channels[i] = SoundIoChannelIdFrontLeftCenter;
|
||||||
|
}
|
||||||
|
if (m_EffectiveLayout.channels[i] == SoundIoChannelIdSideRight) {
|
||||||
|
m_EffectiveLayout.channels[i] = SoundIoChannelIdFrontRightCenter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int packetsToBuffer;
|
int packetsToBuffer;
|
||||||
|
|
||||||
@ -411,9 +429,8 @@ void SoundIoAudioRenderer::sioWriteCallback(SoundIoOutStream* stream, int frameC
|
|||||||
|
|
||||||
for (int frame = 0; frame < frameCount; frame++) {
|
for (int frame = 0; frame < frameCount; frame++) {
|
||||||
for (int ch = 0; ch < me->m_EffectiveLayout.channel_count; ch++) {
|
for (int ch = 0; ch < me->m_EffectiveLayout.channel_count; ch++) {
|
||||||
// SoundIoChannelId - 1 happens to match Moonlight's channel layout.
|
// SoundIoChannelId - 1 happens to match Moonlight's channel layout
|
||||||
// For side L/R, this logic depends on us fixing those up
|
// after we've applied our fixups to m_EffectiveLayout for 5.1 and 7.1.
|
||||||
// in m_EffectiveLayout to back L/R.
|
|
||||||
int readPtrChannel = me->m_EffectiveLayout.channels[ch] - 1;
|
int readPtrChannel = me->m_EffectiveLayout.channels[ch] - 1;
|
||||||
|
|
||||||
if (frame >= framesLeft || readPtrChannel >= me->m_OpusChannelCount) {
|
if (frame >= framesLeft || readPtrChannel >= me->m_OpusChannelCount) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user