mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Fixed the multiple volume vars and the calculation is a bit simplified.
This commit is contained in:
parent
5788da8ddc
commit
4310162b88
2 changed files with 13 additions and 12 deletions
|
@ -21,7 +21,7 @@ pub struct PlayerState {
|
||||||
position_ms: u32,
|
position_ms: u32,
|
||||||
position_measured_at: i64,
|
position_measured_at: i64,
|
||||||
update_time: i64,
|
update_time: i64,
|
||||||
volume:u16,
|
volume:i32,
|
||||||
|
|
||||||
end_of_track: bool,
|
end_of_track: bool,
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ enum PlayerCommand {
|
||||||
Load(SpotifyId, bool, u32),
|
Load(SpotifyId, bool, u32),
|
||||||
Play,
|
Play,
|
||||||
Pause,
|
Pause,
|
||||||
Volume(u16),
|
Volume(i32),
|
||||||
Stop,
|
Stop,
|
||||||
Seek(u32),
|
Seek(u32),
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ impl Player {
|
||||||
position_ms: 0,
|
position_ms: 0,
|
||||||
position_measured_at: 0,
|
position_measured_at: 0,
|
||||||
update_time: util::now_ms(),
|
update_time: util::now_ms(),
|
||||||
volume: 5000,
|
volume: 0x8000,
|
||||||
end_of_track: false,
|
end_of_track: false,
|
||||||
}),
|
}),
|
||||||
Condvar::new()));
|
Condvar::new()));
|
||||||
|
@ -207,7 +207,7 @@ impl PlayerInternal {
|
||||||
if self.state.0.lock().unwrap().status == PlayStatus::kPlayStatusPlay {
|
if self.state.0.lock().unwrap().status == PlayStatus::kPlayStatusPlay {
|
||||||
match decoder.as_mut().unwrap().packets().next() {
|
match decoder.as_mut().unwrap().packets().next() {
|
||||||
Some(Ok(packet)) => {
|
Some(Ok(packet)) => {
|
||||||
let buffer = packet.data.iter().map(|x| x/100*(self.state.0.lock().unwrap().volume/655) as i16).collect::<Vec<i16>>();
|
let buffer = packet.data.iter().map(|&x| ((x as i32*self.state.0.lock().unwrap().volume)/0xFFFF) as i16).collect::<Vec<i16>>();
|
||||||
match stream.write(&buffer) {
|
match stream.write(&buffer) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(portaudio::PaError::OutputUnderflowed) => eprintln!("Underflow"),
|
Err(portaudio::PaError::OutputUnderflowed) => eprintln!("Underflow"),
|
||||||
|
@ -288,7 +288,7 @@ impl SpircDelegate for Player {
|
||||||
self.state.0.lock().unwrap()
|
self.state.0.lock().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn volume(&self, vol:u16){
|
fn volume(&self, vol:i32){
|
||||||
self.command(PlayerCommand::Volume(vol));
|
self.command(PlayerCommand::Volume(vol));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,6 +322,10 @@ impl SpircState for PlayerState {
|
||||||
(self.position_ms, self.position_measured_at)
|
(self.position_ms, self.position_measured_at)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn volume(&self) -> u32{
|
||||||
|
self.volume as u32
|
||||||
|
}
|
||||||
|
|
||||||
fn update_time(&self) -> i64 {
|
fn update_time(&self) -> i64 {
|
||||||
self.update_time
|
self.update_time
|
||||||
}
|
}
|
||||||
|
|
11
src/spirc.rs
11
src/spirc.rs
|
@ -25,7 +25,6 @@ pub struct SpircManager<D: SpircDelegate> {
|
||||||
|
|
||||||
repeat: bool,
|
repeat: bool,
|
||||||
shuffle: bool,
|
shuffle: bool,
|
||||||
volume: u16,
|
|
||||||
|
|
||||||
is_active: bool,
|
is_active: bool,
|
||||||
became_active_at: i64,
|
became_active_at: i64,
|
||||||
|
@ -44,7 +43,7 @@ pub trait SpircDelegate {
|
||||||
fn play(&self);
|
fn play(&self);
|
||||||
fn pause(&self);
|
fn pause(&self);
|
||||||
fn seek(&self, position_ms: u32);
|
fn seek(&self, position_ms: u32);
|
||||||
fn volume(&self, vol:u16);
|
fn volume(&self, vol:i32);
|
||||||
fn stop(&self);
|
fn stop(&self);
|
||||||
|
|
||||||
fn state(&self) -> MutexGuard<Self::State>;
|
fn state(&self) -> MutexGuard<Self::State>;
|
||||||
|
@ -56,6 +55,7 @@ pub trait SpircState {
|
||||||
fn position(&self) -> (u32, i64);
|
fn position(&self) -> (u32, i64);
|
||||||
fn update_time(&self) -> i64;
|
fn update_time(&self) -> i64;
|
||||||
fn end_of_track(&self) -> bool;
|
fn end_of_track(&self) -> bool;
|
||||||
|
fn volume(&self) -> u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: SpircDelegate> SpircManager<D> {
|
impl<D: SpircDelegate> SpircManager<D> {
|
||||||
|
@ -78,7 +78,6 @@ impl<D: SpircDelegate> SpircManager<D> {
|
||||||
|
|
||||||
repeat: false,
|
repeat: false,
|
||||||
shuffle: false,
|
shuffle: false,
|
||||||
volume: 32767,
|
|
||||||
|
|
||||||
is_active: false,
|
is_active: false,
|
||||||
became_active_at: 0,
|
became_active_at: 0,
|
||||||
|
@ -192,9 +191,7 @@ impl<D: SpircDelegate> SpircManager<D> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protocol::spirc::MessageType::kMessageTypeVolume =>{
|
protocol::spirc::MessageType::kMessageTypeVolume =>{
|
||||||
println!("{:?}",frame.get_volume());
|
self.delegate.volume(frame.get_volume() as i32);
|
||||||
self.volume=frame.get_volume() as u16;
|
|
||||||
self.delegate.volume(self.volume);
|
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
@ -266,7 +263,7 @@ impl<D: SpircDelegate> SpircManager<D> {
|
||||||
sw_version: version_string(),
|
sw_version: version_string(),
|
||||||
is_active: self.is_active,
|
is_active: self.is_active,
|
||||||
can_play: self.can_play,
|
can_play: self.can_play,
|
||||||
volume: self.volume as u32,
|
volume: self.delegate.state().volume(),
|
||||||
name: self.name.clone(),
|
name: self.name.clone(),
|
||||||
error_code: 0,
|
error_code: 0,
|
||||||
became_active_at: if self.is_active { self.became_active_at as i64 } else { 0 },
|
became_active_at: if self.is_active { self.became_active_at as i64 } else { 0 },
|
||||||
|
|
Loading…
Reference in a new issue