Skip to content

Commit 998e97f

Browse files
fix(pipewire): recognize FLC, FRC and RC channel positions
Signed-off-by: Maika Namuo <httpworldview@gmail.com>
1 parent 837a924 commit 998e97f

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

‎src/dsp.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ pub enum ChannelPosition {
1515
RearRight,
1616
SideLeft,
1717
SideRight,
18+
FrontLeftCenter,
19+
FrontRightCenter,
20+
RearCenter,
1821
Mono,
1922
Aux(u8),
2023
#[default]
@@ -137,9 +140,9 @@ fn stereo_matrix(
137140
let mut matrix = [[0.0; 2]; MAX_AUDIO_CHANNELS];
138141
for (weights, position) in matrix.iter_mut().zip(positions).take(channels) {
139142
*weights = match position {
140-
ChannelPosition::FrontLeft => [1.0, 0.0],
141-
ChannelPosition::FrontRight => [0.0, 1.0],
142-
ChannelPosition::FrontCenter => [surround; 2],
143+
ChannelPosition::FrontLeft | ChannelPosition::FrontLeftCenter => [1.0, 0.0],
144+
ChannelPosition::FrontRight | ChannelPosition::FrontRightCenter => [0.0, 1.0],
145+
ChannelPosition::FrontCenter | ChannelPosition::RearCenter => [surround; 2],
143146
ChannelPosition::RearLeft | ChannelPosition::SideLeft => [surround, 0.0],
144147
ChannelPosition::RearRight | ChannelPosition::SideRight => [0.0, surround],
145148
ChannelPosition::Mono => [1.0; 2],

‎src/infra/pipewire/graph.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ channel_positions! {
6363
"RR" => RearRight => pw::spa::sys::SPA_AUDIO_CHANNEL_RR,
6464
"SL" => SideLeft => pw::spa::sys::SPA_AUDIO_CHANNEL_SL,
6565
"SR" => SideRight => pw::spa::sys::SPA_AUDIO_CHANNEL_SR,
66+
"FLC" => FrontLeftCenter => pw::spa::sys::SPA_AUDIO_CHANNEL_FLC,
67+
"FRC" => FrontRightCenter => pw::spa::sys::SPA_AUDIO_CHANNEL_FRC,
68+
"RC" => RearCenter => pw::spa::sys::SPA_AUDIO_CHANNEL_RC,
6669
"MONO" => Mono => pw::spa::sys::SPA_AUDIO_CHANNEL_MONO,
6770
}
6871

‎src/infra/pipewire/policy.rs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,12 @@ pub(super) fn desired_links(graph: &Graph, plan: &Plan, tap: &Node) -> Vec<LinkS
172172
}
173173
Channel::resolve_surrounds(&mut positions);
174174
for (output, channel) in ports.into_iter().zip(positions) {
175+
// The tap's 7.1 layout lacks these, so fold them into its nearest speakers.
175176
let remixed = match channel {
176177
Channel::Mono => [Some(Channel::FrontLeft), Some(Channel::FrontRight)],
178+
Channel::RearCenter => [Some(Channel::RearLeft), Some(Channel::RearRight)],
179+
Channel::FrontLeftCenter => [Some(Channel::FrontLeft), None],
180+
Channel::FrontRightCenter => [Some(Channel::FrontRight), None],
177181
channel => [Some(channel), None],
178182
};
179183
for target in remixed.into_iter().flatten().filter_map(target_for) {
@@ -201,8 +205,9 @@ mod tests {
201205
use super::*;
202206
use crate::domain::routing::StreamIdentity;
203207
use crate::dsp::ChannelPosition::{
204-
Aux, FrontCenter as FC, FrontLeft as FL, FrontRight as FR, LowFrequency as LFE,
205-
RearLeft as RL, RearRight as RR, SideLeft as SL, SideRight as SR, Unknown,
208+
Aux, FrontCenter as FC, FrontLeft as FL, FrontLeftCenter as FLC, FrontRight as FR,
209+
FrontRightCenter as FRC, LowFrequency as LFE, RearLeft as RL, RearRight as RR,
210+
SideLeft as SL, SideRight as SR, Unknown,
206211
};
207212
use pipewire::spa::utils::Direction;
208213

@@ -241,6 +246,10 @@ mod tests {
241246
],
242247
&[0, 1, 2, 3, 4, 5, 6, 7],
243248
),
249+
(
250+
&[FL, FR, FC, LFE, SL, SR, FLC, FRC],
251+
&[0, 1, 2, 3, 6, 7, 0, 1],
252+
),
244253
(&[Unknown; 6], &[0, 1, 2, 3, 6, 7]),
245254
(&[Unknown; 8], &[0, 1, 2, 3, 4, 5, 6, 7]),
246255
(

‎src/visuals/loudness/state.rs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,14 @@ fn channel_side(
237237
position
238238
};
239239
match position {
240-
ChannelPosition::FrontLeft | ChannelPosition::RearLeft | ChannelPosition::SideLeft => {
241-
MeterSide::Left
242-
}
243-
ChannelPosition::FrontRight | ChannelPosition::RearRight | ChannelPosition::SideRight => {
244-
MeterSide::Right
245-
}
240+
ChannelPosition::FrontLeft
241+
| ChannelPosition::FrontLeftCenter
242+
| ChannelPosition::RearLeft
243+
| ChannelPosition::SideLeft => MeterSide::Left,
244+
ChannelPosition::FrontRight
245+
| ChannelPosition::FrontRightCenter
246+
| ChannelPosition::RearRight
247+
| ChannelPosition::SideRight => MeterSide::Right,
246248
_ => MeterSide::Both,
247249
}
248250
}

0 commit comments

Comments
 (0)