mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Added Volume in a fishy manner by modulating stream, could maybe be optimized.
This commit is contained in:
parent
3c8d709ff1
commit
17a5bb122a
3 changed files with 23 additions and 2 deletions
|
@ -24,6 +24,7 @@ fn usage(program: &str, opts: &Options) -> String {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
println!("{:?}",i16::max_value());
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let program = args[0].clone();
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ pub struct PlayerState {
|
|||
position_ms: u32,
|
||||
position_measured_at: i64,
|
||||
update_time: i64,
|
||||
volume:u16,
|
||||
|
||||
end_of_track: bool,
|
||||
}
|
||||
|
@ -35,6 +36,7 @@ enum PlayerCommand {
|
|||
Load(SpotifyId, bool, u32),
|
||||
Play,
|
||||
Pause,
|
||||
Volume(u16),
|
||||
Stop,
|
||||
Seek(u32),
|
||||
}
|
||||
|
@ -48,6 +50,7 @@ impl Player {
|
|||
position_ms: 0,
|
||||
position_measured_at: 0,
|
||||
update_time: util::now_ms(),
|
||||
volume: 5000,
|
||||
end_of_track: false,
|
||||
}),
|
||||
Condvar::new()));
|
||||
|
@ -181,6 +184,12 @@ impl PlayerInternal {
|
|||
|
||||
stream.stop().unwrap();
|
||||
}
|
||||
Some(PlayerCommand::Volume(vol)) =>{
|
||||
self.update(|state| {
|
||||
state.volume = vol;
|
||||
true
|
||||
});
|
||||
}
|
||||
Some(PlayerCommand::Stop) => {
|
||||
self.update(|state| {
|
||||
if state.status == PlayStatus::kPlayStatusPlay {
|
||||
|
@ -198,7 +207,8 @@ impl PlayerInternal {
|
|||
if self.state.0.lock().unwrap().status == PlayStatus::kPlayStatusPlay {
|
||||
match decoder.as_mut().unwrap().packets().next() {
|
||||
Some(Ok(packet)) => {
|
||||
match stream.write(&packet.data) {
|
||||
let buffer = packet.data.iter().map(|x| x/100*(self.state.0.lock().unwrap().volume/655) as i16).collect::<Vec<i16>>();
|
||||
match stream.write(&buffer) {
|
||||
Ok(_) => (),
|
||||
Err(portaudio::PaError::OutputUnderflowed) => eprintln!("Underflow"),
|
||||
Err(e) => panic!("PA Error {}", e),
|
||||
|
@ -278,6 +288,10 @@ impl SpircDelegate for Player {
|
|||
self.state.0.lock().unwrap()
|
||||
}
|
||||
|
||||
fn volume(&self, vol:u16){
|
||||
self.command(PlayerCommand::Volume(vol));
|
||||
}
|
||||
|
||||
fn updates(&self) -> mpsc::Receiver<i64> {
|
||||
let state = self.state.clone();
|
||||
let (update_tx, update_rx) = mpsc::channel();
|
||||
|
|
|
@ -44,6 +44,7 @@ pub trait SpircDelegate {
|
|||
fn play(&self);
|
||||
fn pause(&self);
|
||||
fn seek(&self, position_ms: u32);
|
||||
fn volume(&self, vol:u16);
|
||||
fn stop(&self);
|
||||
|
||||
fn state(&self) -> MutexGuard<Self::State>;
|
||||
|
@ -77,7 +78,7 @@ impl<D: SpircDelegate> SpircManager<D> {
|
|||
|
||||
repeat: false,
|
||||
shuffle: false,
|
||||
volume: 0x8000,
|
||||
volume: 32767,
|
||||
|
||||
is_active: false,
|
||||
became_active_at: 0,
|
||||
|
@ -190,6 +191,11 @@ impl<D: SpircDelegate> SpircManager<D> {
|
|||
self.delegate.stop();
|
||||
}
|
||||
}
|
||||
protocol::spirc::MessageType::kMessageTypeVolume =>{
|
||||
println!("{:?}",frame.get_volume());
|
||||
self.volume=frame.get_volume() as u16;
|
||||
self.delegate.volume(self.volume);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue