Skip to content

Commit

Permalink
try to detect how many audio channels
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiyaa committed Sep 11, 2022
1 parent 09a7a2c commit 184c5be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/client/ui/widgets/tui_footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,22 @@ impl<'a> Widget for TuiFooter<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let text = vec![Span::styled(
format!("Audio system: {}", self.player_state.audio_host),
Style::default().fg(Color::Green),
)];
Style::default().fg(Color::Green)),
Span::raw(" "),
Span::raw(format!("Channels: {}",
self.player_state.song.as_ref().map(|song| song.audio_metadata())
.and_then(|metadata| metadata.channels)
.map(|s| s.to_string())
.unwrap_or_else(|| "UNKNOWN".to_string()))),
Span::raw(" "),
Span::raw(format!("Sample Rate: {} Hz",
self.player_state.song.as_ref().map(|song| song.audio_metadata())
.and_then(|metadata| metadata.sample_rate)
.map(|s| s.to_string())
.unwrap_or_else(|| "UNKNOWN".to_string()))),
];



Paragraph::new(Spans::from(text)).render(area, buf);
}
Expand Down
17 changes: 16 additions & 1 deletion src/server/audio/symphonia/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::mpsc;
use std::thread::{self, JoinHandle};
use std::time::{Duration, SystemTime};

use log::{debug, log_enabled, Level};
use symphonia::core::codecs::{DecoderOptions, CODEC_TYPE_NULL};
use symphonia::core::formats::FormatOptions;
use symphonia::core::io::MediaSourceStream;
Expand Down Expand Up @@ -240,6 +241,10 @@ impl PlayerStream {
// Store the track identifier, it will be used to filter packets.
let track_id = track.id;

if log_enabled!(Level::Debug) {
debug!("track: {:#?}", track);
}

// Use the default options for the decoder.
let dec_opts: DecoderOptions = Default::default();

Expand All @@ -250,7 +255,13 @@ impl PlayerStream {
let config = self.device.default_output_config().unwrap();

let audio_config = cpal::StreamConfig {
channels: cpal::ChannelCount::from(2u16),
channels: cpal::ChannelCount::from(
track
.codec_params
.channels
.map(|c| c.count() as u16)
.unwrap_or(2u16),
),
sample_rate: cpal::SampleRate(
track
.codec_params
Expand All @@ -260,6 +271,10 @@ impl PlayerStream {
buffer_size: cpal::BufferSize::Default,
};

if log_enabled!(Level::Debug) {
debug!("audio_config: {:#?}", audio_config);
}

let stream_tx = self.event_poller.stream_tx.clone();

match config.sample_format() {
Expand Down

0 comments on commit 184c5be

Please sign in to comment.